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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tokentrap-1.0.1.tar.gz.
File metadata
- Download URL: tokentrap-1.0.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7a7d529dced3638feaf00164b062603cdcac00202e716353692b0d3bdfe293f
|
|
| MD5 |
6e127997fb2960f637edff983cb6a0a5
|
|
| BLAKE2b-256 |
2f3f29b58b135f2a115a3f1033f0a395ee7747f0e5faa38f32466f3efc85c9de
|
Provenance
The following attestation bundles were made for tokentrap-1.0.1.tar.gz:
Publisher:
publish.yml on kineticquant/TokenTrap
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tokentrap-1.0.1.tar.gz -
Subject digest:
d7a7d529dced3638feaf00164b062603cdcac00202e716353692b0d3bdfe293f - Sigstore transparency entry: 2581707910
- Sigstore integration time:
-
Permalink:
kineticquant/TokenTrap@8843cb2d53f8efdd62e07892f83a02853bc66942 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/kineticquant
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8843cb2d53f8efdd62e07892f83a02853bc66942 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tokentrap-1.0.1-py3-none-any.whl.
File metadata
- Download URL: tokentrap-1.0.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9b336a1b07c479a075d573048d1fdb9ae59a7b884ecf0ec1bca0f888d1a8976
|
|
| MD5 |
95b2e9342fc8679273f88fa21ba8d5a4
|
|
| BLAKE2b-256 |
7f73c20c57318373e1b54e7ad910e0a03d0d0148a91e8f7d3f31b6706d733ce4
|
Provenance
The following attestation bundles were made for tokentrap-1.0.1-py3-none-any.whl:
Publisher:
publish.yml on kineticquant/TokenTrap
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tokentrap-1.0.1-py3-none-any.whl -
Subject digest:
f9b336a1b07c479a075d573048d1fdb9ae59a7b884ecf0ec1bca0f888d1a8976 - Sigstore transparency entry: 2581707919
- Sigstore integration time:
-
Permalink:
kineticquant/TokenTrap@8843cb2d53f8efdd62e07892f83a02853bc66942 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/kineticquant
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8843cb2d53f8efdd62e07892f83a02853bc66942 -
Trigger Event:
push
-
Statement type: