The Token Company Python SDK
Compress LLM prompts to reduce costs and latency. 100K tokens compressed in ~85ms.
Docs · Website · Dashboard · Node.js SDK
Install
pip install the-token-company
Quick start
from thetokencompany import TheTokenCompany
client = TheTokenCompany(api_key="ttc-...")
result = client.compress("Your long prompt text here...", model="bear-2")
print(result.output) # compressed text
print(result.tokens_saved) # tokens removed
print(result.compression_ratio) # e.g. 1.8
SDK wrappers
Drop-in wrappers that auto-compress conversation turns before sending to your LLM. By default every turn — user, system, tool, and assistant/agent — is compressed. To keep the provider's KV cache warm, pass a per-role aggressiveness dict that omits the assistant key (e.g. {"user": 0.2, "system": 0.2, "tool": 0.2}).
OpenAI / OpenRouter
from openai import OpenAI
from thetokencompany.openai import with_compression
client = with_compression(OpenAI(), compression_api_key="ttc-...")
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant..."},
{"role": "user", "content": "Summarize these results..."},
],
)
Works with AsyncOpenAI too — the wrapper detects async automatically.
Anthropic
from anthropic import Anthropic
from thetokencompany.anthropic import with_compression
client = with_compression(Anthropic(), compression_api_key="ttc-...")
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
system="You are a helpful assistant...",
messages=[{"role": "user", "content": "Summarize these results..."}],
)
Both messages and the system parameter are compressed.
Async
from thetokencompany import AsyncTheTokenCompany
async with AsyncTheTokenCompany(api_key="ttc-...") as client:
result = await client.compress("Your long prompt text...")
Models
| Model | Description |
|---|---|
bear-2 |
Latest, recommended |
bear-1.2 |
Previous generation |
Aggressiveness
Control compression intensity with aggressiveness (0.0 – 1.0, default 0.5):
result = client.compress(text, model="bear-2", aggressiveness=0.8)
App ID
Tag compression requests with an application identifier for usage tracking:
# Set on the client — applies to all requests
client = TheTokenCompany(api_key="ttc-...", app_id="my-chatbot")
# Or per-request (overrides the client-level value)
result = client.compress(text, model="bear-2", app_id="my-chatbot")
Also supported in wrappers:
client = with_compression(OpenAI(), compression_api_key="ttc-...", app_id="my-chatbot")
Gzip
Enable gzip compression of request payloads for better performance on large inputs (up to 2.2x faster on 1M+ tokens):
client = TheTokenCompany(api_key="ttc-...", gzip=True)
Protect text from compression
Use protect() to wrap content in <ttc_safe> tags — protected text passes through unchanged:
from thetokencompany import protect
prompt = f"{protect('system:')} You are a helpful assistant.\n{protect('user:')} Hello!"
result = client.compress(prompt, model="bear-2")
Response
CompressResponse fields:
| Field | Type | Description |
|---|---|---|
output |
str |
Compressed text |
output_tokens |
int |
Token count after compression |
input_tokens |
int |
Token count before compression |
tokens_saved |
int |
Tokens removed |
compression_ratio |
float |
Ratio (e.g. 1.8x) |
License
MIT
Metadata
Release files for the-token-company 0.5.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| the_token_company-0.5.1.tar.gz | 32.7 kB | Without provenance | Details for the_token_company-0.5.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| the_token_company-0.5.1-py3-none-any.whl | Python 3 | none | any | Details for the_token_company-0.5.1-py3-none-any.whl |
Total release size: 53.7 kB
Release files / the_token_company-0.5.1.tar.gz
| Download URL | the_token_company-0.5.1.tar.gz |
|---|---|
| Size | 32.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e8b04bb529a398ab001c5fd6431e5608a86051c61c5ae203af9123e08273c05b
|
|
BLAKE2b-256 checksum How to use checksums |
09073f18acfdec1e43d8f59a894b709b153ff83dd9ca8ef7814ccba8de869bce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / the_token_company-0.5.1-py3-none-any.whl
| Download URL | the_token_company-0.5.1-py3-none-any.whl |
|---|---|
| Size | 21.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
550520cc5880b36d5a628b2a815798c0879428f95ebeefef79028c0692072582
|
|
BLAKE2b-256 checksum How to use checksums |
9cca28d881e476a0e3b08ad24ce5677b2db7bf169fdb999586315479fd1e53f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Security for the-token-company 0.5.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.