contenox

Codex API key vs subscription: cost, limits and switching

Updated

MODELS AND COST Codex: API key vs plan

Codex API key vs subscription comes down to how you pay and what you can do: Codex runs on either a ChatGPT plan or an OpenAI API key. Signed in with ChatGPT, Codex uses your plan’s usage limits, and you get cloud tasks and the other ChatGPT-only features. With an API key, every token is billed at standard API rates to your OpenAI Platform account, with no window to wait for, but only in the CLI, the IDE extension and the SDK. You switch with codex logout and a new codex login.

What changes between the two?

ChatGPT sign-inAPI key
You payYour ChatGPT plan; extra credits on Plus and ProPer token, at API rates
When you hit the limitWait for the reset, buy credits, or switch to a keyYour own spend limit and rate limits on the Platform
Where it worksCLI, IDE extension, desktop app, web, cloud tasks, GitHub code review, SlackCLI, IDE extension, SDK and codex exec
ModelsThe plan’s model lineupThe models your API key can access
Data handlingYour ChatGPT workspace’s settings, retention and permissionsYour API organization’s retention and data-sharing settings
Best forDaily work by one personCI, scripts, teams on one bill, days the plan runs out

A ChatGPT plan includes no API credit, and API usage doesn’t count against the plan. They are two separate bills. OpenAI’s Codex pricing page has the current plans and limits.

How do I sign in with my ChatGPT plan?

codex login

Finish the sign-in in the browser. On a machine without a browser, or over SSH:

codex login --device-auth

Device code sign-in has to be turned on in your ChatGPT security settings first, or by an admin on a Business, Edu or Enterprise workspace. Until then, there’s no field for the code. Details are on the ChatGPT subscription page, with install steps for Windows, macOS and Linux.

How do I log in to Codex with an API key?

Create a key in the OpenAI Platform dashboard under API keys. Then pipe it into Codex, so it doesn’t end up in your shell history. macOS, Linux or WSL:

export OPENAI_API_KEY="your-key-here"
printenv OPENAI_API_KEY | codex login --with-api-key

Windows PowerShell:

$env:OPENAI_API_KEY = "your-key-here"
$env:OPENAI_API_KEY | codex login --with-api-key

Codex stores the key with its other credentials, in ~/.codex/auth.json or your system’s credential store, depending on cli_auth_credentials_store in config.toml. The CLI and the IDE extension share that login. Treat the file like a password.

For a single non-interactive run, such as a CI job, set CODEX_API_KEY instead. It works for codex exec, review, the TypeScript SDK and the remote exec-server, not for the interactive CLI. Codex’s docs say to set it inline for the one command, not for the whole job, when the job runs code from the repository.

CODEX_API_KEY="$OPENAI_KEY_SECRET" codex exec "run the tests and fix what fails"

OpenAI’s docs also warn against running Codex with API key auth in untrusted or public environments.

How do I switch between them?

There is no switch command. Log out, then log in the other way:

codex login status
codex logout
printenv OPENAI_API_KEY | codex login --with-api-key

To go back to the plan, codex logout and then codex login.

codex login status shows which method is active. Check it before a long task, so you know which bill the task goes to.

The managed-machine gotcha: if an admin set forced_login_method = "chatgpt" or "api" in a managed config, Codex logs you out and exits whenever your credentials don’t match. If Codex keeps signing you out after a switch, that setting is the reason.

How do I check my Codex usage?

  • On a ChatGPT plan: the usage dashboard shows your current limits and reset times. In the CLI, /usage shows your ChatGPT token activity, with /usage daily, /usage weekly or /usage cumulative to go straight to a view. It’s also where you redeem an earned rate-limit reset, if you have one. /statusline can put the rate limits in the footer.
  • On an API key: the Platform dashboard’s usage page shows spend per day and per model. Set a monthly budget there before the first long session.
  • Either way: /status shows the active model and the current session’s token usage.

What happens when the subscription runs out?

OpenAI lets a turn that’s already running finish, within fair use. After that, you have three options:

  1. Wait for the window to reset. Plus and Business have a short recurring window; weekly limits can apply on top.
  2. Buy credits, on Plus and Pro, or as workspace credits on Business, Edu and Enterprise with flexible pricing.
  3. Log in with an API key and keep working, billed per token.

Fast and Ultrafast modes use your allowance faster than Standard, so turn them off when you’re close to the limit.

Which is cheaper for me?

Work it out from your own tokens, not from the plan names. Prices change, so take them fresh from OpenAI’s API pricing page. The arithmetic is the same either way, because Codex credits are also charged per million tokens of input, cached input and output.

cost of a task = (uncached input × input price
                + cached input   × cached input price
                + output         × output price) / 1,000,000

How big the token counts get, from the Contenox team’s own use in 2026:

  • One month on the DeepSeek API: 23,815 requests and 7.86 billion tokens, about 330,000 tokens per request.
  • One agentic coding session of eight prompts: about 300 million input tokens.

Agents resend the whole conversation on every step, so most of those tokens are cached input. That makes the cached input price the number that matters most. Prompt caching explains why.

To compare on your own work:

  1. Log in with an API key and run three tasks you do often.
  2. After each, read the tokens from /status, and the cost from the Platform’s usage page.
  3. Multiply by how often you do that kind of task in a month.
  4. Compare the total with your ChatGPT plan on the Codex pricing page.

If your month on the key costs more than the plan, and the plan’s limits would have covered the work, the subscription wins. If you code a few days a month, or in bursts, the key usually does. AI coding costs has the background.

Contenox

Contenox keeps both side by side: the ChatGPT subscription, signed in with a one-time code, and an OpenAI API key as a separate provider. You pick one per session in the Model chip, so when the plan’s window closes, you switch the session to the key without logging out of anything.

Related

Esc to close