LLM Inference Cost Calculation and Plan Selection: A Practical Guide

    Comparing per-million-token list prices is a common but unreliable way to choose an LLM service. This article shows why real cost ranking depends on cache hit rate, input/output ratio, and peak-hour distribution, and how to build a three-part cost model to find the crossover hit rate between plans. It also covers practical techniques for raising cache hit rates, converting peak-hour windows into a cost multiplier, and evaluating monthly subscription plans by their converted API credit value. Readers get a reproducible financial model for inference cost attribution and plan selection.

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

    In discussions about selecting a large model service, the most common argument is that “this provider’s per-million-token price is lower, so it is cheaper.” This conclusion is unreliable because the list price is only one slice of a four-dimensional function. A real bill is determined jointly by at least the following variables:

    • The price gap across three tiers: cached input, uncached input, and output (often an order of magnitude apart);
    • The cache hit rate of your workload, which depends on prompt prefix stability, system prompt reuse, and session length distribution;
    • The input-to-output ratio: agent workloads are input-heavy, while summarization workloads are output-heavy;
    • The time distribution of requests, and whether they fall into the provider’s “peak hours.”

    The example in the source material confirms this: at a 98% hit rate, Plan A costs about 12.57 CNY per 100 million tokens and Plan B about 9.40 CNY; dropping the hit rate to 95% puts Plan A at about 14.92 CNY while Plan B rises to about 18.25 CNY, completely reversing the ranking. The takeaway is not “who is cheaper,” but that cost ranking is a function of the hit rate, and there is a crossover point.

    2. Building a Unified Three-Part Cost Model

    Let the cached price be p_hit, the uncached input price be p_in, the output price be p_out, the hit rate be h, the input share be a, and the output share be b (a + b + h = 1). Cost per million tokens:

    1. def cost_per_mtok(p_hit, p_in, p_out, h, a, b):
    2. assert abs(h + a + b - 1) < 1e-9
    3. return h * p_hit + a * p_in + b * p_out
    4. # Illustration only: demonstrates the calculation structure; replace values with current official prices
    5. plan_a = dict(p_hit=0.00115, p_in=0.008, p_out=0.030)
    6. plan_b = dict(p_hit=0.00050, p_in=0.010, p_out=0.035)
    7. for h in (0.90, 0.95, 0.98, 0.995):
    8. ca = cost_per_mtok(**plan_a, h=h, a=(1-h)*0.75, b=(1-h)*0.25)
    9. cb = cost_per_mtok(**plan_b, h=h, a=(1-h)*0.75, b=(1-h)*0.25)
    10. print(h, round(ca*100, 2), round(cb*100, 2))

    From this you can solve for the crossover hit rate h: choose Plan A when the actual hit rate is above h, and Plan B when it is below. A more practical engineering approach is to instrument your service, collect real (h, a, b) values for one week, and plug them into the model, rather than using the optimal ratio advertised by vendors.

    3. Hit Rate Is Designed, Not Prayed For

    A 3-point difference between 95% and 98% can flip the conclusion, so improving the hit rate pays off far more than cutting unit price. Actionable measures:

    1. Stabilize the prefix: put the system prompt, tool definitions, and few-shot examples first in a fixed order, and place volatile content such as timestamps, random IDs, and user nicknames at the end.
    2. Avoid meaningless perturbations: do not re-serialize the tool schema on every request (differences in key order or whitespace change the prefix hash).
    3. Segment the cache: parse long documents once and reuse them many times; append to session history and never rewrite past messages.
    4. Make it observable: log h, a, b, and cache invalidation reasons in your logging service, and set a lower-bound hit rate threshold with monitoring alerts.
    1. [Stable prefix: system prompt + tool definitions + examples] <- high-hit zone
    2. [Semi-stable zone: retrieved knowledge snippets] <- medium-hit zone
    3. [Volatile zone: current question, timestamp, session ID] <- no-hit zone

    4. Peak Hours: The Easily Overlooked Multiplier

    Beyond unit price, providers commonly apply different policies or rate limits during specific windows (for example, a few hours on weekday afternoons). The source mentions one plan whose peak window is 14:00–18:00 Monday through Friday, only 4 hours a day, which is more relaxed than another plan that divides the day into multiple peak periods. During selection, convert “peak window length × share of peak requests” into a multiplier:

    1. effective cost = base cost × (1 + peak share × peak premium factor)

    For schedulable workloads such as offline batch processing, bulk code repository indexing, and nightly regression tests, using a message queue to smooth peaks and shifting tasks into off-peak windows often saves more than switching providers.

    5. How to Evaluate Monthly Subscription Plans

    Plans (the Coding Plan type) are essentially “a discount in exchange for a usage commitment.” Use a single yardstick: how much original-price API credit each unit of subscription fee converts to:

    Tier Monthly fee (illustrative) Converted original-price credit Discount range
    Light ~118 CNY ~160 CNY 60%–70%
    Standard ~538 CNY ~955 CNY 55%–65%
    Heavy ~1078 CNY ~2229 CNY 50%–60%

    In other words, the effective plan unit price is roughly 50%–70% of pay-as-you-go. Decision rules:

    • Stable monthly usage below the lowest tier’s converted credit → pay-as-you-go is cheaper;
    • Usage between two tiers → pick the lower plan plus a small amount of pay-as-you-go as a buffer;
    • Highly volatile usage → keep the plan as a floor plus pay-as-you-go elasticity, and avoid buying out capacity for the peak.

    6. Conclusion and Action Checklist

    1. Do not compare unit prices; compare cost per 100 million tokens across the three dimensions of hit rate, input/output ratio, and time window.
    2. Instrument for one week first to obtain real (h, a, b) and the peak share.
    3. Use the crossover hit rate h* to judge which plan is better, and use engineering techniques to push h higher.
    4. Smooth peaks and fill valleys for schedulable workloads.
    5. Compare plans by “converted credit” rather than the monthly fee number, and keep pay-as-you-go as a buffer.

    Following this process turns selection from subjective impressions into a reproducible financial model. If an organization already uses model services on Baidu AI Cloud, the same model can be applied with logging service and monitoring alert data to complete cost attribution, and batch inference tasks can run on a general-purpose container platform to enable off-peak scheduling.