LLM agent costs are difficult to attribute because a user-visible task can trigger many separately billed model requests: an agent may call tools, retry, hand work to subagents, and generate again. Track usage on every model request, connect each request to its run and agent, and roll it up with a rule that counts each provider request once. Keep provider-reported billed usage distinct from estimates, delayed data, and unknowns.
Why one agent task can create many token charges
A person sees a task—such as “summarize these files”—as one unit of work. A model provider generally reports usage for individual requests. An agent may make several model calls to complete that task, so a task total must account for all of them, not just the final answer. OpenAI’s Agents API observability guidance describes this multi-call pattern and recommends summing usage across calls.
As an Amazon Associate I earn from qualifying purchases.
Each request can carry a different mix of input and output. Inputs may include the system instructions, tool definitions, conversation history, the user’s prompt, files or images, and tool results. Outputs may include a user-facing response or arguments for a tool call. For OpenAI, reasoning tokens are billed as output tokens, even when they are not visible in the final response.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →That means “tokens for the task” is not a single event waiting to be read. It is an accounting total assembled from the requests that made up the task. If instrumentation records only the last response, or only the root agent, it can miss work performed earlier or by delegated agents.
#1 Best Overall
Which boundaries should telemetry record?
Use a hierarchy that matches how work actually runs. A workflow or run represents the job the user initiated; agent invocations show who handled portions of it; generation records capture individual model requests; and tool spans represent client-side tool executions. OpenAI’s tracing guide describes sessions, turns, agent spans, generation spans, and tool spans. OpenTelemetry’s GenAI metrics conventions likewise distinguish agent invocation scope.
| Boundary | What it answers | What to associate with it |
|---|---|---|
| Workflow or run | What did this user-visible task consume? | A stable run ID, owner or feature where known, and links to its agent invocations and request records. |
| Agent invocation | Which root or delegated agent performed this portion of the work? | An agent identity, invocation ID, parent relationship, and its own request records. |
| Generation or model request | Which specific request used the tokens? | Provider and model identity, request or generation ID, usage fields, and the associated agent invocation. |
| Client-side tool call | What operation did the application execute between model requests? | Tool identity, outcome, duration, and the run or invocation that initiated it. |
Generate a run ID when the user-visible job begins and propagate it through root agents, delegated agents, model requests, and client-executed tools. Preserve parent-child relationships and handoff edges: they explain how work flowed without creating a second copy of its usage. OpenTelemetry advises application developers to instrument tool calls made by their own code and any calls automatic instrumentation misses; its span conventions also distinguish client-executed tools from provider-hosted tools.
Why run totals and nested agents are easy to miscount
A run total is useful for the bill of work, not for diagnosis
A framework’s run-level usage total is a convenient summary, but it cannot show which request created a large input or output footprint. The OpenAI Agents SDK aggregates usage across model calls in a run, including calls that produce tool calls or handoffs, and exposes per-request usage entries for detailed accounting. Retain those entries so an operator can trace an unexpected total back to the relevant request. See the SDK’s usage documentation.
Parent and child totals may not mean the same thing
OpenAI’s tracing guide says usage on an agent span covers that agent alone and excludes its subagents. The SDK, meanwhile, documents aggregation across model calls in a run. Those are different boundaries: do not assume that a span’s usage and a framework’s run total include the same work.
Rank #2
Choose and document one rollup rule: count each provider request once, then group its usage by request, agent invocation, run, and—where ownership is known—customer or feature. A parent’s already-aggregated total must not be added to child request or span usage if that total already includes those requests. Treat delegation as context linking work, not as a reason to duplicate its token usage. OpenTelemetry recommends invocation-scoped inference and tool-call counts so delegated agent activity belongs to the child invocation and is counted once across the tree.
Retries are additional work
Record retries as separate model requests and include them in the run’s accounting. A retry can consume tokens even when it produces no final answer, so omitting failed or repeated attempts understates the work. Keep an attempt or retry relationship that lets operators distinguish the original request from its follow-up without collapsing their usage into one untraceable number.
What usage fields should a request record preserve?
Capture request-level usage before any aggregation. At minimum, retain the provider and model identity, request or generation identifier, input tokens, output tokens, and total tokens when supplied. Preserve cache-read, cache-write, or reasoning-output details when the provider exposes them, along with the original provider usage payload where the adapter supports it.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitches- Provider-reported billed units: use these when available and when the provider distinguishes them from model-consumed token counts. OpenTelemetry’s span guidance says instrumentations should report billed counts in that case so the value matches the units charged to the customer.
- Normalized token totals: useful for consistent reporting across providers, but they may not retain every provider-specific billing detail.
- Raw provider usage: preserve it when supported, so later analysis can inspect details lost in normalization. The Agents SDK notes that raw usage preservation depends on provider-adapter support and does not create usage data a provider did not return.
- Usage provenance: label each value as reported by the provider, derived from provider fields, estimated, or unknown. Do not make those states look interchangeable in dashboards or exports.
Token counts are not necessarily a complete bill. Cached input is part of total input; cache-read and cache-creation fields, when present, describe subsets or categories rather than extra tokens to add blindly. Reasoning output is part of total output. OpenAI’s observability documentation notes that its Agents API usage fields do not separately expose cache-write counts, so those fields may not support an exact charge calculation when a pricing model bills cache writes separately. Follow the provider’s definitions and avoid summing a category with a total that already contains it.
Rank #3
Other charges may sit outside token usage. OpenAI’s observability guidance notes that applicable tool, sandbox-compute, third-party, cache, and retry costs can also matter. Attribute those as separate cost categories where relevant instead of labeling every charge “token spend.”
How should a system turn usage into cost?
Store usage first, then calculate estimated cost against a versioned provider-and-model price table. Keep the price-table version and calculation timestamp with the estimate so a later price change does not silently rewrite the assumptions behind an earlier report. Add provider-specific billable categories when they are documented, and retain the underlying usage that produced the estimate.
Do not label that estimate an invoice amount. Documented usage can omit billing categories, provider pricing dimensions can change, and the trace may not yet contain final usage. The reviewed OpenAI guidance explicitly warns that trace usage is best-effort rather than a final bill; its tracing documentation says usage can be null when unknown, can arrive after a turn ends, and may change as it becomes available.
For missing usage, use a state such as unknown or pending, not zero. Zero means a known absence of usage; an empty or delayed field means the system does not yet know. Preserve that distinction in run totals and cost reports instead of allowing missing records to make a task appear free.
How should traces and metrics work together?
Use traces to explain an individual run
A trace is the place to inspect causal structure: which agent handed work to another, which model request followed a tool result, and where a retry occurred. Use high-cardinality identifiers such as run, invocation, and request IDs in trace data so one task can be reconstructed without turning those identifiers into metric dimensions.
Use metrics to monitor aggregate behavior
Use metrics for trends such as inference-call counts, tool-call counts, failures, and duration. OpenTelemetry’s GenAI metrics conventions recommend invocation-scoped inference and tool-call measurements, include failed client-side operations, and assign delegated work to the subagent invocation so the tree is not counted twice. Its client-side tool-call metric does not cover tools executed by the provider, such as provider-hosted web search or code execution; state how those operations appear in your own accounting rather than silently treating the metric as complete coverage.
OpenTelemetry’s GenAI conventions are living documents. Check the current convention and its stability status before treating a particular attribute name as a universal requirement. The useful design principle is the boundary and counting rule; exact field names should fit the conventions and instrumentation version your system actually uses.
Recommended Free Tools
What can make telemetry incomplete or risky to collect?
Provider and adapter behavior varies
OpenAI’s SDK documentation warns that provider adapters differ: some require an explicit option to report usage, and normalized usage may omit provider-specific detail unless raw usage preservation is supported and enabled. Validate the deployed provider, model, streaming mode, framework, and adapter combination rather than assuming that a successful response includes complete usage.
Trace usage can be delayed or unavailable
Usage may not be present when a turn ends and may change as it becomes available. If using OpenAI trace export, the official guide requires organization trace export to be enabled and appropriate project API-key permissions. Treat exported trace usage as operational telemetry, not as a guaranteed final billing record.
Trace content needs data-handling rules
Traces may include prompts, tool arguments, and tool results, not just usage counts. Decide what your application may retain or export, who can access it, and what redaction and retention policies fit your data and security requirements. Usage observability does not require exposing sensitive task content to every person who can inspect cost dashboards.
A practical implementation sequence
- Define the accounting boundary. Decide what constitutes one user-visible workflow or run, how agent invocations are identified, and whether a framework’s run total includes delegated agents.
- Instrument each model request. Capture request identity, provider and model, usage fields, provenance, and raw provider usage when the adapter permits it. Validate usage reporting for the actual provider and execution mode.
- Propagate run and parent context. Attach the run ID to root and child agents, requests, and client-side tools; record delegation, handoff, and retry relationships.
- Retain raw events and define rollups. Publish totals at request, invocation, and run boundaries using a documented rule that counts each provider request once.
- Separate usage from estimated cost. Apply a versioned pricing table, record when the estimate was calculated, and keep non-token charges in distinct categories.
- Represent uncertainty explicitly. Distinguish provider-reported, derived, estimated, pending, and unknown usage; never substitute zero for missing data.
- Review coverage and access. Check failed calls, retries, provider-hosted tools, trace-export permissions, and controls for prompt and tool-result data.
A useful attribution system is therefore not just a token counter. It is a request-level ledger joined to an explicit workflow tree, with audited rollups and visible limits on what the usage data can establish.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Quick Recap
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.




