Pydantic AI
Pydantic AI is a Python agent framework from the creators of Pydantic. It provides a type-safe way to build agents with tools, structured outputs, and multi-model support. Respan gives you full observability over every agent run, model call, and tool invocation — and gateway routing through the OpenAI-compatible Respan endpoint.
Set up Respan
Create an account at platform.respan.ai and grab an API key. For gateway, also add credits or a provider key.
Run npx @respan/cli setup to set up with your coding agent.
Example projects
Tracing
Gateway
Setup
Set environment variables
This example uses the OpenAI provider directly. OPENAI_API_KEY is used for model requests, and RESPAN_API_KEY is used to export traces to Respan.
View your trace
Open the Traces page to see your agent run with model spans, tool calls, tokens, and cost.
Configuration
PydanticAIInstrumentor options
Instrument a single agent
By default, PydanticAIInstrumentor() instruments all Pydantic AI agents globally. To instrument only one agent:
Attributes
In Respan()
Set defaults at initialization — these apply to all spans.
With propagate_attributes
Override per-request using a context scope.
Decorators (optional)
Decorators are not required. Pydantic AI model spans and tool calls are auto-traced by the instrumentor. Use @workflow and @task when you want to add structure around one or more agent runs.
Examples
Tool calls
Tool calls are automatically captured as spans with inputs, outputs, and timing.
Structured output
Structured outputs are traced the same way as normal agent runs.