AI Gateway
Route your LLM calls through the AI Gateway with a single base URL change. Zero vendor lock-in: always run on the best model at the lowest cost for your use case.
Observability
Instrument your code with OpenTelemetry to capture traces, logs, and metrics for every LLM call, agent step, and tool use.
AI Gateway
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 Gateway, you transform experimental agents into production-ready systems with enterprise-grade capabilities.Key Benefits
Orq.ai’s AI Gateway 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 Gateway by passing a custom OpenAI client:Python
base_url: https://api.orq.ai/v3/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
logfire.span('label') to set a custom name on the trace root for ad-hoc per-call labelling. The wrapper becomes the trace root and the agent runs as its child.
Python
Streaming
Useagent.run_stream(...) to consume tokens incrementally. Traces capture the same shape as run_sync: a chat span under the agent run, with usage recorded on the final chunk.
Python
OpenAIChatModel(provider=OpenAIProvider(...)) form.
Troubleshooting
404 on span export: verifyOTEL_EXPORTER_OTLP_ENDPOINT is exactly https://api.orq.ai/v2/otel with no trailing path. The OpenTelemetry SDK appends /v1/traces automatically.
Traces missing entirely: call logfire.instrument_pydantic_ai() before any Agent(...) invocation, and confirm logfire>=4 is installed.
View Traces
View your traces in the AI Studio in the Traces tab.Visit your AI Studio to view real-time analytics and traces.
Evaluations & Experiments
Once your agents are running, use Evaluatorq to score outputs across a dataset and Experiments to compare configurations side-by-side.Run Evaluations with Evaluatorq
Run parallel evaluations across your agents and compare results.
Run Experiments via the API
Compare agent configurations and view results in the AI Studio.