Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk5 min

I Traced My AI Coding Agent’s Calls: Where the Token Consumption Comes From

A multi-step coding agent can resend file contents, tool results, and history across several model requests. Here is how to trace those requests and read billed usage instead of JSON size.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A multi-step coding agent can make several model requests for one small edit, and each request can carry file contents, tool definitions, tool results, and earlier conversation back to the provider. A Reddit author who compared two workflows on the same small task reported three model calls and about 760 KB of exchanged JSON for one tool, against one call and about 100 KB for the other. Those payload sizes do not establish a matching ratio in billed tokens or dollars. The billed figures come from the provider’s usage records, and the way to find where tokens go is to read those records request by request.

What the Reddit comparison actually shows

The author, posting as cgouguen, described a simple PyQt task in a two-file project: changing card width to a third of the total width. The agent-style tool, Pi, made three model calls. In the first, the model requested both files. The harness returned their full contents. The model then made edits through several tool interactions and finished with a summary. The second tool, Aider, sent one preassembled prompt containing a repository map, the raw text of both files, formatting instructions, and the request. The model returned one answer in SEARCH/REPLACE blocks.

As an Amazon Associate I earn from qualifying purchases.

Workflow (author’s account) Model calls Exchanged JSON (self-reported)
Pi, agentic file discovery and edit loop 3 about 760 KB
Aider, single-shot prompt with known files 1 about 100 KB

These are one author’s observations on one task. The post does not include a provider invoice, a token export, a repeated or controlled benchmark, or a quality comparison. The author also says the task was unusually simple, and that the single-shot approach suits cases where the developer already knows which files to edit.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The author further reports that a personal API bill above $400 per month fell to under $100 per month after part of the workflow moved to single-shot edits. That is a personal before-and-after account. The post does not break down how much of the drop came from this change, and it should not be read as a expected result for other projects.

Where tokens come from in an agent run

An agent’s cost accumulates across every model request in a task, not only in the final answer you see. OpenAI’s usage documentation lists the input sources that can count: agent instructions, tool definitions, conversation history, user input, files or images, and tool results. Output counts the visible answer, tool-call arguments, and reasoning. OpenAI’s Observability and usage documentation states that reasoning tokens are billed as output tokens.

In the Pi sequence above, the chain looks like this:

  1. The prompt triggers file-read tools.
  2. File contents return as tool results.
  3. The model emits edit calls, and the harness returns confirmations.
  4. Another generation follows, and each generation carries its own request usage.

Tool execution itself is generally not a token charge from the model provider. But tool definitions and returned text can enter later model requests, and that is where the cost shows up. Other charges, such as sandbox, third-party tool, or observability fees, may also apply. OpenAI recommends counting root-agent and subagent work, retries, and applicable tool or sandbox costs when estimating the cost of a task.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Reading an agent trace

OpenAI’s tracing guide organizes a run into sessions and turns, then groups three kinds of spans:

  • Agent spans identify root or subagent work and show the usage recorded for that agent.
  • Generation spans contain the model inputs and outputs for each request.
  • Tool spans show each tool call and its result.

Session-level usage summaries can arrive late, can be unknown, and can change after a turn ends. A blank or null usage value means unknown, not zero. Recorded trace usage is also not necessarily the final bill, so check it against the provider’s usage dashboard or invoice before drawing cost conclusions.

The OpenAI Agents SDK tracks usage for each API request and adds those figures across a run. Persistent sessions can feed earlier messages back in as input on later runs. So per-run totals, per-request detail, and session-level context answer different questions. Name the boundary you are measuring before comparing two workflows.

Why JSON size is not billed tokens

The Reddit figures measure exchanged JSON bytes. Bytes include JSON syntax and representation details, while tokenization is specific to each model. Provider usage can also include generated content that never appears in the visible message, including some formatting and tool-call structure. Reasoning tokens can count toward output usage even though they are not shown as ordinary text. Two workflows with similar byte counts can therefore bill differently, and a large byte count does not by itself mean a large bill.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Prompt caching adds another distinction. Matching prompt prefixes can reuse cached input, but cache hits are not guaranteed. Eligibility, prefix matching, and cache lifetime rules all apply, and cached input is still billed at its applicable rate. OpenAI cautions that a high cached-input share does not prove lower total cost, because a long repeated history may still be processed on every request.

Anthropic’s pricing documentation reports the exact request usage in each response. It also treats tool definitions and returned tool results as additional consumption, and tool versions can carry different overhead. Accounting details from one provider should not be assumed for another. Check the model, provider, API surface, and tool version you are using.

How to measure a workflow properly

To compare two workflows, run the same task with the same model and the same quality check, then record each model request with the fields below. The list reflects documented trace and usage fields; not every provider exposes all of them.

Field Why it matters
Model identifier and price schedule Lets you convert usage into billed cost for that model.
Run, session, and turn IDs Separates one task from earlier context carried into later runs.
Agent or subagent, and step number Shows which agent triggered each request, so delegated work is not hidden.
Input tokens and cached input tokens Shows repeated context, and whether the cache was actually reused.
Output tokens and reasoning tokens, where exposed Shows generated answers, tool-call arguments, and reasoning billed as output.
Retries and tool results Explains repeated requests and content copied into later prompts.
Tool, sandbox, and observability charges Kept separate from model usage, since they bill differently.

Aggregate these into a whole-run total, including retries and delegated agents. Then compare the totals with the quality or task-success result. A cheaper run that fails the check is not a saving.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When a single-shot workflow makes sense

The Reddit author’s approach fits a narrow case. Consider it when:

  • You already know which files and locations need changing.
  • The change is small enough that one generation can reliably produce the edit.
  • You can check the result with a test or a quick review.

Keep an agent loop when the task requires discovering files, running checks, reacting to failures, or revising a plan. Exploration costs tokens, but it can prevent a wrong one-shot edit that costs more in retries and review. The trace is what tells you which side of that trade-off a given task falls on.

When you do keep stable instructions and tool definitions, you improve the chance of cache reuse. Confirm the reuse in the usage data rather than assuming it, and then compare total cost and quality. Caching lowers the applicable input rate on some requests; it does not make repeated input free.

Publish-ready summary of the trace: count the whole run, inspect each request, read the usage object and the invoice rather than serialized sizes, and judge any savings against output quality.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.