---
source: https://iinventedlight.com/library/notes/openai-agents-tracing.md
title: "Trace OpenAI Agents SDK runs and read token usage"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (OpenAI Agents SDK); MIT (openai/openai-agents-python (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: OpenAI Agents SDK, Tracing; openai/openai-agents-python (GitHub), Usage. MIT; MIT."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-19
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-19
as_of: 2026-11-19
confidence: medium
untested: "Not reproduced (2026-11-19). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: agent-operations
topic_area: "agent operations: OpenAI Agents SDK tracing"
tags: [openai-agents, tracing, usage, observability]
client: Librarian
sources:
  - id: S1
    title: "Tracing"
    publisher: OpenAI Agents SDK
    url: https://openai.github.io/openai-agents-python/tracing/
    accessed: 2026-11-19
    license: "MIT"
  - id: S2
    title: "Usage"
    publisher: openai/openai-agents-python (GitHub)
    url: https://github.com/openai/openai-agents-python/blob/main/docs/usage.md
    accessed: 2026-11-19
    license: "MIT"
---
# 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

- [otel-genai-spans](https://iinventedlight.com/library/notes/otel-genai-spans/)
- [openai-agents-mcp](https://iinventedlight.com/library/notes/openai-agents-mcp/)
- [ao-evals-inspect-scorers](https://iinventedlight.com/library/notes/ao-evals-inspect-scorers/)

## Claims

- id: C1
  claim: The SDK collects a trace of events in an agent run, including generations and tool calls.
  source: S1
  evidence: "collecting a comprehensive record of events during an agent run"

- id: C2
  claim: Tracing is enabled by default and can be disabled with an environment variable or code.
  source: S1
  evidence: "Tracing is enabled by default"

- id: C3
  claim: After Runner.run, token usage is available on result.context_wrapper.usage.
  source: S2
  evidence: "access usage via `result.context_wrapper.usage`"

## Sources

- [S1] Tracing. OpenAI Agents SDK. https://openai.github.io/openai-agents-python/tracing/ . License: MIT. Accessed 2026-11-19.

- [S2] Usage. openai/openai-agents-python (GitHub). https://github.com/openai/openai-agents-python/blob/main/docs/usage.md . License: MIT. Accessed 2026-11-19.

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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
