LLM Inference Cost Breakdown and Tiered Model Scheduling in Practice
This article explains how to measure large language model inference costs when billing is based on input tokens, output tokens, and cached tokens rather than call counts. It shows how to reverse-engineer per-token pricing from your own usage logs using least squares fitting, how to convert credit quotas into usable token budgets across model tiers, and how to build a four-layer routing strategy that assigns planning and review to flagship models while delegating high-volume execution to faster and lighter tiers. Readers will also find practical notes on cache-friendly context design, budget guardrails, and common cost pitfalls.
1. The Problem: Costs Feel High, but You Cannot Pin Down Why
Many teams using AI coding tools or LLM APIs run into the same issue: credits drain quickly, yet nobody can answer “which step actually spent the money” during a retrospective. There are usually three reasons.
First, billing is not based on a single “number of calls” metric. Input tokens, output tokens, and cache-hit tokens are priced separately, and the output rate is generally much higher than the input rate. Second, the input-to-output ratio varies enormously across tasks: code review tasks have long inputs and short outputs, generation tasks have long outputs, and repeated-context scenarios that hit the cache may cost only a few percent of the normal input price. Third, quotas are often issued in abstract units such as “credits,” with time windows attached (for example, a refresh every few hours and another refresh every week), which means instantaneous availability and total periodic capacity are two separate constraints.
So the first step in cost governance is not switching models. It is establishing a measurable basis for observation.
2. Method: Reverse-Engineering Unit Prices from Your Own Call Records
Without an official price list, you can use least squares fitting on your own historical records to infer the consumption coefficient for each token category. Let the credits for the i-th call be y_i, and the input, output, and cache-hit token counts be x1, x2, and x3. The model is:
y_i = a * x1_i + b * x2_i + c * x3_i + e_i
Solve for the coefficients a, b, and c using multiple samples. Once the sampling covers requests with different input-output ratios, the goodness of fit can be very high (residuals close to 0), which shows that credit consumption is essentially determined linearly by these three terms. Example code:
import numpy as np# rows: [input tokens, output tokens, cache-hit tokens]X = np.array([[820000, 40000, 0],[300000, 120000, 500000],[1500000, 60000, 900000],], dtype=float)y = np.array([120.0, 96.0, 78.0]) # corresponding credit consumptioncoef, *_ = np.linalg.lstsq(X, y, rcond=None)a, b, c = coefprint(f"input {a:.6f} / output {b:.6f} / cache {c:.6f} credits per token")
Three engineering points matter here. First, the sample must include both “long input, short output” and “short input, long output” cases; otherwise the coefficients are not identifiable. Second, count failed retries and tool-call rounds on the input side. Third, keep repeated prefixes such as system prompts and repository context as stable as possible so you can observe the cache benefit.
3. Findings: Cost Magnitude Differences Across Model Tiers
Based on the fit above, we can abstract the “tier-cost” ladder that commonly exists in the industry (the following are order-of-magnitude illustrations, not any vendor’s pricing):
- Flagship reasoning tier: input on the order of tens of thousands of credits per million tokens, output on the order of hundreds of thousands of credits per million tokens;
- Balanced reasoning tier: input on the order of tens of thousands of credits per million tokens, output on the order of just over a hundred thousand credits per million tokens;
- High-speed execution tier: input on the order of thousands of credits per million tokens, output on the order of thousands to ten thousand credits per million tokens;
- Lightweight batch tier: both input and output on the order of around two thousand credits per million tokens.
Two key conclusions are worth remembering. First, the output unit price of the flagship tier can be on the order of a hundred times that of the lightweight tier, which means “having the flagship model write another thousand words” and “having the lightweight model write another thousand words” are completely different economic magnitudes. Second, after a cache hit, input cost may drop to only a few percent of the normal input cost, so the marginal cost of repeated long-context prefixes is extremely low.
4. Quota Conversion: Turning Credits into Usable Tokens
Assume a quota of 60,000 credits per 5 hours and 600,000 credits per week, with a task mix of 80% input and 20% output and no cache assumed. The usable token magnitude within a 5-hour window is roughly:
- Flagship tier: about 400,000 tokens;
- Balanced tier: about 1.2 million tokens;
- High-speed tier: about 12 million tokens;
- Lightweight tier: about 30 million tokens.
The conversion formula can be reused directly:
usable tokens ≈ quota / (0.8 * input price + 0.2 * output price)
If the output share is higher (for example, 40%), the usable amount for the flagship tier drops further, so “output share” should be the first input parameter in model selection.
5. Tiered Scheduling: Expensive Models Think, Cheap Models Do
The core of cost optimization is not pushing prices down but putting model capability in the right place. The recommended four-layer division of labor:
- Planning and review layer (flagship tier): responsible for task decomposition, solution selection, final code review, and security assessment. Long input and short output keep costs controllable with the highest payoff;
- Complex reasoning layer (balanced tier): responsible for diagnosing difficult defects, cross-module refactoring plans, and algorithm derivation;
- Main execution layer (high-speed tier): responsible for routine coding, unit test completion, and script writing; this is the throughput workhorse;
- Batch processing layer (lightweight tier): responsible for formatting, comment generation, log categorization, and simple classification and extraction.
In practice, this can be implemented with a lightweight routing layer, as shown below:
def route(task):if task.type in ("plan", "review", "security"):return "flagship"if task.type in ("debug_hard", "refactor"):return "balanced"if task.type in ("code", "unittest"):return "fast"return "lite"
Three supporting engineering practices: first, place the stable, unchanging system prompt and repository summary at the front to maximize cache hits; second, set a token budget and timeout for each layer, and automatically downgrade to the next tier when the budget is exceeded; third, write each layer’s actual consumption back to logs to continuously correct the fitted coefficients and form a closed loop.
6. Common Pitfalls and Risk Notes
Pitfall one: looking only at unit price and not at structure. If the output share is high, the flagship model’s bill will scale nonlinearly. Pitfall two: ignoring retries and tool-call rounds; in multi-round agent scenarios, input gets billed repeatedly. Pitfall three: treating the cache as a default capability, when in fact you need to explicitly design stable prefixes and call ordering. Pitfall four: using one model for everything, which causes simple tasks to consume high-priced quota.
It should be emphasized that the unit prices and usable amounts above are order-of-magnitude illustrations reverse-engineered from personal testing, not official pricing. Rules and quota policies may change at any time. Production selection should be based on the billing rules published by the service provider for the current period, and actual consumption should be continuously verified through monitoring alerts and logging services.
7. Summary
The actionable path for cost governance is: first fit the unit prices, then convert the quota, and finally apply tiered scheduling. Separate “thinking” from “doing,” use the flagship tier for planning and review, and let the high-speed and lightweight tiers handle throughput. Combined with cache-friendly context design and budget guardrails, this can increase effective output by an order of magnitude under a fixed quota.
