Skip to content
Back to skills

Openrouter

ASecurity

> **Verification Tier:** `code_example_tested` | **Last Verified:** 2026-11-18 > **Official Docs:** https://openrouter.ai/docs/quickstart

  • 13 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 2, 2026
ai-agentsbashapifrontendbackendsecurity

Works with

  • cli
  • api

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro scans all 2 files and shows the line behind each finding

Scanned December 2, 2026

npx -y skills add ashish7802/awesome-api-skills --skill openrouter --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Openrouter?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Openrouter
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ashish7802-openrouter/badge)](https://www.skillsdirectory.com/skills/ashish7802-openrouter)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# 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

Files in this skill

  • SKILL.md2.7 KB
  • examples/quickstart.ts1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.