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 Toqan Routerās AI Gateway, you get access to 500+ models for your prompt optimization pipelines with a single configuration change.Key Benefits
Toqan Routerā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 500+ LLMs and 30+ providers through a single, unified integration
Prerequisites
Before integrating DSPy with Toqan Router, ensure you have:- A Toqan Router account and API Key
- Python 3.8 or higher
To setup your API key, see API keys & Endpoints.
Installation
Configuration
Configure DSPy to use Toqan Routerās AI Gateway withdspy.LM:
Python
api_base: https://router.toqan.ai/eu/v3/router
Basic Example
Python
Chain of Thought
UseChainOfThought for step-by-step reasoning:
Python
Model Selection
With Toqan Router, you can use any supported model from 30+ providers. The leadingopenai/ is not part of the model name ā it tells DSPyās LiteLLM client to speak the OpenAI protocol to the router, followed by Toqan Routerās provider/model identifier (see the Warning above):
Python
Observability
Getting Started
Stanford DSPy is a framework for algorithmically optimizing LM prompts and weights through programming rather than prompting. Tracing DSPy with Toqan Router 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:- A Toqan Router account and API Key
- Python 3.8+
- DSPy installed in your project
- API keys for your chosen LLM providers
Install Dependencies
Configure Toqan Router
Set up your environment variables to connect to Toqan Routerās OpenTelemetry collector: Unix/Linux/macOS: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 Toqan Router through the OTLP exporter. For more details, see Traces.
Advanced Examples
Chain of Thought ReasoningDSPy is also compatible with our AI Gateway, to learn more, see DSPy.

