Routing Rules - Custom AI Model Routing Logic
Overview
Section titled “Overview”Routing rules allow you to create deterministic routing logic based on request properties.
Creating Rules
Section titled “Creating Rules”- Go to Console → Routing Rules
- Click Create Rule
- Define conditions and actions
- Save and activate
Rule Types
Section titled “Rule Types”Content-Based Routing
Section titled “Content-Based Routing”Route based on input content:
IF input contains "code"THEN route to provider: anthropic, model: claude-3-7-sonnet-latestMetadata-Based Routing
Section titled “Metadata-Based Routing”Route based on request metadata:
IF metadata.task = "summarize"THEN route to mode: costModel-Specific Routing
Section titled “Model-Specific Routing”Force specific models for certain requests:
IF input contains "legal" OR input contains "compliance"THEN route to provider: openai, model: gpt-4oRule Priority
Section titled “Rule Priority”Rules are evaluated in order:
- Highest priority first (descending order)
- For rules with the same priority, older rules (lower ID) are evaluated first
- Once a rule matches and applies an action (e.g.,
set_provider), subsequent rules cannot override that specific action - Multiple rules can match and apply different non-conflicting actions
- If no rules match, use default routing mode
Best Practices
Section titled “Best Practices”- Start with broad rules, refine over time
- Use descriptive rule names
- Test rules before activating
- Monitor rule performance in analytics
Examples
Section titled “Examples”Route Code Questions to Anthropic
Section titled “Route Code Questions to Anthropic”Name: Code Questions → ClaudeCondition: input contains "code" OR "function" OR "class"Action: Route to Anthropic Claude 3.7 SonnetPriority: HighCost Optimization for Summaries
Section titled “Cost Optimization for Summaries”Name: Summaries → Cost ModeCondition: metadata.task = "summarize"Action: Route to mode: costPriority: MediumCompliance Requirements
Section titled “Compliance Requirements”Name: Legal/Compliance → GPT-4Condition: input contains "legal" OR "gdpr" OR "compliance"Action: Route to OpenAI GPT-4oPriority: High