LLM Inference Cost: A Practical Guide to Measuring Token Rates and Tiered Model Routing
This article shows how to measure real LLM API credit consumption, fit per-token cost rates with linear regression, and use the resulting cost gradient to build a tiered routing strategy. It covers the sampling requirements for a stable fit, how to judge fit quality, the order-of-magnitude cost differences between model tiers, how to convert a credit quota into a token budget, a four-layer routing architecture, and a practical cost-optimization checklist. All rates are presented as illustrative, personally measured figures rather than official pricing, so they should be kept configurable.
1. Background: Why a Quota That “Should Be Enough” Runs Out Early
When teams build AI coding assistants, document review pipelines, or multi-agent systems on top of LLM APIs, the most common problem is not output quality but quota exhaustion: a five-hour coding session burns far more credits than expected, and a batch job gets throttled halfway through. There are usually three root causes:
- Models from different capability tiers are used interchangeably across every step.
- Input, output, and cache-hit tokens are not treated as separate billing dimensions.
- There is no up-front estimation, so teams only see the bill after the fact.
The core method in this article is to use real usage records as samples, fit credit consumption with linear regression to derive each model tier’s per-token consumption rate, and then build a tiered routing strategy on top of that. Note that these reverse-engineered rates are personal measurements, not an official price list, and the rules can change at any time. In engineering terms, rates should be a configurable value, not a hard-coded constant.
2. Measurement Method: Deriving Per-Token Rates with Linear Fitting
Billing is essentially a linear model. Let a session’s input tokens be x_in, output tokens be x_out, and cache-hit tokens be x_cache. The credits consumed C can be written as:
C = a * x_in + b * x_out + c * x_cache + d
Here a, b, and c are the per-token rates to solve for, and d is a constant term (usually 0). Given a handful of “token usage + credit change” samples, the coefficients can be solved with least squares. To keep the fit stable, sample collection should satisfy three conditions: the sample count should be three to five times the number of unknown parameters; the input-to-output ratio should vary across samples to avoid multicollinearity; and timestamps should align with the quota reset cycle so that periodic settlement errors do not leak into the coefficients.
Fit quality is judged by the coefficient of determination and the residuals. When R² is close to 1 and residuals are close to 0, billing really is linear and the derived coefficients are trustworthy. If residuals show a systematic offset, that usually means there is a minimum charge, per-call billing, or tiered pricing, in which case the data should be fitted in segments.
Illustrative implementation (pseudocode):
# rows: [(input_tokens, output_tokens, cache_tokens, credits), ...]X = [[r[0], r[1], r[2], 1.0] for r in rows]y = [r[3] for r in rows]coef, *_ = np.linalg.lstsq(np.array(X), np.array(y), rcond=None)a, b, c, d = coefr2 = 1 - ((y - np.array(X) @ coef) ** 2).sum() / ((y - np.mean(y)) ** 2).sum()
3. Measured Magnitudes: Tiers Differ by Two Orders of Magnitude
Fitting several model tiers with the method above produces a clear gradient in per-token rates (in credits per million tokens, illustrative magnitudes only): the flagship reasoning tier is roughly 80,000 for input and 400,000 for output; the upper-mid general-purpose tier is roughly 32,000 input and 112,000 output; the high-speed execution tier is roughly 4,000 input and 8,000 output, with cache hits at only about 80; and the lightweight tier is roughly 2,000 for both input and output.
Two key conclusions follow. First, output is more expensive than input: the flagship tier’s output rate is about five times its input rate, so “letting the model write more” costs more than “letting the model read more.” Second, the gap across tiers can reach two orders of magnitude: the flagship tier’s output cost is about 200 times that of the lightweight tier, and for the high-speed execution tier a cache hit leaves input cost at roughly 2% of the normal input rate. That makes stable system prompts, long document prefixes, and repeated context the highest-leverage optimization targets.
4. Quota Conversion: How Many Tokens the Same Credits Buy
Assume a quota cadence of 60,000 credits every five hours and 600,000 credits per week, with input at 80%, output at 20%, and cache ignored for now. The weighted average rate determines the total token volume the quota can carry:
| Tier | Estimated token capacity (per five hours) |
|---|---|
| Flagship reasoning | ~420,000 |
| Upper-mid general-purpose | ~1,250,000 |
| High-speed execution | ~12,500,000 |
| Lightweight | ~30,000,000 |
The conversion formula is:
token capacity = credit quota / (0.8 * a + 0.2 * b)
The point of this table is to turn “model choice” from a subjective preference into a computable engineering decision: when a task is not sensitive to reasoning depth, moving to a lower tier yields a throughput gain on the order of 100x.
5. Tiered Routing Architecture: Expensive Models Think, Cheap Models Execute
Based on the cost gradient, the recommended design splits the system into four layers, with a routing layer dispatching by task characteristics:
- Flagship tier: requirement decomposition, solution design, final code and document review — low-frequency, high-value judgment.
- Upper-mid tier: complex reasoning, hard defect localization, cross-module refactoring suggestions.
- High-speed execution tier: the main coding workload, unit test generation, log analysis and other high-frequency tasks, with prefix caching pushing long-context cost extremely low.
- Lightweight tier: batch classification, format conversion, comment completion, simple Q&A and other parallelizable small tasks.
Routing decisions can be implemented with rules plus heuristic scoring. Inputs include task type, context length, whether multi-step reasoning is required, retry count, and the remaining quota level:
def route(task, remaining_credits):if task.needs_deep_reasoning or task.is_final_review:return "flagship"if task.context_tokens > 32000 and task.cacheable:return "fast" # input cost is minimal on a cache hitif task.batchable and task.difficulty <= 2:return "lite"if remaining_credits < 5000:return "lite" # degrade at low quota to keep tasks runningreturn "mid"
6. Cost Optimization Checklist
- Prefix stabilization: put the system prompt, tool descriptions, and coding conventions at the very front of the context and avoid dynamic concatenation, maximizing cache hits.
- Output budget constraints: explicitly cap maximum output length and require “conclusion first, details after” so the flagship tier’s output rate is not amplified.
- Context compression: rerank and deduplicate retrieval results, keeping only the fragments relevant to the current step.
- Push batch work down: send parallelizable simple tasks to lower tiers uniformly, using queues and concurrency control to manage throughput.
- Observability: instrument every call with input, output, and cache tokens plus credit deltas, and keep re-fitting the coefficients to detect rule changes.
- Degradation and circuit breaking: feed quota level and throttling error rate into circuit-breaker conditions so the system switches tiers automatically instead of failing outright.
7. Implementation Notes
Reverse-engineered rates hold only under the current rules, so keep them configurable and validate them periodically. Fitting samples must cover different input/output ratios, otherwise the coefficients are not identifiable. Cache hit rate is an underrated lever, so “cacheable” should be a first-class design goal in the architecture. Finally, tiered routing should keep a human confirmation step: key decisions and final review should not be handed entirely to lower-tier models. For large-scale call volumes, container platforms can provide elastic concurrency, message queues can smooth out task spikes, and logging services with monitoring and alerting can track usage, forming a closed-loop cost governance system.
