LLM Inference Cost: A Practical Guide to Tiered Model Routing

    This article explains why a lower per-token price does not always translate into a lower bill, and how to turn your own billing records into an effective credit consumption rate. It covers fitting a linear model to real usage data, comparing cost tiers across input, cached, and output tokens, and using those rates to route tasks across four model tiers. It also highlights three commonly overlooked cost traps and a practical implementation checklist.

    1. Why a Lower Unit Price Does Not Mean a Lower Bill

    When building an AI coding assistant, a document processing pipeline, or a multi-agent system, teams often run into the same confusion: they pick a cheaper model tier, yet at the end of the month the effective output per credit has not improved noticeably. There are usually three reasons.

    First, billing is multi-dimensional. Mainstream platforms typically split metering into input, output, and cache hits, and the unit prices for these three can differ by one or two orders of magnitude. Making decisions based on the input price alone almost inevitably leads to a wrong conclusion.

    Second, the input-to-output ratio of real workloads is highly uneven. Scenarios such as code comprehension, long-document question answering, and repository-level retrieval augmentation are often more than 80% input, while generative tasks are more output-heavy. The same model can cost several times more on one workload than on another.

    Third, caching reshapes the cost curve. When system prompts, tool definitions, and code context are carried repeatedly, the cached portion may be billed at only a small fraction of the normal input price, which significantly lowers the average cost of long-context scenarios.

    So a more reliable approach than “comparing unit prices” is this: use your own real call records to back out the credit consumption rate on your platform, then do capacity planning and routing design based on that.

    2. Method: Fitting the Credit Consumption Rate from Real Bills

    The core idea is to approximate the credits consumed by a single call as a linear combination of three token types:

    1. credits ≈ a * input_tokens
    2. + b * cached_tokens
    3. + c * output_tokens
    4. + d

    Here a, b, and c are the credit consumption rates per million tokens to be solved for, and d is a constant term (used to absorb the minimum billing unit, rounding errors, and so on). As long as you collect enough samples of “call volume + actual credits deducted,” you can solve for them with least squares.

    Collection tips:

    • Record the account credit balance once before and once after each call, and use the difference as the consumption for that call;
    • Also record the input, output, and cache-hit token counts (most platforms return usage fields in the response metadata);
    • Cover different task types to avoid an ill-conditioned matrix caused by homogeneous samples;
    • Use at least 20 samples, with a wide span of input lengths.

    Illustrative implementation:

    1. import numpy as np
    2. # rows: [input_M, cached_M, output_M, 1]
    3. X = np.array([
    4. [0.12, 0.00, 0.03, 1],
    5. [0.35, 0.20, 0.08, 1],
    6. # ... more real samples
    7. ], dtype=float)
    8. y = np.array([1.9, 6.4, ], dtype=float) # actual credits deducted
    9. coef, *_ = np.linalg.lstsq(X, y, rcond=None)
    10. a, b, c, d = coef
    11. pred = X @ coef
    12. r2 = 1 - ((y - pred) ** 2).sum() / ((y - y.mean()) ** 2).sum()
    13. print(a, b, c, d, r2)

    When the goodness of fit approaches 1 and the residuals are close to zero, the linear model is sufficient to explain the actual deductions, and the resulting coefficients can serve as the effective rate baseline for that account over that period. It is worth stressing that such results are reverse-engineered from personal measurements; they drift as platform rules, promotional credits, and concurrency policies change, so they should be recalibrated periodically and must not be treated as an official price list.

    3. Measurements: Cost Multiples Across Tiers

    Under a unified setup (60,000 credits per 5 hours, 600,000 credits per week, assuming 80% input and 20% output, with caching ignored for now), plug the coefficients above into the capacity formula:

    1. total tokens supported = budget credits / (0.8 * a + 0.2 * c)

    The measured relative relationships show a clear stepped distribution, which can be abstracted into four tiers:

    • Flagship tier: both input and output rates sit in the highest range, so the budget buys the fewest tokens;
    • Balanced tier: the input rate is roughly one third of the flagship tier, and the output rate roughly one quarter;
    • Fast tier: the input rate is more than an order of magnitude below the flagship tier, the output rate is likewise an order of magnitude lower, and the cache-hit rate is only a few percent of the normal input rate;
    • Lite tier: input and output rates are the same and sit in the lowest range.

    This yields two key multiples: the output cost of the flagship tier can reach on the order of a hundred times that of the lite tier; and for the fast tier, once a cache hit occurs, the input cost collapses to a tiny fraction of the normal input price. These two numbers are the economic foundation of the entire routing strategy.

    4. From Rates to Strategy: Task Tiering and Routing

    With the rate baseline in place, you can tier tasks along two dimensions: “reasoning depth required” and “call frequency”:

    Tier Typical tasks Model tier Target cost share
    Planning Requirement breakdown, solution design, final review Flagship Within 10%
    Reasoning Complex logic, hard defect localization Balanced Around 20%
    Execution Code generation, routine refactoring, test completion Fast Around 50%
    Batch Format conversion, summarization, classification and tagging Lite Within 20%

    Key points for routing implementation:

    1. Declare the task tier explicitly rather than relying on implicit defaults, to avoid high-cost models being called indiscriminately;
    2. Enforce budget circuit breakers at the gateway layer, setting credit caps and a degradation order per tier;
    3. Fix the system prompt, tool descriptions, and long-document prefixes in place to maximize cache hits;
    4. Log each routing decision and its actual consumption, and feed it back into the fitting script for continuous calibration.
    1. route(task):
    2. if task.type in {"plan", "review"}: return FLAGSHIP
    3. if task.complexity >= 3: return BALANCED
    4. if task.batch and task.simple: return LITE
    5. return FAST

    5. Three Easily Overlooked Cost Traps

    First, retry amplification. The cost of a single failed retry on a high-cost tier can exceed ten successful calls on a low-cost tier, so the flagship tier needs stricter timeouts and upfront validation.

    Second, context bloat. Untrimmed history in multi-turn conversations keeps being counted as input, and the average cost of a long session can multiply several times over. Consider rolling summaries and retrieval-based recall instead of concatenating everything.

    Third, cache invalidation. Volatile fields such as timestamps and random IDs embedded in prompt templates can cause the cache hit rate to plummet. Dynamic parts of a template should be placed at the end.

    6. Implementation Checklist

    • Establish a rate baseline: rerun the fit once a week and monitor coefficient drift;
    • Define tier budgets: set credit quotas and alert thresholds for each of the four tiers;
    • Fix prompt prefixes: put stable content first and dynamic content last;
    • Measure effective output: replace raw token throughput with “completed tasks per credit”;
    • Review routing regularly: include degradation and circuit-breaker events in the weekly review.

    In related practice at Baidu AI Cloud, this kind of approach is usually implemented alongside common capabilities such as monitoring and alerting, logging services, and message queues: usage data is collected through the logging service, metrics feed into the monitoring and alerting system, and routing and degradation are handled by asynchronous task orchestration on the queue side, turning cost governance into a sustainable engineering process without binding to a specific model.