Viewing Gentrace v2 documentation View Gentrace v1
Integrate Pydantic AI with automatic Gentrace tracing
pip install gentrace pydantic-ai pydantic-ai-openai
import os from pydantic_ai import Agent from pydantic_ai.models.openai import OpenAIModel from gentrace import init, interaction # Initialize Gentrace (will capture Pydantic AI's OTEL traces) init( api_key=os.getenv("GENTRACE_API_KEY"), base_url=os.getenv("GENTRACE_BASE_URL", "https://gentrace.ai/api"), ) # Create a simple Pydantic AI agent agent = Agent( OpenAIModel("gpt-4o-mini"), system_prompt="You are a helpful assistant that gives concise answers.", ) @interaction(name="pydantic_ai_chat", pipeline_id=os.getenv("GENTRACE_PIPELINE_ID", "")) async def chat_with_agent(prompt: str) -> str: result = await agent.run(prompt) return result.output # Usage import asyncio async def main(): response = await chat_with_agent("What is 2+2?") print(f"Agent says: {response}") asyncio.run(main())
GENTRACE_API_KEY=your-gentrace-api-key GENTRACE_PIPELINE_ID=your-pipeline-id OPENAI_API_KEY=your-openai-api-key