Skip to main content
Routing rules let you dynamically redirect requests to different models based on conditions like cost, content, metadata, or custom logic. This enables cost optimization, load balancing, and model migration strategies.

How Routing Works

When a request arrives, Raven evaluates routing rules in priority order. The first matching rule determines where the request is sent. If no rules match, the original model in the request is used.

Creating a Routing Rule

Navigate to Routing in the dashboard and click Create Rule.

Rule Configuration

FieldDescription
NameDescriptive name for the rule
PriorityEvaluation order (lower = higher priority)
ConditionWhen this rule should trigger
Target ModelThe model to route to when the condition matches
Target ProviderOptionally pin to a specific provider
EnabledToggle the rule on/off

Condition Types

Model-Based Routing

Route requests from one model to another:
{
  "field": "model",
  "operator": "equals",
  "value": "gpt-4"
}
Use case: Gradually migrate from GPT-4 to GPT-4o without changing application code.

Cost-Based Routing

Route to cheaper models for non-critical requests:
{
  "field": "metadata.priority",
  "operator": "equals",
  "value": "low"
}
Use case: Send low-priority batch processing to a cost-effective model.

Content-Based Routing

Route based on request content characteristics:
{
  "field": "content_length",
  "operator": "greater_than",
  "value": "10000"
}
Use case: Send long-context requests to models with larger context windows.

Fallback Routing

When a provider is down or returns errors, Raven can automatically fall back to an alternative provider. Configure fallback behavior in your routing rules to ensure high availability.

Examples

Cost Optimization

Route simple queries to cheaper models:
ConditionTarget
Token estimate < 100gpt-4o-mini
Defaultgpt-4o

Provider Failover

Set up automatic failover:
PriorityProviderModel
1OpenAIgpt-4o
2Azure OpenAIgpt-4o
3Anthropicclaude-sonnet-4-20250514