Token Consumption in LLM Inference: Evaluation and Optimization Practices

    This article explains why LLM token consumption often exceeds expectations and how to control it without sacrificing output quality. It breaks down where tokens are spent, introduces a four-dimension measurement framework, and covers task tier routing, sub-agent scheduling, context engineering, observability, and cost guardrails. It also lists common misconceptions and outlines a practical optimization path for engineering teams.

    1. Why “Simple Tasks” Burn Through Quotas So Fast

    Many developers notice that quota drops far faster than expected when they try the highest inference tier of a new-generation LLM. A request that is not logically complex can consume about 1% of the progress indicator, roughly 2 to 3 times what the previous generation used. Switching to the highest reasoning mode makes the consumption curve even steeper. This is not a billing anomaly, but an inevitable result of the inference mode, context length, and scheduling strategy working together.

    This article does not evaluate or recommend any specific product. Instead, it abstracts the problem into a general engineering question: how to control the token cost of LLM calls without degrading quality.

    2. What Token Consumption Is Made Of

    To assess consumption, first break down where the tokens go. A typical call can be abstracted as:

    1. total consumption ≈ system prompt + tool definitions + conversation history + retrieved snippets + user input + model output + chain-of-thought intermediates

    Three items are easy to overlook:

    1. Fixed overhead from tools and system prompts: carried on every request, so the cost per turn grows as turns accumulate.
    2. Accumulated history context: in multi-turn sessions, early content is repeatedly counted as input.
    3. Intermediate computation at high inference tiers: deeper reasoning produces more intermediate tokens, and this does not scale linearly with task difficulty.

    3. Build a Quantifiable Evaluation Framework

    Use four dimensions to establish a baseline instead of judging “fast or slow” by feel:

    • Cost per task: total tokens consumed to complete one acceptance-ready task.
    • Effective token ratio: the share of adopted code or conclusions in the output relative to total consumption.
    • Retry amplification factor: actual consumption ÷ theoretical minimum consumption, measuring waste from rework.
    • Tier elasticity: the cost multiple of the same task across different inference tiers.

    Illustrative measurement script:

    1. def evaluate(task):
    2. base = run(task, tier="light")
    3. strong = run(task, tier="max")
    4. return {
    5. "cost_light": base.tokens,
    6. "cost_max": strong.tokens,
    7. "ratio": round(strong.tokens / max(base.tokens, 1), 2),
    8. "accepted_ratio": base.accepted_lines / max(base.output_lines, 1),
    9. "retry_factor": round(base.tokens / max(base.min_tokens, 1), 2),
    10. }

    When ratio stays above 2 for a long time and accepted_ratio is low, the tier does not match the task—it is not a model capability problem.

    4. Task Tiering: Reserve the Most Expensive Tier for the Hardest Problems

    A useful observation from the original discussion is that ordinary tasks are fully handled by a mid-tier model from the previous generation. Abstracted into a general principle, this is tiered routing:

    Task type Recommended tier Reason
    Format conversion, renaming, adding comments Lightweight Pattern-based, low reasoning payoff
    Routine business code, unit test completion Mid-tier Balance point of quality and cost
    Cross-module refactoring, tricky defect localization Highest Clear high-reasoning payoff

    In practice, routing rules can be declared explicitly in an AI coding tool, for example:

    1. policy:
    2. default: mid
    3. escalate_when: ["cross-file refactoring", "concurrency defects", "performance bottleneck localization"]
    4. degrade_when: ["comment generation", "copy rewriting", "configuration changes"]

    5. Sub-Agent Scheduling: Shift Unwanted Consumption to Lower Tiers

    The original text mentions handing unimportant tasks to sub-agents. The engineering formulation is a layered agent architecture: the main agent handles planning and acceptance, while sub-agents take on parallelizable fine-grained work such as retrieval, batch rewriting, and test case generation, with an explicitly assigned lower tier.

    1. Main agent (high tier): decompose tasks, define the plan, review results
    2. ├── Sub-agent A (lightweight): batch-generate test stubs
    3. ├── Sub-agent B (lightweight): organize logs and configuration
    4. └── Sub-agent C (mid-tier): local implementation and self-check

    This yields three benefits: the main context is not polluted by redundant information; parallelism reduces wall-clock time; and low-value work no longer consumes high-priced quota.

    6. Context Engineering: Long-Tail Content Is the Main Consumer

    “Long-tail content” refers to large, low-frequency files in the repository, historical logs, and stale documentation. The improvement idea is inject on demand rather than carry everything:

    1. Retrieve first, then inject only the snippets relevant to the current task;
    2. Create structured summaries of long files and let the summary enter the context instead of the original text;
    3. Proactively compress history mid-session, keeping conclusions and dropping the process;
    4. Write stable conventions into long-term memory or rule files to avoid repeating them every turn.
    1. before: context = full repository index + complete history (tens of thousands of tokens)
    2. after: context = rule summary + Top-K relevant snippets + conclusion summary (thousands of tokens)

    In industry practice, this kind of optimization typically brings a several-fold reduction in long-tail usage without losing output quality, because what is cut is content unrelated to the task.

    7. Usage Observability and Cost Guardrails

    No monitoring, no optimization. It is recommended to integrate general-purpose logging and monitoring/alerting capabilities and establish three categories of metrics:

    • Trend metrics: token consumption per unit time, average consumption per task;
    • Anomaly metrics: sudden spikes in the retry amplification factor, abnormal context length growth;
    • Guardrail mechanisms: per-session budget caps, automatic downgrade when exceeded, staggered execution of batch tasks.
    1. guardrails:
    2. session_budget: 200000
    3. on_exceed: downgrade_to_mid
    4. alert:
    5. retry_factor: "> 3.0"
    6. context_growth: "> 50% in 10 turns"

    8. Common Misconceptions

    1. Treating downgrade as quality degradation: most pattern-based tasks are insensitive to reasoning depth, so downgrading is nearly lossless.
    2. Looking only at unit price, not total task cost: rework and repeated context are often the main expense.
    3. Enabling the highest tier for the entire workflow at once: use the high tier in the planning phase and fall back in the execution phase.
    4. Ignoring fixed overhead: tool definitions and system prompts are billed repeatedly across multiple turns.

    9. Conclusion

    The essence of token consumption is a matching problem among task complexity, inference tier, and context strategy. A viable optimization path is: first establish a quantifiable baseline, then implement task tiering and sub-agent scheduling, then compress long-tail overhead through context trimming, and finally lock in the gains with monitoring, alerting, and budget guardrails. In general engineering practice on platforms such as Baidu AI Cloud, this approach can be deployed reliably with foundational capabilities like logging and monitoring/alerting, bringing the cost curve back under control without sacrificing delivery quality.