How to Control Rising LLM Token Costs: Routing, Context Budgets, and Caching
As new flagship models ship with updated tokenizers, the same text can be split into 1.0 to 1.35 times as many tokens, so bills rise even when published prices stay flat. This article breaks down why token counts grow, then lays out a four-layer cost governance framework (model routing, context budgeting and compression, caching and reuse, output control), the observability metrics to collect before optimizing, an evaluation-first approach with rollback switches, and a ten-item checklist you can start on this week.
1. The Symptom: A Hidden Price Increase in Flagship Model Upgrades
An AI research lab releases a new flagship model late at night. The price stays the same, but the model ships with a new tokenizer. The same text is now split into 1.0 to 1.35 times as many tokens as before. The per-token price has not changed, yet actual spending can climb by more than 30%. For developers, this is a classic hidden price increase: it never appears on the price list, it hides in the billing unit.
To understand this, start with the fact that a token is not a character. A token is the smallest unit of text the model processes, produced when a tokenizer splits text according to its vocabulary. The same meaning can yield noticeably different token counts under different tokenizers, especially for Chinese, code, uncommon identifiers, and mixed multilingual text.
The billing logic looks roughly like this (pseudocode, showing the billing model only):
billable_input = tokens(prompt + retrieved_context + history)billable_output = tokens(completion)cost = billable_input / 1e6 * price_in + billable_output / 1e6 * price_out
The key takeaway: cost is determined by token count multiplied by unit price. When the unit price holds steady, any change that inflates token count inflates the bill by the same proportion.
2. Root Causes: Why the New Tokenizer Costs More
- Vocabulary strategy changes. Finer-grained splitting generally improves coverage of rare characters, code symbols, and low-resource languages, at the cost of breaking common text into more pieces.
- Input inflation from added capability. Support for higher-resolution image input, longer context, and stronger multimodal understanding all lead each request to carry more information.
- Agentic call amplification. Once a model can self-verify over long tasks and reflect across multiple rounds, a single user request often maps to multiple model calls, so token consumption grows multiplicatively rather than additively.
- Coarse context management. Sending the full conversation history every time, passing retrieved snippets without trimming, and repeating long system prompts are the most common sources of waste.
3. A Cost Governance Framework: Optimize at Four Layers at Once
3.1 Model Tiering and Routing
Do not send every request to the strongest model. Build a dispatch layer that combines intent recognition, difficulty grading, and routing: simple classification, extraction, and formatting go to small models or a rules engine; only complex reasoning and long-chain planning get escalated to the flagship model.
def route(task):if task.kind in {"classify", "extract", "format"}:return small_modelif task.estimated_steps <= 2 and task.risk == "low":return mid_modelreturn flagship_model
In practice, make routing thresholds configurable and keep calibrating them with replayed production traffic, so a blanket downgrade does not quietly cost you quality.
3.2 Context Budget and Compression
Set a hard budget for every request. For example, the system prompt takes no more than 10% of the total budget, retrieved snippets no more than 40%, and history is kept via a sliding window or summarization. Put the stable, reusable prefix first so prefix caching can hit.
budget = 8000 tokenssystem <= 800retrieved <= 3200history <= 2000 (sliding window + summary)user_query <= remaining budget
Compression techniques include deduplication and near-duplicate merging, reranking by relevance before truncation, replacing source text with structured summaries, and turning long documents into a searchable index instead of stuffing in the whole thing.
3.3 Caching and Reuse
- Prefix caching: keeping a long, stable prompt at the beginning can significantly reduce repeated charges (the exact discount depends on the provider’s policy).
- Semantic caching: build a vector index for frequent, similar questions and return directly on a hit, which suits support and document Q&A scenarios.
- Result materialization: write summaries, labels, and embedding vectors that can be generated offline into object storage or a cache service, avoiding repeated computation.
3.4 Output-Side Control
Output tokens usually cost more per token. Constraining output length, requiring a compact structured format, and cutting unnecessary explanatory padding is one of the highest-leverage optimizations available.
Requirement: output JSON only, fixed fields, no extra explanation.{"label": "...", "score": 0.0, "reason": "<=30 chars"}
4. Observability: Measure First, Then Optimize
No measurement, no optimization. Collect the following metrics and wire them into your logging service and monitoring/alerting system:
- Input and output tokens per request, plus cache hit rate;
- Total calls and total latency per task;
- Cost per unit of business output (for example, cost per thousand tickets handled);
- Failure retry rate and downgrade rate.
metrics: tokens_in, tokens_out, cache_hit, calls_per_task, cost_per_task, retry_rate
Set budget alerts and quota isolation, splitting allocation by business line so a single experiment’s traffic cannot blow up the overall budget.
5. Quality Must Not Regress: Evaluation Comes First
Cost reduction cannot come at the price of collapsing quality. Run offline evaluation and online canary release in parallel: fix a set of real business samples, record pass rate, human spot-check pass rate, and hallucination rate, then run a regression comparison after every change to prompts, compression strategy, or routing thresholds. An optimization only counts if the metrics do not drop.
Also keep a rollback switch: model version, tokenization strategy, and context budget should all be switchable through configuration, so you can revert in minutes if production quality degrades.
6. Architecting for New Capabilities
The new generation of models is stronger at long-task consistency, self-verification, and high-resolution image understanding, which means the application side can move from single-turn Q&A toward auditable long-running agents. But agent architectures are inherently multi-turn and multi-tool, so token consumption grows faster. A workable approach: set a maximum step count and a maximum token ceiling for each task, persist intermediate artifacts for reuse, and keep the full call chain for auditing and retrospectives.
7. Checklist: Ten Things You Can Do This Week
- Measure the token distribution across business lines and find the top 20% of high-consumption calls;
- Ship model routing and push simple tasks down to cheaper models;
- Set a context budget and enforce truncation;
- Move the stable prefix to the front and enable prefix caching;
- Put high-frequency Q&A behind a semantic cache;
- Switch output to strict structured format with a length limit;
- Replace full conversation history with summary plus sliding window;
- Wire up token and cost monitoring with alerts;
- Build an offline evaluation set and run a regression on every change;
- Add rollback switches for model and prompt configuration.
Conclusion
Rising token consumption is not an isolated event but a side effect of capability upgrades. Treat it as a chance to run an architecture checkup: with tiered routing, context budgets, cache reuse, and observability in place, cost turns from an uncontrollable bill into a parameter you can design. When measurement, evaluation, and rollback mechanisms are all in place, the capability gains from a new model can actually convert into business value instead of being swallowed by the bill.
