LLM Token Cost Benchmarking and Tiered Routing in Practice
This article breaks down why a lower per-token price does not always produce a lower bill, and shows how to reverse-engineer real unit consumption rates from your own billing logs using least-squares regression. It presents measured cost gradients across model tiers, a formula for converting a credit budget into usable tokens, and a four-layer routing strategy that assigns planning and final review to flagship models while pushing routine and batch work to cheaper tiers. Readers will also find common pitfalls, an implementation checklist, and engineering constraints for prefix caching, per-layer limits, and cost monitoring. All figures are personal order-of-magnitude estimates, not official pricing.
1. The Problem: A Cheap Unit Price Does Not Mean a Cheap Bill
When building an AI coding assistant or an automated agent pipeline, teams often run into the same confusion: they pick a model with a lower unit price, yet the month-end bill does not drop as expected. The root cause is that two variables get ignored at the same time: how billing is measured, and what the call structure actually looks like.
Large model services typically price three dimensions separately: input tokens, output tokens, and cache-hit tokens. The unit prices of these three can differ by one to two orders of magnitude. In real workloads, the input-to-output ratio is often badly skewed. Coding tasks with long context and repository-level retrieval augmentation usually run above 80% input, while pure generation tasks are dominated by output. If you make decisions based only on a single “dollars per million tokens” number, you are implicitly assuming every task has the same input/output structure, and the conclusion will be distorted.
The second underestimated variable is caching. Most mainstream inference services offer prefix caching, which sharply reduces billing for repeated prefixes such as system prompts, long documents, and codebase context once there is a hit. Whether caching is enabled, and how high the hit rate is, can make the actual cost of the same workload differ by several times.
2. Method: Reverse-Engineering Unit Consumption from Your Own Bills
Rather than trusting the numbers on a pricing page, a more reliable approach is to run a regression fit over your own call logs. Let the credit consumption in a given time window be C, input tokens be x₁, output tokens be x₂, and cache-hit tokens be x₃. The model is linear:
C = a·x₁ + b·x₂ + c·x₃ + da: input unit price coefficient b: output unit price coefficient c: cache-hit unit price coefficient d: fixed overhead
Collect three or more samples with clearly different structures (for example “long input, short output”, “short input, long output”, and “high cache hit”), then solve with least squares to separate the coefficients. To judge whether the fit is trustworthy, look at two indicators: whether the coefficient of determination R² is close to 1, and whether the residuals are close to 0 with no systematic bias. If the residuals vary monotonically with input length, it means you have missed tiered long-context pricing or extra consumption from timeout retries, and you need to add features rather than accept the result as-is.
Illustrative implementation:
import numpy as np# Each row: [input tokens, output tokens, cache-hit tokens, actual credit consumption]samples = np.array([[820_000, 180_000, 600_000, 41_700],[300_000, 700_000, 100_000, 39_500],[900_000, 100_000, 850_000, 12_300],], dtype=float)X, y = samples[:, :3], samples[:, 3]coef, *_ = np.linalg.lstsq(X, y, rcond=None)pred = X @ coefss_res = ((y - pred) ** 2).sum()ss_tot = ((y - y.mean()) ** 2).sum()print("Coefficients:", coef, "R²:", 1 - ss_res / ss_tot)
3. Findings: Consumption Rates Show a Clear Gradient
After running the fit above on call records from several mainstream models, a stable gradient structure emerges (the figures below are order-of-magnitude values reverse-engineered from personal testing, not an official price list, and the rules can change at any time):
- Flagship reasoning: input about 80K per million tokens, output about 400K per million tokens;
- Balanced reasoning: input about 32K, output about 112K;
- High-speed execution: input about 4,000, output about 8,000, cache hits as low as 80;
- Lightweight batch: input and output both about 2,000.
Two key conclusions: the output cost of a flagship model can be roughly 200 times that of a lightweight model; and for the high-speed execution tier, after a cache hit the input cost is only about 2% of the normal value. This means the biggest lever for cost optimization is not “switch to a cheaper model”, but “make repeated prefixes hit the cache” and “don’t put the flagship model on batch work”.
4. Budget Conversion: Turning a Credit Allowance into Usable Tokens
Assume an allowance of 60K credits per 5 hours and 600K credits per week. Estimating with 80% input + 20% output and ignoring caching for now, the supported token volume is roughly: flagship 417K per 5 hours, balanced 1.25M, high-speed execution 12.5M, lightweight 30M. The same budget spans nearly two orders of magnitude across tiers.
The conversion formula can be reused directly:
Usable tokens = Budget credits / (0.8·a + 0.2·b)
If you factor in caching, the input term in the denominator needs to be split by hit rate: 0.8·(h·c + (1-h)·a), where h is the hit rate. Raising h from 0 to 0.7 typically cuts overall cost by more than half in long-context scenarios.
5. Tiered Routing: Expensive Models Think, Cheap Models Do
Based on the gradient above, the pipeline can be split into four layers, each with clear admission criteria:
- Planning and final review layer: task decomposition, solution selection, code review, handled by the flagship model, kept within 5% of total tokens;
- Complex reasoning layer: cross-file refactoring and tricky defect localization, handled by a balanced reasoning model;
- Main execution layer: routine coding, unit test generation, and script writing, handed to the high-speed execution model with prefix caching enforced;
- Batch processing layer: formatting, comment completion, and log categorization, all pushed down to the lightweight model, merging requests where necessary.
For routing decisions, prefer interpretable heuristic rules over letting the model choose for itself:
def route(task):if task.needs_planning or task.is_final_review:return "flagship"if task.cross_file or task.difficulty >= 3:return "balanced"if task.batch or task.simple:return "lite"return "fast"
Three supporting engineering constraints: first, unify the system prompt and place it at the very front to keep the prefix stable and raise the cache hit rate; second, set a token cap and a timeout-retry cap for each layer so the flagship layer is not dragged down by long context; third, instrument credit consumption per layer and report it into the monitoring and alerting system to form a daily dashboard.
6. Common Pitfalls and a Rollout Checklist
Pitfalls include: looking only at unit price without considering input/output structure; ignoring caching and paying twice for the same content; using a flagship model for batch cleanup; and lacking metering instrumentation, which makes it impossible to verify whether an optimization worked.
Rollout checklist: collect three or more samples to calibrate the coefficients and validate R² and the residuals; implement four-layer routing with a fallback strategy; enable prefix caching and monitor the hit rate; build a cost dashboard by model and by business line; recalibrate the coefficients once per quarter, because service rules change.
One point to stress: every number in this article is an order-of-magnitude reference reverse-engineered from personal testing and does not constitute any official pricing basis. Different accounts, different time windows, and different workload structures will all introduce deviations, so always rely on the regression results from your own bills.
