To run an OpenAI API coding agent, create an API key on the OpenAI platform, add credit to the account, and give the key to your agent. Codex CLI, OpenCode and Contenox all take an OpenAI key; Claude Code doesn’t, because it runs Claude models only. You pay per token, separately from any ChatGPT plan.
If you already pay for ChatGPT, you may not need a key at all: sign in with your ChatGPT subscription and usage counts against your plan.
One observation from the field, in a LinkedIn post by Alexander Ertli: OpenAI is “rapidly consuming the application layer”, with Codex, the Atlas browser, the Sora app and a companion product all shipped by the company that sells the API underneath other products. The post’s point is that building on a provider’s API carries the risk of that provider shipping the same idea.
Use an OpenAI API key with your agent
| Agent | Supported? | How | Note |
|---|---|---|---|
| Claude Code | No | Claude Code runs Claude models only, through Anthropic, Amazon Bedrock, Google Cloud’s Agent Platform (Vertex AI) or Microsoft Foundry. Anthropic doesn’t support routing it to other models. | |
| Codex CLI | Yes | codex login --with-api-key, key on stdin |
OpenAI’s own agent. |
| OpenCode | Yes | /connect → OpenAI → Manually enter API Key |
|
| Contenox | Yes | Backends → Providers → More providers → OpenAI |
API key or ChatGPT subscription?
| API key | ChatGPT subscription | |
|---|---|---|
| Billing | Per token, from credit on your platform account | Included in your ChatGPT plan |
| When you run out | Add credit or raise your limits | Wait for the plan’s limit to reset, or buy credits where your plan allows |
| Setup | Create a key, paste it | Sign in in the browser |
| Good for | Steady or heavy use, teams, automation | One person who already pays for ChatGPT |
ChatGPT Plus and the API are separate products with separate billing. A Plus or Pro subscription does not give you API credit. For Codex specifically, see Codex API key vs subscription.
Codex CLI
Install it. Windows PowerShell:
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
macOS or Linux:
curl -fsSL https://chatgpt.com/codex/install.sh | sh
Codex reads the key from stdin. With the key in OPENAI_API_KEY, in PowerShell:
$env:OPENAI_API_KEY | codex login --with-api-key
macOS or Linux:
printenv OPENAI_API_KEY | codex login --with-api-key
Then run codex in your project folder. Codex saves the key in ~/.codex/auth.json or
your system’s credential store.
OpenCode
Install it. On Windows, OpenCode recommends WSL; natively, use npm:
npm install -g opencode-ai
macOS or Linux:
curl -fsSL https://opencode.ai/install | bash
Start opencode in your project, type /connect, choose OpenAI, then
Manually enter API Key, and paste the key. Pick a model with /models. The key is
saved in ~/.local/share/opencode/auth.json.
Which GPT model should I pick?
OpenAI’s models page currently points to GPT-6 Astra as the default for complex reasoning and coding, GPT-6.1 Sol for nearly the same quality at a lower price, and GPT-6 Luna for cheap, high-volume work. For an agent that edits several files, start with Astra or Sol and drop to Luna for small chores.
More reasoning effort usually gives better plans for larger changes, and costs more time and tokens.
How billing works
Every agent step sends context (your files, the conversation, tool results) and gets output back, and both are billed per token. Long sessions cost more than short ones, so start a new session for a new task.
Rate limits depend on your organization’s usage tier. New accounts start low, and the tier rises automatically as your total credit purchases grow. See your limits under Settings → Organization → Limits on the platform. Current numbers are on OpenAI’s pricing and rate limits pages.
Common errors
- 401 “Incorrect API key provided”: check for a missing character or extra space, or create a new key.
- 429 “Rate limit reached for requests”: you sent too much too fast. Wait and try again; the limit rises with your usage tier.
- 429 with
insufficient_quotaor “Credit balance exhausted”: the account has no credit left. Add credit in the platform’s billing settings. Retrying does not help. - 403 “Country, region, or territory not supported”: OpenAI does not serve your location.
Contenox
Contenox takes the same key and lets you switch between OpenAI and other providers per session.
- Open Backends → Providers, then More providers, and choose OpenAI.
- Select Create key, create a key on the OpenAI API keys page and copy it.
- Paste it into API Key, select Connect and wait for Connected.
- Pick a model in the Model chip on the message box. The Think chip sets the reasoning effort.
To keep the key out of the app, enter OPENAI_API_KEY under Advanced in
Environment variable name, set it with setx OPENAI_API_KEY "your-key-here", and
reopen Contenox. Key rejected means a 401; use Replace to paste a new key.
Related
- Codex API key vs subscription: which one to use when
- ChatGPT subscription
- How to choose a model for coding
- AI coding costs
- OpenRouter: one key for many model makers
- Anthropic (Claude)