Beyond the Sticker Price: How Cache Hit Rate Reshapes API Input Costs

    When evaluating LLM API costs, focusing only on the standard list price is a common mistake. The standard input price usually reflects the "cache miss" billing tier, while real-world workloads often reuse large amounts of cached context. As the cache hit rate rises from 0% to 90%, input costs can differ by several times. This article explains the billing formula behind cached input pricing, walks through a cost example at a 90% hit rate, explores where cache hits come from and why they fluctuate, and provides an engineering optimization checklist, selection criteria, and pseudocode for cost estimation—so you can build a realistic cost model instead of treating the list price as the final price.

    Beyond the Sticker Price: How Cache Hit Rate Reshapes API Input Costs

    When evaluating LLM API costs, looking only at the “standard pricing” is a common mistake. The standard input price typically corresponds to the “cache miss” billing tier, while in real-world workloads, a large portion of the context may be reused from cache. As the cache hit rate rises from 0% to 90%, input costs can differ by several times. Therefore, when selecting models and calculating costs, the cache hit rate must be factored into the model rather than treating the list price as the final price.

    1. The Billing Formula: The Standard Price Is a Ceiling, Not the Actual Price

    Input billing for LLM APIs can generally be abstracted into two unit prices: the standard input price and the cached input price. The actual input cost can be expressed as:

    1. Actual input cost = cached tokens × cache price + uncached tokens × standard price
    2. Cache hit rate H = cached tokens / total input tokens
    3. Actual input cost = total input tokens × [H × cache price + (1 - H) × standard price]
    4. Effective discount = effective input unit price / standard input price

    This formula shows that the standard price is only the “worst-case” ceiling. As long as the cache price is lower than the standard price and the workload has reusable context, the effective input unit price will be lower than the list price. The higher the hit rate and the larger the gap between the cache price and the standard price, the greater the effective discount. Conversely, if requests are highly random, prefixes change frequently, and session stickiness cannot be maintained, the hit rate approaches 0% and the actual cost approaches the standard pricing.

    2. A Cost Example at a 90% Hit Rate

    For illustration, assume an LLM API has a standard input price of 4 CNY per million tokens, a cache hit price of 0.7 CNY per million tokens, a total input of 1M tokens, and a cache hit rate of 90%. Then:

    1. Cached portion: 0.9M tokens × 0.7 CNY/M tokens = 0.63 CNY
    2. Uncached portion: 0.1M tokens × 4 CNY/M tokens = 0.40 CNY
    3. Actual input cost = 0.63 + 0.40 = 1.03 CNY
    4. Effective discount = 1.03 / 4 ≈ 25.75% of the list price

    In other words, input priced at 4 CNY on the price list actually costs about 1.03 CNY at a 90% hit rate—roughly a quarter of the list price. The point of this calculation is not any fixed number, but a reminder that the cache hit rate is a core variable in the billing model. If the hit rate is only 50%, under the same assumptions the actual cost would be 0.5 × 0.7 + 0.5 × 4 = 2.35 CNY; at a 0% hit rate, the cost returns to 4 CNY. Changes in hit rate directly affect budgets, rate-limiting strategies, and product pricing headroom.

    3. Where Does the Cache Hit Rate Come From?

    Cache hits are not magic that automatically saves money—they depend on context reuse across requests. Commonly reusable content includes system prompts, tool definitions, fixed-format instructions, long document fragments, stable snippets retrieved from knowledge bases, multi-turn conversation history, and shared prefixes in batch jobs. On the inference side, techniques such as prefix caching, session caching, and KV cache reuse store the computation results of identical or similar prefixes so that subsequent requests can reuse them directly, reducing redundant computation.

    However, caching has boundaries: it is typically sensitive to “prefix stability” and to the position of variable content, and it is affected by cache capacity, eviction policies, time-to-live (TTL), node routing, and tenant isolation. If every request places a random ID, timestamp, or user input at the very front, even a long shared section that follows may fail to form a stable prefix. If requests are scattered across different nodes, cache locality also degrades. A high hit rate therefore comes from both the inference architecture’s capabilities and the way requests are organized and scheduled.

    4. Why Does the Hit Rate Fluctuate?

    The cache hit rate is usually not a fixed value but fluctuates within a range. Causes include changes in workload request patterns, varying session lengths, changing prefix repetition, cache TTL expiration, concurrency and routing changes, cold starts, multi-tenant isolation, and cache capacity eviction. For example, new sessions have low hit rates during cold start; continuous conversations with fixed system prompts have high hit rates; batch jobs with many shared prefixes have high hit rates; open-ended random Q&A has low hit rates. Evaluation should look at percentiles and time series rather than a single day’s average.

    5. An Engineering Optimization Checklist

    First, stabilize prefixes. Place system prompts, tool definitions, fixed instructions, and shared documents at the front of the request, and put variable user input, random IDs, and timestamps at the end. Second, maintain session stickiness. Route requests from the same session to paths with cache locality whenever possible, minimizing cross-node invalidation. Third, set a reasonable cache TTL. Too short causes frequent invalidation; too long increases memory pressure and isolation risk. Fourth, batch requests together. Processing requests that share context together increases the probability of prefix reuse. Fifth, monitor hit rate and cost. Track cached tokens, uncached tokens, cache price, standard price, and actual cost by business line, endpoint, model, and tenant. Sixth, pay attention to isolation and privacy. In multi-tenant scenarios, ensure the cache cannot cause data leakage across tenants, and isolate by tenant or security domain when necessary.

    6. Selection Criteria: Don’t Just Compare Unit Prices

    When evaluating providers, assess at least the following: the ratio of cache price to standard price, the cache billing methodology, the minimum cache granularity, cache TTL, cross-node consistency, cold-start behavior, how hit rate statistics are computed, whether read and write costs are billed separately, whether there is a minimum billing unit, rate-limiting and concurrency policies, and isolation and compliance capabilities. You can ask providers for hit rate ranges under realistic workload patterns rather than relying on theoretical peak figures. For cost-sensitive workloads, run a small-traffic A/B test first and replay actual request logs to estimate the real discount.

    7. Pseudocode Example for Cost Estimation

    1. function estimate_input_cost(total_tokens, hit_rate, cache_price, standard_price):
    2. hit_tokens = total_tokens * hit_rate
    3. miss_tokens = total_tokens * (1 - hit_rate)
    4. cost = hit_tokens * cache_price + miss_tokens * standard_price
    5. effective_price = cost / total_tokens
    6. discount = effective_price / standard_price
    7. return cost, effective_price, discount
    8. # Example
    9. cost, price, discount = estimate_input_cost(1_000_000, 0.90, 0.7, 4.0)
    10. print(cost, price, discount)

    In production, the hit rate should be treated as a continuously monitored metric and analyzed together with request structure, routing strategy, and cache TTL. Only by connecting “list price → hit rate → effective unit price → business cost” can you avoid budget distortion.

    8. Conclusion

    Between the standard price and the actual price lies a key technical variable: the cache hit rate. Developers should not merely compare list prices, but build a cost model that incorporates hit rate, cache pricing, request structure, routing strategy, and isolation requirements. For workloads with large amounts of repeated context, multi-turn conversations, fixed prompts, and batch jobs, cache reuse can often significantly reduce input costs. For highly random, short-request, or strongly isolated scenarios, the achievable hit rate ceiling should be evaluated cautiously. Only by factoring the cache hit rate into model selection and cost accounting can you determine the true cost of LLM APIs.