LLM API Cost Accounting: Cache Hit Rate and Practical Cost Reduction

    Prompt caching can dramatically lower the effective input cost of LLM API calls, but the actual savings depend on token-level hit rates, pricing structure, and cache validity—not on advertised discounts. This article explains how input caching works, how to calculate the effective input price with a weighted average, why request-level and token-level hit rates differ, which request structures benefit most from caching, and how to build a verifiable measurement and billing validation process so that caching becomes an auditable engineering practice rather than a budgeting assumption.

    LLM API Cost Accounting: Cache Hit Rate and Practical Cost Reduction

    1. Evaluating API Cost Requires More Than Comparing Standard Prices

    When choosing an LLM API, developers typically start by comparing the quoted price per million input and output tokens. This is a necessary first step, but it does not reflect the true cost after your application goes live.

    The reason is that real-world requests often contain a large amount of repeated input: fixed system instructions, business rules that rarely change, conversation history in multi-turn sessions, and reference material cited repeatedly. On services that offer input caching with separate billing, input that qualifies for reuse may be charged at a lower cache price. As a result, the same standard input price can produce very different effective costs depending on request structure and cache hit rate.

    Be clear, though: cache discounts are not an inherent, fixed benefit of every model API, and a hit rate measured in one scenario cannot be applied directly to all workloads. Whether caching takes effect, which content is reusable, how long it remains valid, and whether write fees apply—all of these must be verified against the actual service rules and billing fields.

    A more rigorous cost evaluation should answer three questions:

    1. Of the total input, how many tokens are actually billed at the cache price?
    2. Beyond cache reads, are there write, storage, or other related charges?
    3. Assuming quality and latency requirements are met, how much does each successful task actually cost?

    2. What Caching Reuses, and Why It Lowers Cost

    LLM inference usually processes the input context first, then generates output token by token. For repeated input that meets reuse conditions, some services can reuse intermediate states computed previously, reducing redundant computation.

    This mechanism is not the same as “returning the previous answer directly.”

    When input cache hits, the service may still process the newly added context and generate a new response. What is reused is the computation over qualifying input—not a guarantee that the entire request is skipped.

    From a business perspective, distinguish two mechanisms:

    • Input context caching: Reuses computation over repeated input. It mainly affects input processing cost, and in some scenarios may also improve time-to-first-token.
    • Response result caching: Where the business allows it, existing results are returned directly, reducing model calls. However, it requires extra handling of result freshness, permissions, and request equivalence.

    This article covers the former. Do not mix the full-call savings from response caching into calculations of input cache discounts.

    Cache matching usually comes with conditions. For example, some implementations rely on a consistent prefix, while others require explicitly creating reusable content. Two passages that “mean the same thing” will not necessarily hit the cache, and identical text appearing anywhere in a request does not automatically qualify for cache pricing.

    3. Calculating the Effective Input Price with a Weighted Average

    To illustrate the calculation, consider a hypothetical pricing scenario. The following numbers are for demonstration only and do not represent any specific service’s current pricing or actual hit rates:

    • Standard input price: 4 per million tokens;
    • Cache read price: 0.7 per million tokens;
    • Token-level cache hit rate (measured over input tokens): 90%;
    • Cache write, storage, and other fees are ignored for now.

    Let:

    • The standard input price be (P_s);
    • The cache read price be (P_c);
    • The input token cache hit rate be (h).

    The effective price per million input tokens is:

    [
    P_{\text{effective}}=hP_c+(1-h)P_s
    ]

    Substituting the assumptions above:

    [
    P_{\text{effective}}=0.9\times0.7+0.1\times4=1.03
    ]

    That means each million input tokens costs 1.03.

    Compared with billing everything at the standard input price, the actual price ratio is:

    [
    1.03\div4=25.75\%
    ]

    So the rigorous statement is: under the assumptions above, the effective input price is about 25.75% of the standard price, reducing input cost by roughly 74.25%.

    For simplicity, you might summarize this as “about one quarter of the standard price.” A rounder approximation like “roughly 75% savings” should be treated only as shorthand—it cannot replace precise figures in budgets and billing reconciliation.

    4. How Changes in Hit Rate Affect Cost

    Using the same assumptions, the effective input price at different hit rates is:

    Input token cache hit rate Effective price per million input tokens Relative to standard input price
    0% 4.00 100%
    25% 3.175 79.375%
    50% 2.35 58.75%
    75% 1.525 38.125%
    90% 1.03 25.75%
    100% 0.70 17.50%

    This table shows that a high hit rate can indeed reshape the cost structure, but the magnitude of the benefit also depends on the gap between the cache price and the standard price.

    If the cache read price is close to the standard input price, even a very high hit rate may yield limited savings. Conversely, even with a very low cache read price, if the workload has almost no reusable input, the actual benefit remains negligible.

    Therefore, it is not rigorous to discuss “higher hit rates always driving cost down to some level” in isolation from the pricing structure.

    5. Keep Metrics Consistent: Request Hit Rate Is Not Token Hit Rate

    A common mistake in cost analysis is plugging “the percentage of requests that experienced a cache hit” directly into the weighted pricing formula.

    For example, suppose a request contains 10,000 input tokens, of which only 1,000 are billed at the cache price. That request counts as “having a cache hit,” but its input token hit rate is only 10%, not 100%.

    The metric used for input cost accounting should be:

    [
    h=\frac{\text{input tokens billed at cache read price}}{\text{total input tokens}}
    ]

    When aggregating across multiple requests, use the pooled weighted ratio:

    [
    h_{\text{overall}}=\frac{\sum \text{cached input tokens}}{\sum \text{total input tokens}}
    ]

    Do not simply average the hit rate of each request. Otherwise, a very short request and an extremely long request receive equal weight, and the result can deviate from the true cost.

    Also verify whether the “input token count” returned by the service already includes the cached portion. If it does, adding cached tokens on top will double-count them.

    6. Which Request Structures Achieve Stable Cache Benefits

    1. Tasks with a high share of fixed rules

    When many requests share the same task instructions, output format constraints, or business rules, the stable input has reuse value.

    For cache mechanisms that rely on prefix matching, consider placing stable content first and putting the per-request user questions and dynamic data at the end. But any restructuring must preserve the semantics and business behavior of the instructions—never sacrifice correctness for hit rate.

    2. Tasks that repeatedly work on the same material

    When performing multi-turn Q&A, review, or information extraction over the same long document, the document body may have a high reuse ratio. However, the actual benefit also depends on request intervals, cache validity periods, and the service’s matching method.

    If calls are infrequent, even identical material may fail to hit the cache because it has already expired.

    3. Multi-turn sessions with a persistent context prefix

    Some multi-turn sessions carry conversation history forward in subsequent requests, which in theory offers reuse potential. But context trimming, rewritten summaries of history, or changes in message order can all alter the matchable portion.

    Therefore, multi-turn sessions should not be assumed to be high-hit-rate scenarios; they need validation with real call data.

    7. To Raise the Hit Rate, First Remove Unnecessary Input Variation

    The focus of cache optimization is not manufacturing repetition artificially, but preventing本来 stable information from changing meaninglessly.

    Check the following issues first:

    • Whether fixed instructions differ across business modules in punctuation, whitespace, or paragraph order;
    • Whether timestamps, random identifiers, and tracking data have been placed into an otherwise stable input prefix;
    • Whether the same version of rules is repeatedly rewritten by different call paths;
    • Whether the ordering of reference material changes frequently without a business reason;
    • Whether stable content lacks clear version tracking after updates.

    In practice, manage stable templates centrally and record template versions and content digests to help analyze hit rate changes.

    That said, do not keep outdated rules just to maintain input consistency, and never remove required permission information. When handling data belonging to different users or tenants, isolation and access control always come first—never assume that similar content can be reused across permission boundaries.

    8. Avoid “Higher Hit Rate, Higher Total Bill”

    A high hit rate does not equal low total cost.

    Suppose the original request had short input, but the optimization injects a large amount of fixed material that is not actually needed. Even if most of that material hits the cache, input cost can still increase—and the model’s attention to the key question may suffer.

    The correct goal is to reduce the total cost of completing tasks, not to optimize a single metric in isolation.

    The complete cost can be summarized as:

    [
    C{\text{total}}=C{\text{standard input}}+C{\text{cache read}}+C{\text{output}}+C_{\text{other}}
    ]

    Here, “other” may include cache write, storage, or related processing fees explicitly charged by the actual service; fee items that do not exist should not be added.

    For tasks with long outputs, pay special attention: even if input cost drops by roughly 70%, the total bill may not fall by 70%, because output cost does not decrease proportionally.

    Going further, if cheap requests frequently fail and require retries or manual rework, then cheap per-call pricing does not mean cheap business delivery.

    9. Establish a Reproducible Measurement and Billing Verification Process

    Follow these steps for evaluation.

    Step 1: Establish a business baseline.
    Record current request volume, input/output scale, task success rate, and cost level. Test samples should reflect real business traffic, not just highly repetitive demo questions.

    Step 2: Break down statistics by workload type.
    Observe fixed-template tasks, long-document tasks, multi-turn sessions, and one-off Q&A separately, so that overall averages do not mask differences.

    Step 3: Record the necessary metrics.
    Where the service provides the relevant fields, collect total input tokens, cached input tokens, output tokens, template versions, response latency, and task outcomes. Logs should use anonymized identifiers wherever possible, avoiding unnecessary storage of sensitive raw text.

    Step 4: Cover both cold start and steady state.
    First-time access, access after long intervals, and access right after rule updates may all behave differently from consecutive calls. Testing only repeated back-to-back requests tends to overestimate long-term savings.

    Step 5: Reconcile against actual bills.
    Verify costs over the same time range, price version, and billing scope. For gaps between estimates and bills, check failed requests, retries, surcharges, and statistical omissions item by item.

    The business metric to track in the end is:

    [
    \text{Cost per effective task}=\frac{\text{total relevant cost in the period}}{\text{number of successfully completed tasks meeting quality requirements}}
    ]

    10. Conclusion: Validate Discounts with Real Workloads, Not Assume Them

    Input caching can significantly affect the effective price of LLM API calls, but its benefit is determined jointly by input repetition, matching conditions, cache validity, and pricing structure.

    “A 90% cache hit rate” should be a result measured from real business traffic, not a default assumption in cost budgets; “about a quarter of the standard price” applies only under specific pricing and fee assumptions and cannot be generalized into an overall bill discount.

    A sustainable cost-reduction path is to first remove ineffective input, then stabilize the request structure where reasonable, then verify savings with token-level hit rates and actual bills, while continuously monitoring quality, latency, and security boundaries. Only then does cache optimization become an engineering capability that is auditable, reproducible, and maintainable over the long term.