npx @openai/codex@native does not find OPENAI_API_KEY

Resolved 💬 9 comments Opened Jun 17, 2025 by michabbb Closed Sep 5, 2025
💡 Likely answer: A maintainer (seratch, member) responded on this thread — see the highlighted reply below.

i guess because npx spawns its own shell, i am running it inside WSL2

things like that:

codexn() {
  export OPENAI_API_KEY="$OPENAI_API_KEY"
  npx @openai/codex@native "$@"
}

is not working - thanks for any help

View original on GitHub ↗

9 Comments

seratch member · 11 months ago

The latest version should work without this issue. If you're still observing this issue, please let us know.

michabbb · 11 months ago

@seratch thanks for the notice. i am still confused (as many others) - the readme is not mentioning the native version at all, and i only found out about it by reading some issue comments here. is there any official docu for the native version ?

michabbb · 11 months ago
The latest version should work without this issue. If you're still observing this issue, please let us know.

I'm sorry, but the issue continues....

user                                                                                                                                                                                                           
hi
ERROR: Missing environment variable: `OPENAI_API_KEY`. Create an API key (https://platform.openai.com) and export it as an environment variable.

codex-cli 0.0.2505291458

seratch member · 11 months ago

The latest version 0.2.1 uses the native version internally. Could you try the latest version out?

michabbb · 11 months ago

pardon, the latest codex or the latest codex native version ? i´m still confused here.....

seratch member · 11 months ago

I mean the latest series of @openai/codex npm module are a simple wrapper of rust native one. Also, you can download the builds from here: https://github.com/openai/codex/releases/tag/rust-v0.21.0

michabbb · 11 months ago

thanks. yes, the "normal" codex version is working. i always thought the rust version would replace the normal version completely, sorry. that´s why i regularly tested the native version to see if there is any progress, but i will stick to the "regular" version now 😏
feel free to close the issue if you want to, thanks!

jakobdylanc · 11 months ago

Not sure if related but I'm experiencing this issue on my Mac. I'm running codex v0.23.0 installed via brew install codex.

I run echo $OPENAI_API_KEY to confirm OPENAI_API_KEY is set, and then run codex in the same terminal, and I still see:

"To use Codex with the OpenAI API, set OPENAI_API_KEY in your environment"

bolinfest collaborator · 10 months ago

Note that npx @openai/codex@native should not be used anymore, as that includes an outdated version of the CLI. As noted on https://github.com/openai/codex/blob/main/README.md, please do one of:

npm i -g @openai/codex
brew install codex

Also, while setting the OPENAI_API_KEY environment variable is a supported mechanism for API users, most users prefer to go with the newer authentication method, which is to sign in with your ChatGPT account.