Pydantic AI
Overview
Use respan-exporter-pydantic-ai to instrument Pydantic AI agents with Respan. Traces, spans, and metrics from agent runs (including LLM calls and tool use) are sent to Respan via OpenTelemetry and standard semantic conventions. The exporter requires respan-tracing (installed automatically).
You can route LLM calls through Respan as the gateway, so only your Respan API key is needed—no separate OpenAI key.
Setup
1. Install
2. Environment
Set RESPAN_API_KEY (required). Optional: RESPAN_BASE_URL (default https://api.respan.ai/api). For the gateway pattern, also set OPENAI_BASE_URL and OPENAI_API_KEY to your Respan base URL and API key so no separate OpenAI key is needed.
Examples
Each example below is a complete runnable script. Run it and open the Respan dashboard to see the trace.
Example: Hello World
Minimal instrumentation: initialize Respan, instrument Pydantic AI, run one agent call.

Example: Gateway
Use Respan as the LLM gateway and control content capture with include_content and include_binary_content.

Example: Workflows and tasks
Use @workflow and @task from respan-tracing to group spans into workflows and tasks.

Example: Respan params on spans
Set customer_identifier, metadata, and custom_tags on the current span with get_client().update_current_span(respan_params=...).

Example: Tool use
Agents that use tools are traced automatically; tool calls and results appear as spans.

Reference
RespanTelemetry options
instrument_pydantic_ai() options
Instrument a single agent
By default, instrument_pydantic_ai() instruments all Pydantic AI agents globally. To instrument only one agent:
Further reading
- Package: respan-exporter-pydantic-ai on PyPI
- Examples: Pydantic AI tracing examples — runnable scripts in the Respan example projects repo
- Respan: respan.ai, Documentation
- Pydantic AI: ai.pydantic.dev, Models (OpenAI)
- respan-tracing: PyPI — decorators (
@workflow,@task), manual spans, and export options