Skip to main content

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

Project description

TokenPak — local context packing with measurable receipts

The open logistics layer for AI context.

TokenPak is a local proxy that packs AI requests before they ship and records what changed. It helps developers reduce repeated context on eligible routes, without moving prompts or credentials into a TokenPak cloud service.

CI PyPI version Python 3.10+ License: Apache-2.0


30-second demo

python -m pip install tokenpak
tokenpak demo
┌──────────────────────────────────────────────────────┐
│  TokenPak — Offline Fixture Demo                     │
├──────────────────────────────────────────────────────┤
│  Scenario              DevOps agent (config + logs)  │
│  Data source                built-in sample fixture  │
│  Savings drivers                      dedup + alias  │
├──────────────────────────────────────────────────────┤
│  Original                                747 tokens  │
│  Compressed                              502 tokens  │
│  Fixture delta                  245 tokens  (32.8%)  │
│  Fixture cost delta            $0.00073 per fixture  │
│  Receipt status               not a savings receipt  │
├──────────────────────────────────────────────────────┤
│  Stages: dedup, alias, segmentize, directives        │
└──────────────────────────────────────────────────────┘

Then verify:

tokenpak --version
tokenpak 1.17.0

The offline fixture is illustrative, not a measured savings receipt. Token counts vary by route and workload. For the signposted measured path, run a supported authenticated client through the proxy and follow the first-receipt guide.


Works with

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

Run tokenpak integrate to see supported-client setup guidance.


Install

python -m pip install tokenpak

Requires Python 3.10+. See the install guide for isolated-install options and quickstart for client setup.


What's included

  • Context packing — reduces repeated eligible context before provider send; inspect measured results with tokenpak savings.
  • Local proxy and client integration — route supported clients through one local service without changing application code.
  • Spend Guard — a pre-send circuit breaker that can block configured runaway requests before the provider call.
  • Local cost and receipt records — inspect measured activity by model, session, and route.
  • Vault indexing and semantic search — index a codebase and search it locally.
  • Compression recipes — 50 configurable YAML recipes for supported flows.

How it works

Your AI client sends provider-compatible requests to the TokenPak proxy on 127.0.0.1. TokenPak compresses eligible context and evaluates configured Spend Guard limits before forwarding to the selected upstream provider, then records the request result locally.

AI client -> TokenPak proxy -> upstream provider
                   |
                   +-> local receipt and cost records

Documentation


Runnable examples

The repository examples are not bundled inside the PyPI wheel. Read the examples/README.md, or clone the source and run the local, credential-free compression example:

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

Contributing

Issues and pull requests are welcome. See CONTRIBUTING.md.


License

The TokenPak open-source core is Apache-2.0 licensed. TokenPak Pro and hosted services are proprietary. See LICENSE and SECURITY.md.

Project details


Release history Release notifications | RSS feed

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.17.0.tar.gz (2.4 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.17.0-py3-none-any.whl (2.9 MB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tokenpak-1.17.0.tar.gz
Algorithm Hash digest
SHA256 f3851cdf5b7390a353088732ea32e09f6509997d65063741ad6ebaec958957ff
MD5 1b05396034de55b4d7f2bb07e368d391
BLAKE2b-256 2bc754938617ec7f1e5becf9fd1f31203597bba9f5f547e898be294c426b08f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokenpak-1.17.0.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.17.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for tokenpak-1.17.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8038ba4b5878f4b80d70df4a7c0bc0a2c7e7bb3d973184df8cf5beac90f492d1
MD5 3da2cdc710740eadb605e220bc752331
BLAKE2b-256 ad810337ca8a50f8dcb8e536d79d44c963f628de8fa2ec3c30f525174aa584c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokenpak-1.17.0-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