LLM Inference Cost Calculation Guide: Why Price Comparisons Mislead

    This guide explains how to estimate real large language model inference costs beyond per-token pricing. It breaks down a cost model based on cache hit rate, input-to-output token ratio, and time-of-use, shows how small changes in cache hit rate can reverse cost conclusions, and covers how to convert subscription plans into effective unit prices. Readers will learn practical steps for measuring traffic, improving cache reuse, scheduling workloads, and prioritizing cost optimization.

    1. Why “Price Comparison” Almost Always Leads to the Wrong Conclusion

    When evaluating LLM inference costs, the most common approach is to put the per-million-token prices of two services side by side and conclude that one is “twice as expensive.” The problem is that the listed unit price is only one coefficient in the cost function. What actually determines the bill are three variables: cache hit rate, the ratio of input to output tokens, and the time of day when requests occur.

    A typical example from the source material: a general-purpose LLM service charges about CNY 0.115 per million tokens for cache hits, while another vendor’s off-peak cache price is about CNY 0.05. On paper, the difference is more than double. But when the hit rate drops from 98% to 95%, the conclusion completely reverses—the former costs about CNY 14.92 per 100 million tokens, while the latter costs about CNY 18.25. Unit price and final cost are not linearly related; the uncached portion of tokens is the main cost amplifier.

    So the right starting point for cost estimation is not the price sheet, but a characterization of your own traffic patterns.

    2. The Cost Model: Writing the Bill as a Computable Function

    The billing structure of mainstream inference services can usually be abstracted into four token categories: cache-hit reads, uncached input, output, and optional cache writes:

    1. Total cost = hit tokens × P_cache
    2. + missed input tokens × P_input
    3. + output tokens × P_output
    4. + written tokens × P_write

    Here, the hit rate h is the share of total input served from cache, and r is the input-to-output ratio. With a total volume of N = 100 million tokens, h = 98%, input at 1.5%, and output at 0.5%, plugging in the two price tiers yields the 12.57 vs. 9.40 difference mentioned earlier. Replace h with 95%, and the missed portion jumps from tens of thousands of tokens to millions, at which point the cost structure is immediately dominated by the uncached unit price.

    The logic can be captured in a short snippet for batch sensitivity analysis:

    1. def cost_per_100m(h, p_cache, p_miss, p_out,
    2. input_ratio=0.015, output_ratio=0.005):
    3. total = 100_000_000
    4. hit = total * h
    5. miss = total * (1 - h)
    6. return (hit * p_cache + miss * p_miss
    7. + total * output_ratio * p_out) / 1e6

    The key takeaway: there is a critical hit rate h. Below it, the high-cache-price option is more expensive; above it, it is cheaper. Estimating which side of h your traffic falls on is far more meaningful than comparing unit prices.

    3. Cache Hit Rate: The Most Sensitive Variable in the Model

    Hit rate is not a server-side property; it is an engineering outcome determined by how you call the API. Practical ways to improve it include:

    • Stable prefixes: place system prompts, tool definitions, and few-shot examples at the very front of the request, and avoid volatile concatenations such as timestamps or random IDs.
    • Reduce prefix drift: avoid inserting dynamic content in the middle of a long context, or everything after it degrades to a cache miss.
    • Batching and concurrency: issue multiple calls sharing the same prefix together to increase reuse within a given window.
    • Explicit cache lifecycle management: keep write and expiration policies predictable to avoid frequent invalidation.

    Note that a 3-percentage-point gap between 95% and 98% can shift costs by more than 30% in long-context, low-output scenarios. Hit rate should therefore be a continuously monitored metric, not a one-time estimate.

    4. Peak and Off-Peak Windows and Plan Conversion: The Overlooked Second Dimension

    Beyond pay-as-you-go billing, the industry commonly offers monthly plans with peak-hour restrictions to balance resources. In the source example, a plan’s peak window is weekdays 14:00–18:00 (4 hours per day), which is relatively generous. At 98% hit rate off-peak, three plan tiers convert to roughly 317 million, 1.9 billion, and 4.433 billion tokens per week, corresponding to about CNY 160, 955, and 2,229 at list API prices—meaning the effective plan unit price is about 50%–70% of pay-as-you-go.

    The conversion can be generalized:

    1. Effective plan unit price = monthly fee / (weekly available tokens × 4.345)
    2. Discount rate = effective plan unit price / pay-as-you-go unit price

    This leads to three practical recommendations: first, measure weekly consumption with real traffic before choosing a tier, so you do not pay for idle quota; second, schedule deferrable batch jobs (offline summarization, bulk refactoring, log analysis) into off-peak windows; third, treat the 4 peak hours as a scarce resource reserved for interactive requests only.

    5. Implementation Advice

    When doing capacity planning on platforms such as Baidu AI Cloud, you can combine common capabilities like monitoring alerts and log services to build a dashboard tracking hit rate, input/output ratio, and time-of-day distribution, and review it weekly. For cost-sensitive workloads, first stabilize the hit rate above the critical value through prefix governance, then consider a mix of plans and pay-as-you-go. Ultimately, the order of cost optimization should be: change how you call the API first, adjust timing second, and only then discuss unit price.