Skip to main content

Cut LLM costs with deterministic context compression, smart routing, and cost tracking

Project description

TokenPak — Cut your LLM token spend — guided setup

PyPI version Python 3.10+ License: Apache-2.0

The open logistics layer for AI context.

TokenPak starts as a local proxy that packs AI requests before they ship — reducing wasted context and giving teams receipts for what changed. Fewer tokens, lower cost. No code changes, no cloud, no credentials stored.


30-second demo

pip install tokenpak
tokenpak serve                          # start proxy at localhost:8766
tokenpak integrate claude-code --apply  # wire Claude Code to the proxy
✅ Applied: Updated ~/.claude/settings.json (2 changes).

Then verify it's working:

tokenpak demo
┌──────────────────────────────────────────────────────┐
│  TokenPak — Offline Fixture Demo (illustrative)      │
├──────────────────────────────────────────────────────┤
│  Scenario              DevOps agent (config + logs)  │
│  Savings drivers                      dedup + alias  │
├──────────────────────────────────────────────────────┤
│  Original                                747 tokens  │
│  Compressed                              502 tokens  │
│  Fewer tokens                            245 tokens  │
├──────────────────────────────────────────────────────┤
│  Stages: dedup, alias, segmentize, directives        │
└──────────────────────────────────────────────────────┘

Illustrative fixture — token counts vary by route and workload. Measure your own with tokenpak savings; inspect provider-cache vs. TokenPak attribution with tokenpak status --tip-cache.


Works with

Claude Code · Cursor · Cline · Continue.dev · Aider · OpenAI SDK · Anthropic SDK · LiteLLM · Codex

Run tokenpak integrate to see the full client list with setup guides for each.


Install

pip install tokenpak

See docs/quickstart.md for virtual-env setup and per-client configuration.

Requirements: Python 3.10+. No external dependencies for core functionality.

Exposing the proxy beyond 127.0.0.1? Set TOKENPAK_PROXY_AUTH_TOKEN to a shared secret to require Authorization: Bearer <token> on remote requests (see docs/configuration/proxy-auth.md).


Runnable examples

The PyPI wheel keeps the install slim and does not bundle the repository's top-level examples. To run them after a normal package install, clone or download the source tree for the example files:

git clone https://github.com/tokenpak/tokenpak.git
cd tokenpak
python -m venv .venv
source .venv/bin/activate
python -m pip install -U tokenpak
python examples/basic_compression.py

examples/basic_compression.py is local-first and does not require provider credentials. See examples/README.md for the full examples index and developer editable-install path.


What's included (Free)

Dispatch (v0.1-alpha preview): turn a request into a scoped, resumable, reviewable workflow from the CLI. It is a source/main-branch preview and is not yet part of a released pip install tokenpak; see the Dispatch guide.

  • Context compression — deterministic token reduction on real agent workloads, <50ms latency. Savings are route-specific: direct API, CLI, and uncached repeated-agent loops are the best fit, while Claude Code/TUI routes may show lower incremental savings when the provider cache already handled repeated context. Measure your own savings with tokenpak savings; inspect attribution with tokenpak status --tip-cache (reproduce the headline benchmark with make benchmark-headline).
  • Client integration — one command wires Claude Code, Cursor, Aider, and 6 other clients
  • Model routing — send requests to the right model automatically, with fallback rules
  • Cost tracking — per model, per session, per agent; local SQLite, zero cloud
  • TIP Spend Guard — pre-send circuit breaker; blocks runaway requests before provider call. Yes/No release or [TIP: allow=once max=$X] directive. Catches both single-request spikes and the death-by-1000-cuts pattern via session-cumulative tracking. See docs/spend-guard.md.
  • Vault indexing + semantic search — index your codebase; search without an LLM call
  • MultiPak Pro Phase 1 OSS surface — read-only Vault Pak adapter, companion journal promotion-candidate marking, tokenpak pak CLI, /pak/v1/* proxy stubs. Full MultiPak (capture pipeline, recall ranking, Handoff Paks, anchor hydration) requires tokenpak-paid (Pro). See docs/multipak.md.
  • CLI + proxy servertokenpak serve, tokenpak cost, tokenpak savings
  • A/B testing and replay/debug — compare compression configs, replay past requests
  • 50 built-in compression recipes — YAML, customizable

Repeated context is reused from cache instead of re-sent on every call. See docs/quickstart.md and docs/api-tpk-v1.md to get started.


Open source & editions

TokenPak's core is Apache-2.0 open source; TokenPak Pro and hosted services are proprietary. Commercial packaging is not published yet.


Support


License

The TokenPak open-source core is licensed under the Apache License 2.0 — see LICENSE. TokenPak Pro and hosted services are proprietary.

Trademark

"TokenPak", the TokenPak name, logo, and brand assets are trademarks of TokenPak and are not licensed under Apache-2.0 (Apache-2.0 §6 grants no trademark rights). Nominative and reference use — for example "works with TokenPak" or "a plugin for TokenPak" — is fine. Using the name or logo in a way that implies endorsement, sponsorship, or affiliation, or naming a fork, product, or service "TokenPak" (or something confusingly similar), is not.

Project details


Download files

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

Source Distribution

tokenpak-1.11.3.tar.gz (2.1 MB view details)

Uploaded Source

Built Distribution

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

tokenpak-1.11.3-py3-none-any.whl (2.6 MB view details)

Uploaded Python 3

File details

Details for the file tokenpak-1.11.3.tar.gz.

File metadata

  • Download URL: tokenpak-1.11.3.tar.gz
  • Upload date:
  • Size: 2.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tokenpak-1.11.3.tar.gz
Algorithm Hash digest
SHA256 5f891820ac1d14b31f4eba9bac20cbf9ca6168bca67ebfcbc63ce6323f56830c
MD5 3a305c1c4fa610b632e6980e79c9a4f2
BLAKE2b-256 e94514193dc5a505ac3b41a167edb2a44c9d104823fb0b87ead58714327aa49d

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokenpak-1.11.3.tar.gz:

Publisher: release.yml on tokenpak/tokenpak

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

File details

Details for the file tokenpak-1.11.3-py3-none-any.whl.

File metadata

  • Download URL: tokenpak-1.11.3-py3-none-any.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tokenpak-1.11.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0787f2bdc623bd5b60ac4ef846bcf6559e3a428d489f74ea25325d6e203985fd
MD5 b6a8ab76894048e2da43f6e40e1be943
BLAKE2b-256 1c1db59d1c544043001d12c57ea327980fb451b519bc8ccbc673a6fe1214ee12

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokenpak-1.11.3-py3-none-any.whl:

Publisher: release.yml on tokenpak/tokenpak

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

Supported by

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