AI Router
Overview
Pydantic AI is a Python agent framework designed to make it easier to build production-grade applications with Generative AI. By connecting Pydantic AI to Orq.ai’s AI Router, you transform experimental agents into production-ready systems with enterprise-grade capabilities.Key Benefits
Orq.ai’s AI Router enhances your Pydantic AI agents with:Complete Observability
Track every agent step, tool use, and interaction with detailed traces and analytics
Built-in Reliability
Automatic fallbacks, retries, and load balancing for production resilience
Cost Optimization
Real-time cost tracking and spend management across all your AI operations
Multi-Provider Access
Access 300+ LLMs and 20+ providers through a single, unified integration
Prerequisites
Before integrating Pydantic AI with Orq.ai, ensure you have:- An Orq.ai account and API Key
- Python 3.9 or higher
- Pydantic AI SDK installed
To setup your API key, see API keys & Endpoints.
Installation
Install Pydantic AI and the OpenAI SDK:Configuration
Configure Pydantic AI to use Orq.ai’s AI Router by passing a custom OpenAI client:Python
base_url: https://api.orq.ai/v2/router
Basic Agent Example
Here’s a complete example of creating and running a Pydantic AI agent through Orq.ai:Python
Agent with Tools
Pydantic AI agents can use tools while routing through Orq.ai:Python
Structured Outputs
Pydantic AI excels at structured outputs with type-safe validation:Python
Model Selection
With Orq.ai, you can use any supported model from 20+ providers:Python
Observability
Getting Started
Integrate Pydantic AI with Orq.ai’s observability to gain complete insights into your AI agent interactions, tool usage, model performance, and conversation flows using OpenTelemetry.Prerequisites
Before you begin, ensure you have:- An Orq.ai account and API Key
- Pydantic AI installed in your project
- Python 3.9+
Install Dependencies
Configure Orq.ai
Set up your environment variables to connect to Orq.ai’s OpenTelemetry collector: Unix/Linux/macOS:Integration Example
Using LogFire for OpenTelemetry tracing:Python
View Traces
View your traces in the AI Studio in the Traces tab.Visit your AI Studio to view real-time analytics and traces.