home / skills / jeremylongshore / claude-code-plugins-plus-skills / openrouter-routing-rules
/plugins/saas-packs/openrouter-pack/skills/openrouter-routing-rules
This skill implements request-based routing to select optimal models by cost, speed, and quality, improving efficiency across diverse tasks.
npx playbooks add skill jeremylongshore/claude-code-plugins-plus-skills --skill openrouter-routing-rulesReview the files below or copy the command above to add this skill to your agents.
---
name: openrouter-routing-rules
description: |
Implement intelligent model routing based on request characteristics. Use when optimizing for cost, speed, or quality per request. Trigger with phrases like 'openrouter routing', 'model selection', 'smart routing', 'dynamic model'.
allowed-tools: Read, Write, Edit, Grep
version: 1.0.0
license: MIT
author: Jeremy Longshore <[email protected]>
---
# OpenRouter Routing Rules
## Overview
This skill covers implementing request-based routing logic to select optimal models based on content, urgency, or cost constraints.
## Prerequisites
- OpenRouter integration
- Understanding of model capabilities and pricing
## Instructions
Follow these steps to implement this skill:
1. **Verify Prerequisites**: Ensure all prerequisites listed above are met
2. **Review the Implementation**: Study the code examples and patterns below
3. **Adapt to Your Environment**: Modify configuration values for your setup
4. **Test the Integration**: Run the verification steps to confirm functionality
5. **Monitor in Production**: Set up appropriate logging and monitoring
## Overview
This skill covers implementing request-based routing logic to select optimal models based on content, urgency, or cost constraints.
## Prerequisites
- OpenRouter integration
- Understanding of model capabilities and pricing
## Basic Routing Strategies
### Content-Based Routing
```python
def route_by_content(prompt: str) -> str:
"""Route to appropriate model based on content analysis."""
prompt_lower = prompt.lower()
# Code-related
if any(word in prompt_lower for word in ["code", "function", "debug", "python", "javascript"]):
return "anthropic/claude-3.5-sonnet"
## Detailed Reference
See `{baseDir}/references/implementation.md` for complete implementation guide.
This skill implements intelligent model routing for OpenRouter to pick the best model per request based on content, urgency, and cost. It helps teams balance quality, latency, and budget by applying simple, extensible routing rules. Use it to automate model selection without manual intervention for each request.
The skill inspects request metadata and prompt content, then evaluates routing rules such as content-based keywords, cost thresholds, and latency requirements. Rules map requests to specific models or tiers (e.g., fast/cheap vs. high-quality) and can be composed with overrides for special cases. The code integrates with an OpenRouter client to forward requests to the chosen model and returns the unified response.
How do I add a new routing rule?
Add a rule function that inspects request fields (prompt, metadata, urgency) and returns a model key, then register it in the routing chain configuration.
What if multiple rules match a request?
Rules should be ordered by priority; the first matching rule is applied. Alternatively implement scoring and choose the highest-scoring rule for more complex use cases.