LLM Inference Cost Estimation and Plan Selection: A Practical Guide

    This article explains why comparing per-million-token prices often leads to wrong cost conclusions for large language model inference. It builds a minimal cost model based on cache hit rate, input/output ratio, and unit prices, then applies sensitivity analysis across optimistic, neutral, and pessimistic scenarios to find the crossover point between options. It also covers time-of-day pricing, quotas and rate limits, and how to evaluate prepaid plans versus pay-as-you-go using equivalent unit price and discount rate, along with practical implementation recommendations.

    1. Why “Price Comparison” Often Gives the Wrong Answer

    When teams move LLM applications into production, cost evaluation is often reduced to a single question: how much does one million tokens cost? This comparison looks intuitive, but it overlooks a key fact: an inference bill is not a single price multiplied by usage. It is determined by several billing dimensions working together. Cached input, uncached input, and output usually sit at completely different price tiers. Add time-of-day differences, plan quotas, and conversion rules, and the final spend can deviate from intuition by several times.

    The more useful approach is to first build a minimal viable cost model, then use sensitivity analysis to see how each variable affects the result range, and only then move on to product and plan selection. The sections below follow that order.

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

    Suppose a model consumes a total of T tokens in a billing period, with a cache hit rate of h, an input share of r_in, and an output share of r_out, where r_in + r_out = 1. The four billable quantities can be written as:

    1. cached_input = T * h * r_in
    2. fresh_input = T * (1 - h) * r_in
    3. output = T * r_out

    Let the corresponding unit prices be P_cache, P_in, and P_out. Total cost is then:

    1. Cost = T * ( h * r_in * P_cache
    2. + (1 - h) * r_in * P_in
    3. + r_out * P_out )

    This formula makes three things clear. First, cache pricing only dominates the bill when the hit rate is high enough. Second, output usually accounts for a small share, but its unit price is often several times that of input, so it cannot be ignored. Third, any conclusion about “which option is cheaper” must be tied to specific values of h and r_in/r_out; otherwise the comparison means nothing.

    In real engineering, h is not a configuration item but a function of business characteristics. The hit rate naturally runs high when system prompts are stable, tool definitions are fixed, and long documents are referenced repeatedly. If every request concatenates a timestamp, a random ID, or live user state, the prefix changes each time, the cache cannot be reused, and the hit rate drops quickly. To improve it, follow the “stable prefix” principle:

    1. [fixed system instructions] + [fixed tool/template definitions] + [reusable long context] + [per-turn variable content]

    Pushing the volatile parts as far to the end as possible is the lowest-cost way to raise cache reuse.

    3. Sensitivity Analysis: The Crossover Point Matters More Than Unit Price

    The example in the original discussion is representative: at an extremely high hit rate, the option with cheaper cache pricing does win; but once the hit rate falls back to a medium level, the high unit price of uncached input is amplified quickly and the conclusion reverses. Two cost curves therefore have a crossover point, and the real selection question is not which option has the lower point somewhere, but which side of the crossover the business will operate on over the long run.

    In practice, run three scenarios instead of a single-point estimate:

    • Optimistic: high hit rate and high input share, used to assess the theoretical lower bound;
    • Neutral: medium hit rate, used as the budget baseline;
    • Pessimistic: hit rate drops sharply or output share rises, used as a capacity and cost backstop.
    1. def estimate_cost(total, hit, in_ratio, p_cache, p_in, p_out):
    2. out_ratio = 1 - in_ratio
    3. return total * (hit * in_ratio * p_cache
    4. + (1 - hit) * in_ratio * p_in
    5. + out_ratio * p_out)
    6. for hit in (0.98, 0.95, 0.90, 0.80):
    7. print(hit, estimate_cost(1e8, hit, 0.015, 0.00115, 0.008, 0.04))

    Treating the hit rate as the independent variable and unit prices as parameters produces a cost curve that updates automatically as the business changes, rather than a static quote sheet that expires quickly.

    4. Time Windows and Quotas: Two Multipliers That Are Easy to Miss

    Beyond token unit prices, two other factors can significantly change actual spend. One is time-of-day pricing: some services charge differently for peak and off-peak windows, and the length of the peak window directly determines how much off-peak scheduling can save. The other is quotas and rate limits: plans and credit systems usually come with concurrency and throughput constraints, and once those limits are hit, the workload either queues or falls back to pay-as-you-go, causing cost to jump suddenly.

    Practical optimizations include: scheduling latency-insensitive work such as batch jobs, offline summarization, and log analysis into off-peak windows; defining fallback strategies for interactive paths so they switch to a smaller model when quota is tight; and building dashboards with alerts for token consumption, hit rate, and retry rate, so cost anomalies are caught the day they happen rather than at month end.

    5. Prepaid Plans vs. Pay-as-You-Go: How to Tell If It Pays Off

    Prepaid plan billing is essentially paying upfront for a discount. When evaluating it, do not look only at the listed price; convert it into an “equivalent unit price”:

    1. equivalent unit price = plan price / (weekly available tokens * number of periods)
    2. discount rate = equivalent unit price / pay-as-you-go list unit price

    If a plan tier works out to a discount rate in the 50–70% range under off-peak, high-hit-rate conditions, that means locking in capacity at roughly 60% of the price, which suits teams with stable, predictable usage. Conversely, when usage fluctuates widely and frequently hits the ceiling and spills into pay-as-you-go, prepaid credit ends up wasted. The rule of thumb: a plan buys certainty, pay-as-you-go buys elasticity.

    6. Implementation Recommendations

    1. Instrument first, optimize later: log input and output tokens, cache hit status, and time-window tags for every request. Without data there is no credible model.
    2. Compare with a consistent basis: plug every candidate option into the same set of h and ratio parameters so a single low price point does not mislead you.
    3. Start with prompt structure to raise the hit rate; the payoff usually beats repeatedly switching services.
    4. Set three-tier budgets and alert thresholds, and reserve a fallback for sudden traffic spikes.
    5. If you rely on general cloud capabilities, you can use object storage to hold reusable context, a message queue to smooth peaks, a container platform to run elastic inference, and logging plus monitoring and alerting for cost observability, forming a closed loop.

    Overall, optimizing LLM inference cost is not about finding the “cheapest unit price.” It is about putting hit rate, input/output structure, time windows, and quotas into one computable table and letting data drive selection and scheduling. Cloud providers such as Baidu AI Cloud typically publish explanations around these general billing dimensions as well; as long as readers keep the same basis when evaluating, they can reach conclusions that are robust and reproducible.