openrouter-sdk-patterns
Skill by jeremylongshore
Builds reusable OpenRouter client wrappers with retries, typing, and middleware. It is for developers creating SDKs or client libraries that call OpenRouter.
Install openrouter-sdk-patterns
Built from the published package, never by AI.
git clone --depth 1 https://github.com/jeremylongshore/tons-of-skills-marketplace /tmp/tons-of-skills-marketplace && mkdir -p ~/.claude/skills && cp -r /tmp/tons-of-skills-marketplace/skills/.curated/openrouter-sdk-patterns ~/.claude/skills/openrouter-sdk-patternsRun in your terminal. Claude Code loads skills from ~/.claude/skills automatically.
Step-by-step: install openrouter-sdk-patterns in Claude Code
git clone --depth 1 https://github.com/jeremylongshore/tons-of-skills-marketplace /tmp/tons-of-skills-marketplace && mkdir -p ~/.gemini/antigravity-cli/skills && cp -r /tmp/tons-of-skills-marketplace/skills/.curated/openrouter-sdk-patterns ~/.gemini/antigravity-cli/skills/openrouter-sdk-patternsAntigravity CLI loads skills from ~/.gemini/antigravity-cli/skills, or .agents/skills for one project.
Step-by-step: install openrouter-sdk-patterns in Antigravity CLI
Skills can run scripts on your machine. Some need an API key: check the README.
About
OpenRouter SDK Patterns is an agent skill for building reusable OpenRouter client wrappers. It explains how to point the OpenAI Python or TypeScript SDK at the OpenRouter base URL, read the API key from OPENROUTER_API_KEY, and set attribution headers. The skill includes a Python production-style wrapper and a TypeScript variant.
The wrapper returns a typed CompletionResult with content, the served model, token counts, generation ID, and latency. The skill covers retry settings through the SDK's built-in backoff, an optional tenacity decorator, a cost-tracking middleware that queries the generation endpoint, and a credits check against the auth key endpoint. It also maps common SDK exceptions. It is aimed at developers creating SDKs or client libraries that call OpenRouter.
Written from the project's SKILL.md and checked against it.
What it can do
- Python client wrapperWraps the OpenAI SDK with the OpenRouter base URL and attribution headers.
- TypeScript client wrapperProvides an equivalent OpenRouter wrapper built on the OpenAI TypeScript SDK.
- Typed resultsReturns a CompletionResult with content, model, token counts, generation ID, and latency.
- Retry configurationTunes built-in retries for 429, 5xx, and connection errors through max_retries and timeout.
- Custom retriesAdds an optional tenacity decorator for retry behavior beyond the SDK defaults.
- Cost tracking middlewareQueries the generation endpoint after each request and keeps a session cost total.
- Credits checkCalls the auth key endpoint to report remaining credits and rate limits.
- Error mappingMaps AuthenticationError, RateLimitError, APITimeoutError, and BadRequestError to fixes.
- Response cachingCaches deterministic completions when temperature is 0 and caching is enabled.
What you need
- OpenRouter API key
- Python 3.8+ with the OpenAI SDK and requests, or Node.js 18+ with the OpenAI SDK
- Optional tenacity package for custom retries
Try asking
- Build a typed OpenRouter client wrapper with retries for my app
- Add cost tracking middleware to my OpenRouter calls
- Show me how to check my OpenRouter credits with the auth key endpoint
Good to know
- Code examples cover Python and TypeScript only.
- Cost tracking makes an extra request to the generation endpoint for each call.
- Caching applies only when temperature is 0.
Security check
B- Allowed to use Write, Edit without limitsIn
SKILL.md
Checked automatically: skills/.curated/openrouter-sdk-patterns/SKILL.md. This looks for known risky patterns and is not a full audit. How grades work
Inside the skill
Allowed tools: ReadWriteEditGrepBash(python3:*)Bash(node:*)
Alternatives to openrouter-sdk-patterns
All alternatives →Runs a 7-stage workflow for auditing, cleaning up and reviewing GitHub repositories, plus competitor analysis. Written for developers who want a repo checked for secrets, junk files and documentation gaps.
Teaches an AI assistant to build, debug and explain Gradio web UIs and ML demos in Python. It covers the core API, components, event listeners, layouts and the MCP server option. Aimed at Python developers who work with Gradio.
Recommends menus, buttons, toolbars and disclosure controls for Apple platforms using Human Interface Guidelines conventions. Built for developers and designers making iOS, iPadOS, macOS or visionOS interfaces. Checks existing project design context before asking questions.
Creates production-ready FastAPI project structures with async patterns, dependency injection, and error handling. It is for developers starting new FastAPI applications or backend API projects.
Analyzes Android apps to find user workflows to expose as AppFunctions, so AI agents and system shortcuts can run them without opening the app UI. Generates Kotlin code and refines KDoc for Android developers.
Creates, edits, validates and runs Agent QA tests, suites and hooks through MCP or CLI. It keeps canonical IDs and schema contracts intact, for developers and QA teams using Agent QA.
Compare with openclaw-github-repo-commander, gradio or hig-components-menus
openrouter-sdk-patterns: common questions
Does this skill require a separate OpenRouter SDK?
No. The source says the OpenAI Python and TypeScript SDKs work with OpenRouter by changing base_url to https://openrouter.ai/api/v1.
How does the wrapper handle rate limits?
The OpenAI SDK retries 429, 5xx, and connection errors with backoff, and respects the Retry-After header. The source suggests increasing max_retries for RateLimitError.
How is cost tracked per request?
A middleware function queries GET /api/v1/generation?id= after each request and adds the total_cost value to a running session total.
How do I install openrouter-sdk-patterns?
Run the command above to copy the skill into ~/.claude/skills/. Claude Code picks it up automatically.
Is openrouter-sdk-patterns free?
The code is published under the MIT licence. The service it connects to may have its own pricing.
Is openrouter-sdk-patterns safe to use?
It scores 76 of 100. Grades: maintenance A, licence A, quality A. Security check: grade B (allowed to use write, edit without limits). Review the code before you install. How grades work.
What are alternatives to openrouter-sdk-patterns?
Similar skills: openclaw-github-repo-commander, gradio, hig-components-menus, fastapi-templates.
