LLM Inference Cost Estimation and Plan Selection: A Practical Guide
Comparing per-million-token prices across LLM providers usually leads to the wrong conclusion. This article shows how to build a three-part cost model based on cache hit rate, uncached input ratio, and output ratio, why the ranking of two candidates can flip between 95% and 98% hit rates, and how subscription coding plans can be converted back into API-equivalent value. It also covers engineering techniques for raising cache hit rates, a five-step decision workflow, and common estimation mistakes.
1. Why “Unit Price Comparison” Almost Always Leads to the Wrong Conclusion
In LLM adoption discussions, the most common argument is that “this provider charges less per million tokens, so it is cheaper.” That comparison rarely holds up in engineering terms, for three reasons:
- Billing is multi-dimensional. A single request’s bill typically consists of three parts: the cache-hit portion, the uncached input portion, and the output portion. The unit prices of these three parts can differ by an order of magnitude. Comparing only one of them is like measuring an entire building with a single ruler.
- Hit rate is determined by your workload, not by the vendor. It depends on prompt structure, whether the system prompt is stable, multi-turn conversation length, how much RAG context is reused, and other engineering factors. The range can run from 60% to above 98%.
- The time dimension is ignored. Some services price peak hours and off-peak hours differently. The same token volume landing in different time windows can cost several times more.
The right approach, then, is to build your own cost model first and plug candidate services into it, not the other way around.
2. The Cost Model: Break the Bill into Three Parts
Let T be the total tokens in a billing period, h the cache hit ratio, i the uncached input ratio, o the output ratio, and P_cache, P_in, P_out the unit prices for each part:
Cost = T * ( h * P_cache + i * P_in + o * P_out )
Note that h + i + o = 1. Take a typical long-context coding workload with i = 1.5% and o = 0.5%. When h is 98% versus 95%, the relative standing of two candidates (Option A’s cache price is roughly twice Option B’s, with other dimensions close) reverses:
| Hit ratio | Option A (per 100M tokens) | Option B (per 100M tokens) | Conclusion |
|---|---|---|---|
| 98% | ~12.6 CNY | ~9.4 CNY | B is cheaper |
| 95% | ~14.9 CNY | ~18.3 CNY | A is cheaper |
This table reveals the key pattern: when the cache price is low but the uncached input price is high, a drop of a few percentage points in hit rate rapidly amplifies uncached input spending, wiping out or even reversing the advantage from caching. In other words, a cache discount is only a “real discount” in high-hit-rate scenarios.
The engineering implication is straightforward: if you cannot keep your cache hit rate consistently high, low cache pricing should not be your main decision criterion. Conversely, if you can push the hit rate above 98% (for example, with a fixed system prompt, stable tool definitions, and reusable knowledge chunks), cache pricing should be your first consideration.
3. Hit Rate Can Be Engineered Up
Hit rate is not luck; it is designable. Common techniques include:
- Prefix stabilization: Put the system prompt, tool/function definitions, and output format constraints at the very front of the request, and avoid concatenating volatile content such as timestamps or random IDs.
- Session and retrieval layering: Keep stable background knowledge in a cacheable prefix and place dynamic user input after it; for RAG, normalize and deduplicate high-frequency chunks.
- Batching and concurrency orchestration: Merge homogeneous tasks to avoid paying repeatedly for duplicate prefixes.
- Observability: Log hit tokens, uncached tokens, and output tokens per request on the application side, and build a cost dashboard broken down by business line rather than looking only at the month-end total bill.
A minimal local estimation script:
def estimate_cost(total_tokens, hit_ratio, in_ratio, out_ratio,p_cache, p_in, p_out):assert abs(hit_ratio + in_ratio + out_ratio - 1.0) < 1e-6per_token = (hit_ratio * p_cache+ in_ratio * p_in+ out_ratio * p_out)return total_tokens * per_token
Plugging in different hit rates (such as 0.90 / 0.95 / 0.98) gives you a cost curve rather than a single number. Selection should compare curves, not points.
4. Subscription Plans: Convert Quotas Back to API-Equivalent Value
Subscription plans (coding-plan style AI programming bundles) are evaluated differently from pay-as-you-go billing. The core comes down to three conversions:
- Quota conversion: A plan usually specifies a token quota per period. It must be converted into the equivalent amount at original API pricing using the model above before it can be compared on the same scale as pay-as-you-go.
- Discount range: A common result is that the plan’s effective unit price lands between 50% and 70% of original API pricing, meaning you lock in a period of capacity at 50–70% of list price.
- Peak-hour constraints: Plans often distinguish peak from off-peak quotas. In one example, the peak window is limited to roughly 4 hours per workday, clearly narrower than an “all-day, multiple windows” setup, which means most working hours are actually off-peak and the usable quota is more generous.
The resulting decision rule: when your workload is characterized by long context, high cache reuse, and relatively flexible timing, a plan’s “quota × discount rate” often beats pure pay-as-you-go. When the workload is sparse, bursty, and has an unstable hit rate, pay-as-you-go carries more controllable risk.
5. Putting the Model into a Decision Process
Follow these five steps to avoid guesswork:
- Sample: Sample real traffic for one week and measure the distribution of
h / i / o, not just the average. - Bucket: Plug P50 and P90 hit rates into the model separately to get a cost range.
- Compute plan equivalence: Convert the plan quota into API-equivalent spending with the same model to derive the effective discount rate.
- Layer in time constraints: Align peak windows with your business peak and trough patterns, and assess whether quota will be throttled during critical periods.
- Keep a fallback: Maintain a switchable inference path and a degradation strategy to avoid cost or availability risk from a single billing model.
6. Common Mistakes
- Looking only at cache unit price and ignoring the amplification effect of uncached input pricing.
- Using averages instead of distributions, which hides cost spikes during low-hit-rate periods.
- Ignoring the output ratio; output costs for long-form generation workloads are often underestimated.
- Treating plan quota as “unlimited” and overlooking peak throttling and overage billing rules.
- Failing to instrument token metering on the application side, which makes any cost conclusion unverifiable.
7. Conclusion
Comparing LLM inference costs is fundamentally a constrained quantitative problem: hit rate is the independent variable, the input/output mix provides the coefficients, and the time window is the constraint. Write all three explicitly into the model, then compare the equivalent discount of pay-as-you-go against subscription plans, and your conclusion will usually be far more reliable than “whose unit price is lower.” For a team, the real cost-reduction levers are not on the price sheet but in prompt structure, cache reuse design, and an observable token metering system.
