Docs · Provider

Anthropic in Claude Code, Codex, Gemini CLI and OpenCode

Anthropic serves Claude on its Messages API, at api.anthropic.com. Add an Anthropic API key to magpie once, and Claude Code, Codex, Gemini CLI, OpenCode and every other agent you connect can use Claude models through magpie’s local gateway at 127.0.0.1:3425, each agent with a model of its own. Agents that speak another API are translated on the way.

Add Anthropic

  1. Get a keyMake one on console.anthropic.com. An API key starts with sk-ant-api.
  2. Add the providerIn magpie’s Providers tab, press + Add provider, pick Anthropic, paste the key and save. magpie asks Anthropic which models the key can use.
  3. Pick it for an agentIn the Agents tab, click the model on the agent’s row and choose a Claude model such as claude-opus-5-5.
Terminal
magpie provider add anthropic <key>
magpie provider test anthropic

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

Already set Anthropic up in OpenCode or Alma? magpie’s import from those apps brings it in as the Anthropic provider.

This page is about an API key. A Claude Pro or Max subscription is signed in to separately; see Subscriptions in any agent.

Endpoints

APIAddressUsed for
Messageshttps://api.anthropic.com/v1/messagesevery agent’s requests: Claude Code’s as sent, Codex’s, Gemini CLI’s and OpenCode’s translated
Modelshttps://api.anthropic.com/v1/modelsthe model list

magpie’s Anthropic provider has no Chat Completions or Responses address, so an agent that speaks either, or Google’s Gemini API, is translated to Messages and the reply translated back, streaming and tool calls included.

Model list

magpie fetches the list from Anthropic, at https://api.anthropic.com/v1/models, every page of it, so agents see the models your key can use. Names, context windows and prices come from models.dev’s anthropic catalog. Pick the models agents see in the provider’s model list, or from the terminal:

Terminal
magpie provider models anthropic +claude-opus-5-5 +claude-sonnet-5-5 +claude-haiku-5-5
magpie provider refresh-every anthropic 1d

Claude Opus 5.5, Sonnet 5.5 and Haiku 5.5 take 1M tokens. On a window that long, Codex compacts a conversation at 272K rather than send ever more of it on every turn; magpie model compact off lets it run to the whole window. In Claude Code a Claude model runs to its own window, as Anthropic runs it: 200K unless a [1m] one is picked.

In each agent

Terminal
magpie claude anthropic/claude-opus-5-5
magpie codex anthropic/claude-opus-5-5
magpie gemini model anthropic/claude-sonnet-5-5
magpie opencode anthropic/claude-sonnet-5-5

What magpie does for Anthropic

A request magpie translates is built the way Anthropic’s Messages API wants it, and a few things Anthropic would refuse are fixed on Claude Code’s requests too:

Reasoning

Anthropic searches the web itself. Claude Code’s WebSearch goes to Anthropic as it is. When Codex, Gemini CLI or a Chat client asks to search, magpie offers Claude Anthropic’s own web_search_20250305 tool, up to five searches a request, rather than magpie’s searcher.

Cost and usage

Several keys and failover

One Anthropic 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.

Terminal
magpie provider spend-cap anthropic <key> 20 month
magpie provider key-balance anthropic <key> 25
magpie provider fallback anthropic deepseek/deepseek-v4-pro
magpie provider add anthropic <key> id=anthropic-ws2 name="Anthropic WS2" header.anthropic-workspace-id=wrkspc_…

Troubleshooting

FAQ

How do I use an Anthropic API key in Claude Code?

Add your Anthropic API key in magpie (Providers, Add provider, Anthropic), then pick a Claude model such as claude-opus-5-5 on Claude Code’s row, or run magpie claude anthropic/claude-opus-5-5. Claude Code speaks Anthropic Messages, so its requests go to https://api.anthropic.com as it sent them, with what the model would refuse fixed on the way.

Can Codex use Claude models?

Yes. Codex speaks OpenAI Responses, which Anthropic doesn’t serve, so magpie translates each request to the Messages API and the reply back. It marks the prompt for Anthropic’s cache with marks that last an hour, and keeps Claude’s signed thinking across a tool loop in Codex’s encrypted_content. Run magpie codex anthropic/claude-opus-5-5.

How do I use Claude in OpenCode through magpie?

Pick the model in magpie, or run magpie opencode anthropic/claude-sonnet-5-5. OpenCode speaks Chat Completions to magpie, so magpie translates its requests to Anthropic’s Messages API, marks the prompt for the cache and fits the reasoning effort to the model.

Can Gemini CLI use Claude?

Yes. Gemini CLI speaks Google’s Gemini API, so magpie translates its requests to Anthropic’s Messages API and the replies back, streaming and tool calls included. Run magpie gemini model anthropic/claude-sonnet-5-5.

Does magpie keep Anthropic’s prompt cache for agents it translates?

Yes. A request from Codex, Gemini CLI or OpenCode has no cache marks of its own, so magpie marks the system prompt and the conversation’s last block, two marks at most, and the next turn reads what came before from the cache. A request that brings its own cache_control keeps its marks. Codex’s marks last an hour, the rest five minutes.

Why does Claude answer 400 when thinking is turned off?

Newer Claude models don’t all take thinking disabled. magpie sends Sonnet 5.5 between_tools, leaves thinking out for Opus 5.5 and Fable 5, which always think, and asks Opus 5 and Haiku 5.5 at high in place of xhigh or max. Older Claudes get it as sent.

By provider: DeepSeek · Kimi and Kimi Code · GLM Coding Plan · Qwen · MiniMax · OpenAI · Gemini · Grok · Mistral · OpenRouter · 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.