AI & LLM Optimization

Reduce token usage by up to 54% vs JSON (11% better than TOON on average) and save on LLM API costs with Tauq.

The Token Cost Problem

Example: 10,000 API Calls with GPT-4o

Your app makes 10,000 API calls per day, each with 1,000 records of user data in the context.

Using JSON
24,005 tokens
per request
$30.00/day
= $10,950/year
Using Tauq
11,012 tokens
per request (54% fewer)
$13.77/day
= $5,026/year (save $5,924!)

With models like Claude Opus 4.5 ($15/M tokens), the savings are even more dramatic: $23,694/year saved.

LLM Use Cases

1. Structured Data in Context

When providing tabular data (users, products, logs) as context to an LLM:

❌ JSON Approach (68 tokens)
{
  "users": [
    {"id": 1, "name": "Alice", "email": "alice@example.com"},
    {"id": 2, "name": "Bob", "email": "bob@example.com"}
  ]
}
✅ Tauq Approach (24 tokens - 65% savings)
!def User id name email
---
users [
  !use User
  1 Alice "alice@example.com"
  2 Bob "bob@example.com"
]

💡 Pro Tip: Use the playground to paste your JSON and see instant token savings.

2. Few-Shot Examples

When providing training examples for in-context learning:

You are a sentiment classifier. Here are examples:

!def Example text sentiment confidence
"Great product!" positive 0.95
"Terrible service" negative 0.92
"It's okay" neutral 0.78

Now classify: "Amazing experience!"

Instead of verbose JSON objects, schemas make examples compact and the pattern clear.

3. Tool Calling / Function Results

When returning database query results or API responses to the LLM:

// Database query result
!def Order id customer_id total status created_at
12345 789 1299.99 shipped "2025-01-15"
12346 790 49.99 pending "2025-01-16"
12347 789 299.99 delivered "2025-01-14"

// The LLM can easily parse this and generate insights

4. RAG (Retrieval-Augmented Generation)

When embedding retrieved documents in the context:

!def Doc id title snippet relevance
101 "Tauq Basics" "Tauq is a token-efficient..." 0.94
205 "Schema Patterns" "Use !def to define schemas..." 0.89
387 "Streaming API" "Process large files with..." 0.76

Fit more retrieved documents in your context window = better answers.

5. Multi-Turn Conversations with History

Maintain conversation context efficiently:

!def Message role content timestamp
user "What's the weather?" "2025-01-16 10:00"
assistant "It's sunny, 72°F" "2025-01-16 10:01"
user "Perfect for a run!" "2025-01-16 10:02"

Keep longer conversation histories within your token budget.

Calculate Your Savings

Quick Estimate

Tauq Tokens
~4,200
(54% reduction)
Daily Savings
$7.25
Annual Savings
$2,646

💡 These are estimates based on typical token reduction (54%). Actual savings may vary based on your data structure. Use the playground for exact calculations.

Best Practices

📊 Use Schemas for Tabular Data

Arrays of objects with consistent fields are Tauq's sweet spot. Define a schema once, reap 60%+ token savings.

🗜️ Minify for Production

Use tauq minify or the minify button in the playground to compress to a single line:

tauq minify data.tqn -o data.min.tqn

🔄 Convert at Runtime

Use language bindings to convert your app's data structures on-the-fly:

import tauq

# Fetch from database
users = db.query("SELECT id, name, email FROM users LIMIT 100")

# Convert to Tauq for LLM context
tauq_context = tauq.dumps(users)

# Send to LLM
response = openai.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "user", "content": f"Analyze these users:\\n{tauq_context}"}
    ]
)

📈 Monitor Token Usage

Track before/after metrics to quantify savings. Most LLM APIs return token counts in response metadata.

Try It Now

Paste your JSON into the playground and see instant token savings with real tiktoken counts.