LLM Inference Cost Estimation and Plan Selection Guide
Comparing per-million-token prices between two LLM services almost always leads to the wrong conclusion. This guide explains why, breaks inference cost down into three core variables (cache hit rate, input/output mix, and peak-hour structure), and provides a reusable Python script plus a method for converting subscription plans into an effective per-token price. It also covers hidden costs and ends with a practical checklist for validating cost assumptions against real traffic.
1. Why Comparing Unit Prices Almost Always Gives the Wrong Answer
During the evaluation stage of an LLM application, the most common approach is to divide the per-million-token price of one candidate service by another and conclude that one is “twice as expensive” or “half the price.” In most real business scenarios, that conclusion is misleading, because billing itself is multi-dimensional. A single call is split into a cache-hit portion, an uncached input portion, and an output portion, and the unit prices of these three often differ by an order of magnitude. On top of that, many platforms apply time-based pricing that divides the day into peak and off-peak windows. Add the quotas, billing cycles, and rate limits of subscription plans, and the final bill ends up far from the intuitive “unit price × token count.”
The correct order for cost evaluation is therefore: first define the workload profile, then apply the billing model, and only then compare the total cost of ownership across different billing formats.
2. Three Core Variables of the Cost Model
2.1 Cache Hit Rate: The Single Most Influential Variable
Prefix caching (Prompt Cache) is billed as follows: the portion that shares a common prefix with the previous request is charged at the cache price, while the rest is charged at the standard input price. The cache price is usually only a small fraction of the standard input price, so raising the hit rate from 95% to 98% looks like a 3-point difference but can actually flip the total cost in the opposite direction.
The reason is that the marginal effect of the hit rate is non-linear. Let the standard input unit price be P_in, the cache unit price be P_cache, and the hit rate be h. The effective input unit price is:
P_eff = h * P_cache + (1 - h) * P_in
When P_cache is far smaller than P_in, P_eff is extremely sensitive to h. If two candidate services offer different cache discounts, a crossover appears: the one with the lower cache price is more expensive in the high-hit-rate range and cheaper in the low-hit-rate range. This matches the observation in the original text: at a 98% hit rate, the plan with the weaker cache discount has the lower total cost; drop the hit rate to 95% and the ranking immediately reverses.
The engineering implication is clear: do not make decisions with a single fixed hit rate. Run a sensitivity analysis at 90%, 95%, and 98%, and confirm which tier your business actually falls into.
2.2 Input/Output Mix: Context Length and Generation Length Decide the Structure
The second variable is the ratio among cache hits, uncached input, and output. The 98% / 1.5% / 0.5% split used in the original text describes a profile of “very long system prompt + heavily reused context + very short answers,” typical of batch classification, structured extraction, and code completion. Conversational applications, long-form writing, and multi-turn agent reasoning have a significantly higher output share. Since the output unit price is usually several times the input price, a change in the mix can also change the ranking.
It is advisable to build one profile per workload type, for example:
Profile A, batch extraction: cache 98% / in 1.5% / out 0.5%Profile B, customer support chat: cache 80% / in 15% / out 5%Profile C, long-form generation: cache 60% / in 30% / out 10%
2.3 Time-of-Day Structure: Peak Window Length Matters More Than Discount Depth
With differentiated pricing, what matters is not only how deep the off-peak discount is, but how long the peak window lasts. If one platform’s peak is 4 hours per weekday while another covers weekends and more daytime hours, then at the same discount figure the former offers noticeably more usable off-peak time. During evaluation, list “off-peak hours per week” as a separate metric, then multiply it by the time distribution of your workload (offline batch jobs can be moved freely, while online interactions are hard to avoid).
3. A Reusable Estimation Script
Fix the model above into a script to avoid recalculating by hand every time:
def cost_per_100m(cache_hit, miss_in, out, p_cache, p_in, p_out):"""Return the cost per 100 million tokens (CNY)"""return (cache_hit * p_cache + miss_in * p_in + out * p_out) / 1e6def blended(cases, prices):return sum(cost_per_100m(*c, *prices) for c in cases)# Unit price: CNY per million tokensprices_a = dict(p_cache=0.115, p_in=12.0, p_out=60.0)prices_b = dict(p_cache=0.05, p_in=10.0, p_out=50.0)for h in (0.90, 0.95, 0.98):cases = [(h, (1 - h) * 0.75, (1 - h) * 0.25)]print(h, blended(cases, prices_a), blended(cases, prices_b))
The unit prices in the script are illustrative values; actual values must come from the target platform’s current official pricing page. The point is to fix the structure so you can rerun the calculation by swapping in new numbers.
4. How to Convert Subscription Plans
The core of a subscription plan is to convert the “fixed monthly fee” into an “equivalent list-price API quota,” then divide by the token volume included in the plan to get the plan’s effective unit price. The steps are:
- Estimate the monthly total based on the quota definition given officially (for example, the token volume available per week during off-peak hours);
- Using the profiles and unit prices from Section 2, calculate the list price of the same token volume under pay-as-you-go billing;
- Divide list price by the monthly fee to get “the plan as a percentage of list price,” which usually falls in the 50%–70% range;
- Divide the monthly fee by the monthly token volume to get the plan’s real unit price, and compare it directly with the pay-as-you-go price.
The decision rule can be simplified: teams with stable, predictable workloads that can avoid peak hours are better off with a plan; teams with highly variable workloads, concentrated peaks, and a need for strict SLAs and elastic scaling face lower risk with pay-as-you-go. A hybrid strategy is often optimal: use a plan for baseline traffic and pay-as-you-go to absorb burst peaks.
5. Hidden Costs That Are Easy to Overlook
- Cache invalidation and recomputation: a slight change in the prefix causes a full miss, so move volatile fields (timestamps, user IDs, random numbers) to the end of the prompt.
- Rate limits and queuing: plans usually come with concurrency and rate caps, and retries caused by exceeding them are billed again.
- Context growth: without trimming history and summarizing in multi-turn conversations, uncached input keeps accumulating.
- Observability: without usage metrics broken down by business dimension, you cannot validate hit-rate assumptions, and cost optimization loses its basis.
- Migration cost: switching providers requires redoing prompt adaptation and quality regression, which is rarely included in price comparisons.
6. Implementation Checklist
- Sample real traffic for 24 hours and measure the prefix reuse rate and the output length distribution;
- Estimate costs at all three hit-rate tiers and confirm whether the conclusion is robust;
- Measure the share of requests falling in peak windows and assess how movable they are;
- Run both plan and pay-as-you-go conversions for each candidate and take the lower one as the baseline;
- Set up a monthly usage dashboard to continuously correct hit-rate and mix assumptions.
Overall, comparing the cost of model services must move from “unit price” to a three-dimensional model of “billing structure + workload profile + time distribution.” Baidu AI Cloud’s practice in model services and general capabilities such as usage monitoring and log analysis confirms the same principle: quantify the workload first, then discuss price, so that cost conclusions can withstand the test of real traffic.
