LLM Inference Cost: Benchmarking Real Consumption Rates and Tiered Scheduling

    This article shows how to turn raw LLM API logs into a quantitative cost model by fitting input and output token consumption rates with linear regression, then uses that model to compare four model tiers, convert credit quotas into usable tokens, and route tasks across tiers. It covers the sampling and validation details needed for a stable fit, the output premium and cache-hit leverage that dominate real bills, a minimal routing layer with budget guardrails, and common pitfalls such as cache invalidation and over-downgrading.

    1. Why Pay-as-You-Go Bills Are Hard to Predict

    When teams use LLMs for coding, document generation, or batch data processing, the recurring question is rarely “can we do this?” It is “how much quota is left after this round?” Vendors publish unit prices, but real bills also include cache-hit discounts, context-length tiers, batch pricing, and the cost of failed retries. As a result, the same prompt can deduct noticeably different amounts at different times.

    A more engineering-driven approach is to ignore the advertised unit price and instead work backward from your own call logs to derive the actual credits deducted per million tokens, then build a cost model on top of that. This article follows that approach but frames the topic as a general technical problem: the cost profile of multi-tier LLMs and tiered scheduling. No specific vendor or product is involved.

    2. Method: Fitting Consumption Rates from Real Records

    The core idea is to treat credits deducted as the dependent variable and input/output token counts as the independent variables, then run a linear regression.

    Let cost be the credits deducted for a call, in_tok the input tokens, and out_tok the output tokens:

    1. cost = a * (in_tok / 1e6) + b * (out_tok / 1e6) + c

    Here a is the input consumption rate per million tokens, b is the output rate, and c is a constant term (usually close to 0, representing fixed overhead). With enough samples that vary widely in their input-to-output ratio, a and b can be solved.

    A sketch of the implementation:

    1. import numpy as np
    2. # rows: [input_tokens, output_tokens, deducted_credits]
    3. rows = np.array([
    4. [820_000, 41_000, 82.1],
    5. [120_000, 90_000, 36.6],
    6. [50_000, 8_000, 3.6],
    7. # ... more samples
    8. ], dtype=float)
    9. X = rows[:, :2] / 1e6
    10. y = rows[:, 2]
    11. # Least squares solve for a, b, c
    12. coef, *_ = np.linalg.lstsq(np.c_[X, np.ones(len(X))], y, rcond=None)
    13. a, b, c = coef
    14. pred = np.c_[X, np.ones(len(X))] @ coef
    15. r2 = 1 - ((y - pred) ** 2).sum() / ((y - y.mean()) ** 2).sum()
    16. print(f"input={a:.0f}/1M, output={b:.0f}/1M, const={c:.3f}, R2={r2:.4f}")

    Key details in practice:

    • Samples must cover different input/output ratios; otherwise a and b become highly collinear and the solution is unstable.
    • Exclude calls that produced no valid output, such as rate-limit failures or content-moderation blocks.
    • If the platform rounds up per request, the constant term will be larger and needs to be identified separately.
    • After fitting, run a hold-out validation on samples that were not used in the fit and check whether residuals are near zero.

    When residuals are small enough and the coefficient of determination approaches 1, billing is approximately linear and the model is safe to use for capacity planning.

    3. Cost Profile: Order-of-Magnitude Differences Across Four Tiers

    Based on the fit above, models on the market can be roughly grouped into four cost tiers (values are order-of-magnitude illustrations, not official pricing):

    Tier Input rate Output rate Cached input
    Flagship reasoning ~80K / 1M ~400K / 1M A small fraction of the original input price
    Strong reasoning ~32K / 1M ~112K / 1M Discounted
    General execution ~4K / 1M ~8K / 1M As low as ~2% of the original input price
    Lightweight ~2K / 1M ~2K / 1M Limited discount

    Two conclusions are worth emphasizing:

    1. Output costs more than input, and the higher the tier, the more extreme the output premium. Output cost between the flagship and lightweight tiers can differ by two orders of magnitude.
    2. Cache hits are the biggest lever for the general execution tier. When the input side drops to a few percent of the original price, repeated prefixes in long contexts become almost free, which is decisive for codebase Q&A and long-document continuation.

    4. Quota Conversion: Turning Credits into Usable Tokens

    Let Q be the quota in credits for a period, p_in the input share, and p_out = 1 - p_in the output share. Usable total tokens are roughly:

    1. tokens ≈ Q / (p_in * a + p_out * b) * 1e6

    With p_in = 0.8, p_out = 0.2, and a weekly quota of 600K credits, the magnitudes are approximately:

    • Flagship reasoning: ~410K tokens / week
    • Strong reasoning: ~1.25M tokens / week
    • General execution: ~12.5M tokens / week
    • Lightweight: ~30M tokens / week

    In other words, for the same quota, tier selection can change effective capacity by tens of times. This is also why “always use the strongest model” is usually not a viable engineering strategy.

    5. Tiered Scheduling: Let Expensive Models Think, Cheap Models Work

    Layering tasks by “reasoning density” is the main line of cost optimization.

    • Flagship: task decomposition, solution design, final code review and risk assessment.
    • Strong reasoning: complex logical reasoning, hard defect localization, cross-module refactoring suggestions.
    • General execution: main coding work, unit test completion, log analysis, routine Q&A.
    • Lightweight: batch summarization, format conversion, field extraction, classification and tagging.

    A minimal, deployable routing layer:

    1. def route(task):
    2. if task.risk == "high" or task.needs_plan:
    3. return "flagship"
    4. if task.complexity >= 3:
    5. return "strong"
    6. if task.batch and task.complexity <= 1:
    7. return "lite"
    8. return "general"

    Three things are needed alongside it: first, log the tier, token counts, and credits deducted for every call to create a data source that keeps the fit current; second, set budget guardrails with dual thresholds per task and per day, downgrading automatically when exceeded; third, fix the cached prefix (put the system prompt, coding standards, and repository index notes first and keep them stable) to maximize cache-hit gains.

    6. Common Pitfalls and Boundaries

    • Looking only at unit price and ignoring the output premium severely underestimates the cost of long-output scenarios.
    • Ignoring cache invalidation: once a timestamp or random ID is inserted into the prefix, the hit rate collapses.
    • Over-downgrading: sending tasks that need long-chain reasoning to the lightweight tier often costs more in rework than the credits saved.
    • Treating the fit as official rules: billing policies, context tiers, and promotions can all change, so the model needs periodic re-fitting — validate residuals weekly or once per quota cycle.

    7. Summary

    Cost control is not about finding the cheapest model, but about building a quantifiable cost profile and using a scheduling policy to match tasks to the right tier. Fitting consumption rates, converting quotas, fixing the cache prefix, and adding budget guardrails form a reusable engineering method. In general engineering practice on platforms such as Baidu AI Cloud, pairing this with monitoring, alerting, and log services to continuously observe call structure can keep quota efficiency within a predictable range.