Docs · Provider
OpenAI in Claude Code, Codex, Gemini CLI and OpenCode
OpenAI serves its models on two APIs at api.openai.com: Responses and Chat Completions. Its own models are best asked on Responses, and its newest answer only there. Add an OpenAI API key to magpie once, and Claude Code, Codex, Gemini CLI, OpenCode and every other agent you connect can use OpenAI’s models through magpie’s local gateway at 127.0.0.1:3425, each agent with a model of its own. Codex’s requests go to OpenAI as they are; the other agents’ are translated on the way.
This page is about an API key from platform.openai.com. A ChatGPT Plus or Pro subscription is signed in to separately; see Subscriptions in any agent.
Add OpenAI
- Get a keyMake one on platform.openai.com. It starts with
sk-. - Add the providerIn magpie’s Providers tab, press + Add provider, pick OpenAI, paste the key and save. magpie asks OpenAI which models the key can use.
- Pick it for an agentIn the Agents tab, click the model on the agent’s row and choose an OpenAI model such as
gpt-6.1-sol.
magpie provider add openai <key> magpie provider test openai
Model ids in magpie are provider/model, so OpenAI’s read openai/gpt-6.1-sol: the provider, then OpenAI’s own id. The key is kept in magpie’s settings; magpie doesn’t take it from your shell.
Already set OpenAI up in OpenCode or another app magpie imports from? The import brings it in as the OpenAI provider.
Endpoints
| API | Address | Used for |
|---|---|---|
| Responses | https://api.openai.com/v1 | OpenAI’s own models, ids starting gpt-, codex or o and a digit: Codex’s requests as they are, Claude Code’s, Gemini CLI’s and OpenCode’s translated |
| Chat Completions | https://api.openai.com/v1 | the model list, and any other model the key lists |
magpie’s OpenAI provider has no Anthropic Messages address, so Claude Code’s requests are always translated. For OpenAI’s own models magpie keeps Responses first even for an agent that speaks Chat Completions. When OpenAI answers that a model is served only on /v1/responses, magpie asks again there and remembers it. To send a model on one API yourself:
magpie model api openai/gpt-5.5 chat magpie model api openai/gpt-5.5 --reset magpie model apis openai
Azure OpenAI is a provider of its own, Azure OpenAI. Give it your resource’s endpoint, https://<resource>.openai.azure.com, and its key. magpie uses the v1 API under /openai/v1 for Chat Completions and Responses, sends the key in the api-key header, and lists the resource’s deployments as its models. A deployment named for its model, such as gpt-5-codex, goes to Responses first too.
Model list
magpie fetches the list from OpenAI, at https://api.openai.com/v1/models, so agents see the models your key can use. Names, context windows, reasoning levels and prices come from models.dev’s openai catalog. A reasoning model OpenAI has just listed, before its levels are known, gets those of the newest reasoning model in its family: gpt-6.1-sol got gpt-6-sol’s. Pick the models agents see in the provider’s model list, or from the terminal:
magpie provider models openai +gpt-6.1-sol +gpt-6-luna +gpt-5.5 magpie provider refresh-every openai 1d
In each agent
magpie claude openai/gpt-6.1-sol magpie codex openai/gpt-6.1-sol magpie gemini model openai/gpt-6.1-sol magpie opencode openai/gpt-6.1-sol
- Claude Code speaks Anthropic Messages, which OpenAI doesn’t serve. magpie translates each request to Responses and the reply back; the model’s reasoning summary reaches Claude Code as thinking, then the text. Models in Claude Code.
- Codex speaks Responses, so its requests go to OpenAI as they are: its custom tools such as
apply_patch, its reasoning items and its ownprompt_cache_keyincluded. Codex is also offered Fast here; see Reasoning. Models in Codex. - Gemini CLI speaks Google’s Gemini API. magpie translates each request to Responses and the reply back. Models in Gemini CLI.
- OpenCode speaks Chat Completions. OpenAI’s own models go to Responses first, so magpie translates its requests there and the replies back; any other model the key lists gets OpenCode’s requests as they are. Models in OpenCode.
What magpie does for OpenAI
- A prompt cache key. A translated request to OpenAI that carries no
prompt_cache_keygets one, made from the session the agent names, or else its first user message, and hashed, so it names nothing of the agent. Codex sends its own, which goes on as it is, and one you set yourself wins. If OpenAI answers 400 over the field, magpie asks again without it. - Tools loaded where they were loaded. A tool that Claude Code’s tool search loads mid-conversation is sent to OpenAI’s Responses API as an
additional_toolsitem at that point, not added to the tool list, which keeps the cached prefix.additional-tools=offputs it with the other tools. - Sealed reasoning from elsewhere. OpenAI reads only its own sealed reasoning (
encrypted_content). An item sealed under another key, organization or account is refused (“could not be verified”); magpie asks again without those items and remembers it for the conversation. Claude’s thinking, which Codex carries in a reasoning item after a turn on a Claude model, is taken out before the request reaches OpenAI. - Earlier responses. A Responses client may send only a turn’s new input and name the response it follows (
previous_response_id). magpie keeps each response it gave such a client, in memory and under the caller’s gateway key. OpenAI keeps responses too, so when the same key answered the one named, OpenAI is sent only the new input after its own id. Codex over HTTP saysstorefalse and names none. - Codex’s own compaction. With
compaction=native, Codex’s compaction is asked of OpenAI as Codex sent it and the sealed item comes back to Codex as it came. Only the key that sealed it can read it, so later requests carrying it go only there. The default,compaction=magpie, has magpie summarise.
magpie provider set openai compaction=native magpie provider set openai additional-tools=off
Reasoning
- Effort. The effort an agent asks for is fitted to the nearest level the model has, as the catalog lists them:
gpt-6-solhasnone,low,medium,high,xhighandmax. On Responses it is sent asreasoning.effort, withsummaryset toauto, so the model’s reasoning summary comes back. - Reasoning off. When an agent whose requests magpie translates, such as Gemini CLI, turns reasoning off and the model lists
noneamong its levels, magpie asks for none. - Encrypted reasoning. magpie passes on what an agent asks to include, but asks for
reasoning.encrypted_contentonly with reasoning: OpenAI refuses it of a model that doesn’t reason. Codex sends the sealed items back on the next turn, and magpie passes them on as they are. - Fast. On an OpenAI key, Codex is offered Fast for GPT and o-series models. magpie sends it as
service_tier: "priority", OpenAI’s priority processing. A service tier set for Codex in magpie overrides what Codex asked.
Web search
OpenAI’s Responses API searches the web itself. When an agent offers its model web search, as Codex and Claude Code do, magpie gives the model OpenAI’s own web_search tool on Responses, and OpenAI runs the search.
Cost and usage
- Cost. The Usage tab prices each call with OpenAI’s prices from models.dev.
- Cache tokens. When a reply reports cached prompt tokens, the Usage tab counts them apart from the rest of the prompt.
- 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.
- Service tier. Each call records the tier the agent asked for, the one magpie sent, and the one OpenAI’s reply says it ran at.
- Balance. magpie reads no balance from OpenAI; type it in with
key-balance, and the Usage page shows it less what magpie has priced the key’s calls at since.
Several keys and failover
One OpenAI 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. To keep keys apart instead, say from two organizations, add the provider again: the second is openai-2.
- 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 OpenAI is out of quota or down: another provider’s model or a routing group.
magpie provider spend-cap openai <key> 20 month magpie provider key-balance openai <key> 25 magpie provider fallback openai deepseek/deepseek-v4-pro
Troubleshooting
- “The encrypted content for item rs_… could not be verified”. The conversation carries reasoning sealed under another key, organization or account. magpie asks again without those items; see What magpie does.
- A model that answers only on
/v1/responses. magpie moves it to Responses and remembers it.magpie model apis openaishows which API each model is asked on. - A 400 over
prompt_cache_key. magpie asks again without the key it added. - Checking a key.
magpie provider test openaisends 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 OpenAI’s models in Claude Code?
Add your OpenAI API key in magpie (Providers, Add provider, OpenAI), then pick a model such as gpt-6.1-sol on Claude Code’s row, or run magpie claude openai/gpt-6.1-sol. OpenAI serves no Anthropic Messages API, so magpie translates Claude Code’s requests to OpenAI’s Responses API at https://api.openai.com/v1 and the replies back, the reasoning summary as thinking.
Can Codex use an OpenAI API key instead of a ChatGPT sign-in?
Yes. Add the key, then run magpie codex openai/gpt-6.1-sol. Codex speaks Responses, so its requests go to OpenAI as they are, custom tools and reasoning included, and Fast is sent as priority processing. A ChatGPT Plus or Pro sign-in is set up separately, in Subscriptions.
How do I use GPT models in OpenCode?
Pick the model in magpie, or run magpie opencode openai/gpt-6.1-sol. OpenCode speaks Chat Completions, but OpenAI’s own models go to Responses first, so magpie translates OpenCode’s requests there and the replies back. To send a model on Chat Completions instead, run magpie model api openai/gpt-5.5 chat.
Can Gemini CLI use OpenAI?
Yes. Gemini CLI speaks Google’s Gemini API, so magpie translates its requests to OpenAI’s Responses API and the replies back, streaming and tool calls included. Run magpie gemini model openai/gpt-6.1-sol.
Does magpie keep OpenAI’s prompt cache?
Yes. Codex’s own prompt_cache_key goes on as it is. A translated request without one gets a key made from its session or first user message, hashed so it names nothing of the agent. With several keys, a conversation stays on its key while its cache is warm.
Why does OpenAI say the encrypted content could not be verified?
OpenAI reads only reasoning it sealed for the same key, organization or account. When a conversation carries reasoning sealed elsewhere, magpie asks again without those items and remembers it for the conversation.
Does magpie support Azure OpenAI?
Yes, as its own provider, Azure OpenAI. Give it the resource’s endpoint and key; magpie uses the v1 API under /openai/v1, sends the key in the api-key header and lists the resource’s deployments as models.
By provider: DeepSeek · Kimi and Kimi Code · GLM Coding Plan · Qwen · MiniMax · Anthropic · 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.