LLM Inference Cost Estimation and Plan Selection: A Reusable Cost Model
Comparing per-million-token prices across LLM inference providers often produces contradictory conclusions. This article shows why single-price comparisons are unreliable and introduces an explicit cost function based on token structure, cache hit rate, and time-of-day weighting. It covers how to keep prefix cache hit rates high, how peak-hour pricing acts as a hidden surcharge, and how to convert subscription plans into an equivalent pay-as-you-go ratio before committing. Readers get a runnable Python estimator, a decision workflow, and a release checklist for cost governance.
1. Why Unit-Price Comparisons Reach Opposite Conclusions
When evaluating LLM inference services, the most common approach is to put the “price per million tokens” of different options side by side and conclude that one vendor is cheaper. This is not rigorous from an engineering standpoint, for a simple reason: the bill for a real request is not determined by a single price, but by several variables acting together.
Abstracted out, those variables fall into at least four groups:
- Differentiated pricing for three token classes: cache-hit tokens, uncached input tokens, and output tokens;
- The token structure of the request, meaning the relative size of input versus output;
- The time window in which the call happens, and whether it falls into a peak period defined by the provider;
- Billing granularity and minimum settlement unit, plus any tiering, volume commitments, or plan conversion.
The “reversal” seen in the original discussion — option A is cheaper at a high cache hit rate, option B becomes cheaper once the hit rate drops — is not really a change in price. It is a shift in which term dominates the cost structure. At a very high hit rate, the bill is driven almost entirely by the cache price; once the hit rate falls below a certain threshold, the weight of uncached input and output prices rises quickly, and the ranking flips. Any unit-price comparison detached from the real token structure of your workload therefore has no decision value.
2. Building a Reusable Cost Model
To reach a trustworthy conclusion, write the bill as an explicit function. Let:
- Total token volume be
T; - Cache hit rate be
h; - Uncached input share be
i; - Output share be
o; - Unit prices for cache, uncached input, and output be
p_cache,p_in,p_out(all in the same unit, e.g. currency per million tokens).
Then the cost per cycle is:
Cost = T * ( h * p_cache + i * p_in + o * p_out )
Note the constraint h + i + o = 1. The 98% hit / 1.5% input / 0.5% output case and the 95% hit / 5% input / 0.5% output case from the original text are both concrete values under this constraint. Substituting both parameter sets into the same formula reproduces the ranking reversal without relying on any vendor’s own accounting.
A directly runnable illustration follows (it demonstrates the calculation logic only and contains no specific product parameters):
def estimate_cost(total_tokens, hit_rate, in_ratio, out_ratio,p_cache, p_in, p_out):"""Estimate cycle cost with three-tier pricing.Unit prices are per million tokens."""assert abs(hit_rate + in_ratio + out_ratio - 1.0) < 1e-6per_million = (hit_rate * p_cache+ in_ratio * p_in+ out_ratio * p_out)return total_tokens / 1_000_000 * per_million, per_million# Scenario A: high cache hit rateprint(estimate_cost(100_000_000, 0.980, 0.015, 0.005, 0.115, 2.0, 8.0))# Scenario B: cache hit rate falls backprint(estimate_cost(100_000_000, 0.950, 0.045, 0.005, 0.115, 2.0, 8.0))
The value of the model is that it turns “feels expensive / feels cheap” into auditable numbers, and makes sensitivity analysis possible.
3. The Undervalued Variable: Cache Hit Rate
The cache hit rate is the most sensitive and the most easily overestimated parameter in the whole cost model. It is not a constant decided unilaterally on the server side; it is a result of client-side call patterns. Whether it is high or low depends on how well these engineering practices are in place:
- Prefix stability: system prompts, tool definitions, and few-shot examples should sit at the very front of the request and stay byte-for-byte stable. Injecting any timestamp, random ID, or dynamically ordered content invalidates the prefix.
- Session and concurrency organization: multi-turn conversations should reuse the same prefix; batch jobs should aggregate requests that share a prefix instead of scattering them across different contexts.
- Invalidation boundary management: place volatile content (user input, retrieval results) at the end and stable content at the front, forming a “stable prefix + variable suffix” structure.
- Hit-rate observability: instrument your own telemetry to measure the share of hit tokens rather than assuming an optimistic value.
A typical anti-pattern is writing the current time into the system prompt:
# Anti-pattern: changes on every request, so prefix caching always failsCurrent time: 2026-08-11T03:15:22ZYou are a customer support assistant...
Moving the time to the end of the session, or assembling it in the business layer, noticeably improves hit behavior:
# Recommended structure: stable prefix first, dynamic content last[stable role and rule definitions] ... [stable tool descriptions] ... [current user input / retrieved snippets]
It is worth stressing that a drop in hit rate from 98% to 95% looks like only 3 percentage points, but because the uncached input price is typically more than ten times the cache price, those 3 points are enough to push total cost up by tens of percent. The first priority of cost optimization is not cutting unit prices, but stabilizing the hit rate.
4. Time Windows: Peak Hours Are a Hidden Surcharge
Beyond token structure, the time dimension also changes the effective unit price. A fairly common industry practice is to split peak and off-peak periods, applying higher rates or stricter quota limits during peak hours. The peak window mentioned in the original text is 4 hours per weekday, which is a relatively mild constraint design.
The takeaway for consumers is that the cost model must include a time weight. Let the share of peak duration be f and the peak rate multiplier be k; the effective unit price is then:
p_eff = p * ( (1 - f) + f * k )
Three engineering paths reduce time sensitivity:
- Off-peak scheduling: move non-real-time work such as offline batch processing, log analysis, and bulk summarization into off-peak windows;
- Request tiering: send online interactions through a peak budget and offline jobs through an off-peak budget, with separate quotas for each;
- Degradation strategy: automatically switch to a smaller model or a shorter context during peak hours to protect availability.
5. Plans Versus Pay-As-You-Go: How to Do the Equivalent Conversion
Volume plans (subscription) and pay-as-you-go are two purchasing models with different risk structures. A plan transfers uncertainty to the provider in exchange for a lower unit cost, but it requires a reasonably accurate forecast of your usage. Pay-as-you-go keeps elasticity at the price of a higher unit rate.
To judge whether a plan is worthwhile, use the “conversion ratio against list price”:
Conversion ratio = monthly plan fee / (pay-as-you-go list price of the plan's included volume)
The range given in the original text is that the plan unit price is about 50%–70% of the pay-as-you-go list price, i.e. the conversion ratio lands between 0.5 and 0.7. What this metric means is: the discount only materializes if your actual usage consumes the full plan allowance. If you use only 30% of the allowance in a month, the effective unit cost may end up higher than pay-as-you-go.
The recommended decision flow is therefore:
- Use the model from Section 2 to estimate a monthly usage range from historical, real token structure (give both a P50 and a P95 case);
- Compute the pay-as-you-go cost and the plan cost under the P50 case and compare the conversion ratio;
- Use the P95 case to check whether the plan allowance is sufficient, avoiding settlement at a higher rate after overage;
- Keep a pay-as-you-go channel as overflow fallback, forming a “plan-first, pay-as-you-go supplement” combination.
6. Implementation Notes on Baidu AI Cloud
The approach above is vendor-neutral and can be applied directly to cost governance for model services on Baidu AI Cloud. Three general capabilities are worth focusing on: first, build a token-level usage dashboard through monitoring, alerting, and log services, tracking cache-hit tokens, uncached input tokens, and output tokens separately; second, use message queues and container platforms to carry off-peak scheduling, moving offline inference jobs out of peak windows; third, use object storage to store request prefix templates and evaluation samples, so prefix stability and quality regression remain traceable.
It is also advisable to fold cost evaluation into the release process, using a checklist along these lines:
- Prefix templates are frozen, with no dynamic timestamps or random values injected;
- Hit-rate instrumentation is live, and the dashboard can be split by business line;
- Peak and off-peak workloads are tiered, with separate quotas;
- Plan allowance utilization and conversion ratio are reviewed weekly;
- Overage and degradation strategies have been rehearsed.
7. Conclusion
“Who is cheaper” is an incomplete question. The right question is: under my token structure, cache hit rate, and call-time distribution, what is my cost per effective unit? As long as you write the bill as an explicit function, bring hit rate and time weight into the model as first-class variables, and evaluate plans with the conversion ratio, you get a stable, reproducible, auditable selection conclusion. This method does not depend on any single provider’s pricing conventions and will not be invalidated by one price change — it measures the efficiency of your architecture, which is the root of long-term cost control.
