How to Calculate the Real Cost of LLM Inference: A Practical Guide

    Comparing per-million-token prices is misleading because the final bill depends on cache hit rate, input/output mix, and peak-hour multipliers. This guide breaks down the LLM inference pricing formula, shows how small changes in cache hit rate can reverse cost rankings, explains how to model peak-window surcharges, and outlines how to compare subscription plans against pay-as-you-go pricing. It also includes a sample calculation script and a deployment checklist for tracking real usage and keeping cost estimates accurate over time.

    1. The Starting Problem: Why “Price Per Token” Comparisons Are Almost Always Wrong

    In LLM application evaluations, the most common argument is that “Provider X is cheaper because its price per million tokens is lower.” In most real-world workloads, this conclusion does not hold. The reason is simple: the listed unit price is just one coefficient in the pricing formula, while the bill is the result of multiplying several coefficients and summing them up.

    The real cost of a single request is determined by at least five variables:

    1. The pricing of the cache-hit portion (usually significantly lower than the standard input price);
    2. The pricing of standard input tokens that miss the cache;
    3. The pricing of output tokens (usually the most expensive segment);
    4. The time-of-day multiplier (some platforms charge higher rates during business peak hours);
    5. The input-to-output ratio and the cache hit rate itself.

    If any two platforms differ in these variables, the ranking by unit price and the ranking by actual bill can be completely reversed. The correct approach is therefore not to compare unit prices, but to write out the pricing formula explicitly and plug in your own workload parameters.

    2. The Cost Model: Writing the Bill as a Computable Formula

    Let T be the total number of tokens in a given billing period, h the cache hit rate, a the input ratio, and b the output ratio (a + b = 1), with p_cache as the cache price, p_in the standard input price, and p_out the output price. Then:

    1. Cost = T * [ h * a * p_cache + (1 - h) * a * p_in + b * p_out ]

    This formula reveals three key takeaways:

    • The cache price only dominates the bill when h is high enough. Once h drops, the (1-h) term grows quickly, erasing or even reversing the advantage of a low cache price.
    • The output ratio b is an amplifier. For generative workloads (long answers, code completion, document generation), b is often much higher than intuition suggests, making differences in output pricing more damaging than differences in input pricing.
    • The time-of-day multiplier is an extra factor applied to the whole bill or to individual segments. It needs to be modeled separately and cannot be folded into a unit price comparison.

    3. Scenario-Based Calculations: The Fork Between High and Low Hit Rates

    Using “per 100 million tokens” as a common unit of measure makes the fork point clear.

    High hit-rate scenario (cache hit rate around 98%, input 1.5%, output 0.5%): the bill is almost entirely determined by the cache segment, so the option with the lower cache price wins, with the gap between the two candidates being roughly 30%.

    Medium hit-rate scenario (cache hit rate around 95%): a drop of just 3 percentage points in the hit rate multiplies the cost of the cache-miss input segment several times over, reversing the ranking of the bills. The option with a slightly higher cache price but cheaper standard input turns out to be less expensive.

    This yields a practical rule of thumb: the 95% range is a sensitive zone for hit rate, and any selection conclusion must state the assumed hit rate, or the numbers are meaningless. Below a 90% hit rate, cache optimization basically stops working, and you should go back to comparing standard input and output prices.

    Illustrative calculation script:

    1. def cost_per_100m(hit=0.98, in_ratio=0.015, out_ratio=0.005,
    2. p_cache=0.115, p_in=4.0, p_out=16.0, peak_factor=1.0):
    3. total = 1e8
    4. cached = total * hit * in_ratio
    5. miss = total * (1 - hit) * in_ratio
    6. out = total * out_ratio
    7. return peak_factor * (cached * p_cache + miss * p_in + out * p_out) / 1e6

    4. Time-of-Day Strategy: The Width of the Peak Window Matters More Than the Discount

    Some platforms define peak hours and raise rates during those hours. When evaluating them, you cannot just check whether a peak window exists; you need to quantify three parameters: how many hours per day the peak window lasts, which weekdays it covers, and what the surcharge multiplier is.

    Assume the peak window is 4 hours per weekday. That is about 20 peak hours per week, or roughly 12% of the 168 hours in a week. If the window expands to 8 hours per day, the share rises to about 24%. For offline batch jobs, simply scheduling tasks outside the window avoids the surcharge entirely. For online interactive workloads, you should evaluate the actual share of traffic during peak hours and weight it with the real distribution rather than a uniform one.

    A common engineering practice is to make the time-of-day factor a configuration item rather than hard-coding it:

    1. pricing:
    2. peak_window: "weekdays 14:00-18:00"
    3. peak_multiplier: 1.0 # fitted from actual workload traffic distribution
    4. off_peak_multiplier: 1.0

    5. Converting Subscription Plans to Pay-As-You-Go Terms

    Subscription coding plans are often described as “equivalent to a certain percentage of the original API price,” and this kind of conversion needs a consistent basis before it can be compared. The correct steps are:

    1. Multiply the token allowance included in the plan (distinguishing peak and off-peak) by the corresponding unit prices to get the equivalent pay-as-you-go amount;
    2. Divide the monthly plan fee by the equivalent amount to get the effective discount rate;
    3. Use your own average monthly token consumption to judge whether you can fully use the plan; if you cannot, the discount rate is meaningless.

    Typical conversions for the three plan tiers usually land between 50% and 70% of the pay-as-you-go price, and higher tiers have lower unit prices but greater idle risk. The decision rule is simple: when monthly consumption is below the lowest tier’s allowance, pay-as-you-go is cheaper; when monthly consumption consistently exceeds the highest tier’s allowance, the marginal cost of the plan is nearly zero, so the plan should be preferred.

    6. Deployment Checklist

    • Instrument your system first to measure the real cache hit rate, input/output ratio, and peak-hour traffic share before discussing model selection;
    • Normalize with a common unit (per 100 million tokens or per month), and never draw conclusions directly from unit prices;
    • Make the time-of-day multiplier and cache hit rate configurable parameters, and regression-test them periodically with real data;
    • Set token budgets and alerts for cost-sensitive pipelines, and use logging services and monitoring alerts to observe trends;
    • Recalculate every quarter, because both prices and hit rates drift as the workload evolves.

    The core conclusion is a single sentence: the real cost is the value of the pricing formula under your workload parameters, not the smallest number on the price sheet.