TokenCrush
LLM token optimization CLI - compress prompts, save costs.
TokenCrush uses LLMLingua-2 to compress your prompts before sending them to LLMs, reducing token usage by 50-80% while preserving response quality.
Features
- Prompt Compression: Reduce tokens by 2-5x using Microsoft's LLMLingua-2
- Multi-Provider Support: Works with OpenAI, Anthropic (Claude), and Google (Gemini)
- Simple CLI: One command to compress and chat
- Cost Savings: Significantly reduce API costs
Installation
pip install tokencrush
Or with uv:
uv add tokencrush
Quick Start
1. Configure API Keys
# Set API keys (stored in ~/.config/tokencrush/config.toml)
tokencrush config set openai sk-your-openai-key
tokencrush config set anthropic sk-ant-your-anthropic-key
tokencrush config set google your-google-api-key
# Or use environment variables
export OPENAI_API_KEY=sk-your-key
2. Compress a Prompt
tokencrush compress "Your very long prompt text here..."
Output:
┌─────────────────────────────────────┐
│ Compression Result │
├──────────────────┬──────────────────┤
│ Original Tokens │ 500 │
│ Compressed Tokens│ 150 │
│ Compression Ratio│ 30.0% │
│ Tokens Saved │ 350 │
└──────────────────┴──────────────────┘
3. Chat with Compression
# Compress and send to GPT-4
tokencrush chat "Explain quantum computing in detail" --model gpt-4
# Use Claude
tokencrush chat "Write a poem" --model claude-3-sonnet
# Use Gemini
tokencrush chat "Summarize this" --model gemini-1.5-pro
CLI Reference
tokencrush compress
Compress text to reduce tokens.
tokencrush compress <text> [OPTIONS]
Options:
-r, --rate FLOAT Compression rate (0.0-1.0). Default: 0.5
-g, --gpu Use GPU for faster compression
tokencrush chat
Compress and send to LLM.
tokencrush chat <prompt> [OPTIONS]
Options:
-m, --model TEXT Model to use. Default: gpt-4
-r, --rate FLOAT Compression rate. Default: 0.5
-g, --gpu Use GPU for compression
--no-compress Skip compression
tokencrush config
Manage API keys.
tokencrush config set <provider> <key> # Save API key
tokencrush config show # Show configured keys
Supported Models
| Provider | Models |
|---|---|
| OpenAI | gpt-4, gpt-4-turbo, gpt-3.5-turbo |
| Anthropic | claude-3-opus, claude-3-sonnet, claude-3-haiku |
| gemini-1.5-pro, gemini-1.5-flash |
How It Works
- Compression: TokenCrush uses LLMLingua-2's trained model to identify and remove redundant tokens while preserving meaning.
- API Call: The compressed prompt is sent to your chosen LLM provider.
- Response: You get the same quality response with fewer input tokens = lower cost.
Development
# Clone the repository
git clone https://github.com/xodn348/tokencrush.git
cd tokencrush
# Install with dev dependencies
uv sync --all-extras
# Run tests
uv run pytest -v
# Build package
uv build
License
MIT License - see LICENSE for details.
Acknowledgments
Metadata
Release files for tokencrush 0.1.0
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 |
|---|---|---|---|---|
| tokencrush-0.1.0.tar.gz | 188.5 kB | Without provenance | Details for tokencrush-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tokencrush-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for tokencrush-0.1.0-py3-none-any.whl |
Total release size: 196.7 kB
Release files / tokencrush-0.1.0.tar.gz
| Download URL | tokencrush-0.1.0.tar.gz |
|---|---|
| Size | 188.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b184f344d738ac2e2dd65cbe95f0f59808b7cc9997f70cc70e0a8c4bf76b0f94
|
|
BLAKE2b-256 checksum How to use checksums |
7b70d55d97797c7a4970031d42d956d164df353eab51f2d98836f8ddace21181
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / tokencrush-0.1.0-py3-none-any.whl
| Download URL | tokencrush-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b3a07677e4bf5e177333ab070ffd9764bea97cc096b330cc1d45608e0236d1ac
|
|
BLAKE2b-256 checksum How to use checksums |
c6e2debad9fc8ee8703e93e954ecbc0511712cb73ad994caf722887e24d2ad9e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.2
|
Security for tokencrush 0.1.0
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.