codex-cli on WSL: ChatGPT login works but API key mode fails with error sending request for url (https://api.openai.com/v1/responses)
What version of Codex is running?
codex-cli 0.57.0
What subscription do you have?
Pro
Which model were you using?
any
What platform is your computer?
Ubuntu 24.04.1 LTS on WSL2
What issue are you seeing?
When using API key auth in Codex CLI on WSL, every call to the model fails with:
error sending request for url (https://api.openai.com/v1/responses)
The CLI retries a few times and then the conversation effectively times out / stalls.
However:
- The same API key works from WSL with plain
curlagainst/v1/responses. - Codex CLI on Windows PowerShell works with an API key.
- Codex CLI on WSL works if I sign in with ChatGPT instead of using an API key.
So the bug is specific to Codex CLI + WSL + API key auth. Network and the Responses API itself are fine.
What steps can reproduce the bug?
On Ubuntu 24.04.1 LTS in WSL:
-
Install Codex via Homebrew:
brew install codex codex --version # codex-cli 0.57.0 -
Verify basic connectivity and API key working from WSL:
# DNS / TLS checks ping -c 3 api.openai.com curl -sS https://api.openai.com/v1/models \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -H "Content-Type: application/json" \ -o /dev/null \ -w "HTTP %{http_code}\n" # -> HTTP 200 # Responses API check curl -sS https://api.openai.com/v1/responses \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4.1-mini", "input": "Say: hello from WSL." }' # -> returns a successful JSON response ("Hello from WSL!") -
Log into Codex using the same API key:
codex logout || true rm -f ~/.codex/auth.json # API key already set in env: # export OPENAI_API_KEY=... printenv OPENAI_API_KEY | codex login --with-api-key # "Successfully logged in" -
Use a minimal local project on the native Linux filesystem (not
/mnt/c):mkdir -p ~/codex-test cd ~/codex-test echo 'print("hello")' > test.py -
Run Codex:
codex "Say 'hello from codex-cli WSL' and then stop."
Observed behavior:
- The TUI starts, but the turn never completes.
- After ~some seconds the CLI complains about timeouts / “stream disconnected”.
- The log file
~/.codex/log/codex-tui.logshows repeatederror sending request for url (https://api.openai.com/v1/responses)errors.
Log snippet (timestamps redacted, but this is from the failing run):
INFO event.name="codex.conversation_starts" ... auth_mode="ApiKey" terminal.type=xterm-256color model=gpt-5-codex slug=gpt-5-codex provider_name=OpenAI ...
INFO event.name="codex.user_prompt" ... auth_mode="ApiKey" ... model=gpt-5-codex slug=gpt-5-codex ...
INFO event.name="codex.api_request" ... duration_ms=5002 error.message="error sending request for url (https://api.openai.com/v1/responses)" attempt=0
INFO event.name="codex.api_request" ... duration_ms=5002 error.message="error sending request for url (https://api.openai.com/v1/responses)" attempt=1
INFO event.name="codex.api_request" ... duration_ms=5004 error.message="error sending request for url (https://api.openai.com/v1/responses)" attempt=2
INFO event.name="codex.api_request" ... duration_ms=5002 error.message="error sending request for url (https://api.openai.com/v1/responses)" attempt=3
INFO event.name="codex.api_request" ... duration_ms=5005 error.message="error sending request for url (https://api.openai.com/v1/responses)" attempt=4
WARN stream disconnected - retrying turn (1/5 in 193ms)...
INFO event.name="codex.api_request" ... duration_ms=5006 error.message="error sending request for url (https://api.openai.com/v1/responses)" attempt=0
INFO interrupt received: abort current task, if any
INFO Shutting down Codex instance
During the same time window, a manual curl to https://api.openai.com/v1/responses with the same key and model works fine from the same WSL shell.
What is the expected behavior?
-
Codex CLI on WSL should be able to use the API key auth mode successfully, just like:
- Codex CLI on Windows PowerShell does.
- Codex CLI on WSL does when signed in with ChatGPT.
-
Specifically,
codexshould be able to send requests tohttps://api.openai.com/v1/responsesand stream responses without internal “error sending request” failures, given that:- The same endpoint and key work via
curlfrom the same machine. - There are no proxies or network restrictions.
- The same endpoint and key work via
Additional information
-
~/.codex/config.tomlonly contains project trust entries like:[projects."/home/jjohnson/codex-test"] trust_level = "trusted"No custom provider configuration or base URLs are set.
-
Environment related to Codex / OpenAI is minimal:
env | egrep -i 'OPENAI|CODEX|PROXY|HTTPS?_PROXY|ALL_PROXY' # OPENAI_API_KEY=... # (no PROXY or CODEX_* variables) -
Codex works fine on this same WSL instance when I use “Sign in with ChatGPT” instead of
--with-api-key. In that mode, the model responds normally. -
Codex also works fine on the Windows side (PowerShell) with API key auth, against the same project.
So the problem seems localized to codex-cli 0.57.0 → API key / api.openai.com code path on WSL, not to the account, project, key, or network.
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
- #6524
Powered by Codex Action
I also have this issue, albeit I'm on an Arch linux box not WSL. I couldn't use the chat-gpt login because I was getting a token auth failure so I swapped to API mode. I'm now getting the same message
2025-11-20T09:43:14.945468Z DEBUG starting new connection: https://api.openai.com/
2025-11-20T09:43:19.949745Z DEBUG Request failed method=POST url=https://api.openai.com/v1/responses error=error sending request for url (https://api.openai.com/v1/responses)
I have no proxy, VPN, or other shenanigans and I'm on 0.60.1
2025-11-20T09:42:23.439507Z INFO event.name="codex.user_prompt" event.timestamp=2025-11-20T09:42:23.439Z conversation.id=019aa0a4
-a096-7f03-9f68-0dac00e8cf1f app.version=0.60.1 auth_mode="ApiKey" terminal.type=kitty model=gpt-5.1-codex slug=gpt-5.1
-codex prompt_length=1700 prompt=[REDACTED]
I also see this issue.
Through extensive debugging we confirmed a bug in the OpenAI Codex CLI binary on Linux where it never sends an Authorization header in its HTTP requests to the OpenAI API, regardless of how the API key is provided. This is a Linux-specific issue — the Mac version reportedly works correctly.
I just gave up an moved to Claude
Fix: Codex and Claude Code not working in VS Code Remote WSL when VPN is enabled
Context
I was using:
- Windows host
- WSL2
- Ubuntu 26.04 in WSL
- VS Code Remote WSL
- OpenAI Codex CLI / Codex VS Code extension
- Claude Code CLI / Claude Code VS Code extension
- Corporate VPN enabled on Windows
Both Codex and Claude Code worked correctly without the VPN.
As soon as the VPN was enabled, both tools started failing inside WSL / VS Code Remote WSL.
Symptoms
Codex error
Codex failed with errors like:
MCP client for `codex_apps` failed to start
HTTP request failed:
error sending request for url (https://chatgpt.com/backend-api/wham/apps)
The Codex conversation could not start properly.
Claude Code error
Claude Code failed with errors like:
ECONNABORTED timeout
Slow first byte: no stream chunk 30.0s after request sent
At first, it looked like an OpenAI / Anthropic / VS Code extension issue, but it was actually caused by WSL2 networking with the VPN.
Diagnosis
From Windows PowerShell, with the VPN enabled, the Codex endpoints were reachable:
Invoke-WebRequest -Uri "https://chatgpt.com/backend-api/wham/apps" -Method Head -TimeoutSec 20
Invoke-WebRequest -Uri "https://chatgpt.com/backend-api/codex/responses" -Method Head -TimeoutSec 20
Both returned:
405 Method Not Allowed
This 405 is expected because those endpoints expect POST, not HEAD.
The important part is that Windows could reach the endpoints through the VPN.
However, from WSL2, the tools were failing or timing out when the VPN was enabled.
So the real issue was:
Windows + VPN worked.
WSL2 + default NAT networking + VPN caused Codex / Claude Code traffic to fail.
Root cause
The issue was caused by the default WSL2 NAT networking mode interacting badly with the Windows VPN.
With the VPN enabled:
- Windows networking worked.
- WSL2 networking was partially broken.
- Some HTTP/TLS traffic from WSL worked.
- Codex / Claude Code traffic failed or timed out.
- VS Code Remote WSL was affected because the extensions and CLIs were running inside WSL.
The problem was not Codex itself, Claude Code itself, or VS Code itself.
The problem was the WSL2 networking mode.
Fix
Create or edit this Windows file:
notepad $env:USERPROFILE\.wslconfig
Add the following configuration:
[wsl2]
networkingMode=mirrored
dnsTunneling=true
firewall=true
autoProxy=true
Then fully restart WSL:
wsl --shutdown
wsl
After restarting WSL, test the Codex endpoints inside WSL:
node -e "fetch('https://chatgpt.com/backend-api/wham/apps').then(r=>console.log(r.status)).catch(console.error)"
node -e "fetch('https://chatgpt.com/backend-api/codex/responses').then(r=>console.log(r.status)).catch(console.error)"
Expected output:
405
405
Again, 405 is fine here. It proves that the endpoints are reachable from WSL.
After enabling WSL2 mirrored networking, both Codex and Claude Code worked again with the VPN enabled.
Codex installation note
If codex is not installed inside WSL, install it with npm, not snap.
Check Node and npm:
node -v
npm -v
Install Codex:
sudo npm install -g @openai/codex@latest
Verify:
which codex
codex --version
Then log in and test:
codex login
codex "reply only yes"
Avoid installing Codex with snap in this setup:
sudo snap install codex
In my case, installing Codex through npm worked correctly after fixing WSL networking.
Final summary
The issue was:
WSL2 default NAT networking + Windows VPN caused Codex and Claude Code network requests to fail.
The fix was to enable WSL2 mirrored networking:
[wsl2]
networkingMode=mirrored
dnsTunneling=true
firewall=true
autoProxy=true
Then restart WSL:
wsl --shutdown
After switching WSL2 to mirrored networking, WSL used the VPN path correctly and Codex / Claude Code worked again inside VS Code Remote WSL with the VPN enabled.