AI Router
Overview
Instructor is a library for extracting structured outputs from LLMs using Pydantic models. By connecting Instructor to Orq.ai’s AI Router, you get type-safe structured extraction with access to 300+ models through a single configuration change.Key Benefits
Orq.ai’s AI Router enhances your Instructor applications with:Complete Observability
Track every extraction, validation, and retry with detailed traces
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 Instructor with Orq.ai, ensure you have:- An Orq.ai account and API Key
- Python 3.8 or higher
To setup your API key, see API keys & Endpoints.
Installation
Configuration
Configure Instructor to use Orq.ai’s AI Router by patching an OpenAI client with a custombase_url:
Python
base_url: https://api.orq.ai/v2/router
Basic Extraction
Python
Classification
Use Instructor withLiteral types for classification:
Python
Model Selection
With Orq.ai, you can use any supported model from 20+ providers:Python
Observability
Getting Started
Instructor enables structured outputs from language models using Pydantic schemas. Tracing Instructor with Orq.ai provides comprehensive insights into data extraction patterns, validation success rates, retry mechanisms, and structured output performance to optimize your LLM-powered data processing pipelines.Prerequisites
Before you begin, ensure you have:- An Orq.ai account and API Key
- Python 3.8+
- Instructor library installed in your project
- OpenAI API key (or other supported LLM provider credentials)
Install Dependencies
Configure Orq.ai
Set up your environment variables to connect to Orq.ai’s OpenTelemetry collector: Unix/Linux/macOS:Integration
Instructor uses OpenInference instrumentation for automatic OpenTelemetry tracing.Set up the instrumentation in your application:
Use Instructor with automatic tracing:
All Instructor structured output extractions will be automatically instrumented and exported to Orq.ai through the OTLP exporter. For more details, see Traces.
Advanced Examples
Complex Nested SchemasInstructor is also compatible with our AI Router, to learn more, see Instructor.