Codex App (WSL mode): Missing environment variable `AZURE_OPENAI_API_KEY` although variable exists in Windows and WSL
Open 💬 10 comments Opened Mar 5, 2026 by ckorherr
💡 Likely answer: A maintainer (etraut-openai, contributor)
responded on this thread — see the highlighted reply below.
What version of the Codex App are you using (From “About Codex” dialog)?
26.304.1528.0
What subscription do you have?
Azure OpenAI
What platform is your computer?
Microsoft Windows NT 10.0.26100.0 x64
What issue are you seeing?
After the latest update I can successfully start the Codex App with:
runCodexInWindowsSubsystemForLinux: true
However, every prompt returns the error:
Missing environment variable: `AZURE_OPENAI_API_KEY`
My config.toml:
model = "gpt-5.3-codex"
model_provider = "azure"
model_reasoning_effort = "medium"
[model_providers.azure]
name = "Azure"
base_url = "https://xyz.openai.azure.com/openai"
env_key = "AZURE_OPENAI_API_KEY"
query_params = { api-version = "2025-04-01-preview" }
wire_api = "responses"
The environment variable is set in both environments:
WSL:
printenv AZURE_OPENAI_API_KEY
Windows PowerShell:
echo $env:AZURE_OPENAI_API_KEY
Both commands return the correct key.
Despite this, Codex still reports the variable as missing.
What steps can reproduce the bug?
- Create
~/.codex/config.tomlon Windows with the Azure provider configuration - Set the environment variable
AZURE_OPENAI_API_KEY - Enable WSL mode (
runCodexInWindowsSubsystemForLinux=true) - Start the Codex App
- Open a project and send a prompt
Result:
Missing environment variable: AZURE_OPENAI_API_KEY
What is the expected behavior?
Codex should detect the existing environment variable and authenticate successfully.
Additional information
Environment:
Codex App version: 26.304.1528.0
Windows: Microsoft Windows NT 10.0.26100.0 x64
WSL: Ubuntu (WSL2)
Subscription: Azure OpenAI
The variable is available in both the Windows and WSL environments but is still reported as missing when Codex runs in WSL mode.
10 Comments
Are you sure the environment variable is exported? Can you see its value VS Code's built-in terminal?
yes, in VSCode connected to the same repo in WSL and executing "printenv AZURE_OPENAI_API_KEY" -> I see the key.
<img width="1019" height="400" alt="Image" src="https://github.com/user-attachments/assets/d9a9e4e9-ead0-465e-971a-79bbbe0dd97e" />
Fixed ?
same for the ZenMux provider
Also seeing this issue. A related issue is that the environment dropdown (cog in the top right) is not visible for new chats and that a newly created environment has to be manually selected using the environment dropdown, which only appears once you start the session, then still doesn't seem to work once turned on.
<img width="1475" height="701" alt="Image" src="https://github.com/user-attachments/assets/d255f2e7-d158-4d88-a375-250064ac6d41" />
<img width="1472" height="801" alt="Image" src="https://github.com/user-attachments/assets/0664a265-fd44-4c61-9c73-06a052ad1eb4" />
+1 on this. Did you find a way around?
+1
+1
I've kind of found the solution. The issue was my AZURE_OPENAI_API_KEY wasn't setting permanently in WSL.
So for me the solution was to set the key permanently and this is how I managed to do it:
AZURE_OPENAI_API_KEYand value in Edit environment variables for your account --> User variables interface.WSLENVor create one and set the value toAZURE_OPENAI_API_KEY/u(/uis important)wsl --shutdown)If this doesn't work, try this:
In WSL terminal:
nano ~/.bashrcexport AZURE_OPENAI_API_KEY="you-key"source ~/.bashrcLet me know if it helps.
Same problem here with codex app in wsl mode, although it works in cli and in the VSC codex extension, in wsl.
That's the config I am testing with:
Error: Missing environment variable:
OPENROUTER_API_KEY.But when I open a terminal in the codex app and run
echo $OPENROUTER_API_KEYit outputs the value.Same issue here — OpenRouter provider on native Linux (Oracle Linux 9, aarch64), Codex CLI v0.142.5, deepseek/deepseek-v4-flash.
Config:
OPENROUTER_API_KEYwas set in~/.bashrcand confirmed viaecho $OPENROUTER_API_KEY, but Codex still reportedMissing environment variable: OPENROUTER_API_KEY.Root cause: The persistent app-server daemon (
codex doctorshowedapp-server running (persistent mode)) was holding stale environment from before the key was added to.bashrc. The daemon starts on first Codex launch and never picks up new env vars.Fix that worked:
This confirms the issue isn't WSL-specific — it affects native Linux when the app-server daemon predates the env var being set. The CLI itself works fine once the daemon is restarted with the correct environment.