How Cache Hit Rate Determines the Real Cost of LLM APIs
List prices for LLM APIs can be misleading. Output prices may jump several-fold between model generations while input prices seem to rise across the board, yet the amount you actually pay is shaped by a three-tier billing structure — uncached input, cached input, and output — and by two variables: your cache hit rate and your input-to-output token ratio. This article explains how prefix caching works, walks through an effective unit-cost formula, and compares two usage profiles on the same model and price list whose real cost differs by more than 3x. It also offers practical prompt-engineering tips to keep cache hit rates high and lower your actual bill.
1. Check the Price List, Then Check the Bill: Why “Across-the-Board Hikes” Can Be Misleading
When teams evaluate LLM API costs, they often compare price lists directly: how much the output price rose, how much the input price rose. But between the price list and the real bill, there is often a whole caching mechanism you’re missing.
Take a common billing structure as an example (the figures below are illustrative, used only to show the calculation logic): a previous-generation model charged roughly 27 per million tokens for output, about 6.5 for uncached input, and about 1.1 for cached input; a new generation raised output to about 100, uncached input to about 20, and cached input to about 2.
Looking at the numbers alone, you’d conclude “output rose nearly 4x, input rose around 3x” — intuitively, an across-the-board price hike. But break down the ratios and the conclusion is completely different:
- In the previous generation, uncached input was about 6x cached input; in the new generation this ratio stretched to about 10x.
- The ratio between output and cached input also widened, from about 25x to about 50x.
In other words, the tier with the largest jump isn’t the cached-input tier — it’s the output tier that rose the most, while the cached-input tier stayed relatively moderate. What actually determines how much you spend isn’t this price list, but how many tokens in your requests hit the cache.
2. Understanding the Three-Tier Billing Structure
To do the math clearly, first break billing into three tiers, which are priced completely independently:
- Input, uncached: the prompt portion of this request was never cached before, so it must be computed in full at the highest unit price.
- Input, cached: the prompt prefix of this request repeats earlier requests, so intermediate computation results can be reused directly, typically at a fraction of the uncached price — sometimes far less.
- Output: tokens generated by the model, usually at a unit price significantly higher than input.
The key insight: the gap between the cached and uncached input prices can approach an order of magnitude. This means that for the same one million input tokens, users with a high hit rate and users with a low hit rate can differ in cost by several times.
3. The Principle Behind Cache Reuse
Cached hits can be this much cheaper because of a physical property of LLM inference: computation over a prompt prefix can be reused.
Mainstream inference frameworks generally adopt a prefix caching approach, keeping the intermediate state (the key-value cache) of already-computed context. When a new request’s prefix matches cached content, computation only needs to continue from the branch point, skipping repeated computation of the duplicated prefix. Disaggregated inference architectures go further by separating the resource scheduling of the “prefill” and “decode” phases, making cache reuse more efficient. As a result, in coding and long-context scenarios, requests with highly overlapping prefixes often achieve very high hit rates.
This explains an important phenomenon: a fixed system prompt, stable tool definitions, and long, repeated context are all essentially “cacheable assets.” The more stable you make them, the more hits you get, and the lower your effective unit price.
4. Deriving the Effective Unit-Cost Formula
Let the uncached input price be P_miss, the cached price be P_hit, the output price be P_out, the input-to-output token ratio be r, and the cache hit rate be h. The blended cost per million tokens is:
def effective_price(p_miss, p_hit, p_out, io_ratio, hit_rate):# Effective blended unit price on the input sideinput_effective = p_hit * hit_rate + p_miss * (1 - hit_rate)# Weight by the input/output ratio; output counts as 1 unitper_token_cost = (io_ratio * input_effective + 1 * p_out) / (io_ratio + 1)return per_token_cost
This formula reveals two things: first, the cache hit rate h directly lowers the blended input price in a linear way; second, the input-to-output ratio r determines how much the expensive output cost gets diluted. The larger r is (input far exceeds output), the more fully the costly output is spread out.
5. Two Worked Examples — The Same Model, Over 3x the Difference
Using the illustrative prices (output 100, uncached 20, cached 2), compare two typical users:
Scenario A | Enterprise long-context agent: input-to-output ratio ~20:1, hit rate ~90%
Effective input price ≈ 2 × 0.9 + 20 × 0.1 = 3.8 per million tokensOutput = 100 per million tokensBlended per million tokens ≈ (20 × 3.8 + 1 × 100) / 21 ≈ 8.4
Scenario B | Low-frequency individual developer: input-to-output ratio ~5:1, hit rate ~20%
Effective input price ≈ 2 × 0.2 + 20 × 0.8 = 16.4 per million tokensOutput = 100 per million tokensBlended per million tokens ≈ (5 × 16.4 + 1 × 100) / 6 ≈ 30.3
The two differ by about 30.3 / 8.4 ≈ 3.6x. The same model and the same price list — yet merely because of different usage patterns, the real unit cost is several times apart.
The conclusion is clear: the so-called “across-the-board increase” is, for enterprise customers who run the same system prompt over the long term with highly reused prefixes, effectively a near-discounted price; while low-frequency users whose prompts differ every time and who have low hit rates are the ones paying close to list price or even a premium.
6. Cost-Optimization Tips for Developers
Once you understand this mechanism, reducing costs has clear levers:
- Stable prefixes: fix the system prompt, tool definitions, and few-shot examples at the very front of the request and keep them unchanged, so the cacheable portion is maximized.
- Reduce prefix churn: avoid inserting “cache killers” like timestamps, random IDs, or variable ordering at the start of the prompt — they invalidate the entire prefix.
- Raise the input-to-output ratio: within reason, feed enough context in a single pass rather than repeatedly probing in small batches; this both improves hit rate and dilutes output cost.
- Monitor the hit rate: the hit rate is an observable operational metric — put it under monitoring and alerting; an abnormal drop in hit rate often means something went wrong with how the prefix is constructed.
- Choose models by scenario: low-frequency, low-reuse calls suit smaller models or more economical tiers; only high-frequency, high-reuse scenarios justify investing in a large model’s output capability.
7. Summary
To evaluate LLM API costs, don’t look only at the absolute numbers on the price list. Instead, return to the three-tier structure — uncached input / cached input / output — and use the blended unit-cost formula to factor in the two variables that actually matter: cache hit rate and input-to-output ratio. The caching mechanism turns “a stable way of calling” itself into a discount: whoever reuses the prefix to the fullest has the lower unit cost. For businesses and teams, rather than fixating on rumors of price cuts, it’s better to start with prompt engineering and invocation architecture, and hold in your own hands the one lever — hit rate — that most influences the bill.
