LLM Inference Cost: A Practical Guide to Calculating the Real Bill

    Comparing per-token list prices is a common but misleading way to evaluate LLM inference costs, because the final bill is the product of three variables rather than a function of any single rate. This guide introduces a parameterized cost model based on cache hit rate, input-to-output ratio, and peak-hour pricing, and shows how to solve for the break-even cache hit rate that determines which option is cheaper. It also explains how to normalize time-of-use policies into peak hours per week, how to convert subscription coding plans into effective per-token prices, and offers a practical cost governance checklist covering instrumentation, prefix stability, context trimming, batch scheduling, model routing, and monthly reviews.

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

    When evaluating LLM applications, cost assessment is often reduced to a single price comparison: put cache read, input, and output prices in a table and declare whichever number is lower the cheaper option. This ignores a basic fact—the bill is the product of three variables, not a function of any single rate.

    The three variables are:

    • Cache hit rate: determines whether the repeated prefix portion of a request goes through the low-price channel;
    • Input-to-output ratio: output prices are typically much higher than input prices, so even a small shift in the ratio amplifies the difference;
    • Time-of-day structure: the industry commonly uses peak/off-peak pricing, with higher billing multipliers during peak hours.

    If any one of these takes a different value between two candidate options, the option with the lower list price can easily end up with a higher total bill. The right approach is to build a unified estimation model, make the variables explicit, and then run a sensitivity analysis.

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

    Let a given option have a cache read price p_cache, a regular input price p_in, and an output price p_out, with cache hit rate h, input (non-cached) share r_in, and output share r_out, where r_in + r_out + h = 1. The expected cost per unit token is then:

    1. def cost_per_mtok(p_cache, p_in, p_out, h, r_in, r_out, peak_factor=1.0):
    2. """Return the expected cost per million tokens (same currency unit)"""
    3. assert abs(h + r_in + r_out - 1.0) < 1e-6, "Shares must sum to 1"
    4. base = h * p_cache + r_in * p_in + r_out * p_out
    5. return base * peak_factor
    6. # Illustration: shows the calculation structure only; values are assumed
    7. low_hit = cost_per_mtok(0.115, 8.0, 20.0, h=0.98, r_in=0.015, r_out=0.005)
    8. mid_hit = cost_per_mtok(0.115, 8.0, 20.0, h=0.95, r_in=0.045, r_out=0.005)
    9. print(low_hit, mid_hit)

    This formula captures the essence of the phenomenon described above: when h is very high, the bill is almost entirely dominated by the cache price, and the option with the cheaper cache wins; as h drops, the regular input term is quickly amplified, differences in input price begin to dominate, and the ranking can flip. The conclusion is not “who is cheaper,” but “who is cheaper within a given hit-rate range.”

    3. Key Variable One: The Critical Point of Cache Hit Rate

    In engineering practice, you should solve for the break-even hit rate h*—the hit rate at which the two options cost the same. Solve the two cost curves simultaneously:

    1. def breakeven_hit(a, b):
    2. """a and b are (p_cache, p_in, p_out) tuples; returns the hit rate at equal cost"""
    3. # h*p_cache_a + (1-h)*p_in_a*... expands into a linear equation in h
    4. ka = a[0] - (a[1] * 0.97 + a[2] * 0.03)
    5. kb = b[0] - (b[1] * 0.97 + b[2] * 0.03)
    6. ca = a[1] * 0.97 + a[2] * 0.03
    7. cb = b[1] * 0.97 + b[2] * 0.03
    8. return (cb - ca) / (ka - kb)

    h* is the dividing line for the decision: if the measured hit rate is above it, choose the option with the cheaper cache; if below it, choose the one with the cheaper input. Hit rate is not a matter of luck—it depends on the workload shape. Scenarios with a fixed system prompt, stable tool definitions, and repeated Q&A over long documents have high hit rates; scenarios where the prefix changes on every request have low hit rates. Running a small-sample measurement on real traffic before launch is more reliable than any theoretical assumption.

    4. Key Variable Two: Peak/Off-Peak Pricing and Differences in Time Definitions

    The trap in time-of-use pricing is that the definition of “peak” is not standardized: some options split by calendar day, with peak covering the entire daytime working period; others cover only a few hours on weekday afternoons. The practical impact on developers is completely different, so you need to weight by the week:

    1. WEEK_HOURS = 7 * 24
    2. def weekly_cost(per_mtok, weekly_mtok, peak_hours_per_week, peak_factor):
    3. peak_ratio = peak_hours_per_week / WEEK_HOURS
    4. eff = per_mtok * ((1 - peak_ratio) + peak_ratio * peak_factor)
    5. return eff * weekly_mtok

    Only 4 peak hours per week means roughly 2.4% of the time is in the surcharge window, and the weighted average cost barely changes; peak coverage of 8 hours per day means nearly 48% of the time is surcharged, and the effective unit price can rise by a multiple. When evaluating time-of-use policies, always convert to a common measure of “peak hours per week” before comparing.

    5. Key Variable Three: How to Normalize Subscription Coding Plans

    The value of a subscription plan (a fixed monthly fee with a token or request allowance) cannot be judged by the sticker price; it must be converted into an effective unit price:

    1. Effective unit price = monthly fee / monthly available tokens
    2. Discount rate = effective unit price / pay-as-you-go list price on the same basis

    On this basis, the discount rate of common plans falls roughly in the range of 30% to 70% of list price, with higher allowance tiers showing more obvious discounts. But the conversion must correct for three things: first, allowances are usually calibrated on an off-peak basis, and peak usage erodes the allowance; second, plans generally have fair-use limits, after which service is downgraded or throttled; third, allowances do not roll over across months, so idle capacity is wasted. Plans therefore suit teams with stable, predictable usage; when usage fluctuates heavily or strict per-project quota isolation is required, pay-as-you-go is more controllable.

    6. An Actionable Cost Governance Checklist

    1. Instrument the three-tuple: log cached tokens, input tokens, output tokens, and a timestamp on every call to build raw cost data.
    2. Build dashboards and alerts: use cloud monitoring and log services to set threshold alerts on per-token cost and cache hit rate.
    3. Optimize prefix stability: placing the system prompt, tool descriptions, and few-shot examples at the front and keeping them byte-for-byte stable is the most direct way to raise the hit rate.
    4. Trim context: rerank and truncate retrieval results so irrelevant long text is not stuffed into the prefix, reducing both input volume and protecting the hit window.
    5. Batch and off-peak scheduling: move non-real-time tasks to off-peak hours and use queues to flatten the peak asynchronously.
    6. Tiered model routing: send simple requests to a lightweight model and escalate complex ones, avoiding the high-cost tier for the entire flow.
    7. Monthly review: regress the cost model against real data, update the break-even hit rate and plan discount rates, and revise the selection on a rolling basis.

    7. Conclusion

    The right way to evaluate LLM costs is to turn the “price table” into a closed loop of “parameterized model + measured data + periodic review.” The cache hit rate determines the slope of the curve, the input/output ratio determines the intercept, and the time-of-use policy determines the weighting factor—together they determine the final bill. With this method, selection is no longer a camp dispute but an engineering decision that is computable, verifiable, and continuously optimizable; combined with general cloud capabilities such as the monitoring, alerting, and log services offered by Baidu AI Cloud, cost governance can shift from monthly guesswork to real-time control.