The LLM bill nobody forecast: seven levers for cutting inference cost
Training ends. Inference bills on every request, for as long as the product exists. Here are the levers that actually reduce it, in the order we reach for them.
· updated
Why the forecast was wrong
The cost model that gets built during a pilot almost always underestimates production, and the reason is structural rather than careless. A pilot has a handful of users, short prompts, and no retries. Production has traffic skew, conversation histories that grow, retrieved context stuffed into every request, and retry logic that occasionally loops.
The number that matters is cost per thousand predictions at expected volume, and it should be calculated before the architecture is fixed rather than discovered on an invoice. See inference for why this dominates the lifetime cost of a machine learning system.
The levers below are ordered roughly by return on effort. The first two are where most of the savings usually are, and they are the two most often skipped.
1. Use a smaller model
The largest available model is the default choice and usually the wrong one. Most production tasks are narrow: classify this ticket, extract these fields, rewrite this into that format, decide whether this document is relevant. Narrow tasks rarely need frontier reasoning.
The way to find out is an evaluation set of real inputs with known good outputs. Run the small model against it. Teams are routinely surprised — a model a fraction of the size and price frequently matches the large one on the specific job, because the job never required the capability they were paying for.
Where the small model falls slightly short, light fine-tuning often closes the gap. LoRA adapters are cheap to train, produce a small artefact, and can be served against a shared base model. A fine-tuned small model beating a general large one on a narrow task at a fraction of the cost is a common outcome, not an optimistic one.
2. Cache, because traffic is skewed
Real request distributions have heavy heads. A meaningful share of queries to any support or search system are repeats or near-repeats.
Exact-match caching is trivial to implement and catches the literal repeats. Semantic caching catches near-duplicates by embedding the incoming query and returning a cached response when it is close enough to a previous one — set the similarity threshold conservatively, because a wrong cache hit is a wrong answer.
Prompt caching is the one most teams are leaving on the table. If every request begins with the same long system prompt, instructions, and few-shot examples, providers can cache that prefix so you are not paying to process it repeatedly. Structuring prompts so the stable part comes first and the variable part last is a small change with a direct effect on the bill.
3. Stop sending so much context
Attention cost grows with the square of sequence length, and you are billed on tokens. Long prompts are expensive twice.
The frequent offender is retrieval that returns too much. If you are putting 20 passages in the prompt because retrieval quality is uncertain, the fix is better retrieval — a reranker returning 5 good passages instead of 20 mediocre ones cuts token cost by roughly three quarters while improving answer quality, because the model is no longer distracted by irrelevant context.
Conversation history is the other. Sending an entire thread on every turn grows cost linearly with conversation length. Summarise older turns, or keep a rolling window plus a compact running summary.
4. Route by difficulty
Not every request needs the same model. A cascade sends everything to a small cheap model first, and escalates to the expensive one only when the small model's confidence is low or a validation check fails.
Tuned well, this preserves most of the quality at a substantial fraction of the cost, because the difficult minority is genuinely a minority. The engineering cost is a routing layer and a confidence signal you trust — which is why this comes after the simpler levers rather than before them.
5. Batch anything that can wait
Real-time serving is assumed far more often than it is needed. If a prediction is not being waited on by a user or a transaction, batch it — and the saving is commonly an order of magnitude, because hardware runs at high utilisation instead of sitting idle against peak capacity.
The test is simple: identify what changes between a scheduled run and the moment of use, and ask whether that change would produce a different decision. Risk scores, segment assignments, propensity models, and content classification usually pass. Providers also offer discounted asynchronous batch tiers for exactly this. See batch vs real-time inference.
6. Constrain the output
Output tokens typically cost several times more than input tokens, so verbose responses are expensive in a way that is easy to miss.
If you need structured data, use the provider's structured-output or JSON-schema mode rather than asking for JSON in prose — it is more reliable and it stops the model wrapping the answer in explanation you will discard. Set sensible maximum token limits. And where you have asked the model to reason step by step, check that you still need it; on current reasoning-tuned models, explicit chain-of-thought instructions often add tokens without adding accuracy.
7. Put a limit on the loop
The failure that produces genuinely alarming invoices is not steady traffic. It is an unbounded retry or agent loop meeting a long context — a request that fails validation, gets retried with the error appended, fails again, and repeats with a prompt that grows each time.
Every loop needs a hard iteration cap, a per-request token budget, and a timeout. Set spend alerts at the provider, not just at your cloud. And log token counts per request so a cost regression is visible in a dashboard rather than at the end of the month. If you are building anything agentic, this is not optional — see AI agents.
One last piece of sequencing advice: build the evaluation set before you start optimising. Every lever here trades something, and without a way to measure output quality you cannot tell whether a saving was free or whether you quietly shipped a worse product.
Related questions.
What is the fastest way to reduce LLM costs?
Test whether a smaller model does the job. Build an evaluation set of real inputs with known good outputs and run the cheaper model against it — on narrow production tasks it frequently matches the large one at a fraction of the price. After that, prompt caching over a shared system prefix is usually the next largest saving for the least engineering effort.
Does quantisation reduce inference cost?
Yes, if you are self-hosting. Serving weights at 8-bit or 4-bit instead of 16-bit cuts memory and speeds up generation, because inference on large models is typically bandwidth-bound. Eight-bit is usually near-free in quality terms; 4-bit is normally a good trade with a calibrated method. Measure the loss on your own evaluation set, since degradation hits reasoning and precise formatting before it hits fluency. It does not apply to hosted APIs, where you pay per token regardless.
How do I stop unexpected LLM cost spikes?
Cap the loops. Set hard maximum iterations on any retry or agent loop, a per-request token budget, and a timeout — unbounded loops meeting a growing context are what produce the genuinely bad invoices. Then add provider-level spend alerts and log token counts per request so a regression shows up in a dashboard within hours rather than on a monthly bill.
Concepts referenced here.
Inference
Inference is the act of running a trained model on new input to produce a prediction, and because it happens on every request it u…
ReadQuantisation
Quantisation reduces the numerical precision used to store a model's weights and activations, shrinking memory footprint and speed…
ReadFine-Tuning
Fine-tuning continues training a pretrained model on a smaller task-specific dataset so that its weights adapt to your format, ton…
ReadAI Agent
An AI agent is a language model placed in a loop with access to external tools, so that it can decide on an action, observe the re…
ReadWorking on this
right now?
We build and ship production machine learning. If this maps to a problem in front of you, tell us about it.
Start the conversationor write to us at [email protected]