LLM Inference Cost Benchmarking and Tiered Scheduling in Practice

    This article shows how to build a measurable unit-cost model for large language model inference, convert credit budgets into token throughput, and apply tiered routing and caching strategies. It covers regression-based cost measurement, budget-to-token conversion, model tier responsibilities, a practical routing skeleton, cache optimization, and common cost pitfalls.

    1. Background: Why a Low Unit Price Doesn’t Mean a Low Total Bill

    In real-world AI application development, the most common question is not “which model is smarter,” but “why does the budget keep running out before we notice?” There are usually three reasons:

    1. Billing is not based on a single dimension. Mainstream LLM services typically price input tokens and output tokens separately, with output often costing several times more than input. Long-context scenarios can also introduce a separate cache-hit price tier.
    2. Usage patterns vary dramatically. Two workloads that each consume one million credits can complete a very different number of requests: a long-document summarization workload is input-heavy, while a code-generation workload is output-heavy, and the difference can be an order of magnitude.
    3. Redundant capability is often ignored. Many tasks—format conversion, field extraction, batch classification—do not need the strongest model, yet they are routed to the highest tier by default, creating pure waste.

    So the first step in cost governance is not to negotiate a lower price, but to build a measurable unit-cost model that turns a vague bill into a computable formula.

    2. Method: Deriving Unit Consumption Rates from Real Usage Records

    The approach is straightforward: let the business run naturally for a period, record the input tokens, output tokens, cache-hit tokens, and credit consumption change for each request, then run a multiple linear regression using least squares.

    Let credit consumption be C, and the input, output, and cache-hit token counts be x_in, x_out, and x_cache. The model can be written as:

    1. C = a * x_in + b * x_out + c * x_cache + d

    Here, a, b, and c are the unit consumption rates to solve for, and d is the intercept (theoretically close to 0). The closer the goodness of fit R² is to 1 and the smaller the residuals, the more reliable the derived result. An illustrative implementation:

    1. import numpy as np
    2. # rows: [input tokens, output tokens, cache-hit tokens, credit consumption]
    3. rows = np.array([
    4. [820000, 180000, 0, 120000],
    5. [610000, 240000, 50000, 98000],
    6. # ... more real samples
    7. ], dtype=float)
    8. X = np.column_stack([rows[:, :3], np.ones(len(rows))])
    9. y = rows[:, 3]
    10. coef, *_ = np.linalg.lstsq(X, y, rcond=None)
    11. a, b, c, d = coef
    12. pred = X @ coef
    13. r2 = 1 - ((y - pred) ** 2).sum() / ((y - y.mean()) ** 2).sum()
    14. print(f"input rate={a:.6f} output rate={b:.6f} cache rate={c:.6f} R2={r2:.4f}")

    A typical measurement produces the following relative magnitudes (in credits per million tokens, used only to illustrate order-of-magnitude relationships, not any official pricing):

    Model tier Input Output Cache hit
    Flagship inference ~80,000 ~400,000 Not priced separately
    Mid-tier general ~32,000 ~112,000 Not priced separately
    Lightweight execution ~4,000 ~8,000 ~80
    Minimal batch ~2,000 ~2,000 Same as input price

    Two key conclusions: the flagship tier’s output cost can be about 200 times that of the minimal tier; and for the lightweight tier, a cache hit reduces input cost to only about 2% of the normal input price. This means that for long-context repeated-prefix scenarios, whether the cache hits almost determines the cost magnitude.

    Note that the above is derived from personal measurement and will change with platform rules, model versions, and promotional strategies. In engineering practice, collection and fitting should be periodic tasks, not one-time conclusions.

    3. Budget Conversion: Translating a Credit Allowance into Processable Token Volume

    Let the periodic allowance be Q, the input share be p_in, and the output share be p_out (ignoring cache for now). The total processable token volume is approximately:

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

    With 60,000 credits per 5 hours and 600,000 credits per week, assuming 80% input and 20% output, the order-of-magnitude comparison is:

    • Flagship inference: ~417,000 tokens / 5 hours
    • Mid-tier general: ~1.25 million tokens
    • Lightweight execution: ~12.5 million tokens
    • Minimal batch: ~30 million tokens

    The same budget yields a throughput difference of nearly two orders of magnitude depending on the tier chosen. This is the mathematical justification for tiered scheduling.

    4. Tiered Scheduling: Let Expensive Models “Think” and Cheap Models “Do”

    The recommended division of responsibilities:

    • Flagship tier: task decomposition, solution design, final code and copy review;
    • Mid tier: complex logical reasoning, difficult defect localization, cross-module refactoring suggestions;
    • Lightweight tier: the main execution tier, handling most routine generation and rewriting;
    • Minimal tier: batch extraction, tagging, formatting, template filling.

    A practical routing skeleton:

    1. def route(task):
    2. if task.needs_arch_decision or task.is_final_review:
    3. return "flagship"
    4. if task.complexity >= 3 or task.cross_module:
    5. return "mid"
    6. if task.batch and task.max_tokens < 512:
    7. return "tiny"
    8. return "light"

    Three engineering constraints: first, the review stage must be closed-loop with a stronger model to avoid “downgrade means quality degradation”; second, set budget circuit breakers and alerts for each tier, with real-time observability based on logging and monitoring/alerting capabilities; third, incorporate the fitting script into the daily pipeline so coefficients are automatically recomputed after model version updates.

    5. Cost Engineering for Caching and Context

    The cache-hit price is usually far lower than the regular input price, so improving the hit rate is a high-value optimization:

    1. Stable prefix: place the system prompt, tool descriptions, and long documents at the very front of the request and keep them byte-for-byte unchanged; avoid timestamps and random IDs polluting the prefix.
    2. Fixed order: place dynamic content afterward, and never insert variable fields into the prefix.
    3. Session reuse: keep the same context carrier across multi-turn tasks to reduce repeated feeding.
    4. Trim context: inject only necessary fragments via retrieval, using vector search and object storage to hold the original material rather than concatenating everything.

    6. Common Pitfalls

    • Looking only at the input unit price while ignoring the output multiplier, causing severe overspending for generation-heavy workloads;
    • Running all tasks on the strongest model, letting redundant capability eat up the budget;
    • Fitting once and never updating, so coefficients become distorted after model iterations;
    • Ignoring failed retries—retry requests are billed too, so set limits and backoff strategies.

    7. Conclusion

    The essence of cost optimization is turning “model selection” from experience-based judgment into a computable decision: first measure the unit consumption rates, then convert the budget into throughput, and finally implement tiered routing and caching strategies. If you are already using Baidu AI Cloud’s model services, it is likewise recommended to fit based on your own real usage, forming a coefficient table and scheduling rules for your team, and to keep calibrating them as rules change.