← All notes

Trace OpenAI Agents SDK runs and read token usage

Answer: The OpenAI Agents SDK records a trace of an agent run, including model generations, tool calls, handoffs, and guardrails. It also aggregates token usage on the run context after Runner.run.

Built-in tracing

The Agents SDK ships tracing by default. A run records LLM generations, tool calls, handoffs, guardrails, and custom events. Using the Traces dashboard, you can debug, visualize, and monitor workflows during development and in production. Tracing is enabled by default. You can disable it by setting OPENAI_AGENTS_DISABLE_TRACING=1, calling set_tracing_disabled(True), or setting RunConfig.tracing_disabled to True for a single run. If an organization uses a Zero Data Retention policy with OpenAI's APIs, tracing is unavailable. Traces represent a single end-to-end operation of a workflow and are composed of Spans. A trace has workflow_name and trace_id. A trace_id is automatically generated if you don't pass one, and must have the format trace_<32_alphanumeric>.

Usage after a run

Token usage is tracked automatically on every run. Read it from the run context to enforce limits or record analytics. Tracked fields include requests, input_tokens, output_tokens, total_tokens, request_usage_entries, and details such as cached_tokens and reasoning_tokens. After Runner.run, access usage via result.context_wrapper.usage. Usage is aggregated across all model calls during the run, including calls that produce tool calls or handoffs.

| workflow_name | trace_id | |---|---| | workflow_name | name of the logical workflow or app | | trace_id | unique ID for the trace | | OPENAI_AGENTS_DISABLE_TRACING | env var that disables tracing | | set_tracing_disabled | disables tracing in code |

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: OpenAI Agents SDK, Tracing; openai/openai-agents-python (GitHub), Usage. MIT; MIT. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: OpenAI Agents SDK, Tracing; openai/openai-agents-python (GitHub), Usage. MIT; MIT.

Cite this

Permanent ID: iil:note:dvzmdxk2

iinventedlight. 2026. "Trace OpenAI Agents SDK runs and read token usage." iinventedlight Library, iil:note:dvzmdxk2, version of 2026-11-19. https://iinventedlight.com/library/notes/openai-agents-tracing/. License: CC-BY-4.0.

@misc{iil_note_dvzmdxk2,
  author = {{iinventedlight}},
  title = {{Trace OpenAI Agents SDK runs and read token usage}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-19},
  url = {https://iinventedlight.com/library/notes/openai-agents-tracing/},
  note = {Permanent ID iil:note:dvzmdxk2. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/openai-agents-tracing.md.