LLM Inference Cost Estimation and Plan Selection: A Practical Guide

    Comparing per-token list prices is often misleading because the real bill depends on cache hit rate, input/output ratio, time-of-day pricing, and billing granularity. This article shows how to build a reusable blended-price model, how to improve cache hit rate through prompt engineering, how to convert peak/off-peak pricing into weekly equivalent token capacity, and how to choose between pay-as-you-go and committed plans based on workload type. It also outlines how to align cost governance across billing, capacity, and monitoring.

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

    As LLM applications move into large-scale production, the cost structure has shifted from “how much does one call cost” to “the blended cost per effective token.” Public pricing usually lists only a few tiered unit prices: cached input, uncached input, and output. Comparing just one of these tiers can easily lead to a conclusion that contradicts the actual bill.

    The real bill is determined by four variables:

    • Cache hit rate: determines whether most input tokens fall into the low-price or high-price tier;
    • Input-to-output ratio: output tokens usually cost several times more than input tokens, so a higher output share significantly raises the average price;
    • Time-of-day structure: some services charge different prices during peak and off-peak hours;
    • Billing granularity and minimum billing unit: the more fragmented the requests, the higher the share of fixed overhead.

    The right approach is to define a “blended unit price” first, and only then discuss what is expensive or cheap.

    2. Building a Reusable Cost Model

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

    1. mix = h * p_cache + (1 - h) * p_in + b * p_out_scaled

    Illustrative implementation (only to show the calculation logic; parameters must be filled in with actual prices):

    1. def blended_price(p_cache, p_in, p_out, hit_rate, out_ratio):
    2. in_ratio = 1 - out_ratio
    3. return (hit_rate * p_cache
    4. + (1 - hit_rate) * p_in * in_ratio
    5. + p_out * out_ratio)
    6. # High hit-rate scenario
    7. print(blended_price(0.115, 8.0, 30.0, 0.98, 0.005))
    8. # Medium hit-rate scenario
    9. print(blended_price(0.115, 8.0, 30.0, 0.95, 0.005))

    There are three key conclusions. First, when the cache hit rate is extremely high (for example, close to 98%), differences in the cached price are amplified into differences in the bill, so the provider with the cheaper cache price does not necessarily win, because although the absolute volume of uncached input and output is small, their unit prices are high. Second, when the hit rate falls back to around 95%, the volume of that 5% uncached input is enough to change the ranking, and the option with the lower cache price may actually end up more expensive. Third, once the output share rises from 0.5% to 5%, the average price of every option moves up noticeably, and the benefit of the cache strategy is diluted.

    3. Cache Hit Rate Is Not a Constant, but a Metric That Requires Engineering

    A common root cause of distorted cost estimates is treating the hit rate as an externally given condition. In practice, the hit rate is determined by how requests are constructed, and it can be improved steadily with the following practices:

    1. Stable prefix: place the system prompt, tool descriptions, and few-shot examples at the very front and do not concatenate dynamic content into them;
    2. Variables at the end: move volatile content such as timestamps, user identifiers, and random IDs to the tail of the prompt;
    3. Template versioning: ship prompt changes as versioned releases to avoid sharp hit-rate fluctuations during canary rollouts;
    4. Batch and concurrency control: excessive concurrency may trigger cache eviction and lower the hit rate;
    5. Observability: log cached and uncached tokens for every request in a logging service to build a hit-rate time series.
    1. Recommended request structure:
    2. [Stable prefix: role definition + tool list + output spec] <- high reuse
    3. [Semi-stable section: business knowledge snippets] <- medium reuse
    4. [Dynamic section: user input + context variables] <- not reused

    4. How to Convert Time-of-Day Differences into Usable Capacity

    When a service uses peak/off-peak differential pricing, the comparison baseline should be the “equivalent token volume available within a week,” not the monthly fee. The conversion steps are:

    • Measure the hourly call distribution of the target workload to obtain the peak-hour share r;
    • Recalculate the weekly cost using the blended price of off-peak and peak;
    • Divide the plan’s monthly fee by the blended price to get the equivalent pay-as-you-go API quota;
    • Calculate the discount rate = plan price / equivalent pay-as-you-go quota.

    With this method, a common finding is that plan prices land roughly between 50% and 70% of the equivalent pay-as-you-go quota; if the workload is highly concentrated in peak hours, the discount is significantly weakened and the plan’s value drops accordingly. Conversely, if the workload can shift to off-peak hours (for example, offline batch processing or overnight data processing), the actual benefit of the plan is higher than the headline discount.

    5. Selection Checklist

    • Interactive coding workloads: high output share and high context repetition; prioritize the cached input price and the plan quota;
    • Long-document extraction workloads: high input share, where the uncached input price carries the most weight;
    • Batch workloads: shift to off-peak hours deliberately to maximize off-peak pricing and plan quota;
    • Volatile workloads: prefer pay-as-you-go with budget alerts to avoid wasting plan quota;
    • Compliance-sensitive scenarios: evaluate total cost of ownership together with private deployment or dedicated resource options.

    6. Aligning Cost Governance Across Engineering and Finance

    It is recommended to unify three definitions. First, the billing definition: use the “blended price per million effective tokens” as the single comparison metric. Second, the capacity definition: measure plans by “weekly equivalent token quota.” Third, the governance definition: set thresholds for hit rate, output share, and peak-hour share through monitoring and alerting. If you use Baidu AI Cloud capabilities, you can deliver call logs to a logging service, track hit rate and cost drift with monitoring alerts, and run batch jobs on a container platform to shift load off-peak, gaining cost advantages at the architecture level rather than at the negotiation table.

    In summary, the essence of model selection is not comparing a single tier’s unit price, but plugging the cache hit rate, input/output ratio, and time-of-day structure into a unified model to derive the blended cost. Building a reproducible estimation script and incorporating it into routine capacity reviews is the fundamental way to avoid budget overruns.