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

TechniqueTypical impactWatch out for
Route easy tasks to small modelsLargeValidate quality per route
Prompt caching for stable prefixesLarge for repeated contextKeep prefixes identical
Trim prompts and tool resultsMediumDo not drop needed context
Limit output length / ask for concise formatsMediumTruncated answers
Batch APIs for offline jobsMedium (discounted pricing)Higher latency
Semantic caching of answersVariesStale or wrong cache hits
Fewer agent steps (better tools/context)Medium-largeNeeds redesign
Self-host for steady high volumeVariesOps and GPU costs

Stacking savings

Baseline$10,000/month+ routing$5,500+ caching$3,800+ trimmed context$3,000
Illustrative cumulative savings for a support assistant.

How to approach it

  1. Instrument cost per feature and per request
  2. Find the top 3 features by spend
  3. Try a cheaper model on their eval sets
  4. Cache stable prefixes; trim inputs and outputs
  5. Re-measure quality and cost; repeat
A cost optimisation loop.

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.

More AI articles