MyRelay

← Back to the notebook

How a Coding Agent Spends Tokens

Start with one task and its complete transcript

A coding agent’s final answer might be three sentences, but producing it can require several model requests. The agent reads instructions, inspects source material, proposes changes, runs tools, and reacts to results. Each return to the model can add another charge.

To understand that spending, choose one finished task, such as fixing a failing test. Open its conversation or execution transcript alongside the available request usage records. The transcript explains what happened; the usage records show what was counted. Neither view tells the whole story alone.

Find the boundaries between model requests

Read from the beginning and identify each point where the agent asks the model what to do next. A typical sequence might include an initial inspection, a tool call, another model response, a test run, and a final explanation.

A tool action is not necessarily a model request. Reading source text or running a test can happen locally. However, when the result is sent back to the model, that text becomes part of a later request’s input. Several tool actions may be grouped into one round, depending on the agent.

Count the model requests rather than treating the entire task as one exchange. This gives you a useful map before you examine individual token totals.

Inspect what the first request already contains

The first input often includes more than your latest message. There may be system instructions, repository guidance, tool definitions, earlier conversation, and source material supplied automatically by the client.

If a small question starts with a surprisingly large input total, look for that background context. It is not automatically waste: project rules can prevent mistakes, and tool definitions enable useful actions. The practical question is whether the material helps this task.

A visible transcript may omit some of these components. Treat its text as evidence of the workflow, not as an exact reconstruction of every billed token.

Follow tool results as they enter the context

Next, locate the material returned by searches, source inspection, and tests. A broad search can produce hundreds of irrelevant matches. A failing test can return a long diagnostic report. When these results enter the next request, they increase input usage.

Look for moments when a narrow task triggered a broad read. Did the agent inspect an entire module to locate one function? Did it collect every test failure when one example would have been enough? These are opportunities to give tighter scope on the next attempt.

Do not remove useful evidence just to make the transcript shorter. A focused diagnostic result can save several rounds of guessing.

Notice how earlier context returns in later requests

Many agent workflows send accumulated conversation context again when asking the model for its next action. Suppose three requests report 8,000, 11,000, and 14,000 input tokens. Their combined input usage is 33,000 tokens, even though much of the content overlaps.

This does not mean every repeated token has the same price. Supported caching can make some repeated input cheaper, while context compaction can replace older material with a summary. Availability and accounting vary by provider and client.

Use reported usage and applicable rates, not transcript length alone, to estimate cost. Where cache categories are available, inspect them separately rather than assuming all repeated context was discounted.

Separate visible output from other reported usage

Model output includes more than the final explanation. Tool-call arguments, intermediate responses, and generated edits can also contribute. Some models additionally report reasoning-related usage that is not visible as ordinary transcript text.

Check how your provider defines each usage field before adding categories together. A reasoning total may already be included within another reported total. The request’s recorded cost is a useful cross-check against accidental double counting.

Turn one expensive run into a better next request

In MyRelay, compare each request’s tokens and cost with the corresponding transcript stage. Find the largest charge, then ask whether it came from broad context, repeated rounds, or substantial output. Create a MyRelay account if you want one personal budget and request-level visibility across supported models.

For your next task, change one thing: narrow the scope, request focused test output, or start a fresh conversation when old context is irrelevant. Compare the cost and the result. The aim is not the shortest transcript; it is a reliable solution without avoidable work.

More to read