openrouter-fallback-config
Installation
SKILL.md
OpenRouter Fallback Config
Overview
OpenRouter supports native model fallbacks: pass multiple model IDs and OpenRouter tries each in order until one succeeds. You can also use provider.order to control which provider serves a specific model. This skill covers native fallbacks, provider routing, client-side fallback chains, and timeout configuration.
Prerequisites
- An OpenRouter API key (
sk-or-v1-...) exported asOPENROUTER_API_KEY— see theopenrouter-install-authskill for setup - Python 3.8+ with the OpenAI SDK (
pip install openai) for the fallback patterns;curlandjqfor the Testing Fallbacks step - A ranked list of acceptable models for your workload, matched by capability (tool calling, vision, context length) so a fallback never silently drops a feature you depend on
Instructions
- Start with Native Model Fallback (Server-Side): pass a
modelsarray plusroute: "fallback"inextra_bodyand let OpenRouter try each model in order. - Log
response.modelafter every call — it tells you which model actually served the request, which is how you detect that a fallback fired. - If you need the same model from specific vendors (e.g., Claude via Anthropic direct vs AWS Bedrock), use Provider Fallback with
provider.orderandallow_fallbacks. - For per-model timeouts and custom error handling, implement the Client-Side Fallback Chain:
resilient_completion()walksFALLBACK_CHAIN(primary → secondary → budget-fallback → last-resort) and raises once every entry fails. - Pick chains per feature with Fallback with Capability Matching —
CAPABILITY_CHAINSkeeps tool-calling, vision, long-context, and budget workloads on models that actually support them. - Verify the behavior with Testing Fallbacks: send the curl request with an invalid primary model and confirm the response comes back from
openai/gpt-4o-mini.