Models & auth6 min read

Codex authentication: ChatGPT, API keys, and auth.json

Separate authentication from provider routing and credential storage, including why exporting a key is not the same as signing in.

Choose the authentication path

ChatGPT sign-in and API-key sign-in use different access and billing arrangements. Do not assume a subscription supplies API credits. Third-party providers also need explicit routing. Decide which path you intend to use before mixing keys or editing files.

Check the CLI authentication state
codex login status

A direct OpenAI key needs a login step

This example assumes OPENAI_API_KEY is already set securely on your computer. Pass it through standard input rather than placing a real secret in command arguments or screenshots.

Bash / zsh · use an existing OpenAI key
printenv OPENAI_API_KEY | codex login --with-api-key
codex login status

In PowerShell, use $env:OPENAI_API_KEY | codex login --with-api-key. Exporting a variable alone does not establish the cached login for the built-in OpenAI route. A custom provider’s env_key is a separate mechanism covered in the provider guide.

A missing auth.json is not proof of failure

ValueStorageWhat to check
fileauth.json under CODEX_HOMEContains secrets; never upload it
keyringOS credential storeFails if that store is unavailable
autoOS store, with file fallbackA file inspection alone is inconclusive
ephemeralCurrent process memoryNot persistent; check installed-version support
User config · change only when needed
cli_auth_credentials_store = "auto"

After changing the storage mode, check login status again. Do not assume existing credentials moved automatically. Managed authentication requirements can restrict these choices.

Compare the Client and CLI

  1. Distinguish local and remote hosts.
  2. Compare CODEX_HOME and whether the desktop process predates your changes.
  3. Check storage settings without printing auth.json.
  4. Prepare the correct login method before signing out; shared credential caches can affect another client.

Validate the actual request

Login status identifies authentication, not the final provider route. Restart, run one small task, and check the model and upstream request logs. A saved key or visible model name is not enough.

For HTTP failures or client differences, continue with the layered troubleshooting checklist.

Sources and version notes

Based on the official documentation below. Replace example URLs, models, and paths for your environment. Older versions and managed environments may differ.

Sources checked:

More guides

Put your configuration to work

Generate a configuration, follow the setup flow, or diagnose the next issue.

Client + CLI setupOpen configuration tools