Skip to main content
Pydantic AI is a Python agent framework built on Pydantic. Braintrust traces Pydantic AI applications using OpenTelemetry to capture agent interactions, tool calls, and performance metrics.

Setup

Install the Braintrust Python SDK with OpenTelemetry support and the Braintrust Pydantic AI integration:
pip install "braintrust[otel]" pydantic-ai
Configure your environment variables:
.env
BRAINTRUST_API_KEY=your-api-key
BRAINTRUST_PARENT=project_name:my-otel-project

# If you are self-hosting Braintrust, set the URL of your hosted dataplane. You can omit this otherwise.
# BRAINTRUST_API_URL=https://api.braintrust.dev

Trace with Pydantic AI

Configure OpenTelemetry with Braintrust’s span processor and enable instrumentation on your agents:
pydantic-ai-braintrust.py
from braintrust.otel import BraintrustSpanProcessor
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from pydantic_ai.agent import Agent

# Configure the global OTel tracer provider
provider = TracerProvider()
trace.set_tracer_provider(provider)

# Send spans to Braintrust
provider.add_span_processor(BraintrustSpanProcessor())

# Enable instrumentation on all agents
Agent.instrument_all()

agent = Agent(...)
This automatically sends all agent interactions, tool calls, and performance metrics to Braintrust.

Resources