Skip to content

Model Routing

Instead of hardcoding a single model, agents can use routing strategies to dynamically select the best model for each request.

Uses the configured modelId for every request.

Selects the cheapest model from candidates that meets the required capabilities.

Selects the highest-quality model from candidates, falling back to cheaper options only if budget constraints apply.

Balances cost and quality using a scoring function across candidates.

Evaluates rules in order. Each rule has a condition expression and a modelId. The first matching rule wins; if none match, uses fallbackModelId.

{
"routingStrategy": {
"mode": "cost_optimized",
"candidates": [
"openai/gpt-4o",
"openai/gpt-4o-mini",
"anthropic/claude-sonnet-4-20250514"
],
"maxCostPerRequest": 0.05,
"requiredCapabilities": ["reasoning"],
"fallbackModelId": "openai/gpt-4o-mini"
}
}
CapabilityDescription
codingCode generation and review
reasoningComplex logic and analysis
creativeCreative writing and ideation
visionImage understanding
long_contextLarge context windows (100k+)
{
"routingStrategy": {
"mode": "custom",
"rules": [
{
"condition": "input.length > 10000",
"modelId": "anthropic/claude-sonnet-4-20250514"
},
{
"condition": "task === 'code_review'",
"modelId": "openai/gpt-4o"
}
],
"fallbackModelId": "openai/gpt-4o-mini"
}
}