How to Calculate Blended Inference Costs and Choose the Right LLM Plan
This article presents a reproducible framework for calculating the blended per-million-token cost of LLM inference services. Instead of comparing input or output prices in isolation, it shows how to derive token-mix weights from request logs, compute weighted prices across plans, handle time-of-day pricing, and avoid common pitfalls in cost estimation, plan ranking, and budget auditing.
How to Calculate Blended Inference Costs and Choose the Right LLM Plan
When comparing LLM inference services, looking only at the “input price” or “output price” often leads to distorted conclusions. Real cost depends on the structure of your requests: how many input tokens hit the cache, how many miss it, what share of tokens are output, and whether unit prices change at different times of day. This article provides a reproducible framework for computing a blended unit price that can be used for cost estimation, plan ranking, and budget auditing.
1. Why You Need a Blended Unit Price
Token-billed inference services typically distinguish three unit prices: the cached-read price for cache hits, the uncached input price, and the output price. All three are usually quoted per million tokens. Different plans rank differently across these three prices, so focusing on any single one leads to one-sided conclusions. For example, one plan may have a low uncached input price but a high output price; another may offer an extremely low cached-read price but with strict cache-hit conditions. Only by plugging your actual traffic structure into the formula can you get comparable numbers.
The blended unit price can be defined as: given a token composition, the weighted average cost of processing one million tokens. Its basic form is:
[
P = wr \times P{read} + wi \times P{input} + wo \times P{output}
]
where (P{read}) is the cached-read price, (P{input}) is the uncached input price, and (P_{output}) is the output price; (w_r), (w_i), and (w_o) are the normalized weights of the three token types within the measurement window, summing to 1. The original example uses:
[
P = 0.8 \times Read + 0.1 \times Input + 0.1 \times Output
]
This assumes that out of every million tokens, about 80% are billed at the cached-read price, 10% at the uncached input price, and 10% at the output price. Note that 0.8/0.1/0.1 is only an illustrative ratio, not a universal rule; in production, weights should be derived by sampling your own logs.
2. Where the Ratios Come From: From Logs to Weights
The key to a blended unit price is not the formula itself, but the credibility of the weights. We recommend recording, at the gateway or inference-calling layer, each request’s input tokens, cache-hit tokens, uncached input tokens, output tokens, and timestamp. After aggregating over a fixed time window, compute:
- Cache-hit ratio = cached-read tokens / total tokens;
- Uncached input ratio = uncached input tokens / total tokens;
- Output ratio = output tokens / total tokens.
If your workload heavily reuses long contexts, the cache-hit ratio may be high; if it consists of short prompts with long outputs, the output weight rises. Because the output price is usually significantly higher than the cached-read price, a rising output ratio noticeably pushes up the blended price. Ratios must come from actual measurements, not guesswork. For new workloads, start with a small traffic sample, then run a sensitivity analysis: shift the cache-hit ratio up and down by 10 percentage points and see whether the plan ranking reverses.
3. Example Code: Calculation, Ranking, and Scenario Weighting
The following generic example code does not depend on any specific platform API. The first snippet computes the blended price and validates the weights:
def blended_cost(read_price, miss_input_price, output_price,hit_ratio=0.8, miss_ratio=0.1, output_ratio=0.1):total = hit_ratio + miss_ratio + output_ratioif abs(total - 1.0) > 1e-9:raise ValueError("The three ratios must sum to 1")return (hit_ratio * read_price +miss_ratio * miss_input_price +output_ratio * output_price)
The second snippet ranks anonymized plans. The values below are for demonstrating the calculation only and do not correspond to any specific product:
plans = [("Plan A", 0.9337),("Plan B", 1.3104),("Plan C", 1.9712),("Plan D", 3.5700),("Plan E", 4.2000),("Plan F", 4.3610),]ranked = sorted(plans, key=lambda item: item[1])for name, cost in ranked:print(name, cost)
The third snippet handles peak and off-peak periods. If different price tables apply within a day, compute the blended price for each period first, then weight by traffic share:
def time_weighted_cost(scenarios):# scenarios: [{"weight": 0.3, "cost": 1.31}, ...]return sum(s["weight"] * s["cost"] for s in scenarios)peak = blended_cost(0.08, 0.20, 1.80, 0.8, 0.1, 0.1)off_peak = blended_cost(0.03, 0.12, 0.90, 0.8, 0.1, 0.1)monthly_blend = time_weighted_cost([{"weight": 0.4, "cost": peak},{"weight": 0.6, "cost": off_peak},])
When ranking, results computed under different price tables or different ratios must not be mixed into a single list. For example, one anonymized sample set yields blended prices from about 0.93 to 47.60 per million tokens, while another set ranges from about 0.0655 to 0.5312 per million tokens. If the two sets use different ratios, time periods, or price tables, each must be labeled with its own assumptions and cannot simply be merged into one leaderboard.
4. Edge Cases and Auditing Requirements
First, when a public reference price is missing or unverified, do not treat the missing value as 0 in ranking; instead, mark the plan as “not eligible for ranking” or provide a range estimate. Second, every price table must carry a version and a timestamp, since peak and off-peak prices may differ. Third, units must be unified as “per million tokens” — never substitute a per-thousand-token price directly into the formula. Fourth, the blended unit price is an estimate; the precise monthly cost should be computed by multiplying each token type by its respective price and summing:
[
Monthly\ cost = \frac{cached\ read\ tokens}{10^6} \times Read\ price
- \frac{uncached\ input\ tokens}{10^6} \times Input\ price
- \frac{output\ tokens}{10^6} \times Output\ price
]
Fifth, cache savings can be estimated as the difference: savings are approximately “cached tokens / 10^6 × (uncached input price − cached-read price)”, though cache invalidation, prefix-reuse conditions, and maintenance overhead must still be considered. Sixth, plan selection should not rely on blended price alone; you must also evaluate output quality, latency, concurrency stability, rate-limiting policies, context length, and other constraints.
5. Practical Conclusions
We recommend treating the blended unit price as a configurable, auditable cost metric: pin the price-table version, fix the measurement window, record the three token ratios, compute per time period, and separately flag unverified items. For cost-sensitive workloads, prioritize improving cache-hit rates and controlling output length; for quality-sensitive workloads, run multi-metric evaluations within an acceptable cost range. Only by closing the loop among the formula, logs, and example code can you avoid being misled by any single price figure and give your plan selection and budgeting a reproducible foundation.
