The Evolution of LLM Inference Cost Optimization: Caching, Routing, and Evaluation
This article examines how LLM inference pricing and model tiering are reshaping cost engineering. It explains why per-token price comparisons mislead, then walks through four practical optimization layers—prefix caching, model routing, batch and asynchronous processing, and an evaluation loop—along with a quantitative cost formula, common pitfalls, and the shift from picking a model to designing a system.
1. The Signal Behind a “Galaxy-Style” Model Family Release
A cloud provider recently disclosed a new model family that uses celestial naming to separate capability tiers: a “star” for the strongest general capability, a “planet” for a balanced option, a “moon” for lightweight high-speed work, plus an enhanced variant—four layers in total. The names matter little to developers. What matters is the engineering signal behind the tiering: inference serving is no longer “one model for everything,” but a composable capability matrix split by task difficulty, latency budget, and cost ceiling.
From the published price structure, the flagship tier charges $8 per million input tokens, $0.4 for cached input, and $40 for output; the balanced tier charges $2 for input, $0.1 for cached input, and $10 for output. Compared with the previous generation, the flagship tier dropped roughly 20% on both input and output, while cached input fell from $1 to $0.4, about a 60% cut. The balanced tier kept its price but moved up in capability. One more detail stands out: the flagship price matches a competitor released within the same week, which suggests high-end inference pricing has entered a phase of head-to-head competition.
2. Why Per-Token Price Comparisons Almost Always Mislead
Choosing a model by unit price alone is the most common—and most error-prone—approach, for three reasons.
First, output and input prices differ in magnitude. Output is 5x the input price in both the flagship and balanced tiers. A long-output task (code generation, report writing, structured data extraction) is therefore dominated by output tokens, and cheaper input can only save a limited share.
Second, different models need different token counts to reach the same quality. A stronger model often gets it right on the first pass with fewer retries; a weaker one may need multiple rounds of patching, and the cumulative token count ends up higher.
Third, the cache hit rate determines the effective unit price. Cached input at $0.4 versus uncached input at $8 is effectively a 20% rate. If system prompts, tool definitions, and knowledge base snippets can be reused reliably, the real average input cost lands well below the list price.
This is why the industry generally evaluates with a “quality-cost” curve: cost per completed unit of work on the horizontal axis, evaluation score on the vertical axis. The goal is to find the knee of the curve, not the absolute lowest price.
3. Four Cost Optimization Layers You Can Actually Ship
3.1 Prefix Caching: Turn Repeated Context into a Sunk Cost
Caching pays off only when the prefix is exactly identical. System prompts, few-shot examples, tool schemas, and long documents should sit at the front and stay stable, with volatile user input at the end.
[Stable prefix] System instructions + tool definitions + domain knowledge + examples[Semi-stable] Conversation history summary[Volatile tail] Current user question
A few engineering caveats: caches usually have a time-to-live, and both writes and hits incur scheduling overhead; randomized timestamps, randomly ordered examples, and dynamically concatenated IDs will all punch holes in the cache. Making the prefix a versioned configuration and swapping the whole version on change is a more controllable approach.
3.2 Model Routing: Let a Cheaper Model Absorb Most Requests
The typical implementation is “small first, large second”: a lightweight model answers first, a rule check or lightweight discriminator scores the result, and only low-confidence samples escalate to the flagship model. Sketch of the logic:
def route(prompt, ctx):draft = light_model.chat(prompt, ctx) # Low-cost first answerscore = verifier.score(prompt, draft) # Confidence scoringif score >= 0.85:return draftreturn flagship_model.chat(prompt, ctx) # Escalate hard cases
The key to routing is an evaluation set that covers the real distribution—thresholds must not be set by feel. Also cap the escalation path so long-tail requests cannot blow through the budget.
3.3 Batching and Asynchrony: Trade Throughput for Unit Price
For offline work (log classification, bulk labeling, document summarization), merge requests into batches and hand them to an asynchronous queue, which usually earns a better billing tier. Pairing object storage for input/output landing, a message queue for peak shaving, and a container platform for elastic scaling lets you drain the backlog during business troughs.
3.4 Evaluation Loop: Give Cost Optimization Something to Stand On
Cost optimization without evaluation is blind tuning. Fix a layered evaluation set: unit-test level (format and constraints), task level (accuracy/pass rate), and end-to-end level (human or model review). Every time you change a prompt, cache strategy, or routing threshold, run it and record two numbers—score and cost per task—to build a comparable curve.
4. Writing the Cost Model Quantitatively
Express cost in a computable form so it can feed monitoring and alerting:
Cost per task =Uncached input volume x input unit price+ Cached input volume x cache unit price+ Output volume x output unit price+ Retry count x average cost per attempt
Take the flagship tier: a task with 20k input tokens (16k cache hits) and 2k output tokens costs about 4×8 + 16×0.4 + 2×40 = 118.4 per million tokens normalized, or roughly $0.118. With no cache hit at all, the same task runs about $0.238—a 2x gap. The simple formula shows that caching and output length are the two main levers on cost.
5. Common Pitfalls
- Looking at list price while ignoring hit rate, which distorts the budget model;
- Routing every request to the strongest model, where quality gains are limited but cost rises linearly;
- Embedding timestamps or random IDs in the prefix, so the cache never takes effect;
- Missing retry statistics, letting long-tail requests quietly eat the budget;
- Tuning thresholds on a single evaluation sample, which breaks as soon as the live distribution shifts.
6. Conclusion
Capability tiering plus lower prices turns “choosing a model” into “designing a system.” What developers really deliver is not the unit price of a single call, but a stable cost per unit of work at acceptable quality. Get caching, routing, batching, and evaluation solid, then add logging and monitoring to close the feedback loop, and you can capture both quality and cost gains during a capability upgrade window. Teams that want to build this on Baidu AI Cloud can assemble it from general-purpose building blocks—model services, object storage, message queues, container platforms, and monitoring/alerting—without binding to any proprietary interface.
