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.1.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.1-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

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

Hashes for tokentrap-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d7a7d529dced3638feaf00164b062603cdcac00202e716353692b0d3bdfe293f
MD5 6e127997fb2960f637edff983cb6a0a5
BLAKE2b-256 2f3f29b58b135f2a115a3f1033f0a395ee7747f0e5faa38f32466f3efc85c9de

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokentrap-1.0.1.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.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

Hashes for tokentrap-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f9b336a1b07c479a075d573048d1fdb9ae59a7b884ecf0ec1bca0f888d1a8976
MD5 95b2e9342fc8679273f88fa21ba8d5a4
BLAKE2b-256 7f73c20c57318373e1b54e7ad910e0a03d0d0148a91e8f7d3f31b6706d733ce4

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokentrap-1.0.1-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

1.0.2

2 files

This release

1.0.1 This release

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