Token Billing Needs a Rework in the Agent Era
As AI agents move into large-scale production, a long-overlooked question is coming to the forefront: is the token still a unified billing unit? This article explains why total token count alone cannot determine cost, since input and output tokens are priced differently and agent loops inflate both. It then lays out a reproducible cost estimation framework covering input/output ratios, context caching, and separately billed items such as reasoning tokens, tool calls, and long-context surcharges, along with a sample Python script. Finally, it discusses four cost levers that work better than simply hunting for a cheaper API—model tier routing, context governance, caching and batching, and rate limits with budget guardrails—and argues that billing should evolve from flat total-volume pricing toward structure-aware pricing.
Introduction: When Tokens Shift from a Unit of Measurement to a Cost Variable
After agentic applications reached large-scale adoption, a previously overlooked question has been pushed to the center: is a token still a “unified” billing unit?
During budget planning, many teams run a simple calculation—roughly ten million tokens consumed per month, multiplied by a unit price, to arrive at a monthly spend. That estimate was reasonably accurate in the early days of single-turn question answering, but in today’s multi-step reasoning, tool-calling, and long-context replay scenarios, it is almost guaranteed to be off. The reason is not complicated: the same ten million tokens can produce bills that differ by several times depending on the input/output mix, cache hit rate, and model tier.
The goal of this article is not to provide a “standard quote,” but to build a reproducible estimation framework and, on that basis, discuss how billing should evolve for the agent era.
1. Why “Total Token Count” Cannot Determine Cost
1.1 Input and Output Are Two Different Products
Mainstream large model APIs generally split consumption into two categories:
- Input tokens: prompts, system instructions, conversation history, retrieved documents, tool return values, and so on;
- Output tokens: generated text, code, structured results, and so on.
The two usually carry different unit prices, and output is generally priced higher than input. This means the cost function is not “total volume × unit price” but a two-variable linear combination.
1.2 Three Scenarios with the Same Total but Different Structures
Assume a fixed monthly total of ten million tokens:
- Scenario A: 8 million input, 2 million output;
- Scenario B: 5 million input, 5 million output;
- Scenario C: 2 million input, 8 million output.
Under the common pricing where output costs more than input, the three costs increase in order, and Scenario C may be several times Scenario A. This explains a common puzzle: why two businesses with similar call volumes can receive wildly different bills.
1.3 Agent Scenarios Skew the Structure Further
Traditional Q&A applications typically have an output share of around 20%, while coding agents, long-form writing agents, and data analysis agents can exceed 50%. More importantly, the “loop” nature of agents amplifies input at the same time: after each round of tool calling, the conversation history must be resubmitted, so input tokens grow roughly linearly with the number of steps, or even faster. The result is a “double-high” input/output structure, with a cost curve noticeably steeper than that of ordinary applications.
2. A Reproducible Cost Estimation Model
2.1 The Basic Formula
When pricing is quoted per million tokens:
Monthly cost = input tokens / 1e6 × input unit price+ output tokens / 1e6 × output unit price
Plugging in the earlier example (8 million input, 2 million output):
Monthly cost = 8 × input unit price + 2 × output unit price
This formula applies to the vast majority of text models billed separately for input and output, and it is the first-principles formula for budget estimation.
2.2 Adjusting for Caching
Services with context caching typically split input into “cache hit” and “cache miss” segments. The cache read price is significantly lower than the regular input price, while cache writes may be billed separately. The adjusted form is:
Effective input cost = missed input volume × input unit price+ hit input volume × cache read unit price+ cached write volume × cache write unit price
For agents, stable prefixes such as system prompts, tool descriptions, and long-term memory are well suited to caching, and improving the hit rate often reduces the bill more than switching to a cheaper model.
2.3 Separately Billed Items That Are Easy to Miss
- Thinking/reasoning tokens: some models meter the internal reasoning process separately;
- Tool calls and retrieval: external search and structured queries may be billed per call or per volume;
- Long-context surcharges: the unit price rises beyond a certain window length;
- Batch asynchronous calls: usually discounted, but with higher latency.
If these are all folded into regular input and output during estimation, the error can reach a considerable proportion.
2.4 A Runnable Estimation Script Skeleton
def estimate_monthly_cost(inp, out, p_in, p_out,cache_hit=0, p_cache_read=0.0,cache_write=0, p_cache_write=0.0):miss = max(inp - cache_hit, 0)cost = miss / 1e6 * p_in + out / 1e6 * p_outcost += cache_hit / 1e6 * p_cache_readcost += cache_write / 1e6 * p_cache_writereturn round(cost, 2)# 8 million input, 2 million output, of which 6 million hit the cacheprint(estimate_monthly_cost(8_000_000, 2_000_000,3.0, 12.0,cache_hit=6_000_000,p_cache_read=0.3))
Treating unit prices, ratios, and hit rates as parameters rather than constants is what makes sensitivity analysis possible during design reviews: identify which two variables have the largest marginal impact on total cost, and invest optimization resources there.
3. Four Things That Work Better Than “Finding a Cheap API”
3.1 Model Tier Routing
Layer requests by difficulty: route intent recognition, format conversion, and summarization/classification to lightweight models; route complex reasoning, code generation, and long-form writing to flagship models. A common practice is to try a small model first and escalate when confidence is insufficient, so most traffic stays in the low-cost tier.
3.2 Context Governance
Input expansion is one of the main drivers of agent cost. Viable measures include rolling summaries of conversation history, reranking retrieved snippets and keeping only highly relevant passages, trimming tool return values, and fixing stable prefixes to reuse the cache. Halving the context roughly halves input cost.
3.3 Caching and Batching
Stable prefix caching, semantic caching (reusing prior answers for similar questions), and asynchronous batch discounts stack together to usually deliver a structural reduction without sacrificing answer quality.
3.4 Rate Limits and Budget Guardrails
Set token quotas and step limits per tenant and per session to prevent runaway consumption when an agent falls into a loop; pair this with monitoring and alerting to track cost per request over time, so abnormal fluctuations can be located immediately.
4. How Billing Should Change
From the buyer’s perspective, ideal billing should move from “single total-volume pricing” to “structure-aware pricing”:
- Finer dimensions: input, output, cache reads/writes, and reasoning tokens listed separately, with bills attributable to business functions;
- More transparent rules: cache hit rate and context length tiers publicly documented for precise modeling;
- Better-aligned incentives: discounts for cache reuse, batching, and off-peak calls to encourage users to optimize proactively;
- More controllable budgets: quotas, caps, and alerting that turn cost from “after-the-fact settlement” into “in-process constraint.”
In general engineering practice on platforms such as Baidu AI Cloud, these capabilities typically fall under common product categories like monitoring and alerting, logging services, and quota management. Combined with model tiering and caching strategies, they can form a complete cost governance loop.
Conclusion
Agents have turned token consumption from “linearly predictable” into “structure-driven.” Continuing to estimate cost by total token count will only lead to repeated misses during budget reviews. A more pragmatic path is to first build an estimation model that includes input/output ratios, caching, and separately billed items, then reduce unit cost through model tiering, context governance, cache reuse, and rate-limit guardrails. When billing rules and optimization levers are aligned with each other, a token truly becomes a manageable, optimizable engineering metric rather than a vague unit of measurement.
