trialswithai
Essay systems

Cutting LLM inference cost without losing quality

Inference cost is a measurement problem first. Lock the quality metric, then trim context, route steps to a cheaper model and cache the stable prefix.

Essay · systems Cutting LLM inference costwithout losing quality5 min · systems
TL;DRthe 30-second version
  • Lock a quality baseline in CI before you cut anything. Without it, a cost saving and a quietly worse product look identical.
  • Three levers, in the order to try them: send the model less context, route the cheap steps to a cheaper model, and cache the stable prefix.
  • How much each lever saves depends on your token mix. In a RAG pipeline the retrieved context is usually most of the bill, so trimming it tends to come first.
  • The step with the biggest per-call cost, grounded synthesis, is the most tempting to move to the cheap model and the one most likely to fail the quality gate.

The bill is the part nobody demos. You ship the feature, everyone’s pleased, and then the first full month of usage lands and the inference line on the invoice is large enough that someone in finance learns your name. That’s a good problem, because it means people are using the thing, but it’s a problem with a deadline.

For me it was a projection more than one invoice. Usage was climbing the way you want it to, and when I drew inference cost forward along that curve, the line went somewhere nobody had budgeted for. Each question fanned out into several model calls: an intent step, a query-generation step, and a synthesis step over a pile of retrieved context. So a question cost several times what the synthesis call alone suggested, and the total scaled with adoption.

The naive options were both bad: cap usage and slow adoption, or absorb the cost and watch margin shrink as traffic grows. The useful answer is to serve the same quality for less, and the only way to claim that is to define “same quality” before you start cutting. Otherwise you’re trading accuracy for money and calling it optimisation.

Lock the quality floor first

Before touching cost, fix a quality baseline: the eval set you already run in CI, scored against hand-labelled ground truth, plus a breakdown of where any regression lands (which stage, which kind of question). Then set the rule. A cost change ships only if the metric stays above its bar and the breakdown doesn’t shift.

Without that gate, any cost number is meaningless, because the easiest way to cut inference cost is to make the output worse and hope nobody measures it. Every lever below gets judged against the baseline, never against a feeling that the answers still look fine.

The levers, in the order to try them

Send the model less context. In a RAG system the input is the bill: the retrieved context dwarfs the question and the answer. So the work that pays most is assembling less context without losing the parts that matter. Put a hard token budget on the bundle, give each source a cap so no single one crowds out the rest, and deduplicate by content hash so a chunk fetched two ways isn’t paid for twice. The tuning is all in the budget: too tight and quality drops, too loose and you’re paying for noise. Tune it against the quality set.

Route the cheap steps to a cheap model. Most steps don’t need your most expensive model. Intent classification and turning a question into a structured query are usually fine on a small model. Synthesising the grounded answer is the step that rewards the big one. The price gap is large: on Anthropic’s current list, Haiku 5.5 input costs $0.10 per million tokens against $2 for Sonnet 5.5, a factor of 20. Move each step down a tier only after the quality gate confirms it holds.

Cache the stable prefix. Much of every call is identical from request to request: system instructions, the schema the model needs to write a valid query, the few-shot examples. Re-sending that at full price is pure waste. With prompt caching, a cached prefix on Sonnet 5.5 is billed at $0.10 per million tokens, 5% of the normal input price, and on Haiku 5.5 at $0.01. Writing to the cache costs 1.25× the input price, and the prefix has to be at least 512 tokens or it silently won’t cache. Because the cached bytes are identical, this one costs nothing in quality.

Try your own numbers. Each lever stacks on the ones before it:

What one question costs, lever by lever

per 1,000 questions · your inputs
Your token mix
Levers

Fig. 1 Cost per 1,000 questions for the three-call pipeline, from Anthropic's published prices (14 Nov 2026). Baseline: every call on Sonnet 5.5, full context, no cache. Fixed per question: a 50-token question and 10, 60 and 250 output tokens for the three calls. Caching assumes a warm cache, so cache writes (1.25× input) are ignored.

Play with the sliders and the order of the levers changes. A long retrieved context makes trimming dominant. A long system prompt with short contexts makes caching worth more. A prefix under 512 tokens makes caching worth nothing. That’s why any “we cut cost X%” number belongs to one system’s token mix, and why yours needs measuring.

The lever that usually isn’t worth it

The tempting next move is routing synthesis to the cheap model too. It’s where the biggest per-call cost lives, so the saving looks huge on paper: tick the last box in the calculator and watch the bar collapse.

It’s also the step that does the work your users came for. Grounded synthesis over several retrieved passages is where a smaller model can drop a citation, merge two facts or answer from memory, and those are the failures users notice. This is the change your quality gate exists to catch. Let the gate decide.

Measure it on your own system

The calculator shows how the levers interact, but your token mix, traffic and quality bar decide what each one is worth. costcut is a small open harness for measuring exactly that: it runs the same intent, query and synthesis pipeline on a public dataset, applies each lever, and scores it against a quality gate written down before any lever runs.

The takeaway

Inference cost optimisation is a measurement problem wearing an optimisation costume. The techniques are well known and most of them work. What separates a real saving from a fake one is whether you fixed the quality metric before you started cutting, so that “the savings are real” is something you can prove. Define the floor first. Then go find the waste.

References

  1. Anthropic. Pricing (model, cache-write and cache-read rates; checked 14 Nov 2026).
  2. Anthropic. Prompt caching (minimum cacheable prompt length, cache lifetimes).
  3. costcut: an open harness for measuring these levers against a pre-registered quality gate.