Overview
Model routing is a core feature of MythIQ that allows you to specify a model type rather than a specific implementation, letting the system intelligently select the most appropriate model based on your requirements. This approach provides several benefits:
- Simplified API usage without needing to know the details of each model
- Automatic fallback to alternative models if your preferred model is unavailable
- Optimization for cost, performance, or feature support based on your preferences
- Future-proofing your application as new and improved models become available
Intelligent Selection
MythIQ's routing system automatically selects the optimal model based on your specified criteria, balancing factors like cost, performance, and feature support.
How It Works
When you make a request to the MythIQ API, you specify a model using the format base/model[:version]
. The system then:
- Identifies all providers that support the requested model
- Filters providers based on compatibility with your request parameters
- Applies your routing strategy to select the most appropriate provider
- Executes the request using the selected provider
- Falls back to alternative providers if the primary provider fails
Model Resolution Process
The diagram below illustrates how MythIQ resolves a model request:
Request → Model Lookup → Provider Filtering → Strategy Application → Execution ↓ ↓ ↓ ↓ ↓ model: "stability/sdxl" Find providers Filter by parameter Apply routing Execute with supporting SDXL compatibility strategy selected provider
Routing Strategies
MythIQ supports several routing strategies that determine how providers are selected for a given request. You can specify a strategy using the routing
parameter:
optimal
(default)Balances cost and feature support. Selects the cheapest provider that supports all requested features, or may choose a slightly more expensive provider (within 20% price difference) if it supports more features.
This is the default strategy and is recommended for most use cases as it provides a good balance between cost and functionality.
Example
// Using the default 'optimal' strategy
const response = await openai.images.generate({
model: 'stability/sdxl',
prompt: 'A beautiful sunset over the ocean',
size: '1024x1024',
// routing: 'optimal' is implied
});
cheapest
Always selects the lowest-cost provider that can fulfill the basic requirements of your request. This strategy prioritizes cost savings over additional features or capabilities.
Use this strategy when cost is your primary concern and you don't need advanced features that might only be available from more expensive providers.
Example
// Using the 'cheapest' strategy
const response = await openai.images.generate({
model: 'stability/sdxl',
prompt: 'A beautiful sunset over the ocean',
size: '1024x1024',
routing: 'cheapest',
});
compatible
Selects a provider that supports all the parameters you've specified in your request, even if some are optional. This strategy ensures that all features you've requested are supported, even if it means using a more expensive provider.
Use this strategy when you need specific features or capabilities and are willing to pay a premium to ensure they're available.
Example
// Using the 'compatible' strategy with advanced parameters
const response = await openai.images.generate({
model: 'stability/sdxl',
prompt: 'A beautiful sunset over the ocean',
size: '1024x1024',
routing: 'compatible',
// These advanced parameters will ensure a provider that supports them is selected
cfg_scale: 10,
steps: 50,
seed: 12345,
});
Specifying Providers
While model routing is powerful, there may be cases where you want to use a specific provider. You can do this by including the provider
parameter in your request:
// Specifying a provider explicitly
const response = await openai.images.generate({
model: 'stability/sdxl',
prompt: 'A beautiful sunset over the ocean',
size: '1024x1024',
provider: 'stability', // Use Stability AI specifically
});
When you specify a provider, the routing strategy is ignored and the system will attempt to use the specified provider. If the provider doesn't support the requested model or parameters, or if it's unavailable, the request will fail.
Best Practices
Use Generic Model References
When possible, use generic model references (e.g., stability/sdxl
) rather than specific versions to benefit from automatic updates and improvements.
Choose the Right Routing Strategy
Select a routing strategy that aligns with your priorities:
optimal
for a balance of cost and featurescheapest
for cost-sensitive applicationscompatible
for feature-rich requirements
Handle Fallbacks Gracefully
Even with routing, providers may occasionally fail. Implement proper error handling in your application to gracefully handle these situations and provide a good user experience.
Monitor Usage and Costs
Regularly review your usage patterns and costs to ensure your routing strategy is aligned with your business needs. Adjust as necessary to optimize for your specific requirements.