The Model Name Rewrites feature provides a powerful, rule-based system for dynamically transforming model names before they are processed by the proxy.
This feature enables seamless model routing, backend abstraction, and fallback strategies without requiring changes to client applications. It uses regex-based pattern matching with configurable rules and precedence to transform model names on the fly.
- Backend Abstraction: Hide specific backend details from client applications
- Seamless Migration: Switch underlying models without updating client code
- Cost Optimization: Route expensive models to cheaper alternatives
- Fallback Strategies: Create catch-all rules for unrecognized models
- Provider Consolidation: Route all requests of a certain type through a preferred provider
Model aliases can be configured through three sources with the following precedence order:
# Single alias
--model-alias "^gpt-(.*)=openrouter:openai/gpt-\1"
# Multiple aliases
--model-alias "^gpt-(.*)=openrouter:openai/gpt-\1" \
--model-alias "^claude-(.*)=anthropic:claude-\1" \
--model-alias "^(.*)=gemini-oauth-plan:gemini-1.5-pro"export MODEL_ALIASES='[
{"pattern": "^gpt-(.*)", "replacement": "openrouter:openai/gpt-\\1"},
{"pattern": "^claude-(.*)", "replacement": "anthropic:claude-\\1"},
{"pattern": "^(.*)$", "replacement": "gemini-oauth-plan:gemini-1.5-pro"}
]'model_aliases:
# Static replacement for specific model
- pattern: "^claude-3-sonnet-20240229$"
replacement: "gemini-oauth-plan:gemini-1.5-flash"
# Dynamic replacement with capture groups
- pattern: "^gpt-(.*)"
replacement: "openrouter:openai/gpt-\\1"
# Catch-all fallback for any other model
- pattern: "^(.*)$"
replacement: "gemini-oauth-plan:gemini-1.5-pro"- First Match Wins: Rules are processed in order, and the first matching pattern is applied
- Regex Support: Patterns use Python regular expressions with full capture group support
- Validation: Invalid regex patterns are caught early with helpful error messages
- Precedence: CLI parameters override environment variables, which override config file settings
model_aliases:
- pattern: "^gpt-(.*)"
replacement: "openrouter:openai/gpt-\\1"model_aliases:
- pattern: "^gpt-4o$"
replacement: "gemini-oauth-plan:gemini-1.5-pro"
- pattern: "^claude-3-opus.*"
replacement: "anthropic:claude-3-sonnet-20240229"# Development environment - use free models
export MODEL_ALIASES='[
{"pattern": "^.*$", "replacement": "gemini-oauth-plan:gemini-1.5-flash"}
]'
# Production environment - use premium models
export MODEL_ALIASES='[
{"pattern": "^gpt-(.*)", "replacement": "openai:gpt-\\1"},
{"pattern": "^claude-(.*)", "replacement": "anthropic:claude-\\1"}
]'# Force a specific application to use your preferred model
./my-app | llm-proxy --model-alias ".*=my-backend:my-preferred-model"Model aliases work seamlessly with other proxy features:
- Static Route:
--static-routetakes precedence over model aliases - Planning Phase: Operates on the rewritten model names
- Failover: Failover routes use the final rewritten model names
- In-Chat Commands:
!/model(...)commands respect alias rules
The proxy provides robust error handling for model aliases:
- Invalid Regex: Patterns are validated at startup/parse time
- Malformed JSON: Environment variable errors are logged as warnings
- Schema Validation: Config file validation ensures proper structure
- Graceful Fallback: Invalid rules are skipped, processing continues
Migrate from one provider to another without updating client code:
model_aliases:
- pattern: "^openai:(.*)"
replacement: "openrouter:openai/\\1"Route expensive models to cheaper alternatives automatically:
model_aliases:
- pattern: "^gpt-4-turbo$"
replacement: "gpt-4o-mini"
- pattern: "^claude-3-opus$"
replacement: "claude-3-sonnet"Use different models in different environments:
# Development
export MODEL_ALIASES='[{"pattern": ".*", "replacement": "gemini-oauth-free:gemini-1.5-flash"}]'
# Production
export MODEL_ALIASES='[{"pattern": ".*", "replacement": "openai:gpt-4o"}]'- Test Patterns: Validate regex patterns before deploying to production
- Order Matters: Place more specific patterns before general catch-all patterns
- Document Rules: Add comments explaining the purpose of each alias
- Monitor Usage: Track which aliases are being used most frequently
- Version Control: Store alias configurations in version control
- URI Model Parameters - Specify model parameters in model strings
- Hybrid Backend - Combine reasoning and execution models
- Planning Phase Overrides - Use strong models for planning