Overview
Routing rules let you control where your AI requests go based on their context — feature, task type, provider, or model. Set a rule once in the dashboard. Every matching request is routed automatically from that moment forward.How it works
When a request arrives at Lectr, the routing engine evaluates your rules in priority order.model and/or provider before the request is sent upstream.
If no rule matches — or if rule evaluation fails — the request is forwarded unchanged.
Passthrough is always the fallback. Routing cannot block or degrade a request.
Rule conditions
Each rule can match on any combination of four conditions. All specified conditions must match — AND logic. Unset conditions are wildcards.| Condition | Matches against | Header / field |
|---|---|---|
| Feature tag | X-Lectr-Feature header value | Your feature name |
| Task type | X-Lectr-Task header value | Task type string |
| Provider | Detected or declared provider | Auto-detected or X-Lectr-Provider |
| Model | model field in request body | Exact model name |
Creating a rule
Go to Rules in the dashboard sidebar. Click New rule and fill in:- Name — a label you’ll recognise in logs (e.g. “Downgrade classifiers to mini”)
- Conditions — one or more of: feature tag, task type, provider, model
- Target provider — where to send matching requests
- Target model — which model to use
Priority
Rules are evaluated in ascending priority order. Priority 1 is evaluated first. The first matching enabled rule wins — evaluation stops.Toggling rules
Rules can be enabled or disabled without deleting them. A disabled rule is never evaluated — it’s invisible to the routing engine. Useful for:- Testing a rule without committing to it
- Temporarily disabling routing during an incident
- Keeping rules around for future use without activating them
Seeing rules in action
Every request log shows whether a routing rule was applied and which one. In the Requests table:model_actual differs from model_requested, the substitution is clearly visible.
Routing coverage:
The dashboard overview shows what percentage of your traffic is being routed
versus passing through:
Common rule patterns
Downgrade all classification tasks to a cheaper modelWhat routing changes
When a rule matches, Lectr:- Rewrites the
modelfield to the target model - Routes the request to the target provider
- Normalises authentication headers automatically
- Your prompts or messages
- Any other request fields
- The response format — it remains identical to provider output
Routing and recommendations
The recommendation engine surfaces opportunities to reduce cost. Routing rules let you apply those optimizations instantly without changing your code. The workflow:Safety guarantees
Routing is designed to be safe for production use.- No matching rule → request is forwarded unchanged
- Rule evaluation error → request is forwarded unchanged
- Provider error → passed through unchanged
Reference
Condition matching:- Exact string matching (provider is case-insensitive)
- All conditions must match (AND logic)
- Unset conditions act as wildcards
- Lower number = higher priority
- Priority 1 is evaluated first
- No duplicate priorities allowed
- Rules are evaluated from an in-memory cache
- No database on the hot path
- Cache updates immediately when rules are created, edited, toggled, or deleted
- No match = unchanged request
- Routing never blocks execution
FAQ
How quickly do rule changes take effect?
How quickly do rule changes take effect?
Immediately. When you save, toggle, or delete a rule, the routing cache is
reloaded server-side within milliseconds. The next matching request uses the
updated rules.
What happens if my target model is unavailable?
What happens if my target model is unavailable?
Can a request match more than one rule?
Can a request match more than one rule?
No. Evaluation stops at the first match. Only the highest-priority matching
rule is applied.
Can I route to a different provider than the one my client is configured for?
Can I route to a different provider than the one my client is configured for?
Yes. If your client is configured for OpenAI but a rule routes to Anthropic,
Lectr handles the provider switch — including auth header normalisation —
automatically. Your client doesn’t need to know.
Does routing affect streaming requests?
Does routing affect streaming requests?
Yes. Routing works identically for streaming and non-streaming requests.
Is there a limit to the number of rules?
Is there a limit to the number of rules?
No hard limit. Most teams use fewer than 20 rules.