LLM Inference Cost Benchmarking and Tiered Scheduling in Practice

    This article breaks down how to reverse-engineer real LLM inference pricing from your own usage data, compares the cost gaps across model tiers, and shows how to build a tiered routing strategy that pairs expensive models with cheap ones. You will learn practical methods for cost modeling, cache and context management, observability, and common pitfalls to avoid when optimizing token spend.

    1. The Real Problem: Quota Anxiety Is a Cost Structure Problem

    When teams use large language models for coding, document processing, and AI Agent tasks, the most common complaint is not that “the model isn’t smart enough” — it’s that “we run out of quota too fast.” By the time the quota is exhausted, the root cause becomes clear: the calling structure is wrong. Sending every task to the most capable and most expensive model pushes the effective token throughput per unit of time to a very low level.

    Solving this requires two foundational insights.

    First, billing typically covers three dimensions: input tokens, output tokens, and cache-hit tokens. The per-unit prices across these three often differ by more than an order of magnitude. Output is the most expensive; cache hits are the cheapest.

    Second, in real workloads, input volume is usually far larger than output volume. For scenarios like code comprehension, long-document Q&A, and repository-level retrieval augmentation, the input-to-output ratio frequently reaches 4:1 or higher. This means the input unit price is often the dominant variable driving total cost, and the cache hit rate directly determines whether that portion of cost can be significantly amortized.

    2. Reverse-Engineering Cost: Fitting Unit Prices from Real Usage

    Rather than guessing at prices, derive them from actual usage data. The method is lightweight and takes only three steps.

    Step 1: Fix the quota window. Choose a statistical window (for example, a quota that refreshes every 5 hours, plus a quota that settles weekly) and record the start and end times of the window.

    Step 2: Collect samples. Within the window, make calls to a single model only. Record the input tokens, output tokens, and whether the cache was hit for each request, along with the total quota consumed when the window closes. Collect at least 5 samples of varying sizes, covering both short requests and long-context requests.

    Step 3: Run a linear regression. Use quota consumption as the dependent variable and input tokens and output tokens as the independent variables, then solve for the coefficients.

    A sample implementation:

    1. import numpy as np
    2. # Each row: [input tokens, output tokens, credits consumed]
    3. samples = np.array([
    4. [120_000, 8_000, 520],
    5. [260_000, 15_000, 1100],
    6. [80_000, 4_000, 340],
    7. [500_000, 30_000, 2150],
    8. ])
    9. X = samples[:, :2]
    10. y = samples[:, 2]
    11. # Solve least squares to get input/output unit costs
    12. coef, residual, rank, _ = np.linalg.lstsq(X, y, rcond=None)
    13. input_rate, output_rate = coef
    14. pred = X @ coef
    15. r2 = 1 - ((y - pred) ** 2).sum() / ((y - y.mean()) ** 2).sum()
    16. print(f"input rate/1M={input_rate*1e6:.0f}, output rate/1M={output_rate*1e6:.0f}, R2={r2:.4f}")

    When samples are collected properly and the statistical window has no cross-period interference, the goodness of fit can approach 1.0 with residuals near zero. This shows the cost model is linearly separable and that the reverse-engineered results are engineering-usable — you can rely on them for budgeting and scheduling decisions without depending on any official price list.

    Note: this method applies only to personal usage estimation. Rules and quota policies can change at any time, so the results should be recalculated periodically.

    3. Benchmark Results: Cost Multiples Across Model Tiers

    Under a unified basis (60,000 credits per 5 hours, 600,000 credits per week, assuming 80% input + 20% output, cache not yet counted), the total token capacity each tier can support varies dramatically:

    • Flagship tier: ~417,000 tokens / 5 hours; input ~80,000 / 1M, output ~400,000 / 1M;
    • Mid-high tier: ~1.25M tokens / 5 hours; input ~32,000 / 1M, output ~112,000 / 1M;
    • Fast tier: ~12.5M tokens / 5 hours; input ~4,000 / 1M, output ~8,000 / 1M, cache hit as low as 80 / 1M;
    • Lite tier: ~30M tokens / 5 hours; input and output both 2,000 / 1M.

    Two key multiples are worth remembering: the flagship tier’s output cost can be roughly 200x that of the lite tier; and with cache hits, the fast tier’s input cost drops to only about 2% of the normal input unit price. In other words, from the most expensive to the cheapest, the overall cost span reaches two orders of magnitude. This is not a minor adjustment — it’s an architectural-level difference. It means “which model to use” must be part of system design, not an ad-hoc choice.

    4. Tiered Scheduling: Expensive Models Think, Cheap Models Do

    Based on the cost structure above, you can establish a four-layer task division.

    1. Planning and final review layer (flagship tier): handles only low-frequency, high-value judgment such as requirement breakdown, solution design, code review, and risk identification. These tasks consume few tokens but have the greatest impact on result quality.
    2. Complex reasoning layer (mid-high tier): handles cross-file refactoring, difficult defect localization, algorithm derivation, and other tasks requiring strong reasoning.
    3. Main execution layer (fast tier): handles the vast majority of routine coding, unit test generation, comment completion, and log analysis — the primary source of throughput.
    4. Batch processing layer (lite tier): handles parallelizable repetitive work such as format conversion, batch summarization, keyword extraction, and simple classification.

    The routing logic can be expressed in pseudocode:

    1. def route(task):
    2. if task.type in ("plan", "review"):
    3. return "flagship"
    4. if task.complexity >= 0.7 or task.cross_file:
    5. return "mid_high"
    6. if task.batch and task.max_tokens < 2000:
    7. return "lite"
    8. return "fast"

    In practice, configure circuit breaking and fallback: when the flagship tier’s remaining quota drops below 20%, automatically defer non-critical review tasks to the next statistical window, preventing high-value tasks from being crowded out by routine ones.

    5. Cache and Context Governance: The Underrated Cost Lever

    Cache hits can push input costs extremely low, but the hit rate won’t improve on its own — it depends on how you organize context. Four practical points:

    • Stable prefix: place the system prompt, tool definitions, and project conventions at the very front and keep them byte-for-byte unchanged; put volatile content (timestamps, user input) at the end;
    • Segment reuse: split long documents into stable fragments and repeatedly reference the same fragment to reuse the cache;
    • Timely cleanup: trim outdated large tool outputs from conversation history early to avoid polluting the prefix;
    • Retrieval over full context: use vector retrieval to recall relevant fragments instead of stuffing the entire repository in every time.

    Illustration:

    1. [Stable prefix] System prompt + tool schema + coding conventions ← high reuse, cache hit
    2. [Semi-stable] Relevant file fragments (retrieved)
    3. [Volatile tail] Current user instruction + timestamp ← no hit, but small share

    6. Observability and Continuous Tuning

    No measurement, no optimization. Collect the model tier, input/output tokens, cache hit rate, task success rate, and latency for each call to build a cost dashboard. Review three metrics weekly: cost per unit of effective output, cache hit rate, and the call share of each tier. If the lite tier’s call share stays below 50% over the long term, the tiered strategy hasn’t truly been adopted.

    7. Common Pitfalls

    • Looking at unit price but not structure: when input share is high, the input unit price is the main driver;
    • Ignoring output cost: in long-form generation scenarios, the output side quickly becomes the bottleneck;
    • Blind faith in “the strongest model”: most routine tasks don’t need flagship capability — it’s pure waste;
    • Ignoring window differences: short-cycle and long-cycle quotas have different available amounts, so budgets must be calculated separately.

    In summary, the core of cost optimization is not driving down prices but aligning tasks with cost tiers: let expensive models focus on thinking, let cheap models handle scale, and use caching and prefix governance to amplify the effect. In related practice at Baidu AI Cloud, this “tiered scheduling + observable measurement” approach applies equally to general LLM application engineering and AI Agent platform scenarios.