OpenAI API coding agent: key, model and billing
Updated
To run an OpenAI API coding agent, create a key for a funded OpenAI Platform project and connect it to your agent. OpenAI supports keys for local Codex work in the ChatGPT desktop app, an IDE extension and the CLI. OpenCode and Contenox Harness also accept an OpenAI key. API usage is billed to the key’s organization. OpenAI authentication
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 | Yes, for local work | Desktop: Sign in another way. IDE: Use API Key. CLI: codex login --with-api-key, key on stdin. |
Cloud tasks require ChatGPT sign-in and workspace access. |
| OpenCode | Yes | /connect → OpenAI → API key |
Choose a model in /models. |
| Contenox Harness | 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 and OpenAI Platform have separate billing. Eligible Pro and Business customers can claim promotional API credit for a linked API organization. OpenAI excludes Codex usage with an API key from that credit. OpenAI’s credit terms · Codex API key vs subscription
Use a key in the ChatGPT desktop app or Codex IDE extension#
In the signed-out desktop app, select Sign in another way, enter your Platform key and choose Continue. Open a local project folder, choose Codex and start a chat. In the signed-out IDE extension, choose Use API Key and enter the key. You can check which credential is active in the profile menu. OpenAI sign-in instructions
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#
In the OpenCode terminal, enter /connect, choose OpenAI, and select the API-key option. Enter your OpenAI Platform key and choose a model with /models. For a ChatGPT Plus or Pro subscription, choose Sign in with ChatGPT at the same provider prompt. OpenCode install options · OpenCode provider setup
Which GPT model should I pick?#
OpenAI’s models page currently points to GPT-6.2 Astra for complex reasoning and coding, GPT-6.2 Sol for everyday work at a lower cost, and GPT-6 Luna for high-volume tasks. 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 Harness#
Contenox Harness 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 Harness. Key rejected means a 401; use Replace to paste a new key.
Related#
Codex API key vs subscription: which one to use whenCodex API key vs ChatGPT subscription — which account pays?See which account pays when you sign in to Codex with ChatGPT or an API key, which subscription credits apply, and where to check usage before you switch.
ChatGPT subscriptionUse your ChatGPT subscription for a coding agent | ContenoxUse your ChatGPT subscription for a coding agent. Set up device sign-in in Contenox or use Codex on desktop, in an editor or in the terminal. Check plan limits.
How to choose a model for codingHow to compare AI coding models on your own codebaseCompare AI coding models on five tasks from your repository. Score each run on passing tests, unnecessary edits, elapsed time and cost per finished task.
AI coding costsAI coding costs: why agents burn tokens and how to cut itAI coding costs explained: why one agent session can send hundreds of millions of tokens, what sessions really cost, and the habits that cut the bill.
OpenRouter: one key for many model makersOpenRouter coding agent: Claude Code, Codex, OpenCode setupUse OpenRouter with a coding agent: setup for Claude Code, Codex CLI and OpenCode, a capped API key, models that call tools well, and 401 and 402 fixes.
Anthropic (Claude)Claude coding agent on Windows: API key setup | ContenoxRun a Claude coding agent on Windows: Claude Code with a subscription or API key, OpenCode with a key, why Codex can't, plus models, billing and key errors.
GitHub Copilot subscriptionUse your GitHub Copilot subscription in other coding agentsUse your GitHub Copilot subscription outside VS Code: sign-in steps for OpenCode, Codex and Contenox Harness, which plans you need, and how AI Credits are billed.
GeminiGemini coding agent: API key, free tier and setup | ContenoxSet up a Gemini coding agent: AI Studio key in OpenCode, Antigravity CLI or Contenox Harness, why Claude Code and Codex can't, free-tier data use, models and 429 fixes.