A Practical Guide to Measuring the Real Cost of LLM Inference

    Comparing per-million-token list prices is the most common shortcut in LLM cost evaluation, and it almost always leads to the wrong conclusion. This guide shows how to build a reusable cost model based on cache hit price, uncached input price, output price, hit rate, output ratio, and peak-hour factors, explains why hit rate is the most sensitive variable, and covers peak-hour scheduling, how to convert subscription plan quotas into equivalent pay-as-you-go API value, and the instrumentation needed before any price comparison is meaningful.

    1. Why “price-per-token comparison” almost always leads to the wrong conclusion

    In LLM cost evaluation, the most common approach is to put the “price per million tokens” of two candidate offerings side by side and declare the cheaper one the winner. The problem is that inference billing is not a single dimension. It is a weighted result of cached reads, uncached input, output, and time-of-day factors. Change the value of any one dimension and the ranking can flip.

    A typical example from the original observation: one platform’s cache read price is about CNY 0.115 per million tokens, while another platform’s off-peak cache price is about CNY 0.05. Looking at that line item alone, the first is more than twice as expensive. But plug hit rate and the input/output mix into the full formula and the conclusion changes completely. Under assumptions of 98% hit rate, 1.5% uncached input, and 0.5% output, the first costs about CNY 12.57 per 100 million tokens and the second about CNY 9.40. Under a 95% hit rate assumption, the first rises to about CNY 14.92, while the second jumps to about CNY 18.25.

    The real value of these numbers is not “who won.” It is the pattern they reveal: the offering with the lower cache price is more sensitive to hit rate, while the offering with the higher cache price is more forgiving of it. So the first step in cost evaluation is not comparing prices, but measuring the hit rate distribution of your own workload.

    2. Building a reusable cost model

    Let the cache hit price be p_hit, the uncached input price be p_in, the output price be p_out, the hit rate be h, the uncached share of input be 1 - h, and the output share be r. The expected cost per million tokens is:

    1. cost_per_1M = h * p_hit + (1 - h) * p_in + r * p_out

    Three modeling details matter:

    1. Use a consistent denominator. Some offerings price cache reads and uncached input separately; others price output separately. When comparing, convert everything to the same “total tokens” basis, or you will introduce errors of several times over.
    2. Time-of-day factors are multipliers. Peak/off-peak pricing usually multiplies peak hours by a factor greater than 1 and off-peak hours by 1 or less. If requests are spread evenly across the day, use a weighted average by the duration share of each period rather than the off-peak price.
    3. Hit rate is not a constant. It fluctuates with session length, system prompt stability, codebase size, and the share of repeated user questions. Use P50/P90 percentiles rather than the mean for capacity planning.

    The model below fixes the formula in code so it can be recomputed automatically once monitoring data is connected:

    1. def estimate_cost(p_hit, p_in, p_out, hit_rate, out_ratio,
    2. peak_hours_per_day=0, peak_factor=1.0):
    3. base = hit_rate * p_hit + (1 - hit_rate) * p_in + out_ratio * p_out
    4. day_weight = (peak_hours_per_day * peak_factor + (24 - peak_hours_per_day)) / 24
    5. return base * day_weight # cost per million tokens

    3. Hit rate: the most sensitive variable in the model

    A 3-percentage-point drop in hit rate often changes cost more than the entire cache price gap between two offerings. The reason is that uncached input usually has to go through the full context encoding path again, and its unit price is significantly higher than a cache read. So engineering-side gains come before commercial price negotiation:

    • Stable prefix: put the system prompt, tool definitions, and examples at the very front of the request and keep them byte-for-byte identical; avoid dynamic timestamps or random IDs in the prefix.
    • Session stickiness: route the same session to the same cache domain as much as possible to reduce cross-node invalidation.
    • Context trimming: summarize long histories or use a sliding window, which both improves hit rate and reduces uncached input volume.
    • Observability: log hit tokens, uncached tokens, output tokens, and time-of-day labels for every request in your logging service, and build a cost attribution dashboard.

    When hit rate stays above 95%, the offering with the higher cache price is usually more predictable. When the workload is a large volume of one-off short requests with a long-run hit rate below 90%, the off-peak advantage of the low-cache-price offering is more likely to materialize.

    4. Time-of-day strategy: factor the definition of “peak” into the math

    Platforms define peak hours very differently. Some count a few hours per day; others cover the entire daytime of a workday. This has a systemic effect on cost: the higher the share of peak hours, the closer the weighted average price moves to the peak price. On the engineering side, queue-based peak shaving, offline batch processing, and off-peak scheduling of non-real-time tasks (such as batch summarization, code scanning, and log analysis) can move deferrable traffic out of the peak window, buying more token allowance under the same budget.

    5. Converting subscription plans to pay-as-you-go terms

    A subscription coding plan cannot be evaluated on monthly fee alone. Convert it into “equivalent list-price API credit” and a “plan discount rate”:

    1. discount_rate = monthly_fee / (weekly_token_quota * 4.33 * list_price_per_1M)

    By publicly stated figures, one class of plans under off-peak, high-hit-rate conditions maps three tiers to roughly CNY 160, CNY 955, and CNY 2,229 of list-price API usage, against monthly fees of CNY 118, CNY 538, and CNY 1,078, putting the discount rate in the 50%–70% range. The nature of a plan is therefore trading a usage commitment for a discount, and its economics only hold if the quota can actually be consumed. If real usage is only 30% of the quota, the effective unit price quickly degrades past pay-as-you-go.

    The decision rule simplifies to: if usage is stable and predictable and the team is small but intense, prefer a plan; if usage fluctuates with clear troughs, prefer pay-as-you-go combined with caching and off-peak optimization.

    6. Implementation recommendations

    1. Instrument first, compare prices second: without hit rate and time-of-day distribution data, any price comparison is a guess.
    2. Use percentiles for capacity planning and the mean for financial budgeting; run both in parallel.
    3. Recompute the model once a quarter, since prices and peak definitions both change.
    4. If your organization already runs inference services on platforms such as Baidu AI Cloud, you can build a cost dashboard on general capabilities like monitoring alerts and logging services, attributing token consumption, cache hits, and time-of-day labels to individual business lines for continuous optimization.