codex exec hangs when not OPENAI_API_KEY supplied

Resolved 💬 2 comments Opened Jul 14, 2025 by dn-scribe Closed Aug 18, 2025
💡 Likely answer: A maintainer (seratch, member) responded on this thread — see the highlighted reply below.

What version of Codex is running?

0.6.0

Which model were you using?

codex-mini-latest

What platform is your computer?

MacOS, Darwin 23.6.0 arm64 arm

What steps can reproduce the bug?

Assure no OPENAI_API_KEY
Run
codex exec "solve the halting problem"

Seems to be hanged:

[2025-07-14T19:11:04] OpenAI Codex v0.6.0 (research preview)
--------
workdir: XXX
model: codex-mini-latest
provider: openai
approval: Never
sandbox: read-only
reasoning effort: medium
reasoning summaries: auto
--------
[2025-07-14T19:11:04] User instructions:
solve the halting problem
[2025-07-14T19:11:04] ERROR: Missing environment variable: `OPENAI_API_KEY`. Create an API key (https://platform.openai.com) and export it as an environment variable.


### What is the expected behavior?

Exit immediately with error.

### What do you see instead?

Nothing.

### Additional information

_No response_

View original on GitHub ↗

2 Comments

dn-scribe · 1 year ago

Same happens if an invalid api-key is supplied.
This does not allow integrating into a CI.

seratch member · 1 year ago

The latest version (0.22.0) tells an error this way:

🖐 unexpected status 401 Unauthorized: {
  "error": {
    "message": "Incorrect API key provided: foo. You can find your API key at https://platform.openai.com/account/api-keys.",
    "type": "invalid_request_error",
    "param": null,
    "code": "invalid_api_key"
  }
}