LLM Inference Cost: A Practical Guide to Measurement and Tiered Scheduling
This article explains why large language model (LLM) inference costs often spiral out of control despite being hard to explain, and how to fix it. It shows how to reverse-engineer per-unit consumption rates from real usage records using linear regression when billing details are opaque, compares cost magnitudes across model tiers that can differ by up to two orders of magnitude, and estimates effective throughput under quota limits. It then presents a tiered scheduling architecture that routes deep reasoning to expensive models and routine execution to cheaper ones, along with engineering practices and risk considerations for production budgets.
1. The Problem: Costs Feel High, but No One Can Explain Why
When building an intelligent coding assistant, a document review pipeline, or a multi-agent system, teams most often struggle not with insufficient model capability but with costs that spiral out of control and cannot be explained. A typical pattern: the end-of-month bill or quota consumption far exceeds expectations, yet no one can point to which category of requests drained the budget. There are usually three reasons:
- Billing is a three-part structure of “input + output + cache hits,” but most teams estimate only by “number of requests.”
- Output prices for different model services are often significantly higher than input prices, and long-text generation scenarios amplify this several times over.
- Cache hits from prompt reuse may cost only a few percent of the regular input price, and whether a hit occurs directly shapes the cost curve.
So the first step in cost governance is not to cut requirements, but to build a quantifiable unit-cost model.
2. Method: Reverse-Engineering Unit Consumption Rates from Real Usage Records
When a platform bills in abstract units like “credits” or “quota” without publishing a breakdown, you can use regression fitting to work backward. The core assumption is that the credit consumption of a single request is approximately linear with respect to input tokens, output tokens, and cache-hit tokens.
Illustrative implementation:
import numpy as np# X columns: [input tokens, output tokens, cache-hit tokens, 1]X = np.array([[120_000, 8_000, 0, 1],[300_000, 15_000, 200_000, 1],[80_000, 20_000, 0, 1],# ... more real samples], dtype=float)y = np.array([96.0, 210.5, 88.0, 1.0]) # measured creditscoef, *_ = np.linalg.lstsq(X, y, rcond=None)pred = X @ coefr2 = 1 - ((y - pred) ** 2).sum() / ((y - y.mean()) ** 2).sum()print(coef, r2)
When sampling covers different input/output ratios and includes cache-hit samples, the goodness of fit can approach 1 with residuals near 0, showing that a linear model is sufficient to explain actual consumption. Three engineering caveats apply: samples must include both extremes of “very long input, very short output” and “short input, long output,” otherwise the coefficients are not identifiable; the cache-hit column must be strictly mutually exclusive with the input column; and consumption from failed-request retries must be excluded separately.
3. Cost Magnitudes: The Same Task Can Differ by Two Orders of Magnitude
Using the fitted consumption rates, you can place different model tiers on the same scale (in “credits consumed per million tokens,” rounded for clarity):
- Flagship reasoning tier: input about 80,000, output about 400,000;
- Balanced reasoning tier: input about 32,000, output about 112,000;
- High-speed tier: input about 4,000, output about 8,000, cache hit about 80;
- Lightweight tier: input and output both about 2,000.
Key takeaway: the flagship tier’s output price is about 200 times that of the lightweight tier; for the high-speed tier on a cache hit, input cost is only 2% of regular input. This means output-heavy and input-heavy tasks have completely different cost structures, and you cannot budget with a single average price.
4. Estimating Effective Throughput Under Quota Constraints
Assume a quota of 60,000 credits per 5 hours and 600,000 credits per week. Estimating at 80% input + 20% output and ignoring cache for now, the supported token magnitudes are roughly: flagship tier about 417,000, balanced tier about 1.25 million, high-speed tier about 12.5 million, lightweight tier about 30 million. The gap comes from the amplification effect of the output share: the higher the output price, the more the 20% output devours most of the budget.
The implication is direct: handing all traffic to the flagship tier means doing batch work that the lightweight tier could handle at 200 times the price.
5. Tiered Scheduling Architecture: Expensive Models Think, Cheap Models Execute
Classifying tasks by “reasoning depth requirement” is the most effective means of cost governance:
- Flagship tier: task decomposition, solution design, final review and risk gatekeeping;
- Balanced tier: complex logical reasoning, cross-file refactoring, tricky defect localization;
- High-speed tier: mainstream code generation, routine rewrites, unit test completion;
- Lightweight tier: batch formatting, comment generation, log categorization, and other simple tasks.
Supporting engineering practices: tag each call with a task-level label and use a unified gateway for routing and rate limiting; stabilize the ordering of system prompts and code context to maximize cache hits; build consumption dashboards and alerts by level and by scenario to avoid exhausting a single quota point.
6. Implementation Advice and Risk Considerations
First calibrate coefficients with small-traffic sampling, then roll out the routing policy; review fitting residuals weekly, and a clear deviation indicates the model or billing rules have changed. Note that the figures above come from personal measurement and reverse-engineering, not official pricing, and rules may change at any time, so production budgets should keep redundancy and a fallback plan. If you use relevant Baidu AI Cloud capabilities, you can combine them with general cloud product capabilities such as monitoring and alerting and logging services to build a cost observability system for quota warnings and automatic degradation.
