LLM Inference Pricing Reworked: Why Cache Hit Ratio Determines Your Real Cost

    LLM API pricing is no longer a single number but a three-tier vector of output, cache-miss input, and cache-hit input tokens — and the ratios between those tiers matter far more than the headline prices. This article breaks down why a cache hit can be priced at roughly one-twentieth of a miss, shows how the same token volume can cost enterprise long-context agents about a quarter of what ad-hoc developers pay, and explains why agent workloads make input cost grow quadratically (O(N²)) with step count. It includes a minimal Python cost model, a token-by-token explanation of prefix caching, the prompt anti-patterns that silently destroy hit rates, a layered prompt design that lifts hit rates from ~20% to ~90%, the memory economics of sparse MoE that keep prices from falling, and a 14-item checklist spanning prompt engineering, context management, and cost observability.

    1. First, break the price sheet apart: three tiers, three cost curves

    Arguing about whether prices “went up several times” is not very meaningful, because LLM API billing has never been a single price. It is a vector made up of three tiers. For analysis, here are illustrative prices (in $ / million tokens):

    Tier New-generation model (illustrative) Previous-gen model, same class (illustrative)
    Output 100 27
    Input (cache miss) 20 6.5
    Input (cache hit) 1 1.1

    The absolute numbers only tell the surface story. What actually carries information are three ratios:

    • Miss input / hit input: widened from about 6x to 20x
    • Output / hit input: widened from about 25x to 100x
    • Output / miss input: expanded only from about 4x to 5x

    The third ratio barely moved, while the first two pulled far apart. This tells us the point of the change is not “an across-the-board price hike” but reallocating weight inside the pricing vector: concentrating the cost pressure on output tokens and on input tokens that cannot reuse cache, while deliberately pinning the cache-hit price at an extremely low level.

    From the vendor’s point of view, this is a fairly clear structural nudge. It does not want customers to dodge cost by rewriting prompts or constantly opening new sessions. It wants customers to fix inherently reusable content — system prompts, tool definitions, knowledge-base snippets — in place and reuse it over the long term. Whoever keeps a more stable request prefix gets a lower effective unit price.

    2. Why the “cache hit” tier can be pushed to nearly free

    Understanding this pricing means going back to the technical reality of inference serving. During autoregressive decoding, each token’s attention computation depends on the Key/Value tensors of all preceding tokens — the KV Cache. Once a prefix’s KV Cache has been computed, any subsequent request that shares the same prefix can skip that computation entirely.

    This means the marginal cost structure of a cache hit is completely different from that of a miss:

    • What gets saved is the entire prefill-phase compute. In long-context scenarios, prefill is compute-intensive, and the attention portion scales roughly quadratically with sequence length, so eliminating it pays off far more than intuition suggests.
    • What remains is VRAM occupancy and VRAM bandwidth. The KV Cache still has to be resident and moved around; that cost cannot be removed, but it is far lower than the cost of recomputing.

    So “hit price ≈ 1/20 of miss price” holds up on a cost basis: it is not a discount handed out for free, but a clean separation between one class of requests whose marginal cost is genuinely low and another class that is expensive. This is also the direct commercial motive behind the Prefill/Decode disaggregation (P/D disaggregation) inference architecture now widely used in the industry — prefill and decode have completely different resource profiles (one is compute-bound, the other is memory-bandwidth-bound). Once split apart, each can scale independently, and the prefix cache can become a shared cache pool across instances, which is the engineering foundation that makes a high hit rate achievable.

    3. Quantified comparison of two scenarios: same model, 3.6x gap

    Assume the new-generation model is priced as in the table above. Consider two typical user profiles:

    Scenario A: enterprise-grade long-context agent

    • Input/output ratio around 20:1 (common in long-context coding agents)
    • Cache hit rate 90% (system prompt, tool schemas, and repository context are highly stable)

    Effective input price ≈ 1 × 0.9 + 20 × 0.1 = $2.9 / million tokens
    Output side stays at 100 / million tokens
    Blended price ≈ (20 × 2.9 + 1 × 100) / 21 ≈ $7.5 / million tokens

    Scenario B: low-frequency hobbyist developer

    • Input/output ratio around 5:1
    • Cache hit rate 20% (every prompt is different, almost no reuse)

    Effective input price ≈ 1 × 0.2 + 20 × 0.8 = $16.2 / million tokens
    Output side stays at 100 / million tokens
    Blended price ≈ (5 × 16.2 + 1 × 100) / 6 ≈ $30.2 / million tokens

    Same model, same tokens — Scenario A’s unit cost is about 1/4 of Scenario B’s. Push the hit rate down to 0% (a brand-new prefix every time), and Scenario B’s blended price climbs to about 36.7 / million tokens, widening the gap to nearly 5x.

    The conclusion is clear: on the surface everything went up, but what the vendor is really handing out is a tiered price list where the cache hit rate is the discount coupon. Long-running enterprise customers with a fixed prefix get the discounted price; hobbyist developers whose prompt changes every time pay list price — or even a premium.

    4. Write the cost model in code: measure first, then optimize

    Before discussing any optimization, every team should first have a reproducible cost model. Here is a minimal working version:

    1. from dataclasses import dataclass
    2. # Prices in $ / million tokens
    3. PRICE_OUTPUT = 100.0
    4. PRICE_INPUT_MISS = 20.0
    5. PRICE_INPUT_HIT = 1.0
    6. @dataclass
    7. class TaskCost:
    8. input_tokens: int
    9. output_tokens: int
    10. cached_input_tokens: int # input tokens served from cache
    11. @property
    12. def hit_ratio(self) -> float:
    13. if self.input_tokens == 0:
    14. return 0.0
    15. return self.cached_input_tokens / self.input_tokens
    16. def cost(self) -> float:
    17. miss = self.input_tokens - self.cached_input_tokens
    18. return (
    19. miss * PRICE_INPUT_MISS
    20. + self.cached_input_tokens * PRICE_INPUT_HIT
    21. + self.output_tokens * PRICE_OUTPUT
    22. ) / 1_000_000
    23. def blend_price_per_mtok(self) -> float:
    24. total = self.input_tokens + self.output_tokens
    25. return self.cost() * 1_000_000 / total if total else 0.0

    The key insight is that hit_ratio is not an observed metric — it is an input variable your architecture decides. It depends on how you organize requests, not on luck. When instrumenting, you should record at least three quantities: input tokens for this call, cached tokens among them, and output tokens. Aggregate them by business task rather than by individual call, or you will never be able to compute a meaningful cost_per_successful_task.

    5. From 20% to 90% hit rate: prompt engineering, not the model

    Prefix-cache matching is token-by-token longest-common-prefix matching. If even the very first token differs, nothing after it can hit. This explains two common patterns of “invisible money burning”:

    Anti-patterns that destroy the hit rate

    1. Putting timestamps, request IDs, or usernames at the very front of the system prompt
    2. Building tool/function definitions by iterating over a hash map, so the order changes on every call
    3. Injecting retrieval results (RAG snippets) at the beginning of the prompt, when retrieval output naturally changes every time
    4. Assembling JSON with f-strings, producing unstable numeric formatting, spacing, and field ordering
    5. Rebuilding the prefix after session timeout, with a cache TTL shorter than the business idle interval

    A layered design that raises the hit rate

    Sort the prompt by “rate of change” from lowest to highest, and strictly guarantee that the prefix is monotonically stable:

    1. [Layer 1 · near-static] system instructions, output-format constraints, safety policy
    2. [Layer 2 · static] tool/function schemas (fixed order), few-shot examples
    3. [Layer 3 · semi-static] repository structure summary, domain knowledge-base snippets (cached by version)
    4. [Layer 4 · dynamic] current user input, retrieval results, environment state, timestamps

    The core principle is a single sentence: the more volatile the content, the further back it goes. Content in layers 1–3, once fixed, should stay unchanged for a long time, and be made idempotent by content hash so that retries, failovers, and concurrent scale-out all hit the same prefix.

    Pair this with engineering measures: session affinity at the routing layer (send the same prefix to the same instance where possible), choose a sufficiently long cache TTL, and keep context-concatenation order stable across multi-turn sessions. None of these change any business logic, yet they often lift the hit rate from 20–30% to 80–90%. Under the pricing structure above, that is equivalent to a 3–5x cost reduction.

    6. The real change in the agent era: the shape of the token-consumption curve changed

    In the chat era, one interaction was tens to a few thousand tokens, the per-call cost was negligible, and users were insensitive to price. The agent scenario has a completely different structure: a single task can run thousands of tool-call steps, accumulate hundreds of thousands of tokens, and multiple agents can run autonomously in parallel for days.

    There is a scale problem here that is easy to overlook. Say a task has N steps, and each step appends a fixed c tokens of observation, so the context length at step i is roughly i·c:

    • Total output tokens ≈ O(N)
    • Total input tokens ≈ Σ(i=1..N) i·c = O(N²)

    In other words, an agent’s input consumption grows quadratically with the number of steps, while output grows only linearly. Going from N=200 to N=1000 multiplies output-side cost by 5x but input-side cost by 25x. This directly explains why the “input miss price” has become the front the vendor most wants to defend: it corresponds to the least controllable, most easily runaway part of the agent bill.

    From the inference side, the cost of long context is just as non-linear:

    • KV Cache VRAM usage ≈ layers × 2 × sequence_length × hidden_dim × bytes_per_element (precision), and it multiplies linearly across concurrent requests and context length
    • Once VRAM is squeezed out by the KV Cache, the batch size you can fit drops, throughput falls, and per-token cost is pushed up
    • The decode phase is memory-bandwidth-bound, with inherently low compute utilization; long sequences further inflate the volume of KV Cache traffic that must be moved
    • Multi-agent parallelism stacks these effects: it is not the cost of N agents, but N agents each running their own O(N²) input bill

    So running long-horizon agent tasks at previous-generation price levels would very likely lose the vendor money. The price increase is less a business choice than a return of the cost structure to reality.

    7. Why the supply side can’t come down: the memory bill of sparse architectures

    Some argue that the new generation adopts a sparse MoE architecture with trillions of total parameters that activates only a tiny fraction of experts per forward pass; with activated parameters controlled so tightly, cost should fall. That is only half right.

    Sparse MoE saves compute (FLOPs), not VRAM:

    1. Weights must stay resident in VRAM. Whether or not an expert is activated, it has to sit on some card on standby. Total VRAM usage is determined by total parameters, not activated parameters.
    2. Expert routing adds communication overhead. Tokens are dispatched to experts on different devices according to routing decisions and then aggregated back, forming all-to-all communication. The more experts and the higher the parallelism, the greater the cross-node bandwidth pressure — and cross-node bandwidth is exactly the scarcest, most expensive resource.
    3. Load imbalance. Hot experts get hammered while cold ones sit idle, so overall utilization is dragged down by the slowest device.
    4. Hybrid attention mechanisms demand extra engineering. Mixing linear and full attention — or attention variants with state compression and gating — can reduce the compute and cache cost of long sequences, but only if you hand-write or deeply optimize the operator kernels; otherwise the theoretical gains never materialize. Introducing recurrent state also means extra handling for state caches, checkpoints, and concurrent scheduling.
    5. Native support for ultra-long context. Position-encoding extrapolation and long-sequence parallel sharding are pure engineering investment.

    Together, these overheads form the “floor” under the price. Expecting unit prices to return to the previous generation’s level, against a backdrop where long context and high concurrency have become mainstream demand, is not realistic.

    8. An actionable checklist

    Architecture & prompt layer

    1. Concatenate prompts strictly by rate of change, guaranteeing token-by-token prefix stability
    2. Give tool/function definitions an explicit sort order; never rely on iteration order
    3. Always place dynamic content (retrieval results, timestamps, user input) at the end
    4. Build prompts through structured templates rather than manual string concatenation
    5. Version the system prompt and route changes through a release process, so a casual “one-line tweak” can’t invalidate the entire cache

    Context management layer

    1. Rolling summaries: compress early tool-call results into summaries to suppress O(N²) growth
    2. On-demand retrieval instead of full injection — put only what the current step truly needs into the window
    3. Subtask decomposition plus context isolation: split long-horizon tasks into independently billable subtasks instead of letting a single context grow without bound
    4. Truncate and structurally trim tool outputs, so large chunks of raw output don’t get stuffed into the context

    Cost & observability layer

    1. Establish a cost_per_successful_task metric whose denominator is successfully delivered tasks, not call count
    2. Put cache hit rate on the core dashboard, observed alongside P50/P95 latency
    3. Set per-scenario budgets and circuit breakers: per-task token caps, per-agent step caps, and abnormal-retry caps
    4. Tiered model routing: send light tasks like planning, summarization, and classification to small models; route complex reasoning and code generation to the flagship model
    5. Deduplicate retries on idempotent operations, so failed retries don’t stack into double the bill

    9. Judging whether a price hike is acceptable: back to unit economics

    Whether a price is “expensive” cannot be judged by unit price alone — look at unit economics:

    1. Effective cost = cost_per_successful_task
    2. Business value = the worth the task delivers (labor replacement, delivery speed, lower error rate)

    A workload should only go to production when effective cost < business value with enough margin left. Under the pricing structure above, optimizing the hit rate is usually more effective than switching models or negotiating a lower price: it is the only lever that can cut cost by several times without changing model capability or business logic.

    Conclusion

    The real meaning of this round of price adjustment is not “LLMs got more expensive,” but that LLM billing is moving from “usage-based” to “structure-based.” The pricing vector shifts weight from the input side to the output side and the cache-miss side; in essence it uses price signals to reward teams with good engineering and high context-reuse rates.

    For developers, the conclusion compresses into three sentences: prompt stability is cost; context-length management is cost; and agent steps are cost — quadratic cost. Engineer these three things and even a high sticker price can yield an acceptable unit cost. Ignore them and even a low price will run out of control.