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
9 Comments
The latest version should work without this issue. If you're still observing this issue, please let us know.
@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 ?
I'm sorry, but the issue continues....
codex-cli 0.0.2505291458The latest version 0.2.1 uses the native version internally. Could you try the latest version out?
pardon, the latest codex or the latest codex native version ? i´m still confused here.....
I mean the latest series of
@openai/codexnpm 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.0thanks. 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!
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_KEYto confirm OPENAI_API_KEY is set, and then runcodexin the same terminal, and I still see:"To use Codex with the OpenAI API, set OPENAI_API_KEY in your environment"
Note that
npx @openai/codex@nativeshould 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:Also, while setting the
OPENAI_API_KEYenvironment 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.