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
- Get a keyMake one on console.anthropic.com. An API key starts with
sk-ant-api. - 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.
- 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.
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
| API | Address | Used for |
|---|---|---|
| Messages | https://api.anthropic.com/v1/messages | every agent’s requests: Claude Code’s as sent, Codex’s, Gemini CLI’s and OpenCode’s translated |
| Models | https://api.anthropic.com/v1/models | the 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:
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
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
- Claude Code speaks Anthropic Messages, so its requests go to Anthropic as Claude Code sent them, its own cache marks, thinking and betas included, with the fixes below. Models in Claude Code.
- Codex speaks OpenAI Responses, which Anthropic doesn’t serve. magpie translates each request to Messages and the reply back, marks the prompt for Anthropic’s cache, and keeps Claude’s signed thinking across a tool loop. Models in Codex.
- Gemini CLI speaks Google’s Gemini API. magpie translates each request to Messages and the reply back. Models in Gemini CLI.
- OpenCode speaks Chat Completions to magpie, so its requests are translated to Messages too. Models in OpenCode.
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:
- Prompt caching. Anthropic caches a prompt only up to a block marked with
cache_control, and a request from another API has no marks. magpie marks the system prompt (or the last tool, when there is no system prompt) and the conversation’s last block, two marks at most, so the next turn reads what came before from the cache. A request that bringscache_controlof its own keeps its marks, and magpie adds none. - An hour’s cache for Codex. Codex’s turns are often more than five minutes apart, so the marks magpie adds to its requests last an hour, unless Codex asks
prompt_cache_retentionin_memory. An upstream that turns the hour’sttlaway is asked again with five-minute marks, and magpie remembers it. - Signed thinking. Claude signs its thinking and wants it back on a tool loop’s next turn. Codex gets each thinking block, signature included, in its reasoning item’s
encrypted_content, and magpie sends it back to Anthropic as it was; redacted thinking goes back sealed. Thinking with no signature is left out, and so is thinking another vendor signed, such as DeepSeek’s earlier in a routing group, which Claude refuses. - Tool calls. A call an interrupted turn left unanswered gets a result saying it is unavailable, and a result for a call Anthropic never saw becomes text, where Anthropic would refuse the request. A history with calls but no tools declared declares them, with
tool_choicenone. A required tool goes asany, a named one astool, and parallel calls turned off asdisable_parallel_tool_use. - Sampling. Opus 4.7 and later, Sonnet 5 and 5.5, Haiku 5.5 and Fable 5 refuse
temperature,top_pandtop_k, which Claude Code’s auto mode classifier sends. magpie leaves them out for those models. - Betas. The betas an agent asks in
anthropic-betago on to Anthropic, save Claude Code’s own sign-in beta (oauth-…), which names a credential that never leaves magpie. - Structured output. A request for JSON in a schema goes to Anthropic as
output_config.format.
Reasoning
- Effort. Claude models from 4.6 on think adaptively. A translated request’s effort goes as
output_config.effort, with thinking adaptive and its summary shown (display: summarized), since Opus 4.7 and later leave the thinking text out unless asked. Opus and Sonnet 4.6 have no xhigh, so xhigh is asked as max. - Budgets. Older Claude models get a thinking budget: 4,096 tokens at low, 10,000 at medium, 24,000 at high, 32,000 at xhigh and max, fitted under the request’s
max_tokens. - A budget to a newer model. A request with a thinking budget to a model from 4.6 on, which Claude Opus 5.5 refuses (“requires adaptive thinking”), goes as adaptive thinking, the budget asked as the nearest effort.
- Reasoning off. Codex’s or a Chat client’s effort none turns thinking off, not down to a low budget. Each model takes off its own way: Sonnet 5.5 is sent
between_tools, an effort above high asked as high; Opus 5.5 and Fable 5 always think, so thinking is left out; Opus 5 and Haiku 5.5 are asked high in place of xhigh or max; older Claudes take it as sent. Claude Code’s requests with thinking off are fitted the same way.
Web search
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
- Cache tokens. The Usage tab counts cache reads, five-minute cache writes and hour-long cache writes apart from the rest of the prompt, as Anthropic reports them.
- Cost. The Usage tab prices each call with Anthropic’s prices from models.dev. An hour-long write is priced at twice the input price where the catalog gives none, as Anthropic bills it. magpie reads no balance from Anthropic; type it in with
key-balance, and the Usage page shows it less what magpie has priced the key’s calls at since. - Keeping the cache. With several keys, a conversation stays on its key while its cache is worth keeping, 1,024 tokens or more, and still warm: read within the last five minutes, or within the hour when it was written for an hour.
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.
- Spend caps.
spend-capstops a key at a dollar amount a day, a month or in all, as the Usage tab prices its calls; routing then goes on to the other keys and the fallbacks. - Fallbacks.
fallbacknames where requests go when Anthropic is out of quota or down: another provider’s model or a routing group. - Workspaces. A key that reaches several workspaces names the one each request is for with the
anthropic-workspace-idheader. Add the provider again under an id of its own, with the header set in its Headers field or from the terminal; its models then readanthropic-ws2/….
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
- “requires adaptive thinking”. A thinking budget sent to a model from 4.6 on. magpie sends it as adaptive thinking with the nearest effort; see Reasoning.
- 400 when thinking is turned off. Sonnet 5.5, Opus 5.5 and Fable 5 each refuse
disabled, and Opus 5 and Haiku 5.5 refuse it at xhigh and max. magpie sends each model off the way it takes it. - “
temperatureis deprecated for this model”. magpie leavestemperature,top_pandtop_kout for the models that refuse them. - “
tool_useids were found withouttool_resultblocks”. An interrupted turn left a call unanswered. In a request magpie translates, the call gets a result saying it is unavailable. - “Invalid
signatureinthinkingblock”. The conversation ran on another vendor first. magpie leaves thinking another vendor signed, or left unsigned, out of what goes to Claude. - A 400 about
cache_controlandttl. The upstream doesn’t take the hour-long marks magpie adds for Codex. magpie asks again with five-minute marks and keeps to them for that provider. - “this is an Anthropic API key, not a setup-token”. The key went to the Claude subscription’s sign-in. Add it as the Anthropic provider instead.
- Checking a key.
magpie provider test anthropicsends a tiny request through each endpoint, or to each model you name. Add--as codexor--as claude-codeto send it the way that agent would.
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.