AI Module
The AI module provides a unified interface for interacting with multiple large language model providers. Switch between OpenAI, Anthropic, Google, Groq, and local models without changing application code.
Configuration
example.py
python
Copied!
Basic Usage
example.py
python
Copied!
Multi-Provider Routing
The AI module supports multiple routing strategies to distribute requests across providers. Configure the strategy at the application level or override per-request.
| Strategy | Description |
|---|---|
STATIC | Always use the configured default provider |
ROUND_ROBIN | Cycle through providers in order |
COST_OPTIMIZED | Select the cheapest provider that supports the model |
LATENCY_OPTIMIZED | Select the fastest provider based on recent response times |
QUALITY_OPTIMIZED | Select the highest quality provider for the task |
FAILOVER | Try primary, then fall back to alternatives on error |
Configuring a Routing Strategy
example.py
python
Copied!
Per-Request Strategy Override
example.py
python
Copied!
Streaming Completions
chat_stream.py
python
Copied!
Embeddings
example.py
python
Copied!
Structured Output
sentiment.py
python
Copied!
Provider Health and Metrics
example.py
python
Copied!