The Real Cost of LLM APIs: Cache Hit Rate Determines Effective Input Price
Standard price lists for LLM inference can mislead cost planning because prompt caching changes the actual input cost. This article explains how prefix caching is billed, quantifies the impact of cache hit rates with a pricing example, identifies workloads that naturally achieve high hit rates, and outlines engineering practices for improving and monitoring cache hit rate. Readers will learn why effective input price, rather than list price, should be used for cost estimation and capacity planning.
The Real Cost of LLM APIs: Cache Hit Rate Determines Effective Input Price
1. Why Standard Pricing Misleads Cost Evaluation
When selecting models or planning budgets for LLM applications, most teams start by checking standard pricing tables and multiplying the price per million tokens by expected call volume to estimate monthly cost. This approach seems reasonable, but it misses one of the most important variables in modern LLM inference billing: cache hit rate.
Current mainstream inference services generally support prompt caching. When the input prefix of a request overlaps heavily with previous requests, the server can reuse the already computed KV cache and skip repeated prefill computation. Tokens that hit the cache are billed at a much lower cache price, typically only 15%–25% of the standard input price.
This means that for the same model and the same call volume, raising the cache hit rate from 0% to 90% can change actual input cost by 3 to 5 times. Making decisions based only on standard pricing can easily overestimate costs, misjudge options, and even exclude the most cost-effective choices during model selection.
2. How Cache Billing Works
To understand why cache hit rate matters so much, it helps to distinguish the two stages of inference:
- Prefill: The model performs a forward computation over all input tokens and generates the KV cache. This is compute-intensive and is the main source of input token billing.
- Decode: The model generates output token by token and reuses the KV cache that has already been generated.
The essence of prefix caching is to store computed KV caches by prefix hash. When the input prefix of the next request matches a segment in the cache, those tokens do not need to go through prefill again. The server therefore saves substantial compute and passes part of that saving to the caller in the form of a cache price.
The actual input cost of a request can therefore be expressed as:
Actual input cost = cached tokens × cache unit price+ uncached tokens × standard unit price
Converted into an effective unit price:
Effective input unit price = hit rate × cache price + (1 - hit rate) × standard price
3. Quantitative Example: What a 90% Hit Rate Means
Consider a hypothetical inference service pricing example: the standard input price is 4 RMB per million tokens, and the cache hit price is 0.7 RMB per million tokens. In real production workloads, especially where system prompts are fixed and multi-turn conversations accumulate, the cache hit rate observed in practice often reaches the 85%–95% range. At a 90% hit rate, the actual cost per million input tokens is:
- Cached portion (90%): 900,000 tokens × 0.7 RMB per million = 0.63 RMB
- Uncached portion (10%): 100,000 tokens × 4 RMB per million = 0.40 RMB
The total actual cost is 1.03 RMB per million tokens. Compared with the standard price of 4 RMB, the actual input price is about 25% of the standard price.
For a direct comparison of effective unit prices at different hit rates:
| Cache hit rate | Effective input price (RMB per million tokens) | Approx. share of standard price |
|---|---|---|
| 0% | 4.00 | 100% |
| 50% | 2.35 | About 59% |
| 70% | 1.69 | About 42% |
| 90% | 1.03 | About 25% |
| 95% | 0.87 | About 22% |
Each step up in hit rate lowers cost by a significant margin. From 0% to 90%, input cost falls from 4 RMB to 1.03 RMB, a difference of nearly 4 times. This is the source of the observation that looking only at standard price can lead to a 3–5x misjudgment.
4. Workloads That Naturally Achieve High Cache Hit Rates
Cache hit rate is not an arbitrary metric; it is closely tied to application call patterns. The following workloads naturally tend to achieve high hit rates:
1. Fixed System Prompts
Most applications prepend a fixed system prompt to every request, including role definitions, output format constraints, and business rules, often amounting to thousands of tokens. As long as this content remains stable, the prefix of every request is identical, and the cache is almost certain to be hit.
2. Multi-Turn Conversations
The input of a multi-turn conversation is the accumulation of historical messages. The input of the Nth turn fully contains the input of the N−1th turn, so the hit rate increases as the conversation progresses. In a 20-turn conversation, later turns often exceed a 95% hit rate.
3. RAG and Document QA
When multiple questions target the same long document or the same set of retrieval results, the document portion forms a shared prefix. Placing the changing user question at the end of the input and stable content at the beginning can significantly improve the hit rate.
4. Agent Tool-Calling Chains
During loop execution, an agent repeatedly carries the same tool definitions, task descriptions, and accumulated execution history. Prefix overlap is extremely high, making this one of the biggest beneficiaries of caching.
5. Engineering Practices to Improve Cache Hit Rate
Cache hit rate is not only a passive statistic. It is also a metric that can be actively optimized through engineering design:
1. Put stable content first and dynamic content last. Prefix caching only matches continuous content starting from the beginning. System prompts, tool definitions, reference documents, and other stable content should be placed at the front of the input, while user questions, timestamps, random IDs, and other dynamic content should be placed at the end. Even inserting a changing field at the beginning can completely invalidate the cache.
2. Avoid meaningless perturbations. Dynamically concatenating the current time, request ID, or similar fields into a prompt template is a hidden killer of cache hits. Unless necessary, remove such fields or move them to the end of the input.
3. Merge and align prefixes. For RAG scenarios, try to keep retrieval result ordering and truncation strategy stable so that multiple requests share the longest possible common prefix.
4. Monitor hit rate metrics. Responses from mainstream inference services return the number of cached tokens, such as a cached tokens field. This metric should be continuously collected in logging and monitoring/alerting systems, and cache hit rate should be treated as an observation dimension as important as latency and error rate. When the hit rate drops abnormally, prompt changes should be investigated promptly.
5. Use effective unit price, not list price, for cost accounting. When doing capacity planning and quote estimates, backtest the effective unit price based on the real hit rate instead of directly applying the standard price. This avoids inflated budgets or underestimated costs.
6. Conclusion
The right way to evaluate LLM API cost is not to look only at list price, but to look at structure: standard price is only the upper bound, while cache hit rate is the leverage that determines actual spending. With a 90% hit rate and a cache price of 0.7 RMB, the actual cost per million input tokens is only 1.03 RMB, about 25% of the standard price. Understanding prefix caching, designing cache-friendly prompt structures, and continuously monitoring hit rate are essential for every LLM application team that wants to control inference cost. When building applications on a cloud platform, combining general cloud capabilities such as logging and monitoring/alerting to make cache hit rate a core observation metric can move cost optimization from after-the-fact accounting to upfront design.
