codex icon indicating copy to clipboard operation
codex copied to clipboard

Codex CLI uses OPENAI_API_KEY instead of logged-in session

Open abdulmunimjundurahman opened this issue 1 year ago • 2 comments

What version of Codex is running?

codex-cli 0.23.0

Which model were you using?

gpt5

What platform is your computer?

Linux 6.8.0-52-generic x86_64 x86_64

What steps can reproduce the bug?

  1. Log in with codex login successfully.
  2. Run a Codex CLI command (e.g., codex run ...).
  3. Notice that the CLI attempts to use OPENAI_API_KEY from the environment instead of the logged-in session.

What is the expected behavior?

Codex CLI should use the logged-in session token when a user is authenticated via codex login, even if an OPENAI_API_KEY is set.

What do you see instead?

Codex ignores the login session and tries to use OPENAI_API_KEY, which may cause authentication errors or unexpected behavior.

Additional information

No response

abdulmunimjundurahman avatar Aug 24 '25 08:08 abdulmunimjundurahman

  • Log in with codex login successfully.

  • Run a Codex CLI command (e.g., codex run ...).

  • Notice that the CLI attempts to use OPENAI_API_KEY from the environment instead of the logged-in session.

Sorry for the possibly stupid question, but did you log in via the chatgpt with a redirect through the browser? What did your login process look like?

If so, check your /home/USER/.codex/auth.a json (~/.codex/auth.json) file. Try to delete it and/or execute a codex logout. After that, codex login again. Enter the string in /home/USER/config.toml: preferred_auth_method = "chatgpt" Then log in again.

prime9dev avatar Aug 24 '25 17:08 prime9dev

The auth and login code for codex has changed significantly since 0.23.0, so this issue is probably no longer relevant. If you're still having a problem related to login with the latest published version of Codex, please file a new issue.

etraut-openai avatar Oct 28 '25 00:10 etraut-openai