The Truth About Token Consumption: The Underlying Logic of Context Costs

    This article explains why token consumption in AI agent applications is driven mainly by repeatedly resubmitting context rather than by model output. It clarifies that a context window is a per-call limit, not a cumulative task total, and shows how costs grow close to quadratically as steps accumulate. It then covers why context is necessary for long-horizon tasks and outlines four cost-control levers: managing context growth, increasing information density, externalizing memory, and building usage observability, along with practical tips for teams.

    1. Where Tokens Actually Go: Not “Output,” but “Replay”

    When developers see their first bill, the intuition is usually the same: the model’s output is so short, so why is consumption so high? The answer is that in agent-style applications, the bulk of token usage is not the text the model generates. It is the context that has to be resubmitted with every single request.

    When an AI coding tool tackles a complex task, it rarely happens in one exchange. It is an execution chain made up of dozens or even hundreds of steps: reading files, searching code, running tests, fixing issues based on errors, and running verification again. No step is independent. Step N must carry all the information from the previous N-1 steps so the model knows “where we are now and what to do next.”

    This creates a critical amplification effect: the content from step 1 has already been resubmitted 199 times by step 200. Token consumption is not a linear sum. It grows roughly quadratically with the number of steps.

    Schematic view of the process:

    1. Call 1: system prompt + tool definitions + user's first message
    2. Call 2: system prompt + tool definitions + user's first message + round 1 output/thinking/tool call + tool result
    3. Call 3: all of the above + round 2 output/thinking/tool call + second tool result
    4. ...
    5. Call N: full history of the previous N-1 rounds + this round's additions

    In other words, the real cost of tokens is approximately number of steps × average context length. The more steps and the longer the history, the higher the cost per unit of output.

    2. Clearing Up a Common Misconception: A 1M Context Does Not Mean 1M Total Consumption

    The industry often interprets “supports a 1M context” as “a total of 1M tokens are used from the start of the task to the end.” This is wrong.

    The accurate understanding is that the context window describes the upper limit of tokens a single API call can carry. It constrains “how much each request can bring,” not “how much the entire task has used cumulatively.”

    From this, a simple estimation model follows: if the context in a task grows linearly from 0 to 1M, then the average per call is about 500K. A single tool call usually corresponds to two API round trips (one to request the model’s decision, one to feed the tool result back), so the actual consumption of a single tool action is about 1M tokens. It is normal for a single prompt to involve dozens of tool calls, and cumulative consumption reaching tens of millions or even hundreds of millions makes complete sense.

    This also explains why “longer context, stronger task” and “longer context, higher cost” are two sides of the same coin: memory capability is bought with repeated submission.

    3. Why This Cost Is Unavoidable: Memory Is a Prerequisite for Complex Tasks

    A single question-and-answer interaction only needs “this current sentence,” and a stateless model can handle it. But engineering tasks are essentially long-horizon decision-making: the model needs to remember constraints, remember the options already ruled out, remember the specific error from a failed test, and remember preferences the user added midway.

    Once you cut the history, the model degrades into something that can only perform a single action and cannot carry out multi-step reasoning or self-correction. So context is not redundancy; it is the necessary cost of wrapping a “stateless model” into a “stateful execution body.” The real question is not “do we need context,” but “does the context’s signal-to-noise ratio justify its price.”

    4. Four Levers for Cost Governance

    4.1 Control the Context Growth Curve

    Pushing quadratic growth back to near-linear yields the biggest payoff. Common practices include: summarizing and compressing early tool results, keeping only the fragments relevant to the current decision, and replacing large blocks of logs and file content with structured summaries or reference locations.

    4.2 Increase the Information Density of Each Request

    The system prompt and tool definitions are a fixed cost repaid every round and should be kept as lean as possible: merge tools with overlapping semantics, remove low-frequency tools, and turn lengthy descriptions into searchable, load-on-demand content.

    4.3 Replace “Unlimited Memory” with Engineering Means

    Externalize stable facts to the codebase, documentation, log services, and monitoring/alerting systems, and let the model retrieve them on demand instead of stuffing everything into the context. Retrieval augmentation and chunked reading are essentially trading “cheap storage and queries” for “expensive repeated submission.”

    4.4 Build an Observable Usage View

    Only by instrumenting and dashboarding call counts, average context length, and per-task token distribution can you pinpoint whether the problem is “too many steps” or “a single round that is too long.” Without measurement, optimization is just guesswork.

    5. Practical Advice for Teams

    • Set a step budget for tasks, and trigger context compression or task splitting when it is exceeded;
    • Break large tasks into small tasks that can be verified independently, avoiding a single overly long chain;
    • Keep tool return results minimally sufficient, avoiding feeding back entire files or whole blocks of logs;
    • At the prompt level, make it explicit to “output only what is necessary,” reducing invalid output that gets replayed repeatedly;
    • Use general-purpose cloud container platforms, object storage, and log/monitoring capabilities to carry retrieval and observability, leaving the context for the information that truly drives decisions.

    Conclusion

    Consumption reaching hundreds of millions of tokens is not mysterious: it is the inevitable result of long-horizon tasks trading repeated submission for memory capability. Understanding that “the context window is a per-call limit rather than a cumulative total,” combined with growth-curve control, information-density optimization, memory externalization, and usage observability, lets you reshape the cost structure of AI coding to be sustainable without sacrificing task quality.