Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Is that skill safe to install?
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
Are you the author of Openrouter?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ashish7802-openrouter)
# OpenRouter API Skill
> **Verification Tier:** `code_example_tested` | **Last Verified:** 2026-11-18
> **Official Docs:** https://openrouter.ai/docs/quickstart
## Overview
OpenRouter provides a single OpenAI-compatible API (`https://openrouter.ai/api/v1`) and official `@openrouter/sdk` to route requests across multiple LLM providers with automatic failover, provider preferences, and unified billing.
## Installation
```bash
npm install @openrouter/sdk
# Or OpenAI-compatible client:
npm install openai
```
## Authentication
Send `Authorization: Bearer <OPENROUTER_API_KEY>` (keys start with `sk-or-v1-`). Optionally include `HTTP-Referer` (your app URL) and `X-OpenRouter-Title` (your app name) for attribution on OpenRouter rankings.
```bash
export OPENROUTER_API_KEY="sk-or-v1-..."
```
## Core Concepts
- **Provider routing & fallbacks**: Pass `models: ["primary/model", "backup/model"]` to fall back automatically when an upstream provider returns errors or rate limits.
- **Key & credit inspection**: Call `GET https://openrouter.ai/api/v1/key` to monitor remaining credit limits and rate-limit quota programmatically.
- **Data policy controls**: Use `provider: { data_collection: "deny" }` when zero-data-retention providers are required.
## Error Handling & Rate Limits
- Free-tier (`:free`) models are strictly rate-limited (e.g., 20 RPM and daily caps). Paid credits scale by account balance.
- Handle HTTP `402` (insufficient credits — do not retry blindly), `403` (moderation/policy), `429` (rate limit — respect backoff), and `502/503` (upstream provider outage — trigger fallback model).
## Security Best Practices
- Enforce per-key spending limits in the OpenRouter dashboard or via Provisioning Keys.
- Never expose `OPENROUTER_API_KEY` in frontend apps; proxy via backend endpoints.
## AI Pitfalls
- Omitting `https://openrouter.ai/api/v1` baseURL when using the OpenAI SDK.
- Retrying HTTP `402 Payment Required` in an infinite loop.
- Assuming all routed models share identical context limits or JSON-mode behavior without checking `provider` constraints.
## Production Checklist
- [ ] API key has an explicit spend cap configured
- [ ] `HTTP-Referer` and `X-OpenRouter-Title` headers set for observability
- [ ] Fallback model list configured for critical paths
- [ ] Distinct handling for `402`, `429`, and `5xx` responses
## References
- [OpenRouter Quickstart](https://openrouter.ai/docs/quickstart)
- [OpenRouter Errors & Rate Limits](https://openrouter.ai/docs/api-reference/limits)
## Related skills
- [`openai`](../openai/SKILL.md) — alternative to
- [`langfuse`](../langfuse/SKILL.md) — works well with
- [`vercel-ai-sdk`](../vercel-ai-sdk/SKILL.md) — integrates with