Implement common SDK usage patterns for OpenRouter. Use when building reusable client libraries or wrappers. Trigger with phrases like 'openrouter sdk', 'openrouter client library', 'openrouter wrapper', 'openrouter patterns'.
Scanned 9/10/2026
Install to Claude Code
npx -y skills add micsapp/micstec-skills --skill openrouter-sdk-patterns --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Openrouter Sdk Patterns?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/micsapp-openrouter-sdk-patterns)More formats (shields.io, HTML) on the badges page.
---
name: openrouter-sdk-patterns
description: |
Implement common SDK usage patterns for OpenRouter. Use when building reusable client libraries or wrappers. Trigger with phrases like 'openrouter sdk', 'openrouter client library', 'openrouter wrapper', 'openrouter patterns'.
allowed-tools: Read, Write, Edit, Grep
version: 1.0.0
license: MIT
author: Jeremy Longshore <jeremy@intentsolutions.io>
compatible-with: claude-code, codex, openclaw
---
# Openrouter SDK Patterns
## Overview
This skill covers best practices for building OpenRouter client wrappers, including retry logic, error handling, response typing, and reusable patterns.
## Prerequisites
- OpenRouter integration
- OpenAI SDK (Python or TypeScript)
## Instructions
1. **Create a typed client wrapper**: Build a class that wraps the OpenAI SDK with OpenRouter-specific defaults (base URL, default headers, retry config)
2. **Add automatic retries**: Implement retry logic with exponential backoff for 429 and 5xx errors; the OpenAI SDK has built-in retry support via `max_retries`
3. **Type your responses**: Define TypeScript interfaces or Python dataclasses for your expected response shapes to catch errors at compile time
4. **Implement request/response middleware**: Add hooks for logging, cost tracking, and metrics collection that run on every request
5. **Build reusable prompt templates**: Create typed functions for common tasks (summarize, translate, classify) that encapsulate model selection and prompt engineering
## Output
- A reusable OpenRouter client class with built-in retry, logging, and typing
- Prompt template functions for common AI tasks
- Middleware pipeline for cross-cutting concerns (logging, cost tracking)
## Error Handling
| Error | Cause | Fix |
|-------|-------|-----|
| Type mismatch on response | Model returned unexpected format | Add runtime validation alongside static types; handle gracefully |
| Retry exhaustion | Max retries exceeded on persistent errors | Log the final error with full context; surface to caller with actionable message |
| Middleware error | Logging or metrics code threw an exception | Wrap middleware in try/catch so it never breaks the main request flow |
See `${CLAUDE_SKILL_DIR}/references/errors.md` for full error reference.
## Examples
See `${CLAUDE_SKILL_DIR}/references/examples.md` for runnable code samples.
## Resources
- [OpenRouter Documentation](https://openrouter.ai/docs)
- [OpenRouter Models](https://openrouter.ai/models)
- [OpenRouter API Reference](https://openrouter.ai/docs/api-reference)
- [OpenRouter Status](https://status.openrouter.ai)

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!