Skip to main content
The OpenAI Agents SDK is OpenAI’s framework for building agentic workflows. Braintrust traces each agent run as a single trace, so you can inspect the whole workflow, including tool calls, guardrails, handoffs, and nested model calls.
Trace OpenAI Agents SDK runs from your TypeScript application.

Setup

Install the Braintrust and OpenAI Agents SDKs, then set your API keys.
1

Install packages

2

Set environment variables

.env

Auto-instrumentation

To trace OpenAI Agents SDK runs without modifying your application code, initialize Braintrust normally, then run your app with Braintrust’s import hook. The hook wires Braintrust’s trace processor into the OpenAI Agents SDK automatically, so you don’t need to install @braintrust/openai-agents or register a processor yourself. Requires @openai/agents v0.0.14 or later.
1

Initialize Braintrust and run an agent

2

Run with the import hook

The auto-instrumentation example uses plain JavaScript so node --import can run the file directly. The Braintrust APIs work the same in TypeScript projects — compile your TypeScript to JavaScript, then run the compiled file with the import hook.
If you’re using a bundler, see Trace LLM calls for plugin and loader setup.

Manual instrumentation

To instrument OpenAI Agents SDK runs manually, add Braintrust’s OpenAIAgentsTraceProcessor yourself.
If you omit logger, the processor uses the current Braintrust span, experiment, or logger when one is active.

What Braintrust traces

Braintrust captures:
  • Run spans (the root trace span, named after the workflow), with the run’s first input, final output, and trace group and metadata.
  • Agent spans (named after each agent), with the agent’s tools, handoffs, and output type.
  • Model spans (Generation and Response), with request input, response output, model and configuration details, token usage, and time to first token.
  • Tool call spans (named after the function), with the tool’s input and output.
  • Guardrail spans (named after the guardrail), with whether the guardrail triggered.
  • Handoff spans (Handoff), with the source and destination agents.
  • MCP tool-listing spans (MCP List Tools or List Tools (<server>)), with the server and the tools it exposes.
  • Speech and transcription spans (Speech and Transcription) for voice agents, with their input, output, and model configuration, plus speech group spans (Speech Group) with their input.
  • Custom spans (named by you), with any data you attach.
  • Token usage metrics on model spans (prompt, completion, and total tokens), including cached token counts when the model reports them.
  • Base64 image inputs and generated images as Braintrust attachments.
  • Errors on any span that fails.
  • Parent-child nesting when you run the agent inside an existing Braintrust span.
You can also use OpenAI Agents SDK tasks inside Braintrust experiments. For evaluation patterns, see Create experiments.

Resources