Docs · Provider

OpenRouter in Claude Code, Codex, Gemini CLI and OpenCode

OpenRouter sells many vendors’ models behind one key and serves them on OpenAI Chat Completions and Anthropic Messages. Add the key to magpie once, and Claude Code, Codex, Gemini CLI, OpenCode and every other agent you connect can use any OpenRouter model through magpie’s gateway at 127.0.0.1:3425, each agent on a model of its own.

Add OpenRouter

  1. Get a keyMake one on openrouter.ai/keys.
  2. Add the providerIn magpie’s Providers tab, press + Add provider, pick OpenRouter, paste the key and save. magpie asks OpenRouter which models it serves.
  3. Pick it for an agentIn the Agents tab, click the model on the agent’s row and choose an OpenRouter model such as anthropic/claude-opus-5.5.
Terminal
magpie provider add openrouter sk-…
magpie provider test openrouter

Model ids in magpie are provider/model, so OpenRouter’s read openrouter/anthropic/claude-opus-5.5: the provider, then OpenRouter’s own id. The key is kept in magpie’s settings; magpie doesn’t take it from your shell.

OpenRouter documents two optional headers that credit an app in its rankings, HTTP-Referer and X-OpenRouter-Title. magpie doesn’t send them. The provider editor’s Headers field offers them if you want your requests credited.

Endpoints

APIBase URLUsed for
Chat Completionshttps://openrouter.ai/api/v1the model list, requests to non-Claude models, image models
Anthropic Messageshttps://openrouter.ai/apiClaude Code’s requests, and Claude models from any agent
Decisionshttps://openrouter.ai/api/v1decision models for intent routing

magpie doesn’t use OpenRouter’s Responses API. An agent that speaks Responses, such as Codex, is translated to one of the two above.

Model list

Terminal
magpie provider models openrouter +anthropic/claude-opus-5.5   # expose one more
magpie provider models openrouter best                          # newest of each family
magpie provider auto-include openrouter '*:free'               # every free model, now and later
magpie provider refresh-every openrouter 1d

In each agent

Pick the model on an agent’s row in the Agents tab, or from a terminal. Each guide says what magpie writes in that agent’s config and how to switch back.

Terminal
magpie claude openrouter/anthropic/claude-opus-5.5
magpie codex openrouter/anthropic/claude-opus-5.5
magpie gemini model openrouter/google/gemini-3-pro
magpie opencode openrouter/anthropic/claude-opus-5.5

If OpenRouter says a model isn’t served on the endpoint magpie chose, magpie builds the request again for the other one and remembers that for the model.

Reasoning

Cache, cost and credits

Several keys and free models

One OpenRouter provider can hold several keys: press Add another key under it, or paste several at once. Requests go to the first key that’s on, and when it runs out or is rate limited the next one takes over. The provider’s routing can also rotate, weight or drain them instead. Adding the preset again makes a second OpenRouter provider; to spread requests over several keys, add them all to the one provider.

Terminal
magpie provider rpm openrouter 20
magpie provider spend-cap openrouter <key> 20 month
magpie provider fallback openrouter deepseek/deepseek-v4-pro
magpie group add my-free-pool models='openrouter/*:free' routing=order
magpie group set opus-anywhere stays=session models+=openrouter/anthropic/claude-opus-5.5

Troubleshooting

FAQ

How do I use OpenRouter in Claude Code?

Add your OpenRouter key in magpie (Providers, Add provider, OpenRouter), then pick a model such as anthropic/claude-opus-5.5 on Claude Code’s row, or run magpie claude openrouter/anthropic/claude-opus-5.5. magpie writes Claude Code’s settings.json and passes its requests on to OpenRouter’s Anthropic endpoint as they are.

Can Codex use OpenRouter models?

Yes. Codex speaks only the Responses API, which magpie doesn’t use at OpenRouter. magpie translates each Codex request: a Claude model goes to OpenRouter’s Anthropic endpoint and every other model to Chat Completions, and the reply comes back to Codex as Responses.

Can Gemini CLI and OpenCode use OpenRouter?

Yes. Gemini CLI’s requests are translated the same way as Codex’s. OpenCode speaks Chat Completions, so its requests go to OpenRouter as they are, except for Claude models, which magpie sends to the Anthropic endpoint so the prompt cache works.

How do I use only OpenRouter’s free models?

Make a routing group from the pattern openrouter/*:free, for example magpie group add my-free-pool models='openrouter/*:free' routing=order. It takes every free model OpenRouter lists, including ones it lists later. Models priced at $0 show free in magpie’s pickers.

Why do OpenRouter’s free models answer 429?

OpenRouter’s free models take 20 requests a minute. Set magpie provider rpm openrouter 20 and magpie holds requests back to that rate. When the 429 comes from the shared pool of the provider serving one free model, magpie rests only that model and keeps the other free models in use.

Does magpie show my OpenRouter credits?

Yes. magpie reads OpenRouter’s credits endpoint and shows what is left in dollars: total credits less total usage. The figure is for the whole account, so every key of one account shows the same.

Why does magpie fetch OpenRouter’s model list from /api/v1?

Asked at the Anthropic base, OpenRouter answers with its catalog under anthropic/ names it doesn’t serve. magpie fetches the list from the Chat Completions base, https://openrouter.ai/api/v1, and a provider given only OpenRouter’s Anthropic base is told to add that Chat base.

By provider: DeepSeek · Kimi and Kimi Code · GLM Coding Plan · Qwen · MiniMax · Gemini · Grok · Mistral · GitHub Copilot · Ollama

Every agent: Models in Claude Code, Models in Codex, Models in Gemini CLI, Models in OpenCode. Ask on Discord if you get stuck.