LLM Inference Cost Estimation and Plan Selection: A Practical Guide

    Comparing per-million-token prices across LLM providers almost always leads to the wrong conclusion because cost is not a scalar but a multi-variable function. This article presents a vendor-neutral framework for estimating real inference cost from cache hit rate, input/output ratio, and peak-hour multipliers, then shows how to convert subscription plans into an effective per-token price. It includes a reusable Python estimation function, engineering practices for cost instrumentation, and a checklist for choosing between pay-as-you-go and committed plans.

    1. Why Comparing Unit Prices Almost Always Leads to the Wrong Conclusion

    During LLM application selection, the most common approach is to put two providers’ “price per million tokens” side by side and pick the smaller number. The problem is that this treats cost as a scalar, while a real bill is a function of multiple variables. The cost of a single request is made up of at least four token categories: cache-hit tokens, cache-miss input tokens, output tokens, and reasoning tokens that some services bill separately. Add time-of-day multipliers, cache write and expiry policies, and minimum billing granularity, and the provider with the lower unit price can easily turn out to be more expensive under real business load.

    The right approach is to build a cost model first, then plug in your own workload parameters. Below is a general, vendor-neutral estimation framework.

    2. The Cost Model: Breaking the Bill into Computable Terms

    Let the unit prices of the four token categories be p_cache, p_in, p_out, and p_reason, with corresponding quantities N_cache, N_in, N_out, and N_reason, and let the time-of-day multiplier be m. The cost of a single request is:

    1. Cost = m * (N_cache*p_cache + N_in*p_in + N_out*p_out + N_reason*p_reason)

    In engineering practice, what really matters is the cache hit rate h and the input/output ratio. Define the hit rate:

    1. h = N_cache / (N_cache + N_in)

    The input-side cost can then be rewritten as:

    1. Cost_input = (N_cache + N_in) * (h*p_cache + (1-h)*p_in)

    This reveals a key fact: the effective unit price on the input side is a weighted average of the cache price and the cache-miss input price, with weights determined by the hit rate. When the cache price differs from the input price by several times, raising the hit rate from 95% to 98% often yields more savings than the unit-price gap between two providers.

    Here is an implementation you can drop straight into a budgeting script:

    1. def estimate_cost(total_tokens, hit_rate, in_ratio, out_ratio,
    2. p_cache, p_in, p_out, peak_multiplier=1.0):
    3. n_in_total = total_tokens * in_ratio
    4. n_out = total_tokens * out_ratio
    5. return peak_multiplier * (
    6. n_in_total * (hit_rate * p_cache + (1 - hit_rate) * p_in)
    7. + n_out * p_out
    8. )

    3. Comparison Results Under Two Typical Workloads

    The original estimation produced two representative sets of numbers that abstract into two general rules.

    The first is a high-hit-rate scenario: a hit rate of about 98%, with input at 1.5% and output at 0.5%. Here, per 100 million tokens, the provider with the higher cache price costs about 12.57 yuan, while the one with the lower cache price costs about 9.40 yuan, roughly 30% cheaper. In the second set, the hit rate drops to 95%: per 100 million tokens, the former costs about 14.92 yuan, but the latter rises to about 18.25 yuan, completely reversing the ranking.

    Rule 1: When the cache price is clearly lower than the input price, cost is highly sensitive to the hit rate. Every one-point drop in hit rate inflates the effective input-side unit price, and the inflation factor depends on the gap between the two prices.

    Rule 2: Although the output share is small, it scales up quickly in scenarios like long-form generation and code completion, so don’t be lulled by a “tiny-looking” ratio like 0.5%. Use your own measured workload ratios in estimates rather than the sample values.

    4. Time-of-Day Multipliers: The Underestimated Cost Variable

    Many services apply a multiplier during “peak hours.” Two common designs are worth distinguishing: one with a long peak window (for example, covering the entire daytime of a workday), and one with a very short peak window (for example, only 4 hours per workday). The shorter the window, the higher the probability that jobs can be scheduled outside peak hours, and the closer the effective average multiplier gets to 1.

    The average multiplier can be written in time-weighted form:

    1. m_avg = (T_peak * m_peak + T_off * m_off) / (T_peak + T_off)

    If peak hours are 4 hours a day with a multiplier of 2 and off-peak is 1, then m_avg = (4*2 + 20*1)/24 ≈ 1.33. For deferrable workloads such as offline batch processing, bulk code scanning, and log summarization, funneling requests into off-peak windows through a queue is equivalent to an automatic discount of around 25%, and this saving is usually more controllable than switching providers.

    5. Converting Subscription Plans into an Effective Unit Price

    A monthly subscription plan should not be evaluated on price alone, but on the per-token cost obtained by dividing quota by price, compared against the effective unit price of pay-as-you-go. The recommended conversion steps:

    1. Take the plan’s official quota at a given hit rate (for example, several hundred million tokens per week);
    2. Adjust for actual usable quota based on your workload’s peak/off-peak request distribution;
    3. Divide the plan price by the adjusted quota to get the effective unit price;
    4. Compare it with the pay-as-you-go effective unit price under the same hit rate and the same time-of-day distribution.

    In the original estimation, three plan tiers were equivalent to roughly 160 yuan, 955 yuan, and 2229 yuan of list-price API usage, while the plan prices were about 50% to 70% of the corresponding list prices, meaning discounts landed roughly in the 30%–70% range. This range shows that a plan’s value depends heavily on whether you actually use the full quota. If you consume only 30% of the quota in a month, the effective unit price quickly degrades to near or even worse than pay-as-you-go.

    A practical decision inequality:

    1. plan is better <=> actual usage >= plan price / pay-as-you-go effective unit price

    6. Putting Cost Estimation into Engineering Practice

    Make cost observability a standing capability rather than a month-end look at the bill: instrument the gateway to log the four token counts and time-of-day tags by tenant, model, and endpoint; use monitoring and alerting to flag hit rates falling below a threshold or output share rising abnormally; and use a logging service to retain traceable usage details for retrospectives. A sample instrumentation structure:

    1. {
    2. "tenant": "team-a",
    3. "ts": "2026-01-01T10:00:00Z",
    4. "peak": false,
    5. "tokens": {"cache": 980000, "input": 15000, "output": 5000}
    6. }

    If you use Baidu AI Cloud capabilities, you can combine object storage for usage archiving, a message queue for peak shaving, a container platform to host the inference gateway, and monitoring, alerting, and logging services for observability to form a closed loop, without relying on any single vendor’s proprietary billing definitions.

    7. Conclusion Checklist

    • Don’t compare unit prices; compare the effective unit price under “hit rate × workload ratio × time-of-day multiplier”;
    • A one-point drop in hit rate can change the provider ranking, so estimate with your own measured values;
    • The shorter the peak window, the more scheduling flexibility you have, so batch jobs should proactively shift off-peak;
    • A plan only pays off when you use it fully; verify with the inequality before purchasing;
    • Make cost instrumentation, alerting, and archiving part of your infrastructure so optimization is backed by data.