Skip to main content
Choosing the right model and optimizing costs can reduce your bill by 10x without sacrificing quality. This page covers model cascading, prompt caching, and the TOON format.

Model Selection Decision Framework

The Model Landscape (January 2025): Decision Tree:
As of publication. Verify latest pricing/context on vendor pages: OpenAI pricing, Anthropic pricing, and Google Gemini pricing/models.

Prompt Caching: 50-90% Cost Reduction

The Problem: You’re sending the same 50K token knowledge base with EVERY request.
The Solution: Prompt Caching Mark reusable parts of your prompt for caching: Production Economics:
Best Practices:
  1. Cache static content (knowledge bases, system prompts)
  2. Don’t cache user input (changes every request)
  3. Structure prompts with cacheable parts first
  4. Monitor cache hit rates
  5. Adjust query patterns to maximize cache hits

Model Cascading: Using Cheap Models First

The Strategy:
  • Try cheap/fast model first
  • If uncertain, escalate to expensive/smart model
  • Can reduce cost while maintaining quality when confidence gating is reliable
Implementation: When Cascading Works:
  • High-volume, similar tasks
  • Clear confidence signals (some models provide log probabilities)
  • Cost pressure but quality requirements
When to Avoid:
  • Low latency requirements (cascading adds delay)
  • Tasks where confidence is hard to measure
  • Low volume (not worth complexity)
In Production: Choose cascading when cost pressure is high and confidence signals are trustworthy; otherwise prefer simplicity.

TOON for Token-Efficient Context

Why: For uniform arrays of objects with primitive fields, TOON reduces token usage (often 30-60% vs JSON) and is easy for LLMs to parse. When TOON excels:
  • Uniform tabular arrays (same keys, primitive values).
  • Large lists where repeated JSON keys dominate cost.
When to prefer JSON:
  • Mixed/nested structures, varying field sets, or complex types.
Example (input as TOON): Full runnable TOON notebook
Prompting the model to output TOON:
Practical exercise: Convert your JSON examples to TOON and compare input token counts and task accuracy. See: TOON repository and official site/spec