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

  1. Get a keyMake one on platform.openai.com. It starts with sk-.
  2. 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.
  3. 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.
Terminal
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

APIAddressUsed for
Responseshttps://api.openai.com/v1OpenAI’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 Completionshttps://api.openai.com/v1the 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:

Terminal
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:

Terminal
magpie provider models openai +gpt-6.1-sol +gpt-6-luna +gpt-5.5
magpie provider refresh-every openai 1d

In each agent

Terminal
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

What magpie does for OpenAI

Terminal
magpie provider set openai compaction=native
magpie provider set openai additional-tools=off

Reasoning

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

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.

Terminal
magpie provider spend-cap openai <key> 20 month
magpie provider key-balance openai <key> 25
magpie provider fallback openai deepseek/deepseek-v4-pro

Troubleshooting

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.