The Real Cost of LLM API Usage: How Cache Hit Rate Changes Your Bill
Comparing LLM API prices by multiplying the published input and output rates by expected call volume is a common budgeting mistake, because it treats cache hit rate as a constant when it is one of the most volatile variables in the cost equation. This article explains how prefix caching splits input tokens into cached and uncached tiers, shows the formula and a sample pricing table that translate hit rate into effective input price, outlines what determines hit rate in real workloads, and lists the inference-side engineering capabilities behind high reuse. It closes with a practical checklist for folding hit rate into model selection and budgeting, including small-scale validation with real traffic and ongoing monitoring.
1. Looking Only at the Sticker Price: The Most Common Costing Mistake
In almost every technical design review, model selection reaches the same step: list the input and output unit prices of the candidate models in a table, multiply by the estimated call volume, and produce a monthly budget. The process looks rigorous, but it systematically overestimates cost because it treats a highly variable factor as a constant — the cache hit rate.
Input-side billing for LLM APIs is not a single price. Mainstream inference services generally split input tokens into two categories: the portion that hits a prefix cache and the portion that misses. The unit prices for the two can differ by several times. This means the same “standard input price” can correspond to actual spending that differs by 3x to 5x depending on the calling pattern. In other words, the published price is just one parameter of the cost function, not the cost itself.
Ignoring this has consequences in both directions: budgets come out inflated, so a proposal gets rejected as “too expensive”; and comparison between options gets distorted, pushing the actually cheaper option down the list. The correct order for costing is therefore: first confirm which price tiers exist in the billing model, then estimate which tier your workload will land in, and only then calculate the amount.
2. The Basic Logic of Input-Side Cache Billing
The idea behind prefix cache billing is not complicated. When the input prefix of a request is byte-for-byte identical to content processed recently, the inference service does not need to recompute the key-value state for those tokens and can reuse it directly, so those tokens are billed at a significantly lower “cache price”; the remaining tokens that miss are still billed at the standard price.
Let the standard input price be P, the cache price be k·P (k is usually far below 1), and the hit rate be h. The actual cost per million input tokens is:
effective price = h · (k·P) + (1 - h) · P= P · (1 - h·(1 - k))
This formula tells us two things. First, cost is highly sensitive to h: as h rises from 0 to 0.9, the effective unit price can drop to roughly a quarter of the sticker price. Second, once h is high enough, the marginal gain from further reducing unit price is far smaller than the gain from raising the hit rate further.
Take a common pricing tier of “standard price 4 CNY per million tokens, cache price 0.7 CNY per million tokens” as an example:
| Hit rate h | Effective input price (CNY per million tokens) | Relative to sticker price |
|---|---|---|
| 0% | 4.00 | 100% |
| 50% | 2.35 | ~59% |
| 80% | 1.36 | ~34% |
| 90% | 1.03 | ~26% |
| 95% | 0.87 | ~22% |
The jump from 0% to 90% is the real dividing line on the bill. Note that the values above only illustrate the billing model; tiers and discount ratios differ across providers, and any actual costing must follow the published billing documentation of the service you choose.
3. What Determines the Hit Rate: A Practical Estimate
The hit rate is not a number set by the provider; it is a result of your workload characteristics and calling patterns. A simplified model gives an upper-bound estimate:
h ≈ reusable prefix tokens / total input tokens
“Reusable” requires three conditions to hold at once: the prefix is byte-for-byte identical, it is still within the cache lifetime, and it has not been evicted from capacity by other requests. This leads to a few practical conclusions:
- Prioritize prefix stability. Moving request-specific content (timestamps, random IDs, user nicknames) from the beginning of the prompt to the end can significantly increase the reusable proportion.
- Control concurrency and rotation cadence. Cache capacity is limited, and high concurrency or multi-tenant rotation accelerates eviction, lowering the effective hit rate of a nominally stable prefix.
- Batching and long context cut both ways. Long documents and code-repository workloads offer many reusable tokens per request, but repository changes invalidate the prefix, so inputs need to be organized by version.
A minimal estimation script helps a team self-check during selection:
def effective_input_price(p_std, p_cache, hit_rate):"""Convert the hit rate into the effective price per million input tokens"""return hit_rate * p_cache + (1 - hit_rate) * p_stdfor h in (0.0, 0.5, 0.8, 0.9):print(f"hit={h:.0%} -> {effective_input_price(4.0, 0.7, h):.2f}")
4. The Engineering Behind a High Hit Rate
A high hit rate is not the product of prompt tricks; it reflects the capability of the underlying inference service. To keep reuse high under real traffic, the inference side needs to solve at least four problems:
- Global-view scheduling. Requests must be routed to instances that already hold the relevant prefix cache, which requires the scheduling layer to be aware of cache distribution rather than simply round-robin.
- Tiered storage and eviction policy. Keep hot key-value state on faster storage tiers, push cold data down, and evict based on reuse value rather than time alone.
- Separation of cache and memory pools. Decoupling compute resources from cache resources lets cache capacity scale independently, so compute is not squeezed out by storage.
- Observability. Metrics such as hit rate, eviction rate, and prefix reuse length must be collectable and alertable; otherwise there is no basis for optimization.
This kind of capability has seen systematic public exploration in the industry, and some approaches have received top-tier academic recognition such as best-paper awards at leading storage and systems conferences, and have been released as open source for the community to build on. For users, the criteria are practical: does the service publish its cache billing rules, does it provide usage details related to hit rate, and can it produce reproducible hit rate data on your own workload.
5. Folding Hit Rate into Selection and Budgeting
It is worth fixing the following steps into your technical selection checklist:
- Clarify the billing tiers: confirm details such as the standard price, cache price, minimum cacheable length, and cache lifetime.
- Validate with a small traffic sample using real traffic: replay sampled real prompts and measure the actual hit rate instead of adopting advertised figures.
- Build a cost model: make h a tunable parameter in the budget table, provide three scenarios at 0.7/0.85/0.9, and assess budget elasticity.
- Optimize prompt structure: put the stable prefix first and variables last, split templates by business scenario, and manage them with versioning.
- Monitor continuously: bring hit rate and cache-related usage into your logging and alerting systems so abnormal fluctuations can be traced promptly.
6. Conclusion
Between the sticker price and actual spending sit the inference-side scheduling and caching engineering capabilities. Treating cache hit rate as a first-class input to costing both avoids inflated budgets and reveals the real gap when comparing options. Next time you evaluate an LLM API, take one extra step beyond unit price: given your workload characteristics, which range will the hit rate fall into, and how much cost does that save you.
