Troubleshooting · Codex CLI
Codex: stream error: unexpected status 401/404 — Fix
Mid-stream HTTP failures in Codex print as stream error: unexpected status. What 401, 404 and 429 mean there, and how to reproduce them with curl to find the broken half.
What you see
stream error: unexpected status 401 UnauthorizedWhy it happens
- 401 — the env_key variable is unset, empty, or its key does not belong to the base_url in the profile.
- 404 — the base_url is wrong for the wire protocol: a missing /v1, a doubled /v1/v1, or a host that does not serve the Responses API.
- 429 — the key's per-minute throughput is exhausted; the stream is refused before it starts.
- A proxy or network device cutting the SSE stream mid-response produces the disconnect variant rather than a status.
How to fix it
- Reproduce with curl against the exact base_url from the profile plus /responses, sending the same key — the status tells you which half is broken.
- For 401, fix the key/endpoint pair; for 404, fix the base_url to the documented value; for 429, wait out the window and reduce parallel runs.
- For repeated mid-stream disconnects with no status, test without VPN or proxy — SSE is the first casualty of interfering middleboxes.
Reproduce outside Codex
curl https://openai.api.apitoken.sale/v1/responses \
-H "Authorization: Bearer $APITOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-5.6-sol","input":"Reply with exactly: connected"}'Related searches
codex stream error unexpected statusstream disconnected before completion
FAQ
What does stream error: unexpected status 401 mean in Codex?+
The endpoint rejected the credentials at stream start. Check that the profile's env_key variable is set in the running shell and that its key belongs to the profile's base_url.
Why 404 when the host is clearly right?+
Path mistakes: base_url must include /v1 for this gateway, and must not double it. The Responses path is appended by Codex itself.
The stream dies halfway with no status — is that the API?+
Usually the network path: proxies and VPNs that buffer or terminate SSE. Reproduce with curl on a clean connection before blaming the endpoint.