LLM Inference Cost: A Practical Guide to Measurement and Tiered Scheduling
This article shows how to measure real LLM inference costs from your own usage logs instead of relying on published price lists, then use those measurements for capacity planning and tiered model routing. You will learn how to fit per-token consumption rates with least squares, how to read R² and residuals to judge whether the fit is trustworthy, how to convert a credit window into usable token capacity per model tier, and how to route tasks by reasoning depth so expensive models handle high-value judgment while cheaper tiers handle execution. It also covers cache hit rate as the primary cost lever and common pitfalls such as ignoring output-heavy workloads or treating fitted coefficients as constants.
1. Background: Why “It Feels Expensive” Is Not the Same as “It Is Expensive”
When building an intelligent coding assistant, a code review pipeline, or a multi-agent system, teams most often run into the same confusion: the bill grows much faster than business volume, yet nobody can say which stage the money actually goes to. There are usually three reasons. First, different model tiers are priced along different dimensions—input, output, and cache hits are often billed separately. Second, people treat unit price as total cost, ignoring the nonlinear effects of context length, retry counts, and cache reuse. Third, there is no reproducible measurement method, so the discussion stays at the level of gut feeling.
The core idea of this article is to avoid depending on any official price list. Instead, use your own real call records over a period of time to back out the actual consumption rate of each model tier, and then design task tiering and quota allocation on that basis. One caveat up front: this method produces an empirical fit from a personal environment. It changes as rules change and must not be treated as a basis for pricing.
2. Method: Backing Out Consumption Rates from Real Records
Let C be the credit consumption in a given time window, I the input tokens, O the output tokens, and H the cache-hit tokens. A linear model can describe the relationship:
C = a * I + b * O + c * H + d
Here a, b, and c are the unit consumption for input, output, and cache hits, and d is a constant term used to absorb rounding errors in metering. With three or more linearly independent samples, you can solve for the coefficients by least squares. A minimal illustration:
import numpy as np# Each row: [input tokens, output tokens, cache-hit tokens, 1]X = np.array([[820_000, 90_000, 600_000, 1],[310_000, 40_000, 120_000, 1],[1_050_000, 70_000, 900_000, 1],], dtype=float)y = np.array([128_400, 52_600, 141_000]) # credit consumption for each windowcoef, *_ = np.linalg.lstsq(X, y, rcond=None)pred = X @ coefr2 = 1 - ((y - pred) ** 2).sum() / ((y - y.mean()) ** 2).sum()print(coef, r2)
To judge whether the fit is credible, look at two metrics: whether the coefficient of determination R² is close to 1, and whether the residuals are close to 0. When both hold, pricing is approximately linear in that scenario and the fitted coefficients can be used for capacity planning. If the residuals are clearly large, it usually means nonlinear factors are at play—tiered pricing, a minimum billing unit, or credits expiring and resetting at the end of a window. In that case, fit each interval separately.
3. Measured Results: How Consumption Rates Differ Across Tiers
Using the method above on three tiers—“high-load inference,” “medium-load inference,” and “lightweight inference”—the order-of-magnitude relationships come out as follows (relative values, shown only to illustrate the structure):
| Model tier | Input (per million tokens) | Output (per million tokens) | Cache hit (per million tokens) |
|---|---|---|---|
| Flagship inference | ~80,000 | ~400,000 | close to input price |
| Main inference | ~32,000 | ~112,000 | close to input price |
| Fast tier | ~4,000 | ~8,000 | ~80 |
| Lightweight tier | ~2,000 | ~2,000 | ~2,000 |
Two conclusions are worth stressing. First, the flagship tier’s output unit price can be roughly two hundred times that of the lightweight tier, so mixing tiers without routing tasks lets cost blow up quickly on the output side. Second, after a cache hit the fast tier’s unit consumption drops to about 2% of its normal input price. For batch scenarios with long contexts and repeated prefixes, the cache hit rate is the single biggest cost lever.
4. Quota Conversion: Turning a Credit Window into Usable Tokens
Suppose the quota is “60,000 credits / 5 hours” and “600,000 credits / week.” Assuming input accounts for 80% and output for 20%, and ignoring cache for now, the token volume that can be carried is approximately:
carriable tokens ≈ quota / (0.8 * a + 0.2 * b)
Plugging in the magnitudes from the table above, the rough capacity of the 5-hour window is about 417,000 tokens on the flagship tier, about 1.25 million on the main tier, about 12.5 million on the fast tier, and about 30 million on the lightweight tier. The gap spans nearly two orders of magnitude, which shows that quota planning cannot just ask “is it enough?” but must ask “which tier is it spent on?”
In engineering practice, it is worth turning this step into a script: feed in the current coefficients and quota, output the remaining capacity per tier, and trigger a downgrade strategy as you approach the threshold, rather than passively reacting once requests get rate limited.
5. Tiered Scheduling: Let Expensive Models Think, Cheap Models Execute
Given this cost structure, tasks can be tiered by “reasoning depth required” rather than by lines of code or number of files:
- Flagship tier: requirement breakdown, solution design, final review, and gatekeeping for high-risk changes—few calls but high value per call.
- Main tier: complex logical reasoning, cross-file refactoring, and locating difficult defects.
- Fast tier: the main execution work, including routine coding, test completion, and log and monitoring data analysis.
- Lightweight tier: batch simple tasks such as formatting, comment generation, and large-scale first-pass file screening.
A minimal working router:
def route(task):if task.risk == "high" or task.needs_plan:return "flagship"if task.complexity >= 3:return "main"if task.batch and task.repeat_prefix:return "fast" # high cache hit rate, lowest costreturn "lite"
Four supporting engineering points. First, keep a stable prefix and a fixed prompt structure, putting the system prompt and tool descriptions at the very front to improve cache hits. Second, set a budget and timeout for each tier, and downgrade automatically when the budget is exceeded. Third, write credit consumption, token volume, and cache hit rate into a logging service and configure monitoring alerts, forming an observable closed loop. Fourth, hand review tasks to the flagship tier only once, avoiding the multiplier overhead of repeated reviews across tiers.
6. Common Pitfalls and Cautions
One: looking only at unit price and not at structure—scenarios with a high output share (long-form generation, large-scale refactoring) see costs amplified significantly. Two: ignoring the cache—if repeated prefixes are not normalized, you are voluntarily giving up the largest discount. Three: treating fitted coefficients as constants—rules, model versions, and window policies change, so you must resample. Four: lacking a downgrade path, so the whole chain blocks when the quota runs out. Five: insufficient sampling—when samples are fewer than the number of unknown parameters, the fit is meaningless.
7. Summary
The key to cost governance is not driving down price but spending “expensive capability” on “expensive judgment.” First fit each tier’s consumption rate from real records, then convert the quota window into capacity, and finally land it with task tiering and cache optimization. That is how you get stable output under a limited quota. If you use Baidu AI Cloud capabilities, it is likewise advisable to build the observability and data retention chain on general-purpose categories (such as log services, monitoring alerts, and object storage), letting data drive continuous capacity and cost optimization.
