Fallback Mechanism
Model fallback is ShuYou’s fault-tolerance safeguard. When the primary model or routing strategy fails, the system automatically switches to a backup model to continue processing the request. This ensures your application consistently receives responses and minimizes the risk of service interruptions.Why You Need a Fallback Mechanism
In production environments, model services may encounter various unexpected issues:- Model service failures: Upstream APIs may be temporarily unavailable or time out
- Performance fluctuations: High model load can lead to slow or failed responses
- Routing failures: All candidate models selected by intelligent routing are unavailable
Key Benefits
Global Fallback Model Configuration
ShuYou supports configuring a global fallback model in the console. All requests will automatically use this model as a backup when failures occur.How to Configure
- Visit the ShuYou Strategy Settings page
- Find the Default Fallback Model setting
- Select your global fallback model from the dropdown list
- Save the settings; they take effect immediately
Per-Request Fallback Configuration
For specific business scenarios, you can specify a fallback model within a single request to override the global configuration.Basic Usage
Specify the fallback model using the provider.fallback parameter:cURL Request
OpenAI Python SDK
Using with Intelligent Routing
The fallback mechanism can be used with intelligent routing. If all candidate models selected by routing fail, the system automatically switches to the fallback model:cURL Request
Python SDK
Using with Provider Routing
The fallback mechanism can be used with provider routing. If all specified providers fail, the system automatically switches to the fallback model:cURL Request
OpenAI Python SDK
How It Works
Fallback Trigger Conditions
The system triggers the fallback mechanism in the following cases:- Primary model unavailable: Upstream API returns 5xx errors (Service unavailable errors 502/503) or times out (Model response timeout)
- Authentication failure: Invalid API key or insufficient permissions (401/403 errors)
- Rate limiting: Request frequency limit reached for the model service (Rate limit reached)
- Model not found: Invalid model identifier (404 error)
- Temporary service failure: Primary model service temporarily unavailable (Primary model service temporarily down)
- Routing completely failed: All candidate models in intelligent routing are unavailable
Fallback Execution Flow
- Primary model request: Attempt using the specified primary model or the model selected by routing
- Error detection: Monitor whether the request meets fallback conditions
- Automatic switch: Immediately switch to the fallback model when conditions are met
- Retry request: Reissue the request to the fallback model with the same parameters
- Return result: The actual model used is indicated in the model field of the response
Priority Rules
When multiple configurations exist, the priority from high to low is:- Per-request provider.fallback: Fallback model specified in a single request
- Global Default Fallback Model: Global fallback model set in the console
- No fallback: If neither is configured, errors are returned directly on failure
Best Practices
1. Prefer Global Configuration
For most scenarios, use global fallback configuration: ✅ Recommended:- Configure a global fallback model in the console to simplify code maintenance
- Choose a highly stable, cost-effective model as the global fallback
- Regularly review fallback trigger frequency to optimize primary model configuration
- Repeating the same fallback configuration in each request
- Selecting expensive flagship models as fallback (increases emergency costs)