Free shipping on orders over $99 · Use code LEARN26 for 10% off
Free Trial available for 5 days!4.9 star average ratingFree chapter every monthShipping to 120+ countries Free Trial available for 5 days!4.9 star average ratingFree chapter every monthShipping to 120+ countries
Support · Partner
Get the full year subscription for unlimited reading — 2 months freeBuy a 3-book bundle — 20% off each book!
Back to the blog
LLM Engineering10 min read

LLM Engineering: Cutting Token Costs 60% Without Losing Quality

Most LLM bills are bloated by habits, not by necessity. Here are the levers that cut cost dramatically while keeping — sometimes improving — output quality.

The first production LLM bill is always a shock. A feature that cost pennies in testing costs thousands at scale, and the instinct is to panic or to rip the feature out. Neither is necessary. Most LLM spend is not buying quality — it is paying for habits: prompts stuffed with redundant context, a flagship model answering trivial questions, and identical requests billed again and again. Fix those and a 60% reduction is routine, often with no drop in output at all.

Where the money actually goes

You are billed per token, split into input (everything you send — system prompt, context, history, the user question) and output (what the model generates). Input tokens are cheaper per unit but there are usually far more of them, because teams pile context into every request "just in case". The result is that most bills are dominated by input tokens the model did not need.

Redundant context in prompts 38% Flagship model on easy tasks 27% Re-answering identical requests 21% Genuinely necessary generation 14%
Only a small slice of a typical bill is buying irreplaceable value. The rest is habit.

Trim the prompt, not the quality

The largest, easiest saving is usually the prompt itself. Teams append the entire conversation history, a giant system prompt, and pages of retrieved documents to every single call. Much of it is never used by the model to answer the specific question in front of it.

Send only what the current question needs. Summarise old conversation turns instead of replaying them verbatim. Retrieve three relevant passages, not thirty. A tighter prompt is not just cheaper — it is frequently better, because a model given a focused context is less likely to be distracted by irrelevant material into a worse answer.

Before and after: the same request# Before: 4,200 input tokens every call
prompt = system_prompt + full_history + all_20_docs + question

# After: ~900 tokens, and often a sharper answer
prompt = short_system + summarise(history) + top_3_docs + question
# ~78% fewer input tokens, quality held or improved
Coming soon: Generative AI & AgentOpsBuild agents that survive real users. Get 20% off at launch.
Notify me — save 20%

Route by difficulty

The second big lever is refusing to send every request to your most expensive model. Most applications have a mix of trivial and hard queries, and a small, cheap, fast model handles the trivial ones perfectly. Classify the incoming request — often the cheap model itself can judge — and escalate to the flagship only when the task genuinely needs it.

1 Request in classify difficulty 2 Easy? small cheap model 3 Hard? flagship model 4 Escalate only on low confidence
A cascade sends the bulk of traffic to the cheap model and reserves the expensive one for the queries that earn it.

In most real workloads the majority of requests are easy, so routing them to a model that costs a fraction as much drops the bill sharply while the hard queries — the ones users actually judge you on — still get the flagship treatment.

Cache the repeated work

The third lever is refusing to pay twice for the same answer. Real traffic is repetitive: the same questions, the same document summaries, the same system prompt on every call. Cache aggressively. An exact-match cache handles identical requests for free. A semantic cache goes further, returning a stored answer for a question that means the same thing even if it is worded differently. And many providers now offer prompt caching for the static portion of your prompt, so you are not re-billed for the system prompt on every request.

The compounding win

These levers multiply. Trim the prompt by 70%, route half your traffic to a model that costs a tenth as much, and cache a third of requests, and you are well past a 60% reduction — without touching the quality your users actually see.

Measure before you optimise

None of this should be guesswork. Before optimising, instrument cost per request, tokens in and out, and a quality signal — because the one rule of cost-cutting is that you must prove quality held. It is trivial to make an LLM feature cheaper by making it worse; the skill is making it cheaper while keeping it just as good. Track a small evaluation set through every change, so when you trim a prompt or reroute traffic you can see immediately whether answers got worse.

Approached this way, LLM cost is not a tax you pay for using AI — it is an engineering variable you control. The teams with sustainable AI features are not the ones who found a secret cheap model. They are the ones who stopped paying for tokens that were never buying them anything.

Control the output, not just the input

Most cost advice focuses on the prompt, but output tokens are billed at a premium and are just as controllable. A model told to "explain in detail" will happily produce eight hundred tokens where eighty would do. Be explicit about length: ask for a single sentence, a JSON object, a yes-or-no, whatever the downstream code actually needs. Set a maximum token limit as a hard backstop so a runaway generation cannot blow your budget on one request. And where you only need a structured value — a category, a score, a boolean — constrain the model to produce exactly that rather than a paragraph you then have to parse. Tightening output is often the fastest saving of all, because you are cutting the expensive tokens rather than the cheap ones.

The trap of premature optimisation

One caution before you start slashing. Do not optimise a feature nobody uses yet, and do not trade away quality on the requests that matter most to chase a cheaper bill. The goal is not the lowest possible spend; it is the lowest spend that preserves the experience users judge you on. That means segmenting your traffic: the high-stakes requests — the ones where a wrong answer costs a customer — can justify the flagship model and a generous context, while the long tail of low-stakes queries is where aggressive cost-cutting belongs. Applied bluntly, optimisation makes everything slightly worse to save money. Applied with judgement, it makes the cheap requests dramatically cheaper and leaves the important ones untouched. That judgement — knowing which requests deserve to be expensive — is what separates an engineer who cuts costs from one who just degrades the product.

Treat cost as a first-class engineering metric, tracked on a dashboard next to latency and quality, and it stops being a quarterly surprise and becomes a number you steer. The teams running sustainable AI features review it weekly, catch regressions early, and know exactly which lever to pull when the graph ticks up. That habit — watching the cost as deliberately as you watch the errors — is what keeps an AI product alive long enough to matter.

Python data work on one printable page — $9.99

The idioms you reach for every day, in one place instead of ten browser tabs. Printable PDF, $9.99, free updates for life.

Grab it for $9.99