LLM Inference Cost Estimation and Plan Selection: A Practical Guide

    Comparing per-million-token prices across providers almost always leads to the wrong conclusion, because the real bill is driven by billing structure rather than unit price. This article introduces a cost model based on three variables—cache hit rate, input/output token ratio, and peak-hour distribution—and shows with two scenarios how the cheaper option can flip when the hit rate drops. It also covers practical ways to raise cache hit rates, schedule non-real-time workloads away from peak windows, and convert subscription plans into equivalent pay-as-you-go API credit to calculate an effective discount rate. A cost governance checklist is included to help you build a dashboard, set budget alerts, and keep billing assumptions replaceable.

    1. Why Unit-Price Comparisons Almost Always Lead to the Wrong Conclusion

    When evaluating LLM inference costs, the most common approach is to put two providers’ “price per million tokens” side by side and pick the lower one. The flaw is that a real bill is not determined by unit price alone—it is determined by the billing structure. The same prompt can cost several times more or less depending on the cache hit rate, the input/output ratio, and the time of day the calls are made.

    So the right starting point for cost estimation is not a price list, but three variables:

    • Cache hit rate: the share of repeated prefixes that get reused;
    • Input/output ratio: the proportion of input, cache-read, and output tokens;
    • Time-of-day distribution: whether calls fall inside the provider’s “peak hours.”

    Once these three variables are fixed, the unit price is just a multiplier—and it can even be fully offset by structural differences.

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

    Let total tokens be N, cache hit rate h, input ratio i, output ratio o, and the four unit prices be p_cache (cache read), p_in (uncached input), and p_out (output). Then:

    1. Cost(N) = N * ( h * p_cache + (1 - h) * i * p_in + o * p_out )

    One easily overlooked detail: h and i are two independent dimensions. The cache hit rate describes “tokens that have already appeared being reused,” while the input ratio describes “the share of non-output tokens in the total.” Conflating the two is the root cause of many cost estimation errors.

    Sample implementation:

    1. def estimate_cost(total_tokens, hit_rate, in_ratio, out_ratio,
    2. p_cache, p_in, p_out):
    3. assert abs(in_ratio + out_ratio - 1.0) < 1e-6
    4. cached = total_tokens * hit_rate
    5. miss_in = total_tokens * (1 - hit_rate) * in_ratio
    6. output = total_tokens * out_ratio
    7. return cached * p_cache + miss_in * p_in + output * p_out

    3. Quantified Results for Two Scenarios

    Using the two typical scenarios from the original estimate (per 100 million tokens):

    Scenario A: High cache hit rate (98% hit, 1.5% input, 0.5% output)
    The bill is almost entirely dominated by the cache-read price, and the output share is so small it barely matters. The two options come out at roughly 12.6 CNY and 9.4 CNY; the one with the lower cache-read price wins, by about 30%.

    Scenario B: Medium cache hit rate (95% hit)
    The uncached input share rises from 1.5% to 5%, amplifying the weight of the input price. The result flips to roughly 14.9 CNY and 18.3 CNY—the option with the higher cache-read price but lower input price is actually cheaper.

    The conclusion is clear: the cache-read price is decisive only at extremely high hit rates; once the hit rate drops, the uncached input price becomes the dominant term. Any unit-price comparison detached from the hit-rate range does not hold.

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

    The hit rate is not a configuration item; it is the outcome of business characteristics. Practical ways to raise it include:

    1. Stabilize the prefix: put the system prompt, tool definitions, and examples first and keep them byte-for-byte identical; avoid timestamps or random IDs polluting the prefix;
    2. Reuse within a session: keep the prefix consistent across multi-turn conversations so later turns hit directly;
    3. Batch homogeneous requests: aggregate requests built from the same template to raise the reusable share of each call;
    4. Monitor the hit rate: treat it as a first-class metric in monitoring and alerting—an abnormal drop usually means a template was modified by accident.

    Keep in mind that the hit rate has a ceiling: the more diverse the business and the more personalized the context, the lower the hit rate. Use a conservative hit rate (such as 90%–95%) for budgeting, not an ideal one.

    5. Peak Hours: An Underrated Cost Amplifier

    Subscription plans commonly introduce time-of-day differences: token consumption during peak hours is more “expensive” (quota is consumed faster). A key observation from the original material is that providers define peak windows very differently—some cover only 4 hours a day, others cover a much longer window.

    The engineering response is to fold “time of day” into scheduling:

    • Schedule non-real-time tasks such as batch jobs, offline summarization, and code scanning into off-peak windows;
    • Keep online paths real-time, but use queues to smooth out spikes and avoid concentrated retries during peak hours;
    • Tag every call with its time window on the client side so the peak share can be accounted for after the fact.

    6. Plans vs. Pay-as-You-Go: How to Do the Equivalent Conversion

    To judge whether a plan is economical, convert it into equivalent list-price API quota and divide by the subscription price:

    1. Plan discount rate = monthly subscription fee / (list-price API value of the monthly token allowance)

    The original estimate puts the magnitudes at roughly 160 CNY, 955 CNY, and 2,229 CNY of list-price API usage per month for the three tiers, against subscription prices of about 118 CNY, 538 CNY, and 1,078 CNY—discount rates landing in the 50%–70% range.

    This yields the selection rules:

    • Stable, predictable usage → the plan is better, and the discount rate is a guaranteed gain;
    • Highly variable usage or clear peaks → pay-as-you-go is better, avoiding payment for idle quota;
    • A hybrid strategy is usually optimal: baseline load on the plan, burst traffic on pay-as-you-go.

    7. A Practical Cost Governance Checklist

    1. Build a unified cost dashboard with at least these dimensions: total tokens, hit rate, input/output ratio, peak share, and converted amount;
    2. Set budget thresholds and alerts for each type of business;
    3. Review the hit rate and ratios monthly and recompute the effective unit price;
    4. Version-control prompt templates, and assess the impact of any change on the hit rate;
    5. Keep the billing model replaceable in the architecture, avoiding tight coupling to a single billing scheme.

    8. Conclusion

    Real cost = billing structure × business load characteristics. Unit price is only a surface parameter; the hit rate, the input/output ratio, and the time-of-day distribution are the three levers that actually determine the bill. Bring all three into an observability system and compare pay-as-you-go against plans with a single conversion formula, and you can avoid the misjudgment that “a lower unit price always means savings.” If needed, the dashboard and scheduling pipeline described above can be built on top of Baidu AI Cloud capabilities such as monitoring and alerting, log services, and message queues, making cost quantifiable, alertable, and optimizable.