Overview
LLM API costs are directly tied to token count. These optimization tools help you reduce token usage while maintaining accuracy, enabling cost-effective AI applications at scale.TOON Format
63.9% average token reduction for structured data
Headroom
47-92% token savings through intelligent compression
Why Optimize?
- Cost Savings
- Performance
- Scale
Toonify Token Optimization
What is TOON?
TOON is a compact serialization format designed specifically for LLM token efficiency. It achieves CSV-like compression while maintaining structure and readability.Key Benefits
63.9% Average Reduction
Verified across 50 real-world datasets
73.4% for Tabular Data
Optimal for structured, uniform data
Human Readable
Still easy to understand and debug
<1ms Overhead
Negligible conversion time
Format Comparison
Token Savings: 85 → 39 tokens (54.1% reduction)Cost Impact: 1.17/1K requests
Implementation
1
Install Toonify
2
Convert Data to TOON
3
Send to LLM
4
Decode if Needed
Real-World Example
E-commerce Product Analysis
E-commerce Product Analysis
- JSON: 487 bytes, ~165 tokens
- TOON: 186 bytes, ~68 tokens
- Reduction: 58.8% tokens, 61.8% bytes
Best Use Cases
Tabular Data
Tabular Data
Optimal for:
- Product catalogs
- CSV exports
- Database query results
- API response data
- Survey results
- Analytics data
Structured JSON
Structured JSON
Good for:
- Configuration files
- Uniform object arrays
- API payloads
- Log data
When NOT to Use
When NOT to Use
Avoid TOON for:
- Highly nested data (greater than 3 levels)
- Irregular/heterogeneous structures
- Small payloads (less than 100 bytes)
- Binary data
- When JSON compatibility is critical
Interactive Demo
Streamlit App Code
Streamlit App Code
streamlit run toonify_app.pyPerformance Benchmarks
- Token Reduction
- Conversion Speed
- Scale Test
Headroom Context Optimization
What is Headroom?
Headroom is a context optimization layer that compresses tool outputs and conversation history while preserving accuracy. Unlike simple truncation, it uses statistical analysis to keep what matters.Key Benefits
47-92% Token Reduction
Verified across production workloads
Zero Code Changes
Transparent proxy integration
Reversible Compression
LLM can retrieve original data via CCR
Provider Caching
Optimizes for OpenAI/Anthropic caching
Core Features
- SmartCrusher
- CacheAligner
- CCR System
Statistical Compression
Keeps:- First N items (context)
- Last N items (recency)
- Anomalies (statistical outliers)
- Query-relevant matches
- Repetitive boilerplate
- Redundant middle sections
- Low-information content
Installation & Setup
1
Install Headroom
2
Choose Integration Method
- Proxy (Zero Code)
- LangChain
- Agno
Real-World Performance
- Code Search
- SRE Debugging
- Agent Workflow
GitHub Code Search (100 results)
Scenario: Search 100 code files for error handling patternsCompression strategy:
- Keep first 2 and last 2 results
- Extract only relevant code sections
- Remove boilerplate imports/comments
- Preserve error handling patterns
Needle in Haystack Test
Complete Test Results
Complete Test Results
Setup:With Headroom:What Headroom kept:
- 100 production log entries
- 1 critical FATAL error at position 67
- Question: “What caused the outage? Error code? Fix?”
- Position 67: FATAL error (the needle)
- Position 1-2: Context (timeline start)
- Position 99-100: Most recent state
- Position 45: Anomaly (connection spike)
- 96 INFO/DEBUG entries
- Repetitive health checks
- Standard operational logs
Configuration
LangChain integration with compression
Best Use Cases
AI Agents with Tools
AI Agents with Tools
Optimal for:
- Multi-tool workflows
- Code search agents
- Database query agents
- API integration agents
- Log analysis agents
Large Tool Outputs
Large Tool Outputs
Ideal for:
- Code search results (100+ files)
- Database query results (1000+ rows)
- API responses (large JSON)
- Log files (10K+ lines)
- Documentation searches
Conversation History
Conversation History
Useful for:
- Long chat sessions
- Multi-turn debugging
- Context-heavy conversations
- Memory-intensive agents
Safety Guarantees
Never Removes Human Content
User and assistant messages are always preserved in full
Never Breaks Tool Pairing
Tool calls and responses stay together
Parse Failures = No-op
Malformed content passes through unchanged
Reversible Compression
LLM can retrieve original data via CCR
Best Practices
Choose the Right Tool
Choose the Right Tool
Measure Impact
Measure Impact
Monitor in Production
Monitor in Production
Combine Techniques
Combine Techniques
Cost Calculator
Interactive Cost Calculator
Interactive Cost Calculator
Resources
Toonify GitHub
TOON format library and examples
Headroom GitHub
Context optimization framework
Example Apps
Complete optimization demos
OpenAI Tokenizer
Test token counting
