Overview
Auto-routing enables switchAILocal to automatically select the best available provider for your request. Omit the provider prefix from your model name to activate intelligent routing.How It Works
Basic Auto-Routing
Simply use the model name without a provider prefix:Routing Algorithm
switchAILocal evaluates providers in this order:- Provider Availability: Check if provider supports the model
- Provider Health: Skip unhealthy or quota-exceeded providers
- Priority Order: Follow configured priority preferences
- Cost Optimization: Prefer CLI and local providers (free)
- Success Rate: Favor providers with better historical performance
- Fallback: Try alternative providers if primary fails
Routing Priority
Default Priority
By default, switchAILocal prioritizes in this order:- CLI Providers (
geminicli:,claudecli:, etc.) - Uses your paid subscriptions - Local Providers (
ollama:,lmstudio:) - Free and private - switchAI (
switchai:) - Unified gateway with auto-selection - API Providers (
gemini:,claude:, etc.) - Direct API access
Custom Priority
Override the default priority inconfig.yaml:
config.yaml
Intelligent Features
Health-Based Routing
switchAILocal monitors provider health and automatically routes away from failing providers:config.yaml
Quota-Aware Routing
When a provider exceeds quota, switchAILocal automatically fails over:Success Rate Optimization
With Memory system enabled, switchAILocal learns which providers perform best:config.yaml
Model Mapping
Automatically map unavailable models to alternatives:config.yaml
Configuration
Enable Auto-Routing
config.yaml
Provider Weights
Assign weights to providers for load distribution:config.yaml
Exclude Providers
Exclude specific providers from auto-routing:config.yaml
Examples
Cost-Optimized Routing
config.yaml
Performance-Optimized Routing
config.yaml
Privacy-Optimized Routing
config.yaml
Hybrid Strategy
Combine local and cloud for best of both:Routing Transparency
Response Headers
Check which provider was used via response headers:Logs
View routing decisions in logs:Management API
Query routing decisions:Advanced Patterns
Conditional Routing
Route based on request attributes:Time-Based Routing
Route differently based on time of day:Budget-Based Routing
Monitoring
Usage Statistics
Track provider usage:Provider Health
Monitor provider availability:Troubleshooting
No Providers Available
Error:No providers available for model 'gemini-2.5-pro'
Solutions:
- Verify providers are configured and authenticated
- Check provider status:
GET /v1/providers - Try explicit routing:
geminicli:gemini-2.5-pro - Check logs for provider initialization errors
All Providers Failing
Error:All providers failed for model 'gemini-2.5-pro'
Solutions:
- Check provider health:
GET /v0/management/heartbeat/status - Verify API keys are valid
- Check quota limits
- Try different model:
GET /v1/models
Unexpected Provider Used
Issue: Wrong provider selected during auto-routing Solutions:- Check routing priority: Review
config.yaml - Verify provider health: Unhealthy providers are skipped
- Use explicit routing: Add provider prefix
- Check logs: Review routing decisions
Best Practices
Use Auto-Routing by Default
Use Auto-Routing by Default
Start with auto-routing and only use explicit prefixes when needed:
Configure Priorities
Configure Priorities
Set priorities based on your preferences:
Enable Health Monitoring
Enable Health Monitoring
Use Heartbeat for automatic failover:
Monitor Usage
Monitor Usage
Track provider usage to optimize costs: