LLM Inference Cost Modeling and Plan Selection: A Practical Guide

    Comparing per-million-token prices across LLM inference providers almost always leads to the wrong conclusion, because cost is a function of several variables rather than a single number. This article builds a reusable cost model based on cache hit rate, input/output mix, and time-of-day discount rules, shows how to solve for the critical cache hit rate where two pricing plans flip, explains why hit rate is a property of your workload rather than the provider, and covers how to convert subscription quotas into an effective discount rate with utilization and overage corrections. It closes with engineering practices for cost governance: a unified gateway layer, per-caller cost attribution, prefix and result caching, rate-limit-aware capacity design, and scheduled re-estimation.

    1. Why Comparing Unit Prices Almost Always Leads to the Wrong Conclusion

    When evaluating LLM inference services, the most common approach is to put two providers’ per-million-token prices side by side and pick the smaller number. The problem is that this treats cost as a scalar, when real cost is a function determined by several variables. At least three variables can materially change the final bill:

    • Cache hit rate: cached input is typically billed at a price far below standard input. Moving the hit rate from 95% to 98% looks like a 3-point difference, but its leverage on total cost can exceed 30%.
    • Input-to-output ratio: output tokens often cost several times more than input tokens, so any shift in the mix moves the entire cost structure.
    • Time windows and discount periods: some services discount specific hours, and the definition of “peak hours” is not consistent across platforms. Some count a fixed number of hours per day; others count all hours on business days.

    The right approach is therefore not to compare unit prices but to build a model you can plug your own business parameters into. Here is one such model.

    2. Building a Reusable Cost Model

    Let total processed tokens be T, cache hit rate h, non-cached input share r_in, output share r_out (normally h + r_in + r_out = 1), cached input price p_cache, standard input price p_in, and output price p_out. Then:

    1. Cost(T) = T * ( h * p_cache + r_in * p_in + r_out * p_out )

    Using 100 million tokens as the unit and two typical parameter sets (Plan A has a higher cache price; Plan B has a lower cache price but more expensive standard input):

    Scenario Hit rate Mix (cache/input/output) Plan A Plan B
    High hit rate 98% 1.5% / 0.5% ~12.6 CNY ~9.4 CNY
    Medium hit rate 95% 3.5% / 1.5% ~14.9 CNY ~18.3 CNY

    This table shows the core insight: the provider with the cheaper cache price is not always cheaper. With a high hit rate and a very low output share, the low cache price plan wins. Once the hit rate drops, the savings on cached input are quickly eaten by the high standard input price, and the conclusion reverses. The location of that turning point is determined by the relative prices of the two plans, and you can solve for the critical hit rate h* directly by setting the two expressions equal:

    1. h* = (r_in_b * p_in_b + r_out_b * p_out_b - r_in_a * p_in_a - r_out_a * p_out_a)
    2. / ((p_cache_a - p_cache_b) + (p_in_b - p_in_a) + (p_out_b - p_out_a))

    In practice, put this expression into a config validation script instead of relying on manual estimation:

    1. def cost_per_100m(h, mix, price):
    2. return 100 * (h * price["cache"]
    3. + mix["in"] * price["in"]
    4. + mix["out"] * price["out"])
    5. def crossover(h_grid, mix, pa, pb):
    6. for h in h_grid:
    7. if cost_per_100m(h, mix, pa) > cost_per_100m(h, mix, pb):
    8. return h
    9. return None

    3. Hit Rate Is Not a Constant, It Is a Workload Property

    The value most easily overestimated in any estimate is the cache hit rate. It depends on how stable your request prefixes are, not on the provider’s capabilities. Patterns that reliably hit include a fixed system prompt, repeated question answering over a long document, code repository context reuse, and an unchanged history prefix across multi-turn conversations. Patterns that rarely hit include prepending a timestamp or random ID to the prefix on every turn, placing user input at the very front of the prompt, and frequently reordering context.

    General engineering measures to improve the hit rate:

    1. Prefix normalization: put stable content first and volatile content last, and never insert random values into the shared prefix.
    2. Session-level context reuse: keep the prefix byte-for-byte identical within a session, and avoid subtle differences introduced by template rendering.
    3. Layered caching strategy: split very long, stable background material into its own segment, separate from short dynamic instructions.
    4. Hit rate observability: instrument token-level hit counts in your logging and alerting systems, break the dashboard down by business line, and replace guesswork with real data.

    4. Converting Subscription Plans and Pay-as-You-Go Pricing

    Subscription plans follow a different pricing logic from pay-as-you-go: a fixed monthly fee buys a token quota or request allowance, usually with restrictions during certain peak hours. To judge whether a plan is worthwhile, convert the quota into an “equivalent list-price API amount” and then compute the discount rate:

    1. Discount rate = Monthly plan fee / (List-price API amount for the monthly quota)

    The magnitude to expect is that the tiers work out to roughly 50%–70% of list-price API cost, meaning the plan is effectively a 50%–70% discount. The number itself is not the point; the point is that the conversion must include three corrections:

    • Time-window correction: the plan’s definition of “peak” may be only four hours per business day, far more generous than a scheme that counts the whole day, so the usable quota is effectively larger.
    • Utilization correction: an unused monthly quota is a full waste, so pick a tier based on historical P50 usage rather than peak usage.
    • Overage correction: how you are billed beyond the quota determines the worst-case cost, and must be confirmed in advance.

    A simplified decision rule:

    1. def choose(monthly_tokens, quota, fee, on_demand_price, peak_ratio):
    2. effective_quota = quota * (1 - peak_ratio * 0.0) # quota does not shrink when peak only limits rate
    3. if monthly_tokens <= effective_quota * 0.8:
    4. return "subscription", fee / (monthly_tokens * on_demand_price)
    5. return "on_demand", 1.0

    5. Putting Cost Governance into Engineering Practice

    • Build a unified gateway layer: add an abstraction between your applications and model services that hides provider differences, turning prices, caching strategy, and time-window rules into configuration. Switching cost drops from “change code” to “change config.”
    • Attribute cost to callers: attach a business identifier to every request and aggregate token consumption by team and scenario in your monitoring and alerting system, so total cost does not spiral out of control with nobody accountable.
    • Reduce input with caching and batching: stable prefix caching, result caching, and merged batch requests are more controllable levers than switching providers.
    • Capacity and rate-limit design: factor peak-hour rate limits into client backoff and queue buffering, and use a message queue to smooth spikes where needed, so failed retries during peak hours do not amplify cost.
    • Re-run the estimate on a schedule: prices and discount rules change, so turn the model above into a scheduled job and recompute the turning point and plan discount rate monthly using real hit rate data.

    6. Conclusion

    Unit price is only the starting point. What determines the bill is the combination of hit rate, input/output mix, and time-window rules. Master a formula you can plug your own parameters into, compute the critical hit rate first, then convert the plan quota into an effective discount while correcting for utilization and overage risk. Only then can you make a data-backed choice between pay-as-you-go and subscription plans. If you need an inference foundation that is end-to-end controllable, observable, and easy to attribute costs in, the relevant Baidu AI Cloud product categories (such as container platform, logging service, monitoring and alerting, and message queue) can be included in the architecture design as general-purpose engineering components.