LLM Inference Cost: Benchmarking Real Unit Prices and Building Tiered Scheduling
This article shows how to reverse-engineer per-token inference pricing from your own usage records instead of relying on published rate cards, convert those unit prices into token throughput per budget window, and use the resulting cost gradient to build a four-tier model routing scheme. It includes a least-squares fitting script, R-squared and residual checks for validating the pricing model, a throughput formula, a configurable routing function, and three engineering practices—prefix stabilization, output length limits, and observability—plus caveats on quality variance and fallback escalation.
1. Where the Problem Starts: Why “It Feels Cheap” Usually Means the Math Is Wrong
Once a large language model is wired into a business system, the first problem a team hits is usually not quality—it is the bill. The same feature, implemented on a different model, can differ in monthly inference spend by one or two orders of magnitude. Yet most teams still perceive cost as a vague “a few cents per call,” with no way to measure or reproduce it.
The first step is to normalize the cost unit to tokens. The common industry practice is to price input tokens and output tokens separately, with a lower rate for the portion of input that hits a cache. The reason is structural: computation on the input side can reuse intermediate results from a historical prefix, while the output side must be generated autoregressively token by token and cannot be reused. That structural difference is the physical basis for every cost conclusion below.
The second step is to accept a reality: platforms do not always publish a complete pricing breakdown, and pricing rules can change between versions. The more reliable engineering approach is therefore to fit unit prices backward from actual usage records rather than trusting anyone’s quoted numbers.
2. Method: Deriving Unit Cost from Usage Records
Let the unit input price of a model be $p{in}$ and the unit output price be $p{out}$ (unit: credits per million tokens). Over a measurement window, with cumulative input $X$, cumulative output $Y$, and cumulative credits consumed $C$:
C = p_in * X / 1e6 + p_out * Y / 1e6
A single observation cannot solve for two unknowns, but as long as the $X/Y$ ratio differs across several windows (for example, one day dominated by long-document summarization, another by code generation), you can build a system of equations and run a least-squares fit:
import numpy as np# Each row: [input tokens, output tokens, measured credits consumed]obs = np.array([[1_850_000, 120_000, 168.0],[3_200_000, 260_000, 302.0],[ 920_000, 45_000, 76.0],])A = obs[:, :2] / 1e6b = obs[:, 2]p, residual, rank, _ = np.linalg.lstsq(A, b, rcond=None)p_in, p_out = ppred = A @ pr2 = 1 - ((b - pred) ** 2).sum() / ((b - b.mean()) ** 2).sum()print(f"input price {p_in:.0f} / output price {p_out:.0f}, R^2={r2:.4f}")
Two metrics tell you whether the fit is trustworthy: whether the coefficient of determination $R^2$ is close to 1, and whether the residuals are close to 0. If samples with clearly different ratios all yield $R^2 \approx 1$ with negligible residuals, the pricing model really is “linearly additive across input and output,” and the derived numbers are usable for budgeting. If the residuals are significant, that usually means a minimum billing unit, tiered pricing, or cache credits are not captured by the model.
Fitting this way against real records yields a set of typical magnitudes (illustrative order-of-magnitude relationships only, not any official price list):
| Model tier | Input (credits/1M) | Output (credits/1M) | Cached input |
|---|---|---|---|
| Flagship inference | ~80,000 | ~400,000 | No separate discount |
| Balanced inference | ~32,000 | ~112,000 | No separate discount |
| Fast | ~4,000 | ~8,000 | ~80 |
| Lightweight | ~2,000 | ~2,000 | ~2,000 |
Two conclusions deserve separate emphasis. First, the flagship tier’s output price can be roughly 200x the lightweight tier’s, so the cost gap comes mainly from the output side, not the input side. Second, once a cache hit occurs, the fast tier’s input cost drops to about 2% of its normal input price, which completely rewrites the cost structure for long prefixes, repeated system prompts, and fixed knowledge snippets.
3. Converting to Capacity: What a Budget Actually Means
Unit prices only become decision-relevant once converted into “how many tokens can run.” Let the credits available in a cycle be $B$, the input share be $\alpha$, and the output share be $1-\alpha$. Total processable tokens:
T = B / (alpha * p_in + (1 - alpha) * p_out) * 1e6
With $B$ at 60,000 credits per 5 hours (roughly 600,000 credits per week), $\alpha = 0.8$, and no cache assumed:
- Flagship inference: ~417,000 tokens / 5 hours
- Balanced inference: ~1.25M tokens / 5 hours
- Fast: ~12.5M tokens / 5 hours
- Lightweight: ~30M tokens / 5 hours
That is roughly a 72x spread from top to bottom. The numbers make the point directly: sending all traffic to the strongest model is equivalent to doing batch work on a flagship budget, and it is the root cause of cost overruns for most teams.
4. Tiered Scheduling: Let Expensive Models Think, Let Cheap Models Work
Given that cost gradient, you can define responsibilities across four tiers:
- Flagship handles planning and final review: task decomposition, solution design, code review, risk identification. Low volume, high value per call, insensitive to output price.
- Balanced handles complex reasoning: medium-difficulty tasks requiring multi-step logic or cross-file understanding.
- Fast handles the bulk of execution: most routine generation, rewriting, and unit test completion; combined with prefix caching, cost can drop by another order of magnitude.
- Lightweight handles high-volume simple tasks: format conversion, field extraction, label classification, log merging.
In practice, do not rely on human judgment to pick a tier. Make routing a configurable, quantitative rule set:
def route(task):if task.risk == "high" or task.needs_plan:return "flagship" # planning / final reviewif task.steps > 3:return "balanced" # complex reasoningif task.batch and task.prompt_len < 2000:return "light" # high-volume simple tasksreturn "fast" # bulk execution
Three engineering points go with it. First, prefix stabilization: keep the system prompt, tool descriptions, and knowledge snippets fixed at the very front of the request, with no volatile concatenation such as timestamps, otherwise the cache discount will not be hit. Second, output length constraints: because the output price is far higher than the input price, capping maximum generation length and requiring short structured output is often more effective than compressing the input. Third, observability: emit metrics in your logging service by model tier, input/output tokens, and cache hits, and re-run the fitting script periodically so any unit price change surfaces immediately.
5. Boundaries and Caveats
The unit prices above are reverse-engineered from personal measurements, not an official price list, and the rules may change between versions. Treat them as an internal accounting baseline, not an external commitment. In addition, tiered routing introduces quality variance, so keep a fallback path that automatically escalates a failed low-tier call to a higher tier, and monitor pass rates per tier with a fixed evaluation set—otherwise cost optimization comes at the price of quality regression.
One note: if you use Baidu AI Cloud’s large model services, refer to the official documentation for specific billing items, caching policies, and quotas. The fitting method, capacity conversion formula, and routing framework in this article are vendor-neutral and can be applied directly to any token-priced inference service.
