1- # 🪨 tokenoptim
1+ # 🪨 llm- tokenoptim
22
33> ** Cut LLM token costs by 40–75% — no API key required.**
44> Works as a CLI tool for Claude Code, Gemini CLI, Codex, aider, and any LLM tool.
55> Optional Python SDK for Anthropic · OpenAI · Ollama · PySpark batch.
66
7- [ ![ PyPI] ( https://img.shields.io/pypi/v/tokenoptim )] ( https://pypi.org/project/tokenoptim/ )
8- [ ![ Python] ( https://img.shields.io/pypi/pyversions/tokenoptim )] ( https://pypi.org/project/tokenoptim/ )
9- [ ![ CI] ( https://github.com/manasmourya/tokenoptim/actions/workflows/ci.yml/badge.svg )] ( https://github.com/manasmourya/tokenoptim/actions )
7+ [ ![ PyPI] ( https://img.shields.io/pypi/v/llm- tokenoptim )] ( https://pypi.org/project/llm- tokenoptim/ )
8+ [ ![ Python] ( https://img.shields.io/pypi/pyversions/llm- tokenoptim )] ( https://pypi.org/project/llm- tokenoptim/ )
9+ [ ![ CI] ( https://github.com/manasmourya/llm- tokenoptim/actions/workflows/ci.yml/badge.svg )] ( https://github.com/manasmourya/llm- tokenoptim/actions )
1010[ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( LICENSE )
11- [ ![ Downloads] ( https://img.shields.io/pypi/dm/tokenoptim )] ( https://pypi.org/project/tokenoptim/ )
11+ [ ![ Downloads] ( https://img.shields.io/pypi/dm/llm- tokenoptim )] ( https://pypi.org/project/llm- tokenoptim/ )
1212
1313---
1414
1515## 30-second start (no API key needed)
1616
1717``` bash
18- pip install tokenoptim
18+ pip install llm- tokenoptim
1919
2020# Inject caveman compression into Claude Code (auto-loaded via CLAUDE.md)
21- tokenoptim install-claude --level full
21+ llm- tokenoptim install-claude --level full
2222
2323# Pipe skill into any LLM tool manually
24- tokenoptim skill full | pbcopy # macOS clipboard → paste into any chat
24+ llm- tokenoptim skill full | pbcopy # macOS clipboard → paste into any chat
2525
2626# Wrap ANY LLM CLI tool — works with gemini, codex, aider, sgpt, llm, ollama
27- tokenoptim wrap --level full -- gemini " explain kubernetes networking"
28- tokenoptim wrap --level ultra -- claude " write a redis cache class"
29- tokenoptim wrap --level standard -- aider --model gpt-4o
27+ llm- tokenoptim wrap --level full -- gemini " explain kubernetes networking"
28+ llm- tokenoptim wrap --level ultra -- claude " write a redis cache class"
29+ llm- tokenoptim wrap --level standard -- aider --model gpt-4o
3030
3131# Compress a verbose prompt before sending
32- tokenoptim compress " Could you please help me understand what tokenization means in the context of large language models?"
32+ llm- tokenoptim compress " Could you please help me understand what tokenization means in the context of large language models?"
3333```
3434
3535** Five compression levels — no API, no GPU, <0.1ms overhead:**
@@ -50,7 +50,7 @@ tokenoptim compress "Could you please help me understand what tokenization means
5050
5151Every LLM API call burns money proportional to token count. Most teams waste tokens in predictable, fixable ways:
5252
53- | Waste source | Typical overhead | tokenoptim fix |
53+ | Waste source | Typical overhead | llm- tokenoptim fix |
5454| ---| ---| ---|
5555| Verbose prompts ("Could you please help me...") | +15–30% input tokens | Regex prompt compressor |
5656| Pleasantries in output ("Great question! Certainly!") | +40–75% output tokens | 6-level output compressor |
@@ -73,7 +73,7 @@ Every LLM API call burns money proportional to token count. Most teams waste tok
7373| ` medium ` | 12% | 11% | 24% | <0.1ms |
7474| ` full ` | 14% | 12% | 26% | <0.1ms |
7575
76- > ** With LLMLingua ML backend** (` pip install "tokenoptim[ml]" ` ): 40–60% reduction on verbose prompts. Install the extra to unlock it — the library falls back to regex automatically if not present.
76+ > ** With LLMLingua ML backend** (` pip install "llm- tokenoptim[ml]" ` ): 40–60% reduction on verbose prompts. Install the extra to unlock it — the library falls back to regex automatically if not present.
7777
7878### Output Compression (via system prompt injection)
7979
@@ -93,14 +93,14 @@ Every LLM API call burns money proportional to token count. Most teams waste tok
9393
9494``` bash
9595# Core library — zero dependencies
96- pip install tokenoptim
96+ pip install llm- tokenoptim
9797
9898# With providers
99- pip install " tokenoptim[anthropic]" # Claude (async + streaming)
100- pip install " tokenoptim[openai]" # OpenAI / Groq / Together
101- pip install " tokenoptim[spark]" # PySpark batch compression
102- pip install " tokenoptim[ml]" # LLMLingua ML compression (40-60%)
103- pip install " tokenoptim[all]" # Everything
99+ pip install " llm- tokenoptim[anthropic]" # Claude (async + streaming)
100+ pip install " llm- tokenoptim[openai]" # OpenAI / Groq / Together
101+ pip install " llm- tokenoptim[spark]" # PySpark batch compression
102+ pip install " llm- tokenoptim[ml]" # LLMLingua ML compression (40-60%)
103+ pip install " llm- tokenoptim[all]" # Everything
104104```
105105
106106---
@@ -110,7 +110,7 @@ pip install "tokenoptim[all]" # Everything
110110### Compress a prompt — no LLM, no API key
111111
112112``` python
113- from tokenoptim import PromptCompressor
113+ from llm - tokenoptim import PromptCompressor
114114
115115c = PromptCompressor(level = " medium" )
116116compressed, stats = c.compress(
@@ -125,8 +125,8 @@ print(stats)
125125
126126``` python
127127import asyncio
128- from tokenoptim import AsyncOptimizedClient
129- from tokenoptim.providers import AsyncAnthropicProvider
128+ from llm - tokenoptim import AsyncOptimizedClient
129+ from llm - tokenoptim.providers import AsyncAnthropicProvider
130130
131131async def main ():
132132 client = AsyncOptimizedClient(
@@ -160,8 +160,8 @@ asyncio.run(main())
160160### Sync client (simpler, same optimizations)
161161
162162``` python
163- from tokenoptim import OptimizedClient
164- from tokenoptim.providers import AnthropicProvider
163+ from llm - tokenoptim import OptimizedClient
164+ from llm - tokenoptim.providers import AnthropicProvider
165165
166166client = OptimizedClient(
167167 provider = AnthropicProvider(),
@@ -176,8 +176,8 @@ print(resp["content"])
176176### ML-powered compression (40–60% input reduction)
177177
178178``` python
179- # pip install "tokenoptim[ml]"
180- from tokenoptim.core.ml_compressor import MLPromptCompressor
179+ # pip install "llm- tokenoptim[ml]"
180+ from llm - tokenoptim.core.ml_compressor import MLPromptCompressor
181181
182182c = MLPromptCompressor(target_token_rate = 0.5 ) # keep 50% → 50% reduction
183183compressed, stats = c.compress(very_long_prompt)
@@ -190,10 +190,10 @@ Falls back to regex automatically if `llmlingua` is not installed.
190190### Response caching — avoid duplicate API calls
191191
192192``` python
193- from tokenoptim import ResponseCache, OptimizedClient
194- from tokenoptim.providers import AnthropicProvider
193+ from llm - tokenoptim import ResponseCache, OptimizedClient
194+ from llm - tokenoptim.providers import AnthropicProvider
195195
196- cache = ResponseCache(directory = " ~/.cache/tokenoptim" , ttl_seconds = 3600 )
196+ cache = ResponseCache(directory = " ~/.cache/llm- tokenoptim" , ttl_seconds = 3600 )
197197provider = AnthropicProvider()
198198
199199messages = [{" role" : " user" , " content" : " What is tokenization?" }]
@@ -237,7 +237,7 @@ client.clear_memory() # Wipe history
237237Automatic exponential backoff on 429 / 5xx — configured at construction:
238238
239239``` python
240- from tokenoptim import RetryConfig, AsyncOptimizedClient
240+ from llm - tokenoptim import RetryConfig, AsyncOptimizedClient
241241
242242client = AsyncOptimizedClient(
243243 provider = ... ,
@@ -259,17 +259,17 @@ Compress millions of prompts before sending to any LLM:
259259
260260``` python
261261from pyspark.sql import SparkSession
262- from tokenoptim.spark import SparkTokenOptimizer
262+ from llm - tokenoptim.spark import SparkTokenOptimizer
263263
264- spark = SparkSession.builder.appName(" tokenoptim" ).getOrCreate()
264+ spark = SparkSession.builder.appName(" llm- tokenoptim" ).getOrCreate()
265265df = spark.read.parquet(" s3://bucket/raw-prompts/" )
266266
267267optimizer = SparkTokenOptimizer(level = " full" , spark = spark)
268268df_out = optimizer.compress_dataframe(df, prompt_col = " prompt" )
269269df_out.write.parquet(" s3://bucket/compressed-prompts/" )
270270optimizer.savings_report(df, df_out)
271271
272- # ━━━━ tokenoptim PySpark Savings Report ━━━━
272+ # ━━━━ llm- tokenoptim PySpark Savings Report ━━━━
273273# Prompts processed : 4,500,000
274274# Total original tokens: 892,400,000
275275# Total compressed : 768,000,000
@@ -286,25 +286,25 @@ With the `[ml]` extra, LLMLingua runs as a Spark UDF on each executor — 40–6
286286
287287``` bash
288288# ── Skill injection (primary use — no API key needed) ─────────────────────────
289- tokenoptim skill [lite| standard| full| ultra| ancient] # print skill to stdout
290- tokenoptim install-claude --level full # append to ./CLAUDE.md
291- tokenoptim install-global --level standard # append to ~/CLAUDE.md
289+ llm- tokenoptim skill [lite| standard| full| ultra| ancient] # print skill to stdout
290+ llm- tokenoptim install-claude --level full # append to ./CLAUDE.md
291+ llm- tokenoptim install-global --level standard # append to ~/CLAUDE.md
292292
293293# ── Wrap any LLM CLI tool ─────────────────────────────────────────────────────
294- tokenoptim wrap --level full -- gemini " explain kubernetes"
295- tokenoptim wrap --level ultra -- claude " write a redis cache class"
296- tokenoptim wrap --level full -- codex " refactor this function"
297- tokenoptim wrap --level standard -- aider --model gpt-4o
298- tokenoptim wrap --level full -- llm " summarize this doc"
299- tokenoptim wrap --level ultra -- ollama run llama3
294+ llm- tokenoptim wrap --level full -- gemini " explain kubernetes"
295+ llm- tokenoptim wrap --level ultra -- claude " write a redis cache class"
296+ llm- tokenoptim wrap --level full -- codex " refactor this function"
297+ llm- tokenoptim wrap --level standard -- aider --model gpt-4o
298+ llm- tokenoptim wrap --level full -- llm " summarize this doc"
299+ llm- tokenoptim wrap --level ultra -- ollama run llama3
300300
301301# ── Prompt compression (Python regex, <0.1ms, no API) ────────────────────────
302- tokenoptim compress " Could you please help me understand what a token is?"
303- tokenoptim compress --level full --file my_prompt.txt --output compressed.txt
302+ llm- tokenoptim compress " Could you please help me understand what a token is?"
303+ llm- tokenoptim compress --level full --file my_prompt.txt --output compressed.txt
304304
305305# ── Benchmarks ────────────────────────────────────────────────────────────────
306- tokenoptim bench --input prompts.txt # benchmark one prompt per line
307- tokenoptim levels # show all levels and savings
306+ llm- tokenoptim bench --input prompts.txt # benchmark one prompt per line
307+ llm- tokenoptim levels # show all levels and savings
308308python benchmarks/run_benchmark.py --samples 500
309309```
310310
@@ -313,7 +313,7 @@ python benchmarks/run_benchmark.py --samples 500
313313## Architecture
314314
315315```
316- src/tokenoptim/
316+ src/llm- tokenoptim/
317317├── core/
318318│ ├── compressor.py # Regex prompt compression (3 levels, <0.1ms)
319319│ ├── ml_compressor.py # LLMLingua ML compression (optional, 40–60%)
@@ -331,7 +331,7 @@ src/tokenoptim/
331331├── spark/udf.py # PySpark UDF + SparkTokenOptimizer
332332├── client.py # OptimizedClient (sync)
333333├── async_client.py # AsyncOptimizedClient (async + batch + stream)
334- └── cli.py # tokenoptim CLI
334+ └── cli.py # llm- tokenoptim CLI
335335```
336336
337337---
@@ -349,8 +349,8 @@ Output compression savings (40–75%) apply to the **output side** and are syste
349349## Contributing
350350
351351``` bash
352- git clone https://github.com/manasmourya/tokenoptim
353- cd tokenoptim
352+ git clone https://github.com/manasmourya/llm- tokenoptim
353+ cd llm- tokenoptim
354354pip install -e " .[dev]"
355355pytest tests/ -v
356356python benchmarks/run_benchmark.py --no-download
0 commit comments