contenox

OpenAI API coding agent: key, model and billing

Updated

MODEL PROVIDERSOpenAI API

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 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 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_quota or “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.

  1. Open Backends → Providers, then More providers, and choose OpenAI.
  2. Select Create key, create a key on the OpenAI API keys page and copy it.
  3. Paste it into API Key, select Connect and wait for Connected.
  4. 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

Esc to close