LLM Inference Cost: Benchmarking Real Consumption and Building Tiered Scheduling
This article shows why per-token price lists often mislead when estimating LLM inference bills, and how to reverse-engineer actual consumption rates from real call logs. It walks through a cost formula, tier-by-tier consumption benchmarks, credit-to-token capacity conversion, a four-tier routing strategy, context and caching practices, observability metrics, and common budgeting mistakes. Readers will learn how to place each model tier where it is most cost-effective and scale useful output under a fixed quota.
1. Why “Cheap on Paper” Rarely Means Cheap in Practice
After integrating large language models into production systems, teams repeatedly run into the same puzzle: the listed unit prices differ by only a few multiples, yet the month-end bill differs by an order of magnitude. The reason is straightforward. Billing is a weighted combination of three dimensions: input, output, and cache hits. Real workloads vary enormously in token structure, context length distribution, retry rate, and cache reuse rate. Building a budget from the price table alone will almost certainly be wrong.
A more reliable approach is reverse engineering. Take a window of real call records, including input length, output length, and cache hit status for each request, and fit them against credit consumption over the same period to derive the effective consumption rate of each model tier. When the goodness of fit approaches 1 and the residuals approach 0, the model explains the bill well enough that these coefficients can be used directly for budgeting and scheduling decisions.
One caveat up front: these coefficients come from personal benchmarking and reverse engineering, not from an official price list, and the rules can change at any time. They should therefore be configuration values rather than hardcoded constants.
2. Cost Modeling: Turning the Bill into a Computable Formula
Let a be the input consumption rate, b the output consumption rate, and c the cache hit consumption rate (unit: credits per 1M tokens). The cost of a single request can be written as:
cost = (in_tokens * a + out_tokens * b + cache_tokens * c) / 1_000_000
In multi-turn conversations, cache-hit tokens usually come from reused system prompts, tool definitions, and prior context, so cache_tokens is often the largest share of the input.
Four tiers of consumption rates derived from benchmarking (order-of-magnitude illustration, used only to explain the method):
| Tier | Input | Output | Cache hit |
|---|---|---|---|
| Flagship | ~80K / 1M | ~400K / 1M | Not metered separately |
| Mid | ~32K / 1M | ~112K / 1M | Not metered separately |
| Mainstream | ~4K / 1M | ~8K / 1M | ~80 / 1M |
| Lite | ~2K / 1M | ~2K / 1M | Not metered separately |
Two conclusions deserve emphasis:
- Output on the flagship tier costs roughly 200 times more than on the lite tier. Asking a flagship model to write one more paragraph of explanation is an extremely expensive operation.
- With a cache hit, the mainstream tier costs only about 2% of its normal input cost. Caching is not an optimization; it is a primary variable in the cost structure.
3. Credit-to-Token Conversion: How Far the Same Quota Goes
Given a quota of 60K credits per 5 hours and 600K credits per week, assume input accounts for 80%, output for 20%, and ignore caching for now. The token capacity works out to:
- Flagship: ~417K tokens / 5 hours
- Mid: ~1.25M tokens
- Mainstream: ~12.5M tokens
- Lite: ~30M tokens
That is roughly a 72x spread from top to bottom. This number makes the point better than any price table: choosing a model is really choosing how much effective work a unit of quota can buy.
The conversion script can be simple:
def capacity(budget, a, b, in_ratio=0.8, out_ratio=0.2):# budget: credits; a/b: credits per million tokensblended = in_ratio * a + out_ratio * breturn budget / blended * 1_000_000
4. Tiered Scheduling: Expensive Models Think, Cheap Models Execute
Aligning cost coefficients with task difficulty yields a four-tier division of labor:
- Flagship: task decomposition, solution design, final code review. Few calls, high value per call.
- Mid: complex reasoning, hard defect localization, cross-module refactoring.
- Mainstream: everyday coding, test completion, documentation generation, carrying more than 70% of call volume.
- Lite: batch formatting, log categorization, simple classification and extraction.
The routing layer can start with rules and gradually move to a policy with feedback:
def route(task):if task.risk == "high" or task.needs_plan:return "tier_flagship"if task.difficulty >= 3:return "tier_mid"if task.batch and task.difficulty <= 1:return "tier_lite"return "tier_main"
Three engineering points matter. First, routing decisions must be observable: log the chosen tier and the reason for every call so that billing anomalies can be traced. Second, set a per-task credit cap and a circuit breaker to prevent the flagship tier from being called in a loop. Third, in the review stage, show the flagship tier only a summary plus the key diff, not the full repository context.
5. Caching and Context Governance
Since a cache hit can push input cost down to around 2%, how context is organized directly determines the bill:
- Stable prefixes: put system prompts, tool schemas, and coding standards first and keep them byte-stable. Any timestamp or random ID will break the cache.
- Incremental appends: in multi-turn conversations, only append new content and never rewrite history.
- Context compression: produce structured summaries of long histories and replace the original text with the summary.
- Batch merging: combine fragmented requests to reduce waste from repeated prefixes.
6. Observability and Capacity Planning
Collect four core metrics: average input/output length per task category, cache hit rate, credits consumed per task, and call share per tier. With these four data sets, you can rerun the fit weekly, update the consumption coefficients, and plan capacity accordingly. For example, if call volume is expected to grow 30% next week, project the required quota from the current cache hit rate and spot the bottleneck tier in advance.
7. Common Mistakes
- Budgeting from unit price alone while ignoring the input/output ratio.
- Ignoring caching, which leads to over- or under-estimating cost in long-context scenarios.
- Assigning batch tasks to the flagship model, which amplifies cost by orders of magnitude.
- Hardcoding coefficients in code, so everything breaks once the rules change.
- Looking only at averages and not the long tail: a few extremely long-context requests often account for most of the consumption.
8. Summary
The core of cost optimization is not pushing unit prices down but placing each model tier where it is most cost-effective: give thinking to the expensive tier, execution to the cheap tier, and repeated prefixes to the cache. Combined with coefficient fitting based on real records and continuous observability, you can reliably amplify effective output under a quota constraint. For a fuller engineering setup, the routing and observability pipeline can be built on general-purpose capabilities such as container platforms, logging services, and monitoring and alerting offered by Baidu AI Cloud.
