Skip to main content

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:
  1. Provider Availability: Check if provider supports the model
  2. Provider Health: Skip unhealthy or quota-exceeded providers
  3. Priority Order: Follow configured priority preferences
  4. Cost Optimization: Prefer CLI and local providers (free)
  5. Success Rate: Favor providers with better historical performance
  6. Fallback: Try alternative providers if primary fails

Routing Priority

Default Priority

By default, switchAILocal prioritizes in this order:
  1. CLI Providers (geminicli:, claudecli:, etc.) - Uses your paid subscriptions
  2. Local Providers (ollama:, lmstudio:) - Free and private
  3. switchAI (switchai:) - Unified gateway with auto-selection
  4. API Providers (gemini:, claude:, etc.) - Direct API access

Custom Priority

Override the default priority in config.yaml:
config.yaml

Intelligent Features

Health-Based Routing

switchAILocal monitors provider health and automatically routes away from failing providers:
config.yaml
Unhealthy providers are automatically skipped during routing.

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
Providers with higher success rates are preferred in future requests.

Model Mapping

Automatically map unavailable models to alternatives:
config.yaml
Requests for unavailable models are automatically redirected.

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:
  1. Verify providers are configured and authenticated
  2. Check provider status: GET /v1/providers
  3. Try explicit routing: geminicli:gemini-2.5-pro
  4. Check logs for provider initialization errors

All Providers Failing

Error: All providers failed for model 'gemini-2.5-pro' Solutions:
  1. Check provider health: GET /v0/management/heartbeat/status
  2. Verify API keys are valid
  3. Check quota limits
  4. Try different model: GET /v1/models

Unexpected Provider Used

Issue: Wrong provider selected during auto-routing Solutions:
  1. Check routing priority: Review config.yaml
  2. Verify provider health: Unhealthy providers are skipped
  3. Use explicit routing: Add provider prefix
  4. Check logs: Review routing decisions

Best Practices

Start with auto-routing and only use explicit prefixes when needed:
Set priorities based on your preferences:
Use Heartbeat for automatic failover:
Track provider usage to optimize costs:

Next Steps

Provider Prefixes

Learn about explicit provider routing

Heartbeat

Configure provider health monitoring

Memory

Enable success rate optimization

Configuration

Configure routing preferences