Skip to main content

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

Instructor is a library for extracting structured outputs from LLMs using Pydantic models. By connecting Instructor to Orq.ai’s AI Gateway, you get type-safe structured extraction with access to 300+ models through a single configuration change.

Key Benefits

Orq.ai’s AI Gateway 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 Gateway by patching an OpenAI client with a custom base_url:
Python
base_url: https://api.orq.ai/v3/router

Basic Extraction

Python

Classification

Use Instructor with Literal 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:
Windows (PowerShell):
Using .env file:

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 Schemas
Batch Processing with Validation
Retry with Custom Logic
Instructor is also compatible with our AI Gateway, to learn more, see Instructor.

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.