Agent skill · marketing growth · jeremylongshore
openrouter-routing-rules
Define custom routing rules for OpenRouter requests based on user tier,
Why this skill is useful
Adds a rules engine for dynamic routing based on user context and budget that the AI wouldn't generate on its own.
What it needs
Requires python3 installed locally. Requires openrouter account access. About 5k tokens when loaded. Last updated 2026-08-07. 2,604 stars on the source repository.
What this skill does
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. Prerequisites An OpenRouter API key (sk-or-v1-...) exported as OPENROUTERAPIKEY — see the openrouter-install-auth skill for setup Python 3.8+ with the OpenAI SDK — the rules engine itself is stdlib (dataclasses, json, random) layered on top Per-request metadata available in your app: user tier, task type, remaining budget, tool/vision needs, latency SLA (the RoutingContext fields) Budget tracking wired up (see openrouter-cost-controls) if you use budget-conditioned rules like low-budget Instructions 1. Model each request's metadata as a RoutingContext (user tier, task type, budget remaining, tools/vision flags, latency SLA) per Rules Engine. 2. Define RoutingRule entries in priority order — free-tier first, then budget, capability (tools/vision), task type, latency, and always a priority=99 default catch-all. 3. Resolve the winning rule with evaluaterules(ctx): first match by ascending priority wins; failing conditions return False instead of raising. 4. Execute through routedcompletion() per Routed Completion — it applies the rule's model, fallback chain (models + route: "fallback"), and maxtokens. 5. To make rules hot-reloadable, express them as JSON per Config-Driven Rules and match with matchconfigrule() instead of lambdas. 6. Validate any rule change on a slice of traffic with abtestrouting() per A/B Testing Rules before full rollout. …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills jeremylongshore/openrouter-routing-rules--3de338