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

DSPy is a framework for programmatically optimizing LLM prompts and weights through composable modules and signatures. By connecting DSPy to Orq.ai’s AI Gateway, you get access to 300+ models for your prompt optimization pipelines with a single configuration change.

Key Benefits

Orq.ai’s AI Gateway enhances your DSPy applications with:

Complete Observability

Track every signature execution, module call, and optimization step

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 DSPy 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 DSPy to use Orq.ai’s AI Gateway with dspy.LM:
Python
api_base: https://api.orq.ai/v3/router
DSPy requires double-prefixing the model name when using a custom api_base. Add openai/ before the model identifier: gpt-4oopenai/openai/gpt-4o

Basic Example

Python

Chain of Thought

Use ChainOfThought for step-by-step reasoning:
Python

Model Selection

With Orq.ai, you can use any supported model from 20+ providers:
Python

Observability

Getting Started

Stanford DSPy is a framework for algorithmically optimizing LM prompts and weights through programming rather than prompting. Tracing DSPy with Orq.ai provides comprehensive insights into signature execution, module performance, optimization processes, and few-shot learning effectiveness to optimize your programmatic LLM applications.

Prerequisites

Before you begin, ensure you have:
  • An Orq.ai account and API Key
  • Python 3.8+
  • DSPy installed in your project
  • API keys for your chosen LLM providers

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

DSPy uses OpenInference instrumentation for automatic OpenTelemetry tracing.
Set up the instrumentation in your application:
Use DSPy with automatic tracing:
All DSPy signature executions and module operations will be automatically instrumented and exported to Orq.ai through the OTLP exporter. For more details, see Traces.

Advanced Examples

Chain of Thought Reasoning
Few-Shot Optimization
Multi-Step RAG Pipeline
DSPy is also compatible with our AI Gateway, to learn more, see DSPy.

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.