Smart Routing: Let AI Choose the Best Model
Get optimal model selection automatically with Eden AI’s smart routing feature. Instead of manually selecting models, let the system intelligently route your requests based on context.Overview
Smart routing uses the special model identifier@edenai to dynamically select the best LLM model for your request. The system analyzes your messages, tools, and other context to route to the optimal provider/model combination.
Key Benefits:
- Automatic optimization - No need to research and compare models
- Cost efficiency - Routes to models with the best price/performance ratio
- Context-aware - Selection adapts to your specific request
- Fallback resilience - Automatic fallback if routing fails
- Works with all features - Streaming, function calling, vision, etc.
Quick Start: Your First Routed Request
The simplest way to use smart routing is to setmodel: "@edenai":
That’s it! The system will automatically select the best model from all available options.
How It Works
When you usemodel: "@edenai", here’s what happens:
- Request Analysis - The system analyzes your messages, tools, and parameters
- Model Selection - NotDiamond’s routing engine selects the optimal model from available candidates
- Transparent Routing - Your request is routed to the selected model
- Normal Response - You receive the response as if you had specified the model directly
Customizing Model Candidates
By default, smart routing considers all available models. You can customize the candidate pool withrouter_candidates:
When to Use Smart Routing
✅ Great Use Cases
- General-purpose chatbots - Let the router optimize for diverse queries
- Cost-sensitive applications - Router balances quality and cost
- Multi-task applications - Different queries benefit from different models
- Experimentation - Compare router performance vs. fixed models
⚠️ Consider Fixed Models Instead
- Specific model requirements - You need a particular model’s unique features
- Latency-critical - Every 100ms matters (smart routing adds overhead)
- Consistent behavior - You need identical model behavior across requests
- High-volume production - You’ve already optimized model selection
Model Selection Criteria
The routing engine considers multiple factors:- Task type - Code generation, creative writing, analysis, etc.
- Conversation context - Prior messages and conversation flow
- Tool/function calls - Compatibility with function calling requirements
- Quality requirements - Implicit in message complexity
- Cost efficiency - Price/performance optimization
Default Model Pool
When you don’t specifyrouter_candidates, the system uses all available LLM models, including:
Top-tier Models:
- OpenAI: GPT-4, GPT-4 Turbo, GPT-4o, GPT-5 (latest versions)
- Anthropic: Claude Haiku, Sonnet, Opus (4.x series)
- Google: Gemini 2.0/2.5/3.0 (Flash and Pro)
- Mistral: Large, Medium, Small models
- X.AI: Grok 3, Grok 4
- Together.ai: Llama 3/3.1 models
- Cohere: Command R, Command R+
- Perplexity: Sonar
Fallback Behavior
Smart routing includes intelligent fallbacks:- With custom candidates - Falls back to first candidate on routing failure
- Without candidates - Falls back to
openai/gpt-4o(reliable default) - Transparent errors - You’ll see clear error messages if routing fails completely
Reliability: Fallback ensures your requests always succeed, even if the routing service is temporarily unavailable.
Response Format
Smart routing responses are identical to fixed-model responses. The streaming format follows OpenAI’s SSE standard:Tracking: The
model field in the response shows which model was selected by the router.OpenAI SDK Compatibility
Smart routing works seamlessly with the OpenAI Python SDK:SDK Integration: Use
extra_body to pass the router_candidates parameter when using the OpenAI SDK.Pricing
Smart routing costs are based on the selected model’s pricing. The routing decision itself is free. Example:- If router selects
openai/gpt-4o→ You pay GPT-4o rates - If router selects
google/gemini-2.0-flash→ You pay Gemini Flash rates
Next Steps
Now that you understand smart routing basics:- Smart Routing How-To Guide - Advanced patterns and best practices
- Optimize LLM Costs Tutorial - Complete cost optimization workflow
- Streaming Guide - Handle SSE responses effectively
- Function Calling - Use tools with smart routing
Troubleshooting
Router returns error “no candidates provided”
Cause: Emptyrouter_candidates list or all candidates filtered out
Solution: Omit router_candidates to use default pool, or provide valid model strings
Higher latency than expected
Cause: Routing decision adds 100-500ms overhead Solution: Use fixed models for latency-critical applicationsUnexpected model selection
Cause: Router optimizes for multiple factors, not just quality Solution: Userouter_candidates to limit selection pool, or switch to fixed models
”Router API unavailable” errors
Cause: Temporary routing service outage Solution: System automatically falls back - check if fallback model meets your needsGetting Started: Start with default routing (
model: "@edenai"), then customize with router_candidates if needed.