Tiered LLM Routing and Reverse-Engineering Token Costs from Usage Records

    This article shows how to infer token pricing from actual usage logs when a provider bills in credits or quotas. It fits a cost model that separates uncached input, cache-hit input, and output tokens, then uses that model to route tasks across planning, reasoning, execution, and batch models. It also covers caching, output control, and a monitoring loop with periodic refitting.

    In multi-model, multi-task agent and coding scenarios, cost control has moved beyond “pick a cheaper model” to “allocate model capability according to task value.” Many quota-based or credit-based billing plans do not expose the exact unit price of each model or each token type. This is especially true when input, output, cache hits, batch jobs, and periodic quotas are mixed together, so the bill looks like a single stream of credit consumption. Engineering teams need to infer the cost structure from actual call records, then design a tiered routing strategy on that basis, so that high-cost models do the thinking and low-cost models do the execution.

    1. Build a Computable Tiered Cost Model

    Token billing is usually not a single price. Each request should be split into at least three quantities: uncached input tokens, cache-hit input tokens, and output tokens. Let a be the uncached input price, b the cache-hit input price, and c the output price for a given model, all expressed in credits or quota units per million tokens. The expected consumption of one request can be written as:

    q = a × I_nonhit / 1e6 + b × I_hit / 1e6 + c × O / 1e6

    Here, I_nonhit is the uncached input volume, I_hit is the cache-hit input volume, and O is the output volume. If the provider also charges a fixed per-request fee, applies tiered discounts, or sets a minimum charge, you can add an intercept term d. The value of this model is that it breaks the billing black box into features that can be fitted. Input, cache, and output each get their own cost coefficient. Without the cache split, the only option is to treat total input as one feature. That easily mistakes a cache discount for a lower input price, which then distorts later budget estimates.

    Quota conversion also depends on the ratio of input to output, not just unit prices. Let p be the share of input tokens, 1-p the share of output tokens, and h the cache-hit rate. The average cost per million tokens is then approximately:

    C_avg = p × [(1-h) × a + h × b] + (1-p) × c

    Given a periodic quota Q, the total number of tokens it can support is roughly Q / C_avg × 1e6. This formula explains a common observation: with the same quota, a higher output share and a lower cache-hit rate mean fewer usable tokens. Conversely, stable prefixes, templated prompts, and structured outputs can noticeably change actual throughput. Treat the quota as a budget, tokens consumed as resource usage, and task success rate and retry count as hidden costs. All three should be accounted for together.

    2. Infer Unit Prices from Actual Records: Features, Fitting, and Validation

    The first step is instrumentation. Each call should record at minimum: task type, model alias, uncached input tokens, cache-hit tokens, output tokens, actual credits consumed, whether the call was a retry, latency, and success status. Do not bind model aliases directly to specific product names. Use internal codenames such as “Planning Model A,” “Reasoning Model B,” “Execution Model C,” or “Batch Model D.” This makes governance and replacement easier.

    When fitting, turn each record into a feature vector x = [I_nonhit, I_hit, O, 1], with the target y set to the actual credits consumed. Solve for the coefficients [a, b, c, d] by least squares. The pseudocode is as follows:

    1. records = [
    2. {non_hit_in, hit_in, out, quota_used},
    3. ...
    4. ]
    5. X = [[r.non_hit_in, r.hit_in, r.out, 1] for r in records]
    6. y = [r.quota_used for r in records]
    7. coef = least_squares(X, y)
    8. a, b, c, d = coef
    9. for r in records:
    10. pred = a*r.non_hit_in + b*r.hit_in + c*r.out + d
    11. residual = r.quota_used - pred

    After fitting, check the goodness of fit and the residual distribution. If R² is close to 1 and residuals are close to zero, the billing structure largely matches the feature assumptions. If residuals form clear layers, the billing may include tiered pricing, differences by task type, or cache rules that were not fully separated. In that case, fit separately by task type, model alias, and time window so that different rules are not mixed in one model. Also watch sample coverage. When boundary samples are scarce, such as very high output, very high cache-hit rates, or very low input, extrapolating the coefficients is unreliable. Keep a period of real call records for backtesting, and use the deviation rate between predicted and actual consumption as the acceptance metric.

    The reverse-engineered result is an empirical approximation under the current rules. It is not an official price list. Rules can change, and cache policies can be adjusted, so store fitted parameters with version information and refit them on a regular schedule.

    3. Tiered Routing: High-Cost Models Think, Low-Cost Models Execute

    Once the cost coefficients are available, routing decisions have a quantitative basis. A common design uses four tiers: planning and final review, complex reasoning, primary execution, and bulk simple tasks.

    • Planning and final review: High-cost models. These tasks affect overall correctness, and retries are expensive.
    • Complex reasoning: Mid-cost models for multi-step analysis and the hard parts of code review.
    • Primary execution: Low-cost models for most file edits, information extraction, format conversion, and routine Q&A.
    • Bulk simple tasks: Very low-cost models for high-frequency, low-difficulty work such as classification, tagging, summarization, and template filling.

    Routing should not depend on model price alone. It should also account for task risk, context length, output length limits, and quality thresholds. The pseudocode is as follows:

    1. function route(task):
    2. if task.requires_global_planning or task.risk == "high":
    3. return "Planning Model A"
    4. if task.complexity == "high" and task.budget_ok:
    5. return "Reasoning Model B"
    6. if task.is_batch and task.acceptable_quality <= "standard":
    7. return "Batch Model D"
    8. return "Execution Model C"
    9. function call_with_fallback(task):
    10. model = route(task)
    11. result = call(model, task)
    12. if not quality_gate(result) and model != "Planning Model A":
    13. return call("Planning Model A", task)
    14. return result

    Define fallback rules in advance. When periodic budget consumption exceeds a threshold, downgrade non-critical tasks from high-cost tiers to the execution or batch tier. Critical tasks keep the review tier, but their context is compressed, their output length is limited, and they must return structured results. Set quality thresholds from offline evaluation sets and small-traffic online evaluation, not from intuition. Otherwise, “cheap models do the execution” can turn into “cheap models make repeated mistakes, and retries cost more.”

    4. Caching, Output Control, and a Monitoring Loop

    Caching is an important way to reduce input cost, but it only works on stable prefixes. Put the system prompt, tool descriptions, and fixed knowledge snippets in the stable prefix, and place variables toward the end. Templated prompts and structured outputs also reduce wasted tokens. If output prices are significantly higher than input prices, shift the main optimization to output length control. Set maximum output tokens, ask for bullet points or tables, avoid verbose explanations, and use short fields in batch tasks. After the cache-hit rate improves, recalculate average cost with the fitted model rather than estimating from the original prices.

    The monitoring loop should track at least four metrics: cost per task, average cost per million tokens, cache-hit rate, and quality pass rate with retry rate. Set budget alerts per task type, so that high-value tasks are not crowded out by low-value batch jobs. Redact logs, make sampling reproducible, and keep fitted parameters traceable. Periodically rerun the fit on new records and compare coefficient changes. If the cost of a task type rises abnormally, check in order: input inflation, cache invalidation, runaway output, and increased retries.

    Conclusion

    Reverse-engineering token costs is not a minor finance tool. It is infrastructure for model routing architecture. By splitting input, cache, and output into features that can be fitted, and then using the quota conversion formula to estimate throughput, a team can turn “which model is cheap” into “which tier of model each type of task should use.” The goal is not the lowest unit price. The goal is the lowest cost per task within the quality threshold. High-cost models handle planning and review, low-cost models handle primary execution and batch work, caching and output control reduce peaks, and monitoring with periodic refitting keeps the cost model accurate.