From jr-agent-skills
OpenRouter API integration for unified access to 400+ LLM models from 70+ providers. Use when building applications that need to call OpenRouter's API for chat completions, streaming, tool calling, structured outputs, or model routing. Triggers on OpenRouter, model routing, multi-model, provider fallbacks, or when users need to access multiple LLM providers through a single API.
How this skill is triggered — by the user, by Claude, or both
Slash command
/jr-agent-skills:openrouter-apiThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
OpenRouter provides a unified API to access 400+ models from 70+ providers (OpenAI, Anthropic, Google, Meta, Mistral, etc.) through a single OpenAI-compatible interface.
OpenRouter provides a unified API to access 400+ models from 70+ providers (OpenAI, Anthropic, Google, Meta, Mistral, etc.) through a single OpenAI-compatible interface.
// Using fetch
const response = await fetch("https://openrouter.ai/api/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": `Bearer ${OPENROUTER_API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "openai/gpt-5.2",
messages: [{ role: "user", content: "Hello!" }]
})
});
// Using OpenAI SDK (Python)
from openai import OpenAI
client = OpenAI(base_url="https://openrouter.ai/api/v1", api_key=OPENROUTER_API_KEY)
response = client.chat.completions.create(
model="openai/gpt-5.2",
messages=[{"role": "user", "content": "Hello!"}]
)
Models use provider/model-name format: openai/gpt-5.2, anthropic/claude-sonnet-4.5, google/gemini-3-pro
Append suffixes to modify behavior:
:thinking - Extended reasoning:free - Free tier (rate limited):nitro - Speed-optimized:extended - Larger context:online - Web search enabled:exacto - Tool-calling optimizedExample: openai/gpt-5.2:online, deepseek/deepseek-r1:thinking
Control which providers serve your requests:
{
model: "anthropic/claude-sonnet-4.5",
provider: {
order: ["Anthropic", "Amazon Bedrock"], // Preference order
allow_fallbacks: true, // Enable backup providers
sort: "price", // "price" | "throughput" | "latency"
data_collection: "deny", // Privacy control
zdr: true // Zero Data Retention
}
}
Specify backup models:
{
models: ["anthropic/claude-sonnet-4.5", "openai/gpt-5.2", "google/gemini-3-pro"]
}
const response = await fetch(url, {
body: JSON.stringify({ ...params, stream: true })
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
// Parse SSE: "data: {...}\n"
const data = JSON.parse(chunk.slice(6));
console.log(data.choices[0]?.delta?.content);
}
const response = await fetch(url, {
body: JSON.stringify({
model: "openai/gpt-5.2",
messages: [{ role: "user", content: "What's the weather in NYC?" }],
tools: [{
type: "function",
function: {
name: "get_weather",
description: "Get weather for a location",
parameters: {
type: "object",
properties: { location: { type: "string" } },
required: ["location"]
}
}
}]
})
});
// Handle tool_calls in response, execute locally, return results
{
response_format: {
type: "json_schema",
json_schema: {
name: "response",
strict: true,
schema: {
type: "object",
properties: {
answer: { type: "string" },
confidence: { type: "number" }
},
required: ["answer", "confidence"],
additionalProperties: false
}
}
}
}
// Using plugin
{ plugins: [{ id: "web", max_results: 5 }] }
// Or model suffix
{ model: "openai/gpt-5.2:online" }
{
model: "deepseek/deepseek-r1:thinking",
reasoning: {
effort: "high", // xhigh, high, medium, low, minimal, none
summary: "concise" // auto, concise, detailed
}
}
For detailed API documentation, read the appropriate reference file:
| Parameter | Type | Description |
|---|---|---|
model | string | Model ID (e.g., openai/gpt-5.2) |
messages | Message[] | Conversation history |
stream | boolean | Enable streaming |
max_tokens | number | Max completion tokens |
temperature | number | Randomness [0-2] |
tools | Tool[] | Function definitions |
response_format | object | Output format control |
provider | object | Routing preferences |
plugins | Plugin[] | Enable plugins |
// Check response status
if (!response.ok) {
const error = await response.json();
// error.error.code: 400, 401, 402, 403, 429, 502, 503
// error.error.message: Human-readable error
}
Key status codes:
401 - Invalid API key402 - Insufficient credits429 - Rate limited502 - Provider error503 - No available providerSearches MemPalace before answering questions about past work, people, projects, or prior decisions. Returns verbatim stored content instead of guessing from model memory.
Guides Payload CMS config (payload.config.ts), collections, fields, hooks, access control, APIs. Debugs validation errors, security, relationships, queries, transactions, hook behavior.
Implements vector databases with Pinecone, Weaviate, Qdrant, Milvus, pgvector for semantic search, RAG, recommendations, and similarity systems. Optimizes embeddings, indexing, and hybrid search.
npx claudepluginhub jrajasekera/jr-agent-skills --plugin jr-agent-skills