0

๐ŸŽฏ Toonify Token Optimization

awesome-llm-appstoonify_token_optimization

Reduce LLM API costs by 30-60% using TOON (Token-Oriented Object Notation) format for structured data serialization.

Sign in to save downloads to your library and vote.

Preview

๐ŸŽฏ Toonify Token Optimization

Reduce LLM API costs by 30-60% using TOON (Token-Oriented Object Notation) format for structured data serialization.

๐Ÿ“‹ Overview

This app demonstrates how to use Toonify to dramatically reduce token usage when passing structured data to Large Language Models. TOON format achieves CSV-like compactness while maintaining explicit structure and human readability.

Key Benefits

  • ๐Ÿ’ฐ 63.9% average token reduction compared to JSON
  • ๐ŸŽฏ Up to 73.4% savings for optimal use cases (tabular data)
  • ๐Ÿ’ต Saves $2,147 per million API requests at GPT-4 pricing
  • ๐Ÿ“– Human-readable format
  • โšก Minimal overhead (<1ms for typical payloads)

๐Ÿš€ Features

  • JSON vs TOON Comparison: See the size difference in action
  • Token Cost Calculator: Calculate savings for your use cases
  • LLM Integration Example: Pass optimized data to GPT/Claude
  • Real-world Examples: Product catalogs, surveys, analytics data
  • Benchmarking: Measure compression ratios for your data

๐Ÿ“ฆ Installation

  1. Install required dependencies:
pip install -r requirements.txt
  1. Set up your API key (optional, for LLM integration demo):
export OPENAI_API_KEY='your-api-key-here'

๐Ÿ’ป Usage

Basic Example

Run the basic comparison demo:

python toonify_demo.py

Interactive Demo

Run the interactive Streamlit app:

streamlit run toonify_app.py

๐Ÿ“Š Format Comparison

JSON (247 bytes)

{
  "products": [
    {"id": 101, "name": "Laptop Pro", "price": 1299},
    {"id": 102, "name": "Magic Mouse", "price": 79},
    {"id": 103, "name": "USB-C Cable", "price": 19}
  ]
}

TOON (98 bytes, 60% reduction)

products[3]{id,name,price}:
  101,Laptop Pro,1299
  102,Magic Mouse,79
  103,USB-C Cable,19

๐ŸŽฏ Best Use Cases

Use TOON when:

  • โœ… Passing data to LLM APIs (reduce token costs)
  • โœ… Working with uniform tabular data
  • โœ… Context window is limited
  • โœ… Human readability matters

Use JSON when:

  • โŒ Maximum compatibility is required
  • โŒ Data is highly irregular/nested
  • โŒ Working with existing JSON-only tools

๐Ÿ’ก Example: E-commerce Product Analysis

from toonify import encode
import openai

# Your product data (could be hundreds of products)
products = [
    {"id": 1, "name": "Laptop", "price": 1299, "stock": 45},
    {"id": 2, "name": "Mouse", "price": 79, "stock": 120},
    # ... many more products
]

# Convert to TOON format (saves 60% tokens)
toon_data = encode(products)

# Send to LLM with reduced token cost
response = openai.chat.completions.create(
    model="gpt-4",
    messages=[{
        "role": "user",
        "content": f"Analyze this product data:\n{toon_data}"
    }]
)

๐Ÿ“ˆ Performance

Benchmarked across 50 real-world datasets:

  • 63.9% average size reduction vs JSON
  • 54.1% average token reduction
  • 98% of datasets achieve 40%+ savings
  • Minimal overhead (<1ms encoding/decoding)

๐Ÿ”— Resources

๐Ÿค Contributing

Contributions are welcome! Feel free to:

  • Report bugs
  • Suggest new examples
  • Add benchmarks
  • Improve documentation

๐Ÿ“„ License

This example is provided as-is for educational purposes. Toonify library is licensed under MIT License.

๐Ÿ™ Credits

Built with Toonify by the ScrapeGraphAI team.

Ingestion metadata

Source catalog
awesome-llm-apps
Repository
Shubhamsaboo/awesome-llm-apps ยท main
File path
advanced_llm_apps/llm_optimization_tools/toonify_token_optimization/README.md
Last refreshed
7/24/2026, 3:00:13 AM (51m ago)
Refresh schedule
Daily ยท 03:00 UTC
Dedupe status
Unique ยท deduped by (source, url)