Getting Started with Smart Routing
Learn how Eden AI’s smart routing system automatically selects the best AI model for your requests.Overview
Smart routing is Eden AI’s intelligent model selection system that automatically chooses the optimal AI model for your requests. Instead of manually selecting models, you use the special identifier@edenai and let the system analyze your request to pick the best provider and model.
What you’ll learn:
- How smart routing works
- Basic usage with default models
- Customizing candidate pools
- Understanding routing decisions
- When to use smart routing vs. fixed models
How It Works
The routing system follows this flow:- NotDiamond Integration - Powered by NotDiamond, an AI routing engine that analyzes request context
- Model Inventory - Database of available models with capabilities and pricing
- Redis Cache - Caches available models (1-hour TTL) for performance
- Validation Layer - Ensures models are available and properly formatted
Basic Usage
Quick Start: Default Routing
The simplest way to use smart routing is to setmodel: "@edenai" without specifying candidates. The system will choose from all available models.
Response includes selected model:
Custom Candidate Pool
Restrict routing to specific models usingrouter_candidates:
Benefits of custom candidates:
- Control over which models can be selected
- Cost optimization by limiting to budget-friendly models
- Quality control by restricting to tested models
- Use case optimization (e.g., code-focused models for coding tasks)
Model Format
Models are specified in the format:openai/gpt-4oanthropic/claude-sonnet-4-5google/gemini-2.0-flashcohere/command-r-plus
/v3/llm/models endpoint to list all available models:
Routing with OpenAI SDK
Smart routing works seamlessly with the official OpenAI SDK:When to Use Smart Routing
Use Smart Routing When:
✅ Optimizing cost/performance - Let the system balance quality and cost ✅ Exploring new use cases - Don’t know which model works best yet ✅ Handling diverse requests - Different queries need different models ✅ Minimizing maintenance - No need to update code when better models launch ✅ A/B testing models - Compare routing vs. fixed model performanceUse Fixed Models When:
❌ Strict latency requirements - Routing adds 100-500ms overhead ❌ High-frequency APIs - 100+ requests/second may hit router limits ❌ Compliance requirements - Must use specific certified models ❌ Consistent output format - Need identical behavior across requests ❌ Already optimized - You’ve tested and know the best model for your use caseUnderstanding Routing Latency
Smart routing introduces a small overhead:| Phase | Latency | Notes |
|---|---|---|
| Routing decision | 100-500ms | Analyzing request and selecting model |
| First token | +routing time | First token includes routing overhead |
| Subsequent tokens | No overhead | Normal streaming after first token |
- Use custom candidates (3-5 models) to reduce routing time
- Cache routing decisions at application level for repeated queries
- Consider fixed models for latency-critical applications
Error Handling
The router has built-in fallback mechanisms: Common errors:503 Service Unavailable- Router service temporarily down422 Validation Error- Invalid model candidatesTimeout- Routing took too long (>30s)
Best Practices
1. Choose Appropriate Candidates
✅ Do:- Limit to 3-5 models for faster routing
- Group models by similar capabilities
- Test candidates with your specific workload
- Include at least one budget-friendly option
- Specify 20+ candidates (slows routing)
- Mix specialized models (code + creative)
- Use untested models in production
2. Monitor Performance
✅ Do:- Track which models get selected
- Monitor routing latency
- A/B test routing vs. fixed models
- Set up alerts for routing failures
- Deploy without monitoring
- Assume routing is always optimal
- Ignore cost patterns
3. Handle Errors Gracefully
✅ Do:- Set appropriate timeouts (30s recommended)
- Implement fallback to fixed models
- Log routing failures for analysis
- Retry with exponential backoff
- Use infinite timeouts
- Ignore routing errors
- Rely solely on routing without fallback
Next Steps
- Advanced Usage - Learn advanced routing patterns and optimization strategies
- Monitoring - Track and analyze routing decisions in production
- LLM Smart Routing - Practical LLM-specific examples and use cases
- Chat Completions - Master the LLM endpoint
Quick Reference
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Set to "@edenai" to activate routing |
router_candidates | string[] | No | List of models to choose from (default: all models) |
messages | object[] | Yes | Conversation messages (used for routing context) |
tools | object[] | No | Function definitions (considered in routing) |
stream | boolean | Yes | Must be true for V3 |
Response Fields
The selected model is returned in the response:Supported Features
Smart routing works with all V3 LLM features:- ✅ Streaming (mandatory)
- ✅ Function calling / Tools
- ✅ Vision / Multimodal
- ✅ Multi-turn conversations
- ✅ System messages
- ✅ Temperature and other parameters