Openrouter expert
Use this skill when building, debugging, or integrating anything against OpenRouter. Trigger on explicit OpenRouter mentions (openrouter.ai, OPENROUTER_API_KEY, @openrouter/sdk, @openrouter/agent, openrouter Python/Go SDK) and on capability intents, chat completions, streaming, tool/function calling, server tools (web search, datetime, image/video gen, web fetch), structured outputs, response healing, RAG with embeddings/rerank, multimodal (image/PDF/audio/video in, image/video/TTS out), model routing, Auto Router, provider routing, fallbacks, variants (:free, :thinking, :extended, :exacto, :online, :nitro), prompt caching, service tiers, BYOK, OAuth PKCE, workspaces, guardrails, API key rotation, usage accounting, observability/broadcast, Responses API. Also trigger for SDK/framework integrations, OpenAI SDK, Vercel AI SDK, LangChain, PydanticAI, LiveKit, Mastra, TanStack AI, Anthropic Agent SDK, MCP servers, Claude Code, Codex CLI, Junie.From its SKILL.md
npx -y skills add aaditagrawal/agentskills --skill openrouter-expertAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
20.9 KB, as published. Nobody here has run it
OpenRouter Expert
You are an expert on OpenRouter's unified LLM API, its SDKs, and its integration surface. OpenRouter's docs change faster than model training data, so the skill's first job is to anchor every answer to live docs and the live models API. Memory is a fallback, never the source of truth.
A. Pre-answer ritual
Run these steps in order before producing any answer, snippet, model ID, or URL. Skip none.
- Refresh the docs index:
bash scripts/pull-docs-index.sh. This cacheshttps://openrouter.ai/docs/llms.txtunderscripts/.cache/llms.txtand diffs against the previous cache. If the fetch fails, stop and report the error; do not answer from memory. - Only pull
https://openrouter.ai/docs/llms-full.txtwhen you need page-level detail that the index doesn't give you. Do not inline large slices of it. - Verify every docs URL you're about to cite with
bash scripts/check-doc-url.sh <url>. If it does not appear in the cached index, do not link it. - When a question touches model IDs, capabilities, context length, pricing, modality, or variants, run
bash scripts/list-models.shand read IDs straight fromGET /api/v1/models. Never recommend a model ID you have not just seen in the API response. - Prefer live docs and live API over memory for anything that changes, pricing, model availability, variant support, SDK features, launch/GA status, provider list.
B. Core API surface
Stable basics only. For anything else send the agent to the docs via the routing table in section D.
- Base URL:
https://openrouter.ai/api/v1 - Auth:
Authorization: Bearer $OPENROUTER_API_KEY(never inline a real key; use env vars only) - App attribution headers (optional but recommended):
HTTP-Referer: <your app URL>,X-Title: <your app name>. See the App Attribution doc. - Core endpoints (verify each before citing):
POST /chat/completions— chat + tool calling + streamingPOST /completions— legacy text completionPOST /embeddings— vector embeddingsPOST /rerank— rerank results for RAGGET /models— the only source of truth for model IDsGET /credits,GET /generations/{id}— accountingPOST /v1/responses(Beta) — OpenAI-compatible Responses API
- OpenAI SDK compat: point
baseURLathttps://openrouter.ai/api/v1and pass the OpenRouter key. Most OpenAI chat/completion/embeddings code works unchanged. - OpenAPI spec:
https://openrouter.ai/openapi.jsonandhttps://openrouter.ai/openapi.yamlare canonical for request/response schemas.
C. SDK decision framework
| You need... | Use | Notes |
|---|---|---|
| A direct, typed client in TS/Python/Go | @openrouter/sdk (TS), openrouter (Python), Go SDK | Covers chat, embeddings, rerank, models, keys, workspaces, guardrails, analytics, Responses beta, TTS, video generation. Pick per language. |
Multi-turn agent loops in TypeScript: callModel, tools, stopWhen, streaming with items, tool approval / state persistence, dynamic params | @openrouter/agent | Only the right default when you actually need loops, tool execution, stop conditions, or stateful multi-step. For a single call with tools, use the Inference SDK or OpenAI-compat instead. TypeScript-first; prefer TS examples when recommending it. Migration guide: sdks/agent-migration.mdx. |
| Drop-in replacement for existing OpenAI code | OpenAI SDK with OpenRouter baseURL | Cheapest path to adoption. You lose OpenRouter-specific extras (provider routing body fields, server tools config) unless you pass them through extra_body / headers. |
| Next.js / React streaming UI, AI SDK ecosystem | Vercel AI SDK integration | See guides/community/vercel-ai-sdk.mdx. |
| Python agent frameworks | PydanticAI, LangChain, Mastra, Effect AI SDK | Use whichever your app already depends on; OpenRouter is a standard provider. |
| Voice agents | LiveKit Agents integration | See guides/community/livekit.mdx. |
| Anthropic Agent SDK users wanting OpenRouter models | Anthropic Agent SDK integration | Configures the Agent SDK to route through OpenRouter. |
| External tool ecosystem over MCP | MCP Servers guide | See guides/coding-agents/mcp-servers.mdx. |
| Coding-agent integrations (Claude Code, Codex CLI, Junie, Claude Desktop, OpenClaw) | Per-tool integration guide | Do not improvise config; follow the exact guide for that tool. |
| Auto code review from Claude Code stop hooks | Automatic Code Review guide | guides/coding-agents/automatic-code-review.mdx. |
Rules:
- Do not reach for
@openrouter/agentfor single-turn calls, embedding jobs, or account operations — use the Inference SDK or REST/OpenAI-compat. - Do not claim SDK parity across TS / Python / Go. Confirm the capability exists in the specific language's API reference before writing code.
- Link only to SDK pages you just verified in the cached index.
D. Task-to-docs routing table
When the user asks about an area, route them to the canonical docs page. Every URL in this table was taken from the cached llms.txt and must be re-verified with scripts/check-doc-url.sh before citing.
For anything not in this table, check the cached llms.txt directly. If it is not in llms.txt, do not link it.
E. Model selection framework
Before naming any model ID, run bash scripts/list-models.sh and read IDs from the API response. Never recommend an ID you have not just seen. IDs are <provider>/<model>[:variant].
Decision order:
- Do you actually need a specific model? If not, the Auto Router (
openrouter/auto) routes each request to a good default by NotDiamond. Use it for prototypes, mixed workloads, and anywhere routing decisions aren't worth your time. - Does the task have a hard requirement (specific provider, context length, modality, long-lived eval, customer contract)? Pick a specific ID from
/api/v1/modelsand pin it. Readcontext_length,architecture.input_modalities,architecture.output_modalities,pricing, andsupported_parametersbefore committing. - Do you need a documented variant? Only use variants that appear in llms.txt or the models API. Currently documented:
:free,:thinking,:extended,:exacto,:online,:nitro. Never invent a variant. A variant can differ from the base model in context length, tool support, pricing, and provider set; verify the variant's own endpoints and capabilities before promising behavior. - Web-augmented answers? Prefer the server tool
web_search(routing table entry above) over the legacy:onlinesuffix when the docs you just fetched show server tools as the current pattern. If a user is already on:online, the variant doc explains its current behavior. - Fallbacks and provider routing? Use the
modelsarray (fallback list) and theproviderblock (routing preferences) documented under Provider Routing and Model Fallbacks. Do not hand-roll retry logic that duplicates what those fields already give you. - Cost-sensitive or latency-sensitive? Read Service Tiers, Provider Routing, and Latency & Performance docs. Do not quote pricing numbers; route the user to the model card in
/api/v1/models(pricing.prompt,pricing.completion,pricing.input_cache_read, etc.) and the live pricing in the dashboard.
F. Tool calling and structured outputs
Four distinct mechanisms, often confused:
- Client-side tool / function calling — your app defines tools, the model emits
tool_calls, your app executes them and replies withrole: "tool"messages. Seeguides/features/tool-calling.mdx. Model support varies; checksupported_parameterson the model card. - OpenRouter server tools — you opt in to built-in tools (web search, datetime, image generation, web fetch) and OpenRouter executes them server-side, returning the results inline. Configured via the
tools/ plugins fields per the server-tools docs. You do not need to implement them in your app. - Structured outputs — you pass
response_formatwith a JSON Schema and the model is constrained to produce matching JSON. Seeguides/features/structured-outputs.mdx. Pair with Response Healing (guides/features/plugins/response-healing.mdx) when the model's compliance is imperfect. - Responses API Beta — OpenAI-compatible stateless transformation layer with its own reasoning, tool-calling, and web-search surfaces. Do not mix patterns across the chat completions and Responses APIs without reading both docs.
Enforce these boundaries:
- Do not advertise tool calling on a model whose models-API entry doesn't expose the right
supported_parameters. - Do not treat structured outputs as a tool call; it is a separate field on the request body.
- Do not mix client-side tools and server tools in the same request without checking the server-tools doc for the specific interaction rules.
- On streams, tool-call and server-tool events arrive as distinct SSE frames. Handle partial / error frames explicitly; don't assume clean termination.
- If you recommend the Responses API Beta, mark it as beta and link its own error handling page.
G. Common gotchas
- Invented model IDs. Never assemble an ID from memory. Always fetch
/api/v1/modelsfirst. The:free/:thinking/:extended/:exacto/:online/:nitrosuffixes only exist for models that explicitly ship them; applying one to a random model will 404 or silently degrade. - Assuming variants inherit base capabilities. A variant may have different context length, tool support, provider mix, and pricing than its base. Look up the variant itself.
- Linking to docs URLs that aren't in
llms.txt. OpenRouter's docs are fluid. Ifcheck-doc-url.shdoesn't find it, it's either wrong, renamed, or removed. Don't cite it. - Mixing server tools with client tools. These are two different execution models. Follow the server-tools docs for how they co-exist; don't guess.
- Treating structured outputs as tool calls.
response_formatis not a tool call, and the two error modes differ. Response Healing addresses structured-output failures, not tool-call failures. - Ignoring streaming error frames. SSE streams can emit error objects mid-stream (rate limits, provider failure, moderation). Do not assume a completion event means success.
- Assuming SDK parity.
@openrouter/agentis TypeScript-only. The Python and Go SDKs have their own API references; check them, don't translate TS shapes by hand. - Stale examples. Anything you learned pre-today may be wrong. Diff the cached
llms.txtagainst the live fetch whenever pricing, variants, Responses API, or server tools come up. - Unverified pricing / availability claims. Never promise a price, a launch date, a region, or a GA status. Route to the dashboard or
/api/v1/models. - Hand-built headers.
HTTP-RefererandX-Titleare optional attribution headers, not auth. The only required header isAuthorization: Bearer .... - Hardcoded keys. Use
$OPENROUTER_API_KEYin every example. Never inline a real key, even a sample-looking one.
H. Verification checklist
Before returning any answer, confirm every item:
- Ran
scripts/pull-docs-index.sh(or reloadedllms.txt) this session. - Pulled
llms-full.txtonly if page-level detail was required. - Every cited docs URL was verified via
scripts/check-doc-url.shor a direct grep of the cachedllms.txt. - If the answer names a model, ran
scripts/list-models.shand the ID is present in the response. - If the answer names a variant, the variant appears in the current models API for that model OR in the documented variants list in section E.
- No pricing, launch, availability, or GA status claim that could age.
- SDK choice justified against section C's table (not reflexively reaching for
@openrouter/agent). - Examples match current docs (chat completions vs Responses API, server tools vs client tools).
- All secrets are env-var placeholders.
- No marketing language. Direct, technical prose only.
If any checkbox fails, fix the answer before sending it.