openrouter-routing-rules

Featured

Define custom routing rules for OpenRouter requests based on user tier, task type, cost budget, and availability. Triggers: 'openrouter rules', 'routing rules', 'custom routing openrouter', 'conditional model selection'.

AI & Automation 2,944 stars 440 forks Updated today MIT

Install

View on GitHub

Quality Score: 99/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# OpenRouter Routing Rules ## Overview Beyond simple task-based model selection, production systems need configurable routing rules that consider user tier, cost budget, time of day, model availability, and feature requirements. This skill covers building a rules engine for OpenRouter model selection with config-driven rules, dynamic conditions, and override capabilities. ## Rules Engine ```python import os, json, time from dataclasses import dataclass from typing import Optional, Callable from openai import OpenAI client = OpenAI( base_url="https://openrouter.ai/api/v1", api_key=os.environ["OPENROUTER_API_KEY"], default_headers={"HTTP-Referer": "https://my-app.com", "X-Title": "my-app"}, ) @dataclass class RoutingContext: user_tier: str = "free" # "free" | "basic" | "pro" | "enterprise" task_type: str = "general" # "chat" | "code" | "analysis" | "classification" budget_remaining: float = 0.0 # Remaining daily budget in dollars prompt_tokens_est: int = 0 # Estimated prompt tokens needs_tools: bool = False # Requires function calling needs_vision: bool = False # Requires image input max_latency_ms: int = 30000 # Latency SLA @dataclass class RoutingRule: name: str priority: int # Lower = higher priority condition: Callable[[RoutingContext], bool] model: str fallbacks: list[str] = None max_tokens: int = 1024 def matches(self, ctx: RoutingContext) -> bool: ...

Details

Author
jeremylongshore
Repository
jeremylongshore/claude-code-plugins-plus-skills
Created
1 years ago
Last Updated
today
Language
Python
License
MIT

Integrates with

Bundled in these plugins

Similar Skills

Semantically similar based on skill content — not just same category