LLM Inference Cost Modeling and Plan Selection: A Practical Guide

    Comparing per-token prices across LLM providers almost always leads to wrong conclusions. This article shows how to build a reusable cost model based on cache hit rate, input/output ratio, and peak-hour structure, how to calculate the break-even cache hit rate instead of comparing unit prices, how to convert subscription quotas into equivalent API value, and how to use request shifting to reduce peak-hour premiums. It includes Python snippets for cost estimation and break-even analysis, plus a practical checklist for instrumenting usage data and choosing between pay-as-you-go and monthly plans.

    LLM Inference Cost Modeling and Plan Selection: A Practical Guide

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

    As large language model applications move into large-scale production, cost discussions have become more frequent than discussions of output quality. A common pattern of argument goes like this: put two providers’ cache-hit prices side by side, conclude that “one provider is more than twice as expensive,” and stop there. The conclusion may be mathematically correct, but it is nearly meaningless in engineering terms.

    The reason is that the token unit price is only one multiplier in the bill. What actually determines the bill is the combination of three variables:

    • Cache hit rate: determines what share of input tokens are billed at the cache price, which is typically around one tenth of the regular input price;
    • Input-to-output ratio: output tokens often cost several times more per token than input tokens, so small shifts in the output share get amplified;
    • Time-of-day structure: some services apply different multipliers to peak and off-peak hours, so the temporal distribution of requests shifts the entire cost curve.

    Only when these three are held fixed does comparing unit prices become a meaningful comparison. Otherwise, you are comparing two different workload profiles.

    2. Building a Reusable Cost Model

    Suppose a provider has four price points: cache-hit price p_cache, regular input price p_in, and output price p_out (all normalized to currency per million tokens). Given total tokens T, cache hit rate h, input share r_in, and output share r_out:

    1. Cost(T) = T * [ h * r_in * p_cache
    2. + (1 - h) * r_in * p_in
    3. + r_out * p_out ]

    The formula looks plain, but it exposes two key properties.

    Property 1: There is a break-even point for the cache hit rate. Setting the unit price functions of two options equal lets you solve for a critical hit rate h*. When the actual hit rate is above h*, the option with the lower cache price wins; below h*, the option with the lower regular input price wins. The two sets of numbers in the original analysis fall on opposite sides of that point: at a 98% hit rate option A is clearly cheaper, while at a 95% hit rate option B overtakes it. A 3-percentage-point difference in hit rate is enough to completely reverse the conclusion.

    Property 2: The hit rate is not a constant but a function of workload characteristics. It depends on how stable the prompt prefix is, whether the system prompt is fixed, whether few-shot examples are reused, and whether sessions are multi-turn and continuous. Treating it as a constant you can fill in by guesswork is the most common source of error in cost estimation.

    The model is fixed in the illustrative code below so that it can be wired to monitoring data and produce bills automatically:

    1. def estimate_cost(total_tokens, hit_rate, in_ratio, out_ratio,
    2. p_cache, p_in, p_out):
    3. """Return the inference cost for a period (in currency units)"""
    4. assert abs(in_ratio + out_ratio - 1.0) < 1e-6
    5. cached = total_tokens * hit_rate * in_ratio
    6. fresh = total_tokens * (1 - hit_rate) * in_ratio
    7. output = total_tokens * out_ratio
    8. return (cached * p_cache + fresh * p_in + output * p_out) / 1_000_000
    9. def break_even_hit_rate(in_ratio, out_ratio, a, b):
    10. """Solve for the critical cache hit rate between options a and b"""
    11. # a: (p_cache_a, p_in_a, p_out_a) b: same structure
    12. numerator = (in_ratio * b[1] + out_ratio * b[2]) - \
    13. (in_ratio * a[1] + out_ratio * a[2])
    14. denominator = in_ratio * ((a[1] - a[0]) - (b[1] - b[0]))
    15. return numerator / denominator

    3. Converting “Nominal Quota” into “Equivalent API Value”

    Monthly subscription plans follow a completely different pricing logic from pay-as-you-go billing: they convert uncertain token consumption into a fixed monthly fee. To assess whether a plan is worthwhile, you need a metric called equivalent API value:

    1. Equivalent value = tokens consumable within the plan * pay-as-you-go unit price
    2. Discount rate = monthly fee / equivalent value

    The analysis in the original article shows that, under assumptions of a 98% hit rate and off-peak usage, the discount rates of the three plan tiers land roughly in the 50%–70% range, meaning the plan price is about half to seventy percent of the equivalent pay-as-you-go cost. The range itself is not the point; its sensitivity is. Equivalent value is affected by both the hit rate and the time-of-day structure, so once the hit rate drops or requests concentrate in the peak window, the discount rate converges rapidly toward 100% and the plan’s cost advantage disappears.

    A more robust approach is therefore to estimate a range rather than a single point:

    1. def plan_value(tokens_per_week, hit_rate_range, price_fn, weeks=4.345):
    2. values = [estimate_cost(tokens_per_week * weeks, h, 0.985, 0.015, *price_fn)
    3. for h in hit_rate_range]
    4. return min(values), max(values)

    4. Peak Hours: The Underestimated Cost Lever

    Providers define peak hours very differently. Some define peak as multiple windows across the whole working day; others compress it to roughly four hours per day. The practical impact of this difference can be expressed with a simple weighted model:

    1. Effective cost = off-peak cost * (1 - f) + peak cost * f * m

    Here f is the share of requests falling in peak hours and m is the peak multiplier. When the workload is an interactive scenario concentrated on weekday afternoons, f can exceed 0.6, and at that point whether the peak definition is generous matters more to the bill than the cache hit rate. The engineering countermeasure is request shifting: schedule deferrable work such as batch jobs, code indexing, log summarization, and offline evaluation into off-peak windows, and reserve peak quota for the user interaction path.

    5. Implementation Checklist

    1. Instrument first, negotiate price later: collect cached input tokens, regular input tokens, output tokens, and timestamps for every call to form a real distribution, instead of substituting the provider’s assumptions for your own workload.
    2. Compute the break-even point, not the unit price: use break_even_hit_rate to get the critical hit rate and determine which side of it you are on.
    3. Model plans at both P50 and P95: use a range rather than a single point to decide which tier to buy, and leave room to move down or up a tier.
    4. Actively raise the hit rate: keep the system prompt prefix fixed, reuse stable example context, and avoid rewriting prefix content mid-session. These changes cost almost nothing and the benefit shows up directly on the bill.
    5. Build a cost dashboard: put token structure, hit rate, time-of-day distribution, and cost in one view, and use logging plus monitoring alerts to locate anomalous spikes.

    6. Conclusion

    The unit price is only the surface of the bill; the cache hit rate, the input/output ratio, and the time-of-day structure are the three main axes that determine cost. Rather than arguing about whose unit price is lower, it is better to internalize the cost model as an engineering capability: drive estimates with real instrumentation data, judge options by the break-even point, and shave off peak premiums with shifting-based scheduling. Do these three things and, whether you choose pay-as-you-go or a monthly plan, you can improve the predictability of your budget by an order of magnitude.