request-routing
Configure and manage LLM request routing rules in ai-gateway. Use when you need to: direct specific models to specific providers, set up fallback chains, create routing rules by model pattern, or change provider priority. Triggers include "route gpt-4 to OpenAI", "set fallback provider", "routing rule", "model-to-provider mapping", or any configuration of which provider handles which model.
Best use case
request-routing is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Configure and manage LLM request routing rules in ai-gateway. Use when you need to: direct specific models to specific providers, set up fallback chains, create routing rules by model pattern, or change provider priority. Triggers include "route gpt-4 to OpenAI", "set fallback provider", "routing rule", "model-to-provider mapping", or any configuration of which provider handles which model.
Teams using request-routing should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/request-routing/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How request-routing Compares
| Feature / Agent | request-routing | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Configure and manage LLM request routing rules in ai-gateway. Use when you need to: direct specific models to specific providers, set up fallback chains, create routing rules by model pattern, or change provider priority. Triggers include "route gpt-4 to OpenAI", "set fallback provider", "routing rule", "model-to-provider mapping", or any configuration of which provider handles which model.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# request-routing
Configure routing rules in ai-gateway to control which LLM provider handles each request.
## Routing Rule Format
Each rule has:
- A model glob pattern (e.g., `gpt-4*`, `claude-*`, `command-r*`)
- A primary provider
- An optional ordered fallback chain
- An active/disabled status
Rules are evaluated in database insertion order. First match wins.
## Admin API
### List rules
```bash
curl http://localhost:4081/admin/routes \
-H "Authorization: Bearer gw_your_admin_key"
```
### Create a rule
```bash
curl -X POST http://localhost:4081/admin/routes \
-H "Authorization: Bearer gw_your_admin_key" \
-H "Content-Type: application/json" \
-d '{
"name": "GPT-4 to OpenAI with Anthropic fallback",
"model_pattern": "gpt-4*",
"provider_id": "openai-provider-id",
"fallback_ids": ["anthropic-provider-id"],
"is_active": 1
}'
```
### Update a rule
```bash
curl -X PATCH http://localhost:4081/admin/routes/<rule-id> \
-H "Authorization: Bearer gw_your_admin_key" \
-H "Content-Type: application/json" \
-d '{"fallback_ids": ["anthropic-id", "cohere-id"]}'
```
### Delete a rule
```bash
curl -X DELETE http://localhost:4081/admin/routes/<rule-id> \
-H "Authorization: Bearer gw_your_admin_key"
```
## Pattern Matching
Patterns use glob syntax:
- `*` matches any sequence of characters
- `?` matches a single character
- Literal strings match exactly
Examples:
- `gpt-4*` matches gpt-4o, gpt-4-turbo, gpt-4-vision-preview
- `claude-*` matches all Claude models
- `gpt-3.5-turbo` matches only that exact model
- `*` matches all models (useful as a catch-all last rule)
## Fallback Behavior
The gateway tries providers in order:
1. Primary provider
2. Fallback 1 (if primary fails)
3. Fallback 2 (if fallback 1 fails)
4. ... until all exhausted, then returns 502
Failure triggers:
- HTTP 5xx from provider
- Connection timeout (default 30s)
- Connection refused
- Provider 429 (provider-side rate limit, not gateway rate limit)
Non-retriable (no fallback):
- HTTP 400 invalid request
- HTTP 401 auth error
- HTTP 403 forbidden
## Common Patterns
### Route by cost tier
```json
[
{ "pattern": "gpt-4o", "provider": "openai", "comment": "premium" },
{ "pattern": "gpt-3.5-turbo", "provider": "openai", "comment": "budget" },
{ "pattern": "claude-3-haiku", "provider": "anthropic", "comment": "cheap" }
]
```
### High availability for critical model
```json
{
"pattern": "gpt-4o",
"primary": "openai",
"fallbacks": ["anthropic-claude-3-5-sonnet", "cohere-command-r-plus"]
}
```
### Shadow routing (A/B test)
Create two rules for the same pattern with different providers, then toggle active state to switch traffic.Related Skills
Skill: Uptime Monitoring
## Overview
Skill: Status Page
## Overview
Skill: unit-conversion
## Overview
Skill: recipe-scaler
## Overview
reading-list
Operate the reading-list API to save, manage, tag, search, and export articles.
email-digest
Configure, test, and troubleshoot the reading-list daily email digest delivered via nodemailer.
websocket-realtime
Use the WebSocket connection in poll-builder to receive live vote updates. Use when you need to stream real-time poll results, monitor a poll for new votes, or build a live dashboard. Triggers include "live results", "real-time updates", "stream votes", "watch poll", or "WebSocket".
poll-builder
Self-hosted poll creation tool with real-time results. Use when you need to create a poll, check vote counts, close a poll, export results, or get the shareable link for a poll. Triggers include "create poll", "vote", "poll results", "survey", "collect votes", "share poll", or any task involving polling or voting.
Skill: personal-finance
## Overview
Skill: csv-import
## Overview
Skill: Syntax Highlighting
## Purpose
Skill: Pastebin Core
## Purpose