LLM Cost Accounting and Tiered Routing: A Practical Guide

    Learn how to estimate LLM usage costs from request logs, distinguish tokens from credits, and translate usage models into quota budgets. This guide explains how to validate cost estimates, route tasks by quality requirements, and measure optimization by the cost per accepted result rather than the price of an individual call.

    1. Shift the Focus from Model Prices to Task Costs

    In AI-assisted coding, document processing, and automated workflows, different execution paths can consume very different amounts of resources while completing the same task.

    Model pricing is only one factor. Input context length, output volume, cache hits, tool-call rounds, and retries after failures all affect the final bill or credit deduction.

    Cost analysis should therefore go beyond asking which model is cheaper. Three questions are more useful:

    1. What components make up the consumption of a single call?
    2. How much useful work can the available quota support?
    3. Which execution path meets the quality requirements at the lowest cost?

    This guide develops a general method for answering those questions. It does not evaluate specific products or treat estimates derived from personal usage records as official billing rules.

    2. Distinguish Tokens, Credits, and Monetary Costs

    A token is a unit used by a model to process text. It is not equivalent to a character, a Chinese character, or a word. Different tokenization methods can produce different token counts for the same content.

    For accounting, use the metering data returned with a request or recorded in usage logs whenever possible, rather than estimating token counts from text length.

    Credits are quota units that some services use to manage resource consumption. Whether they have a fixed conversion to monetary costs depends on the applicable rules. A credit deduction for one call does not, by itself, establish its cash cost.

    It is also important to distinguish three types of limits:

    • Per-call limits: Context capacity or maximum output length.
    • Rate limits: Requests or tokens allowed per unit of time.
    • Quota limits: Credit allowances over short and long periods.

    Having sufficient quota does not guarantee that a request can run immediately. Concurrency limits, rate limits, and service availability may still create bottlenecks.

    3. Build an Explainable Model of Per-Call Consumption

    When uncached input, cached input, and output can be measured separately, a linear model is a useful starting point:

    1. C = a × U / 1,000,000
    2. + b × H / 1,000,000
    3. + c × O / 1,000,000
    4. + d

    Where:

    • C: Credits consumed by the call.
    • U: Uncached input tokens.
    • H: Cached input tokens.
    • O: Output tokens.
    • a: Credits per million uncached input tokens.
    • b: Credits per million cached input tokens.
    • c: Credits per million output tokens.
    • d: Any fixed consumption component.

    This is an accounting hypothesis to validate, not a universal billing rule. If a service uses tiered rates, minimum charges, segmented pricing, or additional consumption for specific modes, adjust the model rather than forcing every record into a linear formula.

    Pay particular attention to the definition of input fields. If “total input” already includes cached tokens, adding cached tokens again will double-count them. Typically, calculate:

    1. Uncached input = Total input − Cached input

    4. Estimate Consumption Coefficients from Usage Logs

    Collect Sufficiently Detailed Raw Data

    Keep the following information for each call:

    Field Purpose
    Request ID and timestamp Reconcile usage and track retries or rule changes
    Execution configuration ID Separate capability tiers or operating modes
    Input and output token counts Build the baseline consumption model
    Cached input token count Estimate the cached-input coefficient
    Actual credit change Provide the target value for fitting
    Request status Distinguish successful, failed, and canceled requests
    Retry and call-chain IDs Aggregate the cost of a complete task
    Metering rule version Avoid mixing records from different billing periods or rules

    If only account balance changes over a period are available, ensure that no unrelated calls run concurrently during sampling. Otherwise, the balance difference may include other tasks and distort the estimates.

    Use Samples with Meaningful Variation

    Collecting many similar requests does not necessarily produce reliable coefficients.

    For example, if every sample has nearly the same input-to-output ratio, it may be possible to estimate only a combined consumption rate, not separate input and output coefficients reliably.

    A better sample set includes:

    • Long inputs with short outputs.
    • Short inputs with long outputs.
    • Different cache-hit levels.
    • Different request sizes.
    • Repeated execution of the same content.

    This variation improves parameter identifiability. Nonnegative constraints can also help prevent fitted cost coefficients from taking negative values that lack a reasonable interpretation.

    A Perfect Fit Does Not Prove the Billing Rule

    An R² close to 1 and residuals close to zero indicate that the model matches the current samples closely. They do not establish that future calls will follow the same rule.

    Possible explanations include:

    • Too few samples.
    • Insufficient variation in input-to-output ratios.
    • Nearly as many parameters as samples.
    • Rounded credit records.
    • Additional consumption components that have not yet appeared in the data.

    In particular, when the number of samples equals the number of parameters to solve, zero residuals may simply reflect an exactly solved system of equations. That is not independent validation.

    Reserve some records as validation data and check whether the model accurately predicts requests excluded from fitting. In addition to R², examine absolute error, relative error, and how error changes with request size.

    5. Convert Consumption Coefficients into a Token Budget

    Let:

    • p be the input share of total tokens.
    • 1 − p be the output share.
    • h be the cache-hit share of input tokens.

    The average credit consumption per million total tokens is:

    1. r = p × [(1 − h) × a + h × b] + (1 − p) × c

    For a window quota of Q, assuming fixed consumption is negligible, the theoretical token capacity is:

    1. T = Q / r × 1,000,000

    The following hypothetical values illustrate the calculation. They do not represent any actual service:

    • Uncached input: 10,000 credits per million tokens.
    • Cached input: 1,000 credits per million tokens.
    • Output: 30,000 credits per million tokens.
    • Input share: 80%.
    • Window quota: 60,000 credits.

    Without caching:

    1. r = 0.8 × 10,000 + 0.2 × 30,000
    2. = 14,000

    The theoretical capacity is approximately 4.29 million tokens.

    If half of the input tokens are cache hits:

    1. r = 0.8 × [0.5 × 10,000 + 0.5 × 1,000]
    2. + 0.2 × 30,000
    3. = 10,400

    The theoretical capacity is approximately 5.77 million tokens.

    Caching reduces consumption for the relevant input portion; it does not reduce the entire call’s cost by the same proportion. As the output share increases, the overall benefit of input caching generally becomes smaller.

    These figures are capacity estimates only. Actual task capacity also depends on retries, fixed charges, remaining quota, and rate limits.

    6. Account for Both Short-Window and Long-Term Quotas

    If a service imposes both a short-window quota and a weekly quota, do not simply multiply the theoretical capacity of one short window by the number of windows in a week.

    Actual consumption must satisfy both constraints:

    • Consumption within the current short window must stay within its available balance.
    • Consumption within the current week must stay within the weekly balance.

    A generous short-window allowance combined with a tighter weekly allowance can cause sustained workloads to exhaust the weekly quota early. Conversely, a large weekly balance does not remove the short-window limit.

    Also confirm whether quota windows reset at fixed times or use rolling calculations. These mechanisms affect burst traffic and task queues differently and require different timing estimates.

    Keep a safety margin for retries, unexpectedly large outputs, and estimation errors. Set that margin according to historical variability rather than applying an arbitrary fixed percentage.

    7. Route Tasks by the Lowest Cost That Meets the Quality Threshold

    Cost control does not mean sending every task through the cheapest execution path. Nor does it mean starting every complex task at the highest capability tier.

    A more reliable principle is:

    Choose the execution path with the lowest expected total cost that can meet the task’s quality threshold.

    Tasks can be grouped into the following tiers.

    Planning and High-Risk Review

    For requirements decomposition, architectural decisions, security analysis, and final acceptance, prioritize correctness. The number of calls may be reduced, but decisions should not depend on per-call pricing alone.

    Complex Reasoning and Focused Problem-Solving

    For analysis involving multiple constraints, cross-file changes, and difficult troubleshooting, select an execution tier based on historical success rates.

    If a lower-cost path fails frequently, retries and escalation may eliminate its apparent price advantage.

    Routine Execution and Structured Processing

    For well-defined changes, information extraction, and normalization, start with a lower-cost path and use automated checks to determine whether escalation is necessary.

    Deterministic Tasks

    For format validation, field mapping, and fixed-template filling, prefer conventional code when it can complete the task reliably. Do not call a model merely to keep every step in the same workflow.

    8. Make Quality Checks Part of Routing

    Tiered routing requires explicit escalation conditions. Validation should be built into the workflow, not added only after problems appear.

    A general flow is:

    1. Task arrives
    2. → Assess risk and complexity
    3. → Select an initial execution path
    4. → Validate the result automatically
    5. → Deliver if validation passes
    6. → Otherwise retry, add information, or escalate
    7. → Send high-risk results for human review

    Match validation methods to the task:

    • Structured extraction: Check required fields, types, and allowed values.
    • Code changes: Check compilation, tests, and static rules.
    • Data conversion: Check count preservation, boundary conditions, and consistency.
    • Document generation: Check required sections, factual support, and citation completeness.

    Passing validation does not guarantee absolute correctness. It does, however, turn some quality judgments into repeatable checks, reducing unnecessary escalation and manual rework.

    Set a maximum retry count to prevent workflows from repeatedly consuming quota on failing paths.

    9. Optimize Caching, Context, and Output Together

    Caching benefits generally depend on input reuse, but exact cache-hit conditions must follow the service’s actual rules. Do not assume that any similar text can reuse cached input.

    General optimization strategies include:

    • Separate stable instructions from dynamic content.
    • Reduce meaningless variation in repeated context.
    • Remove history that is irrelevant to the current task.
    • Replace endlessly growing conversations with summaries and structured state.
    • Retrieve only the material needed for the current task.
    • Control output length according to delivery requirements.

    These strategies involve trade-offs. Excessive context compression can omit constraints and cause rework. Overly strict output limits can produce incomplete results.

    Compare consumption across the complete task, not just the tokens saved in one request. Do not include unnecessary sensitive information merely to improve cache-hit rates. Cost optimization must respect data isolation and access-control requirements.

    10. Measure Cost per Accepted Result

    The most meaningful metric is not the cheapest individual call. It is:

    1. Cost per accepted result
    2. = Consumption across all related calls
    3. / Number of results that pass the quality threshold

    “All related calls” includes initial execution, retries, escalation, and automated review. Enterprise accounting can also include human review time, queueing delays, and business losses caused by failures.

    Monitor:

    • Average consumption by task type.
    • First-attempt success rate.
    • Retry and escalation rates.
    • Cache-hit share.
    • Deviation between actual and predicted consumption.
    • Cost per accepted result and delivery time.

    If prediction errors keep increasing, check for changes in metering rules, execution configurations, log fields, or task distribution before deciding whether to refit the model.

    Conclusion

    Effective LLM cost management requires a complete feedback loop: raw logs, consumption models, quota forecasts, and task routing.

    Use verifiable data to separate input, output, and cached-input consumption. Validate fitted models against independent samples. Apply quality thresholds to tiered routing, and evaluate optimization by the cost per accepted result.

    High-capability and low-cost execution paths are not inherently opposed. The goal is to assign each type of work to the most suitable path, with a clear justification for every escalation, retry, and unit of quota consumed.