LLM API Cache Hit Rate and Real-World Cost Calculation

    Sticker prices are only the starting point of cost discussions when selecting LLM inference services. Cache pricing, cache-miss input pricing, output pricing, peak/off-peak discounts, monthly plan quotas, and rate-limiting rules all shape the final bill. This article presents a vendor-neutral cost model that breaks a total token budget into cache-hit input, cache-miss input, and output components, includes sensitivity analysis with worked examples and pseudocode, and covers how to translate peak/off-peak pricing and monthly plans into effective unit prices—plus engineering practices for improving cache hit rates. Use it to convert "list price" into "real business cost."

    LLM API Cache Hit Rate and Real-World Cost Calculation

    When selecting an LLM inference service, the listed price is only the starting point of the cost conversation. Cache unit pricing, cache-miss input pricing, output pricing, peak/off-peak discounts, monthly plan quotas, and rate-limiting rules jointly determine the final bill. If you only compare “how much per million tokens,” you can easily overlook differences in request structure: long system prompts, tool definitions, retrieval context, multi-turn conversations, and output length all change the cache hit rate and the input-to-output ratio. This article does not target any specific vendor or product. Instead, it abstracts a general cost calculation method that helps developers convert “list price” into “real business cost.”

    1. Why List Price Is Not Real Cost

    Billing for LLM APIs typically consists of several components: cache-hit input tokens, cache-miss input tokens, and output tokens. Some services also differentiate between peak and off-peak periods. A cache hit means repeated prefixes can be reused, and the unit price is usually lower than for cache-miss input; output tokens, because decoding is more compute-intensive, are often priced higher than input. As a result, the same 100 million token “volume” can cost several times more or less depending on the cache hit rate and the input/output split.

    Therefore, real cost calculation requires at least four parameters: total token volume, cache hit rate, cache-miss input share, and output share. If peak/off-peak pricing exists, you also need the peak-request share and the proportion of deferrable tasks. If you buy a monthly plan, you must further compute the plan’s effective unit price, quota coverage, and overage rules.

    2. A General Cost Model with Worked Examples

    Let the total token volume be (N) (in millions of tokens), the cache hit rate be (H), the output share be (O), and the cache-miss input share be (1-H-O). Let the unit prices for cache-hit input, cache-miss input, and output be (P_c), (P_i), and (P_o) respectively. The total cost is:

    [
    C = N \times [H \times P_c + (1-H-O) \times P_i + O \times P_o]
    ]

    The key insight of this formula: the higher the cache hit rate, the more tokens are billed at the lower cache price; but output tokens are expensive, so even a small output share can noticeably affect total cost. The following uses a set of hypothetical prices for illustration only—they do not correspond to any specific product or billing rule: cache 0.10 per million tokens, cache-miss input 1.00 per million tokens, output 2.00 per million tokens, with the output share fixed at 0.5%.

    Cache hit rate Cache-miss input share Example cost for 100M tokens
    98% 1.5% 12.30
    95% 4.5% 15.00
    90% 9.5% 19.50
    80% 19.5% 28.50

    As the table shows, dropping the hit rate from 98% to 95% raises cost by about 22%; dropping it to 90% raises cost by about 59%. If the cache unit price falls further, the benefit of high-hit-rate scenarios grows; if the output price rises or the output share increases, the entire cost curve shifts upward. So when comparing providers, don’t look at the cache price alone—factor the hit-rate distribution and the output structure into the calculation.

    The following pseudocode can be used for quick sensitivity analysis:

    1. def cost_per_100m(hit_rate, cache_price, input_price, output_price, output_ratio=0.005):
    2. n = 100 # 100M tokens = 100 million-token units
    3. miss_input_ratio = max(0.0, 1 - hit_rate - output_ratio)
    4. return n * (
    5. hit_rate * cache_price
    6. + miss_input_ratio * input_price
    7. + output_ratio * output_price
    8. )
    9. for h in [0.98, 0.95, 0.90, 0.80]:
    10. print(h, round(cost_per_100m(h, 0.10, 1.00, 2.00), 2))

    In practice, you should collect real production distributions rather than relying on a single average. It’s advisable to measure hit rates separately by business line, request type, conversation length, whether tool definitions are included, and whether retrieval context is used, then aggregate costs from those dimensions.

    3. Translating Peak/Off-Peak Pricing and Monthly Plans

    The common logic behind peak/off-peak pricing is: during peak hours, capacity is tight, so prices are higher or quotas are limited; off-peak prices are lower, which suits deferrable tasks such as offline batch processing, data cleaning, batch summarization, and evaluation regressions. When evaluating a peak/off-peak scheme, answer three questions: what share of requests falls in peak hours? What fraction of those can be shifted off-peak? Does the off-peak window’s length and concurrency capacity satisfy your business SLA?

    For monthly plans, compute the “effective unit price.” Let the plan’s monthly fee be (M) with an included token quota of (Np); the effective unit price is (M/N_p). Compare it with the pay-as-you-go cost (C{api}) to get the conversion ratio:

    [
    R = \frac{M/Np}{C{api}/Np} = \frac{M}{C{api}}
    ]

    When (R<1\), the plan is comparatively cheaper; when \(R>1), pay-as-you-go wins. But this conclusion depends on hit-rate assumptions: the higher the hit rate, the lower the pay-as-you-go cost, and the less attractive the plan becomes. With low hit rates, heavy output, or volatile usage, a plan provides a cost ceiling and budget predictability. In addition, plans usually come with peak-hour rate limits, quota expirations, and overage billing—these must be included in the total cost of ownership.

    A robust approach is to build a “dual-track budget”: cover a stable baseline workload with a plan, and route traffic spikes and experimental workloads through pay-as-you-go billing. At the same time, set up cost alerts and monthly reviews to avoid idle plan quotas or runaway overage charges.

    4. Engineering Practices for Improving Cache Hit Rate

    Cache hit rates don’t happen automatically—they depend on the stability and reusability of request prefixes. Common optimizations include:

    1. Stabilize system prompts and tool definitions: Put fixed content such as role settings, output formats, and tool schemas at the front of the request, and keep timestamps, random IDs, and dynamic user data away from the prefix.
    2. Normalize retrieval context ordering: Sort and truncate retrieval results by fixed rules so the same question doesn’t invalidate the prefix due to context reordering.
    3. Session stickiness and partitioning: Keep multi-turn conversations on a consistent session prefix; use separate cache partitions for different business lines to reduce cross-contamination.
    4. Control output length: Use max_tokens, structured output, summary compression, and streaming truncation to reduce expensive output tokens.
    5. Monitor hit rate and per-business-unit cost: Track cache hit rate, input/output ratio, P95 latency, and cost per thousand requests by endpoint, tenant, and request type, so you can quickly locate the cause when the hit rate drops.
    6. Schedule deferrable tasks: Move batch evaluations, offline summaries, and log analysis to off-peak windows to maximize the benefit of peak/off-peak pricing.

    5. Selection Checklist and Conclusion

    Before making a final decision, confirm each of the following: whether billing distinguishes cache-hit input, cache-miss input, and output; cache validity period and invalidation conditions; peak/off-peak definitions and peak rate limits; plan quota cycles, overage pricing, and refund rules; whether usage detail export is supported; whether there are minimum spend or committed usage requirements; and the latency and retry costs your business can tolerate.

    Overall, real cost calculation should follow a “model first, sample next, decide last” path: build a cost baseline with the general formula, calibrate the hit rate and input/output structure with real production distributions, then run scenario analysis using peak/off-peak and plan rules. A high cache hit rate amplifies the advantage of cheap cache pricing, but it also means a monthly plan’s relative value may decline; low hit rates, long outputs, and volatile usage demand budget ceilings and the smoothing a plan provides. Only by putting the billing structure, engineering optimizations, and business SLAs into the same spreadsheet can you avoid being misled by a single list price and arrive at capacity and procurement decisions that are explainable and reviewable.