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:
``bash``
brew install codex
codex --version
# codex-cli 0.57.0
- Verify basic connectivity and API key working from WSL:
```bash
# 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:
```bash
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):
``bash``
mkdir -p ~/codex-test
cd ~/codex-test
echo 'print("hello")' > test.py
- Run Codex:
``bash``
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.
Additional information
~/.codex/config.tomlonly contains project trust entries like:
``toml``
[projects."/home/jjohnson/codex-test"]
trust_level = "trusted"
No custom provider configuration or base URLs are set.
- Environment related to Codex / OpenAI is minimal:
``bash``
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.
6 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
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
I have no proxy, VPN, or other shenanigans and I'm on 0.60.1
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:
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:
The Codex conversation could not start properly.
Claude Code error
Claude Code failed with errors like:
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:
Both returned:
This
405is expected because those endpoints expectPOST, notHEAD.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:
---
Root cause
The issue was caused by the default WSL2 NAT networking mode interacting badly with the Windows VPN.
With the VPN enabled:
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:
Add the following configuration:
Then fully restart WSL:
After restarting WSL, test the Codex endpoints inside WSL:
Expected output:
Again,
405is 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
codexis not installed inside WSL, install it with npm, not snap.Check Node and npm:
Install Codex:
Verify:
Then log in and test:
Avoid installing Codex with snap in this setup:
In my case, installing Codex through npm worked correctly after fixing WSL networking.
---
Final summary
The issue was:
The fix was to enable WSL2 mirrored networking:
Then restart WSL:
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.