Skip to main content

token-trap (Python backend)

Level-2 TokenTrap backend: full FastAPI service with persistent sessions, structured logging, canary tokens, an OpenAI-compatible bait endpoint, and a one-command CLI.

Install

pip install "tokentrap"            # published package
# or from this monorepo:
pip install -e "packages/backend-python[test]"

60-second start

token-trap serve --port 8787 --strength aggressive --canary-tokens audit-777
# then point the widget at it:
#   TokenTrap.init({ apiEndpoint: "http://127.0.0.1:8787", ... })

Environment variables (all optional): TOKENTRAP_PERSONA, TOKENTRAP_STRENGTH, TOKENTRAP_CANARY_TOKENS, TOKENTRAP_EXTRA_KEYWORDS, TOKENTRAP_RATE_LIMIT, TOKENTRAP_LOG_WEBHOOK, TOKENTRAP_LLM_MODEL.

Endpoints

Route Purpose
POST /api/chat Widget protocol ({sessionId?, message} -> {reply, turn, meta})
POST /v1/chat/completions OpenAI-compatible bait for agents scanning for exposed API endpoints
GET /api/healthz Liveness

/v1/chat/completions is fully stateless: the turn index is derived from the replayed message list, so agents that grow their transcript each iteration walk straight up the escalation ladder.

Embed in an existing FastAPI app

from fastapi import FastAPI
from token_trap import create_app, TrapConfig

app = FastAPI()
app.mount("/trap", create_app(TrapConfig(strength="maximum")))

Optional real-LLM dressing

With pip install "tokentrap[llm]", set llm_model / --llm-model and turn-0 messages get answered by a real model before the trap engages. Failures fall back to the static engagement payload.

Tests

pytest

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tokentrap-1.0.2.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tokentrap-1.0.2-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file tokentrap-1.0.2.tar.gz.

File metadata

  • Download URL: tokentrap-1.0.2.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tokentrap-1.0.2.tar.gz
Algorithm Hash digest
SHA256 62c4aa3249bb95ad84c3aead4b9398f5c02cba1a5c97a25533fb41c8ad65be21
MD5 2ba2c92477451d2473955711118c9c7c
BLAKE2b-256 928741a3fe4c571b2745caff255dfa7130f375e4c3fa9addb89ddb7ff3140c52

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokentrap-1.0.2.tar.gz:

Publisher: publish.yml on kineticquant/TokenTrap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tokentrap-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: tokentrap-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tokentrap-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 490dc6360ce0d4c32d1faa3d66459842601eef8ddf5fdd9dc4f0ffdc7e8ea153
MD5 85242f0079bbc2f0dc007a88b86b8edc
BLAKE2b-256 66fa7c4cffa5e6c4c020d063baa8d16818454e09398653a5c95877249ee281ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokentrap-1.0.2-py3-none-any.whl:

Publisher: publish.yml on kineticquant/TokenTrap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.0.3

2 files

This release

1.0.2 This release

2 files

1.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page