LLM Inference Cost Breakdown and Cache Hit Rate Optimization Practices

    This article breaks down how large language model inference billing actually works across input, output, cache write, and cache read tokens, and shows why a low per-token price does not guarantee a low bill. It introduces equivalent input tokens as a normalized metric for comparing models and caching strategies, outlines a measurement methodology for reliable multiplier conclusions, identifies four common root causes of low cache hit rates, and provides a practical cost optimization checklist covering prefix stabilization, context trimming, tiered routing, budget guardrails, and observability, along with selection and capacity planning advice.

    1. Background: Why a Cheap Unit Price Does Not Mean a Cheap Bill

    With token-based billing for large model services, the first mistake teams make is choosing a model by looking only at the price table. The real bill is determined by four types of tokens: input, output, cache write, and cache read. Their unit prices usually follow this pattern: output is significantly higher than input, while cache read is far lower than input. This means that the same model advertised as “cheap” can cost several times more in scenarios with long context, highly repeated prefixes, and multi-turn tool calls.

    The core phenomenon in the original discussion can be abstracted into a general rule: when the cache hit rate is low and the context retention window is too short, the system repeatedly pays for the same prefix, and the effective input volume rises sharply; when the hit rate approaches saturation, cost falls back close to the theoretical lower bound. Therefore, the first priority in cost optimization is not switching models, but making reusable prefixes solid first.

    2. Turning the Bill into a Computable Quantity: Equivalent Input Tokens

    To compare the real consumption of different models and caching strategies horizontally, you can define “equivalent input tokens per million.” For the i-th time interval, let input be input, output be output, cache read be cache_read, the output-to-input multiplier be w_out, and the cache-read-to-input multiplier be w_cr. Then:

    1. U_i = (input_i + w_out * output_i + w_cr * cache_read_i) / 1e6

    The total cost is the sum across intervals multiplied by the input unit price. The value of this formula is that it converts both “output length” and “cache hits” into the input dimension, so bills from different models can be compared directly. In practice, w_out often falls in the 5–6 range and w_cr often falls in the 0.05–0.10 range; the exact values should follow the provider’s public pricing and should not be set by guesswork.

    You can further define the cache hit rate:

    1. hit_rate = cache_read / (cache_read + input)

    When hit_rate improves from 0.95 to 0.99, the equivalent input volume in long-context scenarios often drops by a clear order of magnitude. This is the mathematical root of “a few points of hit rate difference, a doubling of the bill.”

    3. Measurement Methodology: How to Obtain Trustworthy Multiplier Conclusions

    The experience given in the original text is that the actual billing multipliers across model tiers are roughly 1.64 : 1.00 : 0.39. For conclusions like this to be worth referencing, they must rely on a rigorous observation method. The recommended steps are:

    1. Fix the workload: use the same batch of prompts, the same concurrency, and the same output length limit to avoid crossing variables.
    2. Record by tier: count the Pro tier and the Ultra tier separately, since caching strategies and retention windows often differ across tiers.
    3. Sampling granularity: aggregate by hour or half-hour intervals to avoid instantaneous jitter polluting the conclusion.
    4. Normalization: use the equivalent input formula above to convert consumption across tiers to the same baseline, then take ratios.
    5. Cross-validation: cover at least two workload types, “short context with high concurrency” and “long context with low concurrency,” to prevent the conclusion from holding in only a single scenario.

    Illustrative statistics script (pseudocode):

    1. def equivalent_input(input_t, output_t, cache_read_t, w_out, w_cr):
    2. return (input_t + w_out * output_t + w_cr * cache_read_t) / 1e6
    3. # Aggregate by tier and time interval
    4. for tier in ["A", "B", "C"]:
    5. total = sum(equivalent_input(r.input, r.output, r.cache_read, W_OUT, W_CR)
    6. for r in records[tier])
    7. print(tier, total)

    It must be emphasized that any multiplier conclusion holds only within a specific time window and a specific workload, and cannot be directly extrapolated into a long-term commitment.

    4. Why the Cache Hit Rate Stays Low: Four Common Root Causes

    1. The context retention window is too short. If the server only retains session context on the order of ten minutes, long tasks will expire midway and the prefix will be billed again.
    2. The prefix is unstable. Putting timestamps, random IDs, and dynamically sorted results at the very front of the prompt changes the prefix hash and invalidates the entire cache.
    3. Multi-turn tool calls introduce jitter. Tool return content varies in length, and even when appended at a later position, it can still shift the prefix boundary.
    4. Tier strategy differences. Different service tiers have different cache granularity and eviction strategies, so the same prompt can have significantly different hit rates across tiers.

    The general fix is to split the prompt into a “stable segment + volatile segment”:

    1. [stable segment] system instructions, tool definitions, long documents, examples
    2. [volatile segment] current-turn user input, timestamps, session ID

    Putting the stable segment first and keeping it byte-for-byte unchanged is the basic guarantee of the hit rate.

    5. Cost Optimization Checklist (Ready to Apply)

    • Prefix fixation: make the system prompt, tool schema, and knowledge snippets an immutable prefix; forbid concatenating dynamic fields at runtime.
    • Context slimming: keep only necessary history, and use summary compression instead of stacking raw text to reduce ineffective input.
    • Output constraints: use structured output and length limits to control the amplification effect caused by w_out.
    • Tiered routing: send simple requests to a lightweight tier and complex requests to a high-capability tier, using rules or a small model for front-end classification.
    • Budget guardrails: set daily and weekly quota alerts, and throttle by equivalent input volume rather than request count.
    • Discount window utilization: schedule batch tasks during periods when the provider offers discounts, but do not treat discounts as a long-term budget assumption.
    • Observability: feed the three metrics input/output/cache_read into a logging service and monitoring alerts, forming a daily report.

    6. Selection and Capacity Planning Recommendations

    Selection should not rely solely on “who is stronger” from a single evaluation. Instead, build a three-dimensional assessment: the capability dimension looks at task pass rate, the cost dimension looks at equivalent input volume, and the stability dimension looks at the hit rate decay curve over long sessions. For capacity planning, reserve headroom for peak concurrency and treat the cache hit rate as a first-class monitoring metric; when the hit rate falls below the threshold, trigger an alert automatically rather than waiting until the bill looks abnormal.

    7. Conclusion

    Cost governance for large model inference is essentially about turning an opaque billing black box into computable, observable, and optimizable engineering metrics. By mastering the definition of equivalent input tokens, insisting on prefix fixation and context slimming, and replacing subjective judgment with tiered measurement, you can stably obtain a predictable return on investment under budget constraints.