Measuring LLM Token Costs and Tiered Scheduling in Practice

    This article shows how to reverse-engineer per-token consumption rates for different LLM tiers from real billing records, convert a credit budget into token capacity, and use tiered routing to control cost. It covers least-squares fitting of input, output, and cache-hit coefficients, measured cost gradients across four model tiers, capacity estimation formulas, a rule-based routing example, and further optimizations such as prefix caching, context compression, batching, and observability. Readers will learn a reproducible way to quantify token cost and lower overall spend without sacrificing quality.

    1. Why Token Cost Must Be Quantified

    As AI agents and AI coding tools move into large-scale production use, the token consumption of a single request is no longer a negligible linear fraction. It has become a hard constraint that determines whether a project can run sustainably. Many teams are not sensitive to this during the prototype stage. Once they enter scenarios with continuous calls, long contexts, and multi-turn tool invocation, the bill grows quickly, and the cost gap between different models often reaches one to two orders of magnitude.

    The real difficulty is not whether it is “expensive,” but the lack of a reproducible conversion method. Most platforms only show the deduction result in credits or quota, and do not directly expose the conversion factor per token. A more reliable engineering approach is therefore to run a regression fit on your own real call records, back out the unit consumption rate for each model tier, and then use that for capacity planning and routing design.

    2. Method: Backing Out Unit Consumption Rates from Real Records

    The core idea is to treat credit consumption as a linear combination of input tokens, output tokens (and cache-hit tokens), and to run a least-squares fit over multiple samples to obtain the coefficients for each model tier.

    Illustrative modeling code:

    1. # Each sample: (input tokens, output tokens, cache-hit tokens, credits actually deducted)
    2. samples = [
    3. (120000, 8000, 0, 96800),
    4. (80000, 12000, 50000, 70400),
    5. # ... more real call records
    6. ]
    7. def fit_rate(samples):
    8. # Build a matrix with the three feature types (input / output / cache),
    9. # and solve credits = Σ(coefficient * feature)
    10. # In practice, use numpy.linalg.lstsq or any least-squares implementation
    11. pass
    12. # Output: input coefficient, output coefficient, cache-hit coefficient

    Fit quality is measured with the coefficient of determination and the residuals. When the samples cover different input/output ratios and include cache-hit scenarios, the goodness of fit can ideally approach 1 and the residuals approach zero, indicating that the model form matches the actual billing logic. Note that such results are personal measurements and reverse-engineered estimates, not an official price list. The rules may change with version updates, so the fitting script should be rerun periodically to recalibrate.

    3. Measured Results: The Cost Gradient Across Model Tiers

    Under the credit system of a certain cloud vendor’s token package, fitting four model tiers (flagship reasoning, strong reasoning, fast, and lite) yields the following order-of-magnitude relationships:

    • Flagship reasoning: about 80,000 credits per million input tokens, about 400,000 credits per million output tokens;
    • Strong reasoning: about 32,000 credits per million input tokens, about 112,000 credits per million output tokens;
    • Fast: about 4,000 credits per million input tokens, about 8,000 credits per million output tokens;
    • Lite: about 2,000 credits per million tokens for both input and output.

    Two key conclusions: first, the output unit price of the flagship tier is about 200 times that of the lite tier, so the output side is the cost amplifier; second, on a cache hit, the fast tier’s input cost can drop to about 2% of the normal input unit price, which sharply reduces the marginal cost of scenarios with a repeated long-context prefix.

    4. Capacity Conversion: How Many Tokens a Credit Budget Supports

    With a quota of 60,000 credits per 5 hours and 600,000 credits per week, assuming input accounts for 80%, output for 20%, and ignoring cache for now, the total tokens each tier can support can be estimated:

    • Flagship reasoning: about 417,000 tokens per 5 hours;
    • Strong reasoning: about 1.25 million tokens per 5 hours;
    • Fast: about 12.5 million tokens per 5 hours;
    • Lite: about 30 million tokens per 5 hours.

    The conversion formula is: supported tokens = budget credits / (0.8 * input unit price + 0.2 * output unit price) (unit prices are converted to a common scale per million tokens). The value of this formula is that simply changing the assumed input/output ratio lets you quickly assess endurance under different workload shapes. If the output share rises from 20% to 50%, the flagship tier’s endurance shrinks further, which is the main reason costs spiral out of control for long-form generation tasks.

    5. Tiered Scheduling: Let Expensive Models Think and Cheap Models Execute

    Based on the cost gradient, tasks can be graded by “reasoning depth” and mapped to different model tiers:

    1. Planning and final review: requires global consistency and handling of boundary conditions, assigned to the flagship tier;
    2. Complex reasoning and difficult root-cause analysis: assigned to the strong reasoning tier;
    3. Main execution (code generation, routine rewriting, structured extraction): assigned to the fast tier;
    4. Batch simple tasks (classification, formatting, summarization, tagging): assigned to the lite tier.

    The routing layer can be implemented with rules or a lightweight classifier, as shown below:

    1. def route(task):
    2. if task.needs_global_review or task.risk == "high":
    3. return "flagship"
    4. if task.reasoning_depth >= 3:
    5. return "strong"
    6. if task.batch and task.prompt_tokens < 4000:
    7. return "lite"
    8. return "fast"

    In practice, it is advisable to log the tier, token composition, and actual deduction for each call, forming a replayable billing attribution chain that makes it easy to continuously adjust routing thresholds.

    6. Further Optimization: Caching, Context Governance, and Observability

    • Prefix caching: place stable system prompts, specification documents, and examples at the front of the context to maximize cache hits and push repeated input cost down to a very low level;
    • Context compression: summarize and trim conversation history to avoid linear growth;
    • Batching: merge simple tasks into combined requests to amortize fixed overhead;
    • Observability: combine logging services with monitoring and alerting to build dashboards and threshold alerts for token consumption, cache hit rate, and per-task cost;
    • Elastic capacity: when concurrent fetching or asynchronous processing is needed, use container platforms and message queues to smooth peaks and avoid paying for peak capacity all the time.

    In related practice at Baidu AI Cloud, the same approach is recommended: combine general-purpose capabilities with self-built cost attribution. Use object storage to accumulate call samples, use the logging and monitoring system to visualize cost, and then continuously adjust the model routing strategy based on the data.

    7. Conclusion

    The essence of the cost difference is “pricing by reasoning depth.” Treat the budget as a finite resource, quantify it with the fitted unit consumption rates, and then use tiered scheduling to concentrate high-value thinking in a few high-unit-price tiers while pushing massive execution down to low-unit-price tiers. Combined with caching and context governance, this can reduce overall cost by an order of magnitude while keeping quality essentially unchanged. Remember that all coefficients must be recalibrated periodically with your own data, and a single measurement should never be treated as a long-term fixed pricing basis.