From openrouter
Invoke OpenRouter CLI for chat completions, embeddings, rerank, video generation, API key management, model browsing, credits checks, and scripted LLM calls with stable JSON output from shell, scripts, and agents.
npx claudepluginhub mrgoonie/openrouter-cli --plugin openrouterThis skill uses the workspace's default tool permissions.
Practical instructions for driving `openrouter` (the `@mrgoonie/openrouter-cli` binary) from Claude Code. This skill handles CLI invocation, JSON envelopes, config resolution, and agent-safe workflows. Does NOT handle: direct HTTP calls to `openrouter.ai`, non-OpenRouter providers, or CLI source-code changes (use repo docs for that).
Sets up OpenRouter API keys for Python and Node.js OpenAI clients, configures environment, verifies authentication, checks credits, and tests requests.
Integrates TypeScript apps with OpenRouter's 300+ AI models via SDK packages for callModel agents, tools, streaming, OAuth, and API key management.
Integrates TypeScript apps with 300+ AI models via OpenRouter SDK using callModel for text generation, tools, streaming, and multi-turn conversations. Useful for AI agents.
Share bugs, ideas, or general feedback.
Practical instructions for driving openrouter (the @mrgoonie/openrouter-cli binary) from Claude Code. This skill handles CLI invocation, JSON envelopes, config resolution, and agent-safe workflows. Does NOT handle: direct HTTP calls to openrouter.ai, non-OpenRouter providers, or CLI source-code changes (use repo docs for that).
sk-or-v1-… as secret.auth set-key or env var — do NOT write it into tracked files.Pick one:
brew install openrouter/tap/openrouter # macOS / Linux
curl -fsSL https://raw.githubusercontent.com/mrgoonie/openrouter-cli/main/install.sh | sh
npm install -g @mrgoonie/openrouter-cli # npm
Verify: openrouter --version && openrouter --help.
openrouter auth login (PKCE flow, stores key in OS keychain).openrouter auth set-key sk-or-v1-....export OPENROUTER_API_KEY=sk-or-v1-....credits, keys, guardrails, org) need a separate key:
export OPENROUTER_MANAGEMENT_KEY=sk-or-v1-... OR openrouter auth set-key <key> --management.Check resolution: openrouter auth status and openrouter config doctor --json.
--api-key, --model, --base-url, --timeout)OPENROUTER_API_KEY, OPENROUTER_MANAGEMENT_KEY, OPENROUTER_BASE_URL).env file (searched from cwd upward)~/.config/openrouter/config.toml)Set persistent defaults: openrouter config set defaults.model openai/gpt-4o.
--json to every command so output is a stable envelope:
{"schema_version":"1","success":true,"data":{...},"error":null,"meta":{"request_id":"gen-...","elapsed_ms":312}}
--no-stream when you need a single blocking response (safe for parsing).--output ndjson for streaming where each line is a parseable JSON object.$? after every call — exit codes are stable across patch versions.| Code | Meaning | Handling |
|---|---|---|
| 0 | Success | parse data |
| 1 | Unexpected error | log error.message, retry once |
| 2 | Bad flags / args | fix invocation, do NOT retry |
| 64 | API key not set | prompt user for auth set-key |
| 65 | Unauthorized (401) | key invalid → rotate |
| 66 | Forbidden (403) | wrong scope (need --management?) |
| 67 | Not found (404) | check model/ID slug |
| 68 | Insufficient credits (402) | openrouter credits show |
| 69 | Rate limited (429) | backoff; client already retries 3× w/ exp |
| 70 | Server error (5xx) | retry with jitter |
| 71 | Request timeout | raise --timeout |
| 72 | Unexpected API response shape | report bug |
| 73 | Async video job failed | inspect error in envelope |
openrouter chat send "Summarize the following." \
--model openai/gpt-4o --json --no-stream <<< "$(cat document.txt)"
Parse data.choices[0].message.content. Log meta.request_id for tracing.
openrouter chat send "Write a haiku about Bun" \
--model openai/gpt-4o --output ndjson
Consume line-by-line; each token chunk is one JSON object.
openrouter embeddings create "hello world" \
--model openai/text-embedding-3-small --json
openrouter rerank create \
--query "What is Bun?" \
--documents "Bun is a JS runtime." --documents "Python is a language." \
--model cohere/rerank-english-v3.0 --json
openrouter models list --json | jq '.data[] | select(.pricing.prompt=="0") | .id'
openrouter credits show --json
openrouter keys list --json
openrouter keys create --name "ci-bot" --limit 5 --json
JOB=$(openrouter video create "cat surfing" --model some/video-model --json | jq -r .data.id)
openrouter video wait "$JOB" --json # blocks until terminal state
openrouter video download "$JOB" -o out.mp4
video wait exits 73 on failure/cancel — always check $?.
openrouter config doctor --json # shows resolved sources per key
openrouter auth whoami --json # live API check
--json.$? — a 200-shaped body with success:false still means failure.chat send without --model — no default unless set in TOML config.--timeout — default may be too short for large outputs.credits/keys/guardrails — exit 64/66; needs --management key.| User intent | Command |
|---|---|
| "chat with gpt-4o" | openrouter chat send "<msg>" --model openai/gpt-4o --json |
| "stream a response" | add --output ndjson (drop --no-stream) |
| "what models are free?" | openrouter models list --json | jq '.data[] | select(.pricing.prompt=="0")' |
| "embed this text" | openrouter embeddings create "<text>" --model openai/text-embedding-3-small --json |
| "how many credits left?" | openrouter credits show --json (needs management key) |
| "set default model" | openrouter config set defaults.model <slug> |
| "why is my key not working?" | openrouter config doctor --json && openrouter auth whoami |
| "generate a video" | see workflow 7 (create → wait → download) |
| "list my api keys" | openrouter keys list --json (needs management key) |
| "rerank these docs" | see workflow 4 |
references/command-reference.md — full command/flag matrix.references/agent-json-mode.md — JSON envelope schema + NDJSON parsing patterns.references/chat-workflows.md — multi-turn, stdin piping, tool calling recipes.