Legion CLI supports 500+ AI models across multiple providers with intelligent routing and fallback.
Multi-model support enables:
Legion automatically selects models based on:
# Specify model directly
legion run "implement feature" --model anthropic/claude-sonnet-4
# Use small model
legion run "generate title" --model anthropic/claude-haiku-4
{
"providers": {
"anthropic": {
"apiKey": "env:ANTHROPIC_API_KEY"
},
"openai": {
"apiKey": "env:OPENAI_API_KEY"
},
"google": {
"apiKey": "env:GOOGLE_API_KEY"
}
}
}
{
"model": "anthropic/claude-sonnet-4",
"fallback": {
"chain": [
"openai/gpt-4o",
"google/gemini-1.5-pro"
],
"onError": true,
"onRateLimit": true
}
}
| Capability | Claude 3.5 | GPT-4o | Gemini 1.5 | Llama 3 |
|---|---|---|---|---|
| Vision | ✓ | ✓ | ✓ | ✓ |
| Tools | ✓ | ✓ | ✓ | ✓ |
| Streaming | ✓ | ✓ | ✓ | ✓ |
| JSON Mode | ✓ | ✓ | ✓ | ✗ |
| Context | 200K | 128K | 1M | 128K |
// Check model capabilities
const model = yield* Provider.getModel("anthropic/claude-sonnet-4")
if (model.capabilities.vision) {
// Use vision
}
if (model.capabilities.tools) {
// Use tools
}
{
"routing": {
"coding": "anthropic/claude-sonnet-4",
"review": "anthropic/claude-sonnet-4",
"refactor": "anthropic/claude-sonnet-4"
}
}
{
"routing": {
"title": "anthropic/claude-haiku-4",
"summary": "anthropic/claude-haiku-4",
"rename": "anthropic/claude-haiku-4"
}
}
{
"routing": {
"architecture": "anthropic/claude-3-opus",
"reasoning": "openai/o1",
"analysis": "anthropic/claude-3-opus"
}
}
# View usage
legion usage show
# By provider
legion usage show --provider anthropic
# By model
legion usage show --model anthropic/claude-sonnet-4
{
"providers": {
"anthropic": {
"costLimit": {
"daily": 10.00,
"monthly": 100.00
}
}
}
}
{
"fallback": {
"onError": true,
"onTimeout": true,
"onRateLimit": true
}
}
{
"fallback": {
"ifQualityBelow": 0.8,
"tryNext": true
}
}
{
"fallback": {
"ifCostAbove": 0.10,
"useCheaper": true
}
}
{
"providers": {
"custom": {
"type": "openai",
"baseUrl": "https://your-api.com/v1",
"apiKey": "env:CUSTOM_API_KEY",
"models": ["model-1", "model-2"]
}
}
}
{
"models": {
"custom-model": {
"provider": "custom",
"id": "model-1",
"name": "Custom Model",
"capabilities": ["tools", "streaming"],
"contextWindow": 128000,
"costPer1kTokens": 0.002
}
}
}
# 1. Plan with Opus
legion run "design architecture" --model anthropic/claude-3-opus
# 2. Implement with Sonnet
legion run "implement feature" --model anthropic/claude-sonnet-4
# 3. Test with Haiku
legion run "generate tests" --model anthropic/claude-haiku-4
# 4. Review with Sonnet
legion run "review code" --model anthropic/claude-sonnet-4
# Use small model for titles
legion run "generate PR title" --model anthropic/claude-haiku-4
# Use large model for complex code
legion run "implement auth" --model anthropic/claude-sonnet-4
# If Claude is unavailable, use GPT-4o
# Configured via fallback chain
legion run "implement feature"
# Automatically falls back to GPT-4o if Claude fails