This guide covers manual instrumentation. For quicker setup, use auto-instrumentation.
Setup
Install the Braintrust SDK and Pydantic AI:Trace Pydantic AI agents
Usesetup_pydantic_ai() to automatically instrument all Pydantic AI agents and direct API calls:
- Agent runs:
agent.run(),agent.run_sync(),agent.run_stream(), andagent.run_stream_sync() - Direct API calls:
model_request(),model_request_sync(), and streaming variants - Model interactions: Individual LLM calls made by agents
- Tool calls: Any tools defined on your agents
Example with tools and streaming
Using with existing spans
If you already have a Braintrust span context (e.g., from@traced or start_span), Pydantic AI traces will nest under it:
Alternative: OpenTelemetry integration
You can also use Braintrust’s OpenTelemetry support with Pydantic AI’s built-in instrumentation:pip install "braintrust[otel]". See the OpenTelemetry guide for more details.