openrouter-sdk-patterns
Installation
SKILL.md
OpenRouter SDK Patterns
Overview
Build production-grade OpenRouter client wrappers using the OpenAI SDK. The OpenAI Python/TypeScript SDKs work natively with OpenRouter by changing base_url to https://openrouter.ai/api/v1. This skill covers typed wrappers, retry strategies, middleware, and reusable patterns.
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 plus
requests(used for the/auth/keycredits check and/generationcost lookups), or Node.js 18+ with the OpenAI SDK - Optional:
tenacityif you want the custom retry decorator beyond the SDK's built-in backoff - An app name and URL to send as
HTTP-Referer/X-Titledefault headers for dashboard attribution