LLM Inference Cost Optimization: A Practical Guide to Routing, Caching, and Output Budgets

    This article breaks down why falling per-token prices change architecture decisions rather than just saving money, and how engineering teams can turn inference cost into a measurable metric. It covers the sparse-activation (MoE) structure behind lower-cost models, a minimal cost model that includes retries and orchestration overhead, prefix-stability techniques for prompt caching, retrieval-first strategies for long context and multimodal inputs, and a practical checklist spanning tiered routing, output budgets, batch processing, observability, and regression evaluation.

    1. Reading the Signal Behind a Spike in Token Volume

    A cloud provider recently released a lightweight large model, and on its first day, token usage passed 50 trillion — a record for the first-day volume of that model family. The number itself is not the point. The point is the industry signal it sends: when the unit price per token drops by an order of magnitude, what gets unlocked is not “money saved” but real demand that had previously been suppressed by cost concerns.

    Over the past year, many teams treated “model calls are too expensive” as a hard constraint during architecture design: use rules wherever a model could be avoided, never use a large model where a small one would do, crudely truncate long documents, and cap the number of turns in multi-turn conversations. Every one of those compromises was paying the bill for inference cost. Once the cost of a single task falls from the “yuan” range to the “jiao” range or lower, the engineering optimum changes immediately.

    Based on public information, the pricing structure of this kind of high-value model looks roughly like this: 0.5 yuan per million input tokens, 2 yuan per million output tokens, and input as low as 0.02 yuan per million tokens on a cache hit. That works out to about 0.26 yuan for a typical single task — roughly 1/13, 1/20, and 1/8 of the previous preview version in the same family, the flagship version, and comparable high-tier competitor configurations, respectively. Three structural facts are what developers should actually pay attention to:

    • There is a clear price gap between input and output (about 4x), which means “make the model read more and write less” is cost-efficient.
    • Cache-hit input is roughly 25x cheaper than regular input, which means prompt reuse is not a micro-optimization but an order-of-magnitude one.
    • Per-task cost can be converted into a concrete number, which turns cost from an “unpredictable monthly bill” into a “modelable engineering metric.”

    2. Capability Has Not Shrunk Proportionally: Sparse Activation Is the Technical Foundation

    The easiest thing to question about a price drop is whether capability was cut. To understand this, look at the parameter structure rather than the total parameter count.

    This class of model has roughly 224B total parameters, of which about 64B are Engram (memory/knowledge-carrying) parameters, with only about 12B activated parameters, and it supports multimodal input and a context length on the order of 1M. In other words, although the total parameter count is about a quarter of the flagship model’s, only on the order of 12B parameters actually participate in computation per token.

    This is the core value of MoE (Mixture of Experts) sparse activation: total parameters determine knowledge capacity, while activated parameters determine the compute for a single forward pass. Once the two are decoupled, a model can be “broad in knowledge, narrow in compute.” The impact on inference cost is decisive — because mainstream billing and compute consumption follow actual computation rather than total parameter count.

    One common misunderstanding needs clearing up: a small activated parameter count does not mean weak capability. On everyday office tasks such as deep search, document processing, and presentation generation, a model with about 12B activated parameters already approaches the performance of much larger models. The reason is that the bottleneck in these tasks is usually not “knowledge depth” but instruction following, format stability, and information retrieval within a long context. Those capabilities are determined more by post-training quality than by the number of activated parameters.

    Engineers can think of it as layering:

    1. Task difficulty tiers (illustrative)
    2. ├─ L1 extraction/classification/rewriting → small activated model is enough, lowest cost
    3. ├─ L2 long-document understanding/retrieval → needs long context + cache reuse
    4. ├─ L3 structured generation/multi-step → needs strong instruction following and format constraints
    5. └─ L4 complex reasoning/hard problems → only here is a flagship model worth using

    In real workloads, L1–L3 usually account for more than 80% of requests, and that is exactly the main battlefield for a high-value model.

    3. Cost Modeling: Turning the Bill into a Computable Engineering Metric

    Optimization starts with being able to do the math. A minimal viable cost model is worth building:

    1. Cost per task ≈
    2. input tokens × input price × (1 - cache hit rate × (1 - cache discount ratio))
    3. + output tokens × output price
    4. + retry count × cost per attempt
    5. + orchestration overhead (retrieval, tool calls, embedding, etc.)

    Using the public prices for an illustrative calculation (assume 8,000 input tokens, 800 output tokens, 60% cache hit rate):

    • Uncached input: 8,000 × 40% = 3,200 tokens
    • Cached input: 8,000 × 60% = 4,800 tokens, billed at about 1/25
    • Output: 800 tokens, billed at 4x the input price

    The conclusion is counterintuitive: output tokens, though only about 10% of the tokens, can contribute close to half the cost. So “compressing output” often pays off more than “compressing input.” Practical measures include capping maximum output length, requiring the conclusion first and the supporting evidence after, avoiding having the model restate the source text, and caching and reusing long-document summaries.

    Retries also have to be counted as cost. A JSON output that fails to parse reliably can cost more than three times the theoretical value after three retries, at which point investing in structured constraints (schema validation, constrained decoding, example-based constraints) is a better deal than switching to a cheaper model.

    4. Cache Reuse: The Underrated Order-of-Magnitude Optimization

    The huge gap between the cache-hit price and the regular input price makes prefix stability the first priority of prompt engineering.

    Practical points:

    1. Stable prefix, variable suffix: put system instructions, tool descriptions, examples, and domain knowledge at the front and keep them byte-for-byte stable; put user input, timestamps, and random IDs at the end.
    2. Avoid timestamp pollution of the prefix: many teams habitually write “current time: 2026-08-26 19:07” into the system prompt, which makes the prefix different every time and invalidates the entire cache. Inject it only when the model needs it, or move it to the end.
    3. Shard the knowledge base instead of concatenating it: put variable content last, put stable content first in a fixed order, and avoid jitter in the order of retrieval results on every call.
    4. Reuse within multi-turn sessions: the history prefix in the same session is naturally stable, so prefer incremental appends over rewriting the whole thing.

    Illustrative comparison:

    1. # Bad example: prefix changes every time, cache hit rate ≈ 0
    2. [System] Current time 2026-08-26 19:07:33, request ID a8f3...
    3. [Knowledge] 5 retrieved fragments (random order)
    4. [User] ...
    5. # Good example: stable prefix + variable suffix
    6. [System] Fixed role definition and output spec (unchanged long-term)
    7. [Tools] Fixed tool list and calling spec (unchanged long-term)
    8. [Examples] Fixed few-shot examples (unchanged long-term)
    9. --- cacheable above this line ---
    10. [Context] Retrieved fragments for this call / current time / request ID
    11. [User] ...

    5. Long Context and Multimodal: Capability Upgrades That Need Cost Gates

    A context length on the order of 1M solves the old problem of truncated long documents, but it introduces two new risks: stuffing everything in causes input tokens to explode, and recall of information in the middle of a long context degrades (the “lost in the middle” effect).

    The recommended approach is retrieval first, then layered feeding: use keyword or vector retrieval to locate section-level fragments and send only the relevant ones to the model. For tasks that genuinely require global understanding, use a Map-Reduce style flow — summarize in segments first, then aggregate globally — rather than feeding everything in at once.

    The cost gate for multimodal capability needs even more attention: images and audio convert to far more tokens than text carrying the same amount of information. In engineering terms, preprocess images first (cropping, compression, resolution caps), and be explicit about “do we really need the model to look at the image” — in many scenarios, converting to text with OCR is both cheaper and more stable.

    6. An Actionable Optimization Checklist

    • Tiered routing: let a small activated model handle L1–L3, and escalate only low-confidence or high-difficulty requests to a flagship model; routing criteria can be rules, confidence scores, or a lightweight classifier.
    • Output budgets: set max token limits per task type, and alert on truncation of overly long outputs.
    • Batching and async: send offline tasks (document batch processing, bulk summarization) through an asynchronous queue, use a message queue to smooth out peaks, and avoid high-price tiers during busy periods.
    • Observability: connect logging and monitoring with alerts, break down token consumption and cost by business line, scenario, and model tier, and set daily budgets plus anomaly alerts.
    • Quality gatekeeping: maintain a small-sample regression evaluation set, and run a quality comparison for every cost-reduction change to prevent “saving money while losing accuracy.”
    • Data loop: feed production failure samples back into the evaluation set and few-shot material to keep raising the first-pass success rate — this is the most durable cost optimization.

    7. Closing Thoughts

    When per-task cost drops to the jiao range, what really changes is the space of architectural choices: approaches previously rejected on cost — full long-context understanding, multi-turn deep search, automated document and presentation generation — become viable again. For developers, the coming competitive edge is not “whether you can call a model” but whether you can turn cache hit rate, output budgets, tiered routing, and an evaluation loop into engineering capabilities. As the capability gap between models keeps narrowing in everyday scenarios, cost structure and stability become the deciding factors in system design.