Cost Control for LLM Apps: Caching, Routing and Token Budgets
Cost control for LLM apps: caching, model routing and token budgets. A worked example shows how the three levers cut a $10,140 monthly bill to about $2,416.
By Galactic News Editorial · Published 2026-11-23T14:02:50+00:00 · Updated 2026-11-23T14:02:50+00:00
Cost Control for LLM Apps: Caching, Routing and Token Budgets
Language model bills do not grow the way server bills grow. A small prompt change can triple the cost of every request. A loop in an agent can burn a month's budget in an afternoon. Cost control for LLM apps is therefore an architecture job, not a finance review.
Three levers do most of the work: caching, model routing and token budgets. This guide explains each one, shows how they combine, and gives a checklist for putting them into production.
Know your unit economics first
Cost per request is input tokens times the input price plus output tokens times the output price. But input is really three different things, priced differently: a cacheable prefix that repeats on every request, dynamic input that changes each time, and output, which usually costs several times more per token than input.
That split matters because each lever targets a different part. Caching cuts the price of the repeated prefix. Routing cuts the price of the whole request by using a cheaper model. Budgets cap the total before the call happens.
Before pulling any lever, measure where the tokens go. Log token counts per component, not just per request. The fix usually becomes obvious once you see it. Common bloat includes tool definitions for tools the request will never use, retrieved context with a high top-k, the full conversation transcript resent on every turn, raw API payloads passed back to the model, and output with no cap and a verbose default style.
One worked example shows the scale. A support assistant handling 20,000 requests a day, each with a 2,500-token prefix, 3,700 tokens of dynamic input and about 450 tokens of output, cost about $10,140 a month on a single large model at list prices checked in October 2026. Caching the prefix at a 90 percent hit rate cut that to about $7,650. Routing 60 percent of traffic to a small model cut it to about $3,294. Trimming retrieved chunks and capping output brought it to about $2,416. The same three levers, applied in order, removed three quarters of the bill.
Caching: stop paying for the same intelligence twice
Prompt caching changes the price of the repeated prefix only. On Anthropic's list prices, writing a prefix to the five-minute cache costs 1.25 times the base input price, and reading it back costs 0.1 times on most models. Caching pays for itself after a single cache read. Cache-read rates differ by model, so check the price list for each model you use.
Three kinds of cache cover most apps. An exact-match response cache stores answers to identical prompts. A semantic cache stores answers to near-identical prompts, matched by meaning rather than wording. A retrieval cache stores the results of repeated searches so the same documents are not fetched and re-read on every request.
Caching matches on the prefix, so order the prompt from most stable to least: system prompt, tool definitions, long reference documents, then the per-request part. A single timestamp or user name at the top of the system prompt silently breaks every cache hit. Keep the variable parts at the end.
The 90 percent hit rate in the example above is an assumption, not a guarantee. It holds for a busy prefix requested well inside the cache lifetime. A feature that sees a request every ten minutes will miss a five-minute cache almost every time. Measure the hit rate from your provider's usage fields rather than guessing it.
Routing: the cheapest model that meets quality
Default to small. Escalate only when signals justify it. If you do not encode that rule in a router, your system will drift toward always using the large model.
A simple three-tier policy works well. A small model handles classification, rewriting, summarisation, extraction and tool-argument shaping. A medium model handles normal questions and grounded responses with limited context. A large model handles complex reasoning, multi-step synthesis, ambiguous tasks and high-stakes language.
Two routing patterns work in practice. Rules route on cheap signals: input length, detected intent, customer tier. A cascade sends everything to the small model first and escalates when its output fails a check, such as schema validation, a low grounding score, or an explicit statement of uncertainty. Cascades cost a second call on escalation, so they pay off when most traffic stays small.
Routing is a quality decision, not just a cost decision. In the worked example, routing 60 percent of traffic to the small model removed over 40 percent of the bill on its own, because the small model cost a twentieth of the large one per token. But that saving is only real if quality holds. Run routing changes through your eval set before you bank the saving, and keep measuring quality on both paths after launch, because the traffic mix drifts.
Token budgets: treat tokens like CPU and memory
Budgeting is not setting max_tokens. You need three budgets: a context budget for input tokens, an output budget for output tokens, and a tool budget for calls and iterations. Define a request budget per feature tier, with a maximum input token count, a maximum output token count, a maximum tool call count, and a maximum cost per request.
The key design choice is that exceeding the budget is a hard circuit break, not a warning. If the allocation exceeds the ceiling, you do not call the model. Tie the completion cap directly to the max_tokens parameter you send to the API. The model will not exceed it, but you also need to budget for it on the input side: total equals input tokens plus max_tokens.
Practical patterns keep prompts inside budget. Add explicit constraints that reduce verbosity, such as at most six bullets and no preamble. Use a cheap first pass to summarise or extract, then reason over the compressed result. Trim retrieved context by lowering top-k after checking recall, and summarise conversation history instead of resending the full transcript.
Watch the hidden overhead too. Anthropic documents a tool-use system prompt it adds automatically whenever tools are present, 286 tokens on one of its models, on top of your tool names, descriptions and schemas. On a short request that overhead can be a large share of the input.
Batching and the async lever
Anything that does not need an answer in seconds can go through a batch API. Nightly classification, eval runs, backfills and bulk summaries are the usual candidates. OpenAI's Batch API is 50 percent cheaper than its synchronous endpoints and completes within 24 hours. Anthropic lists batch requests at 50 percent off as well, and says its batch and caching discounts stack.
In the worked example, a nightly job summarising 20,000 tickets cost about $165 a month synchronously and about $82 a month through the batch API. The saving is small in absolute terms, but batch work is also the easiest to schedule off-peak, which keeps it out of the way of live traffic.
Attribute, alert and enforce
Tag every request with the feature, team and customer it serves, so spend can be grouped any way finance asks. Then use three kinds of rule, from soft to hard.
Warn at 80 percent of a monthly budget and enforce at 100 percent, by downgrading to the small model or rejecting new requests. Alert on drift: if cost per request rises more than about 30 percent above its seven-day median, a prompt or retrieval change made every request dearer. A prompt edit that adds 2,000 tokens to every request will not breach a monthly budget for weeks, but it shows up in cost per request the next day.
Per-user caps belong here too. Uncapped usage is a security problem as much as a cost one. Gateways such as LiteLLM and Portkey can enforce budgets per key before a request reaches the provider.
Enforce budgets before the call, not after. Recording usage after the fact tells you what went wrong but does not prevent it. Check the budget before the request, using an atomic counter such as a Redis counter, so concurrent requests cannot slip past the limit together.
LLM app cost control caching routing token budgets: minimal versus production-grade
| Aspect | Minimal | Production-grade |
|---|---|---|
| Visibility | Total spend | Per request, per feature, per component |
| Caching | None | Stable prefix first, hit rate measured |
| Models | One for all | Routed or cascaded, quality tracked per path |
| Async work | Synchronous calls | Batch API for anything non-urgent |
| Limits | None | Capped output, context and per-user usage |
| Budget | Reviewed quarterly | Warn at 80%, enforce at 100%, alert on drift |
Bottom line
Cost control for LLM apps rests on three levers and one habit. Cache the repeated prefix, route each request to the cheapest model that meets the quality bar, and cap every request with a token budget enforced before the call. Move non-urgent work to the batch API. Then measure cost per request, per feature and per user, and alert on drift before the bill arrives.
Start with measurement. Log tokens per component for one week. The biggest lever will be obvious, and the saving will be real instead of guessed.