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,266 stars 315 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
7 months ago
Last Updated
today
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category

AI & Automation Featured

openrouter-model-routing

Implement intelligent model routing to optimize cost, quality, and latency on OpenRouter. Use when building multi-model systems or optimizing spend across task types. Triggers: 'openrouter routing', 'model routing', 'route to model', 'model selection openrouter'.

2,266 Updated today
jeremylongshore
AI & Automation Featured

openrouter-reference-architecture

Design production architectures using OpenRouter as the LLM gateway. Use when planning system design, reviewing architecture, or scaling AI applications. Triggers: 'openrouter architecture', 'openrouter system design', 'openrouter at scale', 'llm gateway architecture'.

2,266 Updated today
jeremylongshore
AI & Automation Featured

openrouter-cost-controls

Implement cost controls for OpenRouter API usage. Use when setting budgets, preventing overspend, or managing per-key limits. Triggers: 'openrouter budget', 'openrouter cost limit', 'openrouter spending', 'control openrouter cost'.

2,266 Updated today
jeremylongshore
AI & Automation Featured

openrouter-team-setup

Configure OpenRouter for multi-user teams with per-user keys, budget controls, and usage attribution. Triggers: 'openrouter team', 'openrouter multi-user', 'openrouter organization', 'team api keys openrouter'.

2,266 Updated today
jeremylongshore
AI & Automation Featured

openrouter-audit-logging

Implement audit logging for OpenRouter API calls. Use when building compliance trails, debugging production issues, or tracking model usage. Triggers: 'openrouter audit', 'openrouter logging', 'audit trail openrouter', 'log openrouter requests'.

2,266 Updated today
jeremylongshore