openrouter-model-routing
Installation
SKILL.md
OpenRouter Model Routing
Overview
OpenRouter gives you access to 100+ models through one API. The key to cost efficiency is routing each request to the right model based on task complexity, required capabilities, cost budget, and latency requirements. This skill covers task-based routing, complexity classification, cost-aware selection, and OpenRouter's native routing features.
Prerequisites
- An OpenRouter API key exported as
OPENROUTER_API_KEY— see theopenrouter-install-authskill for setup - Python 3.8+ with the OpenAI SDK and
requests(pip install openai requests) - A rough inventory of your task mix (classification, summarization, code generation, deep reasoning, ...) to seed the
TASK_ROUTINGtable - Credits sized for the tiers you route to — the premium tier (
openai/o1) runs $15/$60 per 1M tokens, 250x the budget tier
Instructions
- Define your tiers per Task-Based Router: the
MODELSdict (free → budget → mid → standard → premium) and theTASK_ROUTINGmap, then send requests throughroute_request(), which returnscontent, the servingmodel,tier, and token count. - When callers can't label tasks, switch to the Complexity-Based Auto-Router —
classify_complexity()scores word count, code, reasoning, and math markers to pick a tier insideauto_route(). - Add resilience per OpenRouter Native Routing:
extra_body={"models": [...], "route": "fallback"}tries models in order,provider.ordercontrols which provider serves, and the:floorvariant picks the cheapest provider automatically. - Keep pricing current per Cost-Aware Router —
get_model_pricing()pulls live per-1M rates fromGET /api/v1/models, andcheapest_model_for_task()selects under context/tooling constraints. - Log every routing decision (task type, tier, model, cost) and tune per Error Handling and Enterprise Considerations — escalate the tier on quality regressions and cap per-request cost with
max_tokens.