Documentation Index
Fetch the complete documentation index at: https://docs.openlayer.com/llms.txt
Use this file to discover all available pages before exploring further.
Pydantic AI is a Python framework for building
production-ready applications powered by generative AI. Created by the
team behind Pydantic, it offers type-safe agents with structured outputs,
built-in dependency injection, and native support for leading LLM providers
like OpenAI, Anthropic, and Gemini.
This guide shows how to trace Pydantic AI agents with Openlayer.
Configuration
The integration works by sending trace data to Openlayer’s OpenTelemetry endpoint.
The full code used in this guide is available
here.
To set it up, you need to:
Set the environment variables
Set the following environment variables:OTEL_EXPORTER_OTLP_ENDPOINT="https://api.openlayer.com/v1/otel"
OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer YOUR_OPENLAYER_API_KEY_HERE, x-bt-parent=pipeline_id:YOUR_PIPELINE_ID_HERE"
Configure Logfire
Configure Logfire in your application:import logfire
logfire.configure(send_to_logfire=False)
logfire.instrument_pydantic_ai()
Use Agents as usual
Once instrumentation is set up, you can run your Agents as usual.
Trace data will be automatically captured and exported to Openlayer, where
you can begin testing and analyzing it.For example:from pydantic_ai import Agent
agent = Agent('openai:gpt-4o')
result = await agent.run('What is the capital of France?')