LLM Inference Cost Breakdown and Tiered Routing in Practice
This article explains why a cheaper per-token price does not always produce a cheaper bill, and how to build a cost model from real usage records. It covers fitting per-unit consumption rates with least squares, converting a credit quota into usable token budgets across model tiers, and a four-tier routing strategy that reserves expensive models for critical tasks. It also includes observability and recalibration practices for keeping cost governance accurate over time.
1. The Problem: A Low Unit Price Does Not Mean a Low Bill
When building an AI coding assistant, a document review pipeline, or a multi-agent system, teams often run into the same confusion: they pick a lower-priced model tier, yet the monthly bill does not drop as expected. There are usually three reasons.
First, billing is not based on a single dimension. Usage-based pricing typically separates input, output, and cache hits, and the output unit price is often significantly higher than the input unit price. In long-context scenarios, input also makes up a very large share.
Second, the actual workload structure determines where the cost lands. An agent focused on “reading a codebase + short answers” may have an input share above 85%, while an agent focused on “generating long content + refactoring multiple files” will see a much higher output share.
Third, the cache hit rate is a seriously underestimated variable. When the system prompt, tool definitions, and repository context are carried repeatedly, the unit cost of the cached portion can be only a few percent of normal input.
So the right approach is not to compare list prices, but to build your own cost model: use real call records to derive unit consumption rates, then plug in your workload structure to project a budget.
2. Method: Deriving Unit Consumption Rates from Real Records
The idea is to treat a single call as a linear equation. Let the input token count be x_in, the output token count be x_out, the cache-hit token count be x_cache, and the credits consumed by this call be y:
y = a * x_in + b * x_out + c * x_cache + e
Here a, b, and c are the unit consumption rates to solve for, and e is the error term. As long as you collect enough samples with a sufficiently dispersed distribution of the three ratios, you can solve with least squares. Example code:
import numpy as np# rows: [input tokens, output tokens, cache-hit tokens, observed credits]rows = np.array([[820000, 12000, 600000, 78.4],[150000, 40000, 0, 28.0],[2000000, 8000, 1800000, 96.2],# ... more real samples], dtype=float)X, y = rows[:, :3], rows[:, 3]coef, residual, rank, _ = np.linalg.lstsq(X, y, rcond=None)a, b, c = coefpred = X @ coefss_res = ((y - pred) ** 2).sum()ss_tot = ((y - y.mean()) ** 2).sum()r2 = 1 - ss_res / ss_totprint(f"input rate={a:.6f} output rate={b:.6f} cache rate={c:.6f} R2={r2:.6f}")
Key details in practice:
- Samples must cover different input/output ratios; otherwise the coefficient matrix is ill-conditioned and the solution is unstable.
- The credit accounting basis must be consistent. If the platform settles daily or weekly with tiers, fit each segment separately.
- After fitting, always run a residual check. Only when the residuals are near zero and
R²is close to 1 does the model assumption hold. - The fitted result is a personal observation and will drift as platform rules change, so treat it as a “trend ruler” rather than a “price list.”
3. Findings: The Cost Gap Across Tiers Is Huge
Fitting multiple tiers under a consistent accounting basis reveals a stable pattern: unit costs across tiers do not increase linearly, but pull apart almost exponentially. The output cost of a flagship reasoning tier can reach on the order of two hundred times that of a lightweight tier, while the lightweight tier’s input and output unit prices are basically aligned, making its cost structure the simplest.
The cache tier is even more noteworthy. For some mid-to-low tier models, the unit cost on a cache hit is only about 2% of normal input, which means “putting stable context into the cache” is the highest-value one-time optimization.
The following illustrative values (unit: credits / million tokens) show the order-of-magnitude relationship:
| Tier | Input | Output | Cache Hit |
|---|---|---|---|
| Flagship reasoning | 80000 | 400000 | Not disclosed separately |
| Balanced | 32000 | 112000 | Not disclosed separately |
| Mainstream execution | 4000 | 8000 | ~80 |
| Lightweight | 2000 | 2000 | ~2000 |
4. Budget Conversion: From a Credit Quota to Usable Tokens
Suppose the quota is “60,000 credits per 5 hours and 600,000 credits per week,” the workload structure is 80% input + 20% output, and cache is ignored for now. The usable token amount is:
convertible tokens = quota / (0.8 * a + 0.2 * b)
Plugging in the orders of magnitude from the table above, the usable tokens within a 5-hour window are roughly: about 417,000 for the flagship tier, about 1.25 million for the balanced tier, about 12.5 million for the mainstream execution tier, and about 30 million for the lightweight tier. The gap between the flagship and lightweight tiers is about 72x.
The value of this conversion is turning “quota anxiety” into a “task quota”: once you know there are only about 417,000 flagship tokens per 5 hours, you will naturally limit flagship calls to the critical path.
5. Tiered Routing: Let Expensive Models Think and Cheap Models Execute
The core of cost optimization is not pushing down the unit price, but tiering tasks. The recommended four-tier structure:
- Flagship reasoning tier: requirement clarification, solution planning, final code review, and risk judgment;
- Balanced tier: complex reasoning, cross-module refactoring, and hard defect localization;
- Mainstream execution tier: most routine coding, test completion, and log analysis;
- Lightweight tier: batch classification, format conversion, comment generation, and simple extraction.
Routing can be scored by “task type + context length + estimated output length,” with example rules as follows:
def route(task_type, ctx_len, est_out_len):if task_type in {"plan", "review", "architecture"}:return "flagship"if task_type in {"refactor", "debug_hard"} or ctx_len > 400_000:return "balanced"if est_out_len > 8000:return "balanced"if task_type in {"classify", "format", "extract"}:return "lite"return "mainstream"
Combined with three engineering constraints, the gains are further amplified:
- Context governance: inject only the necessary fragments, and keep the system prompt and tool definitions fixed to hit the cache;
- Output constraints: use structured output and length limits to suppress meaningless long outputs;
- Failure fallback: after the mainstream tier fails twice in a row, fall back to the lightweight tier for a retry, avoiding costly repeated retries.
6. Observability and Continuous Calibration
Cost governance must be a closed loop. It is recommended to instrument each call to collect input, output, and cache-hit token counts and the credits consumed, send them to a logging service, and then set thresholds on “cost per task” with monitoring alerts. Re-run the fitting script once a week to observe coefficient drift; if R² drops noticeably below 0.99, the workload structure or billing rules have changed and you need to resample.
In related practice at Baidu AI Cloud, this closed loop is typically completed by combining general cloud product capabilities: using object storage to archive call details, a message queue to smooth peaks and fill valleys, a container platform to host the inference gateway, and a logging service with monitoring alerts for cost attribution.
7. Conclusion
The essence of LLM cost differences is the combination of exponential unit-price gaps across tiers and the workload structure. The reusable methodology is three steps: use least squares to derive unit consumption rates from real records, use a linear model to convert a quota into a task quota, and then use tiered routing to constrain expensive compute to the critical path. It is worth emphasizing that any derived result only represents a personal observation, and rules may change at any time, so always replace one-time conclusions with continuous calibration.
