Agent skill · software engineering · jeremylongshore
openrouter-sdk-patterns
Build reusable OpenRouter client wrappers with retries, typing, and
Why this skill is useful
Provides specific patterns and reusable client wrappers for the OpenRouter SDK that enhance the AI's ability to generate production-grade client libraries.
What it needs
Requires python, requests 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 SDK Patterns Overview Build production-grade OpenRouter client wrappers using the OpenAI SDK. The OpenAI Python/TypeScript SDKs work natively with OpenRouter by changing baseurl 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 as OPENROUTERAPIKEY — see the openrouter-install-auth skill for setup Python 3.8+ with the OpenAI SDK plus requests (used for the /auth/key credits check and /generation cost lookups), or Node.js 18+ with the OpenAI SDK Optional: tenacity if you want the custom retry decorator beyond the SDK's built-in backoff An app name and URL to send as HTTP-Referer / X-Title default headers for dashboard attribution Instructions 1. Start from the Python: Production Client Wrapper (or the TypeScript variant): point the OpenAI SDK at baseurl="https://openrouter.ai/api/v1", read OPENROUTERAPIKEY from the environment, and set the HTTP-Referer / X-Title default headers in the constructor. 2. Return typed results from every call — the CompletionResult dataclass/interface captures content, the served model, prompttokens/completiontokens, generationid, and latencyms. 3. Tune the SDK's built-in retries per the Retry Strategy section (maxretries, timeout in the constructor); add the tenacity decorator only when you need retry behavior beyond the SDK's 429/5xx/connection handling. 4. Layer cross-cutting concerns via the Middleware Pattern — withcosttracking queries GET /api/v1/generation?id= after each request and accumulates a session cost total. 5. Surface remaining credits and rate limits with checkcredits(), which calls GET /api/v1/auth/key with the same key. 6. Map SDK exceptions using the Error Handling table, then apply the Enterprise Considerations (single central wrapper, dependency injection for tests, SLA-based maxretries). …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills jeremylongshore/openrouter-sdk-patterns