Model Routing Strategy
Not every query needs the most expensive model. Routing queries to the most cost-effective model that can still meet the quality bar is one of the highest-leverage cost levers available at the architecture level.
User Query
│
▼
┌───────────────────┐
│ Query Classifier │ (fast, cheap model or rule-based)
│ Complexity: ? │
└────────┬───────────┘
│
┌────┼──────────────┐
▼ ▼ ▼
Simple Medium Complex
│ │ │
▼ ▼ ▼
Cheapest Mid-tier Strongest/most
model model capable model
Classification criteria (typical enterprise distribution):
- Simple (~70% of queries): FAQ, simple extraction, classification → cheapest model.
- Medium (~25%): standard RAG, summarization, code explanation → mid-tier model.
- Complex (~5%): multi-step reasoning, complex analysis, creative generation → strongest model.
Because per-token cost differences between tiers are commonly 10-30x, routing even a modest majority of traffic to the cheapest adequate tier produces dramatic blended cost reduction versus a flat “always use the best model” policy, often 85-90%+ savings versus an all-premium baseline while preserving quality on the traffic that actually needs it.
Token Optimization Techniques
- Prompt compression — remove redundant instructions, tighten system prompts, strip boilerplate that doesn’t change model behavior.
- Context window optimization — retrieve and include only the most relevant chunks, not the maximum allowed context; more context is not free and is not always better for quality.
- Output length control — set
max_tokensappropriately per query type rather than a single global default; uncapped or over-generous limits waste tokens on padding. - Caching — exact-match and semantic caching of identical/similar queries.
- Batching — batch/asynchronous APIs typically offer substantial discounts (often ~50%) for non-real-time workloads.
- Streaming — lets users stop reading (and generation) early once they have their answer, saving otherwise-wasted output tokens.
Caching Strategy Detail
Exact Cache: Hash(query + parameters) → cached response
Hit rate: ~15-20% for enterprise Q&A
Implementation: Redis with TTL
Semantic Cache: Embed(query) → find similar cached queries → return if similarity > 0.95
Hit rate: ~30-40% for repetitive workloads
Implementation: Vector DB with similarity threshold + Redis for response payloads
Inference-Level Cost Optimization (Self-Hosted Models)
| Technique | Mechanism | Typical Impact |
|---|---|---|
| Quantization | Reduce model precision (FP16 → INT8 → INT4) | 2-4x cost reduction |
| Efficient inference engines (e.g., PagedAttention-based serving) | Optimized memory management for serving | 2-4x throughput improvement |
| Dynamic batching | Batch concurrent requests for better GPU utilization | Better hardware utilization, lower cost per request |
| KV-cache optimization | Reduce memory overhead for long-context inference | Enables higher concurrency at the same hardware footprint |
| Speculative decoding | Small model drafts, large model verifies | 2-3x latency speedup |
Data Pipeline Cost Optimization
- Incremental embedding: only re-embed changed documents, not the whole corpus on every update.
- Embedding deduplication: don’t re-embed identical or near-identical chunks.
- Off-peak batch processing: schedule non-urgent jobs during lower-cost compute windows.
- Tiered storage: hot vectors in memory, warm in SSD-backed storage, cold in low-cost object storage.
Worked Example: Reducing a Large Monthly LLM Spend
Scenario: A system spending significantly on LLM API calls per month needs cost reduced without degrading quality.
Step 1 — Analyze current spend: categorize queries by type/complexity, measure input/output token usage per query type, identify the top cost-driving features/endpoints.
Step 2 — Quick wins (1-2 weeks):
- Semantic caching (typically 30-40% reduction)
- Prompt optimization — shorter system prompts, remove redundant instructions (10-20% reduction)
- Output length control per query type (5-15% reduction)
- Query deduplication (catch retry/UI-bug-driven duplicate requests)
Step 3 — Model routing (2-4 weeks): classify by complexity, route the bulk of simple queries to the cheapest adequate model, reserve the most expensive model for the small complex-query tail. Expected additional savings: 60-70%.
Step 4 — Architecture optimization (1-2 months): pre-compute answers for top FAQ questions, use batch APIs for non-real-time requests, consider self-hosting an open-source model for high-volume simple tasks, add a retrieval-confidence gate that skips the LLM entirely when retrieval confidence is very high and the answer is directly extractive.
Typical combined outcome: 60-75% total cost reduction while holding or improving quality metrics, because much of the savings comes from routing away from unnecessary use of the most expensive model rather than from degrading any individual response.