Sign in to Codex: ChatGPT account or API key

Codex supports two sign-ins. Sign in with ChatGPT to use your plan's included Codex access, or sign in with an OpenAI API key for usage-based billing at API rates. Codex cloud requires ChatGPT sign-in. In the CLI, run codex login for the browser flow, codex login --with-api-key for a key, or codex login --device-auth on headless machines.

ChatGPT sign-in vs API key

Sign in with ChatGPTSign in with an API key
BillingIncluded in your ChatGPT planStandard OpenAI API rates
Codex cloudSupportedNot supported
Some workspace and cloud featuresAvailableLimited or unavailable
Good forEveryday interactive useScripts, CI/CD, usage-based billing

CLI commands

codex login                                       # browser sign-in with ChatGPT
printenv OPENAI_API_KEY | codex login --with-api-key
codex login --device-auth                         # headless / SSH (beta)
codex login status                                # which method is active
codex logout

In the desktop app, choose Continue to sign in, or Sign in another way for an API key. In the IDE extension, choose Sign in with ChatGPT or Use API Key.

Signing in on a server or over SSH

The browser flow needs a callback to localhost:1455, which doesn’t work on a headless machine. In order of preference:

  1. Device code. Enable device code login in your ChatGPT security settings, or ask your workspace admin. Then run codex login --device-auth, open the link, and enter the code.
  2. Forward the callback port. Run ssh -L 1455:localhost:1455 user@remote, then run codex login in that session.
  3. Copy the auth cache. Sign in on a machine with a browser, then copy ~/.codex/auth.json to the same path on the server. This only works if Codex uses file storage for credentials.

Keep your credentials safe

Codex caches login details in ~/.codex/auth.json or in your OS credential store. Choose where with cli_auth_credentials_store in config.toml:

# file | keyring | auto | ephemeral
cli_auth_credentials_store = "keyring"

Never commit auth.json, paste it into a ticket, or share it in chat. It contains access tokens.

Questions people ask

Which ChatGPT plans include Codex?

The Codex README lists Plus, Pro, Business, Edu, and Enterprise. Plan details change, so check OpenAI's help center article on Codex in ChatGPT for the current list and limits.

Can I use Codex in CI?

Yes. OpenAI recommends API key authentication for programmatic CLI workflows such as CI/CD, and warns against exposing Codex execution in untrusted or public environments.

Sources

We link to the official source for every instruction on this page. If anything here disagrees with them, trust the official source and tell us.