Production and case studies
Latency and cost optimization
Streaming, routing, cascades, batching and parallelism: making LLM apps fast and affordable without dropping quality.
An LLM request is not a database query. You pay for every input and output token, and wall-clock time is dominated by how many tokens you send, how many you generate, and which model does the work. A support bot that feels snappy at ten users can burn a six-figure monthly bill at a million conversations if you never measure cost per successful task.
Latency and cost are the same knobs once you treat quality as a hard constraint. Optimize accuracy first. A cascade that deflects the wrong tickets destroys CSAT faster than it saves API spend. Gate every cost change on your eval suite.
Concept
A token is a chunk of text the model processes, roughly 3 to 4 characters of English, or about 0.75 words. Pricing and context limits are in tokens, not characters. See tokens.
A support bot at 1M conversations per month
Assumptions for planning, not a quote: 1,000,000 conversations per month, 3 model turns each, mid-tier $3 / M input and $15 / M output. Baseline: 3,500 input tokens plus 300 output tokens per turn, no cache, no routing.
Turns/month = 1e6 × 3 = 3,000,000
Input tokens = 3e6 × 3,500 = 10.5e9 → $31,500
Output tokens = 3e6 × 300 = 0.9e9 → $13,500
Total ≈ $45,000 / month → $0.045 / convoCut input to 1,400 and output to 180 (RAG plus shorter answers) and the bill drops to about $20,700 (−54%). Add prompt caching at an 80% hit rate on 1,000 of those 1,400 tokens, with cached reads at ~10% of base input, and you land near $14,220 (−68%). Route 75% of turns to a small model at about $0.40 / $1.60 per million and the blend can approach $5,500 (−88%), or about $0.0055 per conversation.
The structure matters more than the exact discount: tokens × price tier × cache hit rate. A human support interaction often costs several dollars fully loaded. At roughly $0.01 to $0.05 model cost you still have room for tooling and gross margin, but only if you keep measuring.
Concepts in this section
| Step | Concept | What it answers |
|---|---|---|
| 1 | LLM latency metrics | What do I measure before I change anything? |
| 2 | Streaming for perceived latency | Why does the first token matter more than the last? |
| 3 | Reducing LLM tokens | What is the cheapest latency win? |
| 4 | Model routing and cascades | When does a smaller model take the easy traffic? |
For prompt-prefix reuse, see caching. For GPU-side math, see cost per token. Offline jobs belong on batch LLM APIs, often about 50% off sync prices as of when this was written.
Walk this list, in order
- Is quality good enough on a fixed eval? If not, stop.
- What does the user wait on: first token, full answer, or job completion?
- Can you stream or show progress without changing the model?
- Can you remove tokens without hurting the eval?
- Can independent work run in parallel?
- Is there a detectable easy subset for a smaller model?
- Is the traffic interactive (sync plus prompt cache) or offline (batch)?
- Only then consider serving-side tricks or fine-tunes.
Most production wins stop at step 6.
Common mistakes
- Streaming TTFT while three serial tools run first. Users still wait. Move retrieval and account fetches ahead of generation.
- No
max_tokens. A "short answer" prompt still lets a reasoning model emit thousands of tokens. - Cascade ping-pong. If the small model always escalates, you pay for two calls. If escalate rate sits above about 40%, the router is wrong.
- Batch for interactive chat. You save money and destroy the product.
Key takeaways
- Instrument TTFT, tokens/s, end-to-end latency and cost per successful task.
- Stream for interactive UX. Cut tokens before exotic serving tricks.
- Route or cascade only when evals show a detectable easy/hard split.
- Quality gates every optimization.
Further learning
Claude docs: Reducing latencyReduce Claude's response latency by choosing a faster model like Claude Haiku 5.5, trimming prompt and output tokens, and streaming responses.Claude Platform Docs
Related
LLM latency metrics
Measure TTFT, tokens per second, end-to-end latency and cost per successful task before you change the prompt or the model.
Caching for LLM apps
Prompt caching, exact-match and semantic caches: where each fits, and how to avoid serving the wrong answer.
The economics of inference
Turn $/GPU-hour into $/million tokens with utilization and throughput, then decide API vs self-host and price products with real margins.