LLM Cost Optimization: 10 Techniques to Cut Your AI Bill
Reduce LLM API costs without hurting quality: model routing, prompt caching, shorter prompts, output limits, batching, semantic caching and measurement.
Published December 1, 2026
LLM features that cost cents in a demo can cost thousands per month at scale. The good news is that most applications have plenty of savings available without degrading quality. The key is to measure cost per feature first, then apply the techniques with the biggest impact for your traffic pattern.
The concept
Cost is roughly (input tokens × input price) + (output tokens × output price), summed over every call, including retries, agent steps and evaluations. Savings come from three directions: use cheaper models where they are good enough, send fewer tokens per call, and make fewer calls.
Always pair cost work with evals. A cheaper model or shorter prompt is only a win if quality stays within your acceptable range, so measure both on the same dataset before and after each change.
Techniques
| Technique | Typical impact | Watch out for |
|---|---|---|
| Route easy tasks to small models | Large | Validate quality per route |
| Prompt caching for stable prefixes | Large for repeated context | Keep prefixes identical |
| Trim prompts and tool results | Medium | Do not drop needed context |
| Limit output length / ask for concise formats | Medium | Truncated answers |
| Batch APIs for offline jobs | Medium (discounted pricing) | Higher latency |
| Semantic caching of answers | Varies | Stale or wrong cache hits |
| Fewer agent steps (better tools/context) | Medium-large | Needs redesign |
| Self-host for steady high volume | Varies | Ops and GPU costs |
Stacking savings
How to approach it
- Instrument cost per feature and per request
- Find the top 3 features by spend
- Try a cheaper model on their eval sets
- Cache stable prefixes; trim inputs and outputs
- Re-measure quality and cost; repeat
Practical examples
Measure cost per feature first
Aggregate usage logs.
SELECT feature, SUM(cost_usd) AS spend, COUNT(*) AS calls, AVG(in_tokens) AS avg_in
FROM llm_calls WHERE ts > now() - interval '30 days'
GROUP BY feature ORDER BY spend DESC LIMIT 10;Use a batch API for offline work
Many providers discount asynchronous batch jobs.
# write one request per line, submit as a batch, poll for results later
{"custom_id": "doc-1", "body": {"model": "fast", "messages": [{"role": "user", "content": "Summarise: ..."}]}}
{"custom_id": "doc-2", "body": {"model": "fast", "messages": [{"role": "user", "content": "Summarise: ..."}]}}Ask for compact output
Output tokens are usually the most expensive.
Return JSON only, no explanation: {"category": ..., "priority": ...}Common mistakes
- Optimising without per-feature cost data.
- Switching to a cheaper model without running evals.
- Agent loops with no step limits.
- Including large unchanged documents on every call without caching.
Key takeaways
- Measure cost per feature before optimising.
- Model routing and prompt caching usually give the biggest wins.
- Trim inputs and constrain outputs.
- Validate every change with evals.
FAQ
Are output tokens more expensive?
With most providers, yes, often several times the input price, which is why concise output formats save money.
What is semantic caching?
Returning a stored answer for a new query that is semantically similar to a previous one. It saves calls but needs careful thresholds to avoid wrong answers.
Should I fine-tune to save money?
Fine-tuning a small model can replace a large one for a narrow task at high volume, but include training and evaluation costs in the comparison.