The starting position
We cut LLM costs on one production system by about 64%, from roughly $18,000 to about $6,500 a month, with four changes: model routing, semantic caching, prompt compression and structured output. The client ran a document analysis product handling around 400,000 requests a month. Every request went to the largest available model with the full document in context. The bill kept rising with usage, and the unit economics of their pricing were getting more uncomfortable every month.
LLM cost optimization means lowering what a language-model application spends on tokens without lowering the quality of its output. The main levers are sending simple requests to cheaper models (routing), reusing answers to repeat questions (semantic caching), sending only the context the model needs (prompt compression) and removing retries caused by output that fails to parse (structured output).
The implementation wasn’t incompetent. It was built quickly to validate the product, and it worked. It just had no cost architecture, because at prototype volume there was no reason to build one.
What drives LLM costs?
Monthly LLM cost comes down to one formula: requests × (input tokens × input price + output tokens × output price) × (1 + retry rate). Every lever in this article shrinks one of those terms.
At $18,000 a month across 400,000 requests, this client paid about 4.5 cents per request on average. Routing lowers the price per token, caching lowers the number of requests that reach a model at all, compression lowers input tokens, and structured output lowers the retry rate. Because the savings compound, each lever is measured against what was left after the one before it.
Lever one: model routing
Not every request needs the strongest model. Their traffic split into classification and routing steps, straightforward extraction, and complex analysis. Only the third category got measurably better results from the largest model.
We added a routing layer that classifies each request and sends it to the appropriate tier. The classifier is itself a small, fast model that costs a fraction of a cent. About 60% of traffic moved to cheaper models with no measurable quality change against the evaluation set.
- Measured saving: monthly spend fell from $18,000 to about $11,160 (38% of the original bill)
Lever two: semantic caching
Their query log had a lot of near-duplicates. Different users asked essentially the same question about the same document, and individual users re-ran a query after a minor edit.
A semantic cache embeds each incoming query and returns a stored response when a similar enough query has already been answered against the same document version. The similarity threshold matters. Set it too loose and users get subtly wrong answers, so we tuned it conservatively against the golden set. The cache hit rate settled at around 22%.
- Measured saving: 18% of the remaining spend, taking the bill from about $11,160 to about $9,150
Lever three: prompt compression
Every request passed the whole document, often 40 pages, when the relevant content was two or three sections. This is the most common source of avoidable token spend we come across.
We added a retrieval (RAG) step before generation that selects the relevant passages and leaves the rest out. Average input tokens fell by about 71%, and answer quality went up slightly. We see that consistently: models reason better over focused context than over long documents with the relevant passage buried somewhere inside.
- Measured saving: 24% of the remaining spend, taking the bill from about $9,150 to about $6,955
Lever four: structured output
Outputs were free-form prose, and downstream code parsed them with regular expressions. When parsing failed the system retried, and every retry was duplicated cost.
Switching to enforced JSON schema output removed that failure mode. The retry rate fell from about 9% to under 1%. As a side benefit, the downstream code got a lot simpler.
- Measured saving: 7% of the remaining spend, taking the bill from about $6,955 to about $6,470
Which lever saved the most?
Routing did most of the work on this project. The table shows each lever’s saving as a share of the original $18,000 bill, so the rows add up to the total cut of about 64%.
| Lever | What it changes | Saving on this project | Main risk |
|---|---|---|---|
| Model routing | Price per token | About $6,840 a month (38%) | Quality drops on hard requests |
| Semantic caching | Requests that reach a model | About $2,010 a month (11%) | Wrong answers if the threshold is loose |
| Prompt compression | Input tokens per request | About $2,195 a month (12%) | The model misses context it needed |
| Structured output | Retry rate | About $485 a month (3%) | Little risk |
| All four together | Monthly bill | About $11,530 a month (64%) | Needs an evaluation set first |
The result, and one caveat
Together, these changes took monthly spend from roughly $18,000 to about $6,500, about 64% lower. Evaluation scores held steady and latency improved, since smaller models and shorter prompts both return faster.
The caveat is that none of this is safe without an evaluation harness. Each of these levers trades a little capability for cost, and without a golden set to score against, you’re guessing whether quality held. Build the evaluation first and optimise second.
We cover the retrieval side in more detail in how we build production RAG systems. If you want your own LLM spend reviewed, our AI consulting team runs this audit for a fixed price, agreed after a free discovery call.
What else can reduce LLM costs?
This client did not need them, but four more levers are worth checking on any system with a growing bill.
For what it costs to build an AI product in the first place, see how much AI development costs.
- Batch processing: work that can wait a few hours, such as overnight document runs, can go through the providers’ batch APIs at a lower price per token.
- Provider prompt caching: OpenAI, Anthropic and Google charge less for input tokens they have already seen, so a long system prompt that stays the same on every call gets cheaper.
- Output limits: a max-token cap on each request type stops the model writing three paragraphs where one line will do.
- Cost tracking per request type: when you can see which feature spends the money, you know which lever to pull next.
Frequently asked questions
Does routing to cheaper models hurt quality?
Not if you measure it. Base routing decisions on evaluation scores for each request type, because intuition is a poor guide here. Some categories show no measurable difference between a small model and a large one, and others degrade immediately. The evaluation set tells you which is which.
Is semantic caching risky?
It is if the similarity threshold is loose, because near-miss matches return confidently wrong answers. Tune it conservatively against a golden set, scope cache keys to the document version, and accept a lower hit rate in exchange for correct answers.
What is the first step to reduce LLM costs?
Start with prompt compression. Most systems pass far more context than they need, it is the easiest lever to ship, and it often improves answer quality as well as cost. Routing saved the most on this project, but build an evaluation set before you try it.
How much can you realistically cut LLM costs?
On systems that were never tuned for cost, we usually find savings of at least half. This one went from $18,000 to about $6,500 a month. Systems that already route and cache requests tend to have less left to save.
Working on something like this?
We build AI agents, AI automation and the web and mobile apps they run inside, for clients in the United States and Australia. A free 30-minute discovery call with an engineer, then a fixed-price quote.
Book a free discovery call