LLM Inference Cost: A Practical Guide to Calculating Real-World Costs

    Comparing per-token list prices is the most common mistake teams make when choosing an LLM. Real bills are driven by three variables: cache hit rate, the input-to-output token ratio, and when requests actually happen. This guide shows how to model inference cost with a single formula, how time-of-day pricing shifts the ranking between providers, how to find the break-even point between subscription coding plans and pay-as-you-go, and how to optimize cache hit rate as a first-class engineering metric. It also outlines the assumptions behind each number and how to recalibrate them against real invoices.

    1. Why Per-Token Price Comparisons Are Almost Always Wrong

    During LLM application selection, the most common mistake is to focus entirely on the price sheet: comparing cache hit price, input price, and output price line by line, then concluding that one vendor is “twice as cheap.” But a real bill is never a linear sum of unit prices. It is the result of three variables working together: the cache hit rate, the input-to-output token ratio, and the time distribution of requests. Shift any one of them, and the ranking can flip.

    The original discussion shows exactly this. Under an extreme configuration with a very high cache hit rate (around 98%), input at 1.5%, and output at 0.5%, the side with the lower cache price had a total cost of roughly RMB 9.4 per 100 million tokens, versus about RMB 12.6 for the other. When the cache hit rate fell back to around 95%, the two became roughly RMB 18.3 and RMB 14.9, and the order reversed completely. The point is not to memorize these two sets of numbers, but to understand why they happen: the absolute level of the cache unit price gets overridden by the amplification effect of the “missed” portion. The hit rate is a lever sitting in the denominator, and once that lever moves, any unit-price advantage is quickly erased or even overtaken.

    2. Building a Unified Cost Model

    Any rigorous estimate should start by abstracting the billing structure into a formula rather than comparing quotes one by one. Let the total token volume be N, the cache hit rate be h, the input share be p_in, and the output share be p_out. Then:

    1. cost per request =
    2. N * h * p_in * price_cache
    3. + N * (1 - h) * p_in * price_input
    4. + N * p_out * price_output
    5. cost per 100M tokens = the above * 1e8

    This model has three prerequisites that must be emphasized:

    1. The cache hit rate is not a product parameter but a business characteristic. It is determined by whether the system prompt is stable, whether sessions are multi-turn and continuous, and whether knowledge base snippets are reusable. It must be derived from load testing or production sampling, not carried over from official example values.
    2. The input-to-output ratio also depends on the scenario. Code completion, long-document summarization, and multi-turn customer support differ enormously in output share. Using a 0.5% output share to extrapolate a conversational application will inevitably distort the conclusion.
    3. Prices must be on the same basis. Mixing off-peak and peak prices, or pay-as-you-go rates with converted subscription rates, in one comparison table is a frequent source of cost misjudgment.

    3. Time-of-Day Strategy: The Underrated Cost Lever

    Beyond the hit rate, time distribution is the second high-value lever. The industry commonly uses time-based pricing to shave peaks and fill valleys, typically designating a few hours in the afternoon of business days as a peak window and discounting the rest. Peak window lengths vary noticeably across platforms: some run more than ten hours, others only about four. The shorter the window, the more room a business has to move batch work out of peak hours.

    Practical engineering measures include:

    • Task tiering: fully separate offline batch jobs (batch summarization, log classification, offline evaluation) from online interaction, and schedule all of the former into off-peak hours.
    • Queue-based peak shaving: buffer burst traffic with a message queue, and let consumers adapt their throughput to the current time-slot price.
    • Observability support: aggregate token consumption and cost hourly through logging and monitoring alerts to build a time-of-day cost heatmap, then use the data to decide which tasks to move.
    1. # Pseudocode: select the inference channel based on the current time slot
    2. if now().weekday() < 5 and 14 <= now().hour() < 18:
    3. route = primary_channel # peak: online interaction only
    4. else:
    5. route = batch_channel # off-peak: offline batch jobs

    4. Subscription Plans vs. Pay-as-You-Go: Calculating the Break-Even Point

    A subscription coding plan is essentially prepayment in exchange for a discount. Take a certain Coding Plan as an example: the three tiers cost roughly RMB 118, 538, and 1,078 per month, with official off-peak weekly quotas of roughly 317 million, 1.90 billion, and 4.433 billion tokens. Converted to list-price API credit, that is about RMB 160, 955, and 2,229, meaning the plan’s effective unit price lands roughly in the 50% to 70% range of the pay-as-you-go list price.

    This yields two decision rules:

    • If your actual usage consumes more than 70% of the plan quota, the plan is almost certainly better than pay-as-you-go.
    • If usage stays below 30% of the quota over the long term, you are effectively paying for idle quota and should use pay-as-you-go.

    A more rigorous approach is to solve for the break-even point. Let the monthly plan fee be S and the pay-as-you-go cost per 100 million tokens be C; the minimum monthly usage required is S / C hundred million tokens. Compare that threshold against the P50 and P95 of historical usage to judge whether the tier fits. Also watch for three hidden constraints: whether the quota resets monthly, whether peak hours are deducted separately, and what the overage unit price is beyond the quota.

    5. Engineering Optimizations for Cache Hit Rate

    Since the hit rate is the biggest lever, treat it as a first-class citizen:

    1. Stable prefix: keep the system prompt, tool definitions, and few-shot examples byte-for-byte unchanged, and avoid writing timestamps or random IDs into the prefix.
    2. Content chunking: split long documents on stable boundaries so reusable segments are placed as early as possible.
    3. Session stickiness: route multi-turn conversations to the same instance as much as possible to reduce cache invalidation.
    4. Hit-rate instrumentation: report cached token counts as a core metric, displayed alongside cost, forming an “optimize-and-verify” loop.

    6. Conclusion

    Real cost = hit rate × time distribution × input-output ratio × billing basis. Miss any one of the four and the conclusion is unreliable. Teams should hard-code the formula above into an internal estimation script, plug it into the monitoring and logging stack for continuous regression, and recalibrate the parameters against real invoices once per quarter. If you already use Baidu AI Cloud’s inference and observability products, you can reuse their monitoring, alerting, and log analysis capabilities to build a cost dashboard, so selection decisions rest on data rather than a price sheet.