Stream error

Resolved 💬 9 comments Opened Sep 27, 2025 by EthanDuan05 Closed Nov 12, 2025
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

What version of Codex is running?

codex-cli 0.42.0

Which model were you using?

gpt-5-codex-high

What platform is your computer?

Darwin 24.2.0 arm64 arm

What steps can reproduce the bug?

Simply type anything into the CLI
Example:
1, start codex: codex
2, type anything: hi
3, Bug occurs:
⚠️ stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 1/5 in 199ms…

⚠️ stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 2/5 in 432ms…

⚠️ stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 3/5 in 824ms…

⚠️ stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 4/5 in 1.629s…

⚠️ stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 5/5 in 3.166s…

■ exceeded retry limit, last status: 401 Unauthorized

What is the expected behavior?

Simply type anything into the CLI
Example:
1, start codex: codex
2, type anything: hi
3, Bug occurs:
⚠️ stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 1/5 in 199ms…

⚠️ stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 2/5 in 432ms…

⚠️ stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 3/5 in 824ms…

⚠️ stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 4/5 in 1.629s…

⚠️ stream error: exceeded retry limit, last status: 401 Unauthorized; retrying 5/5 in 3.166s…

■ exceeded retry limit, last status: 401 Unauthorized

What do you see instead?

_No response_

Additional information

_No response_

View original on GitHub ↗

9 Comments

maxiedaniels · 9 months ago

I fixed this yesterday by logging out and back in on Codex, but its happening today suddenly again. Surely this is a bug?

codedevmk · 9 months ago

same issue, yet when I check my context rate it clearly shows near zero usage.
5h limit. 0% used · resets 11:13 PM
Weekly limit. 10% used · resets Oct 1

CryptoScient · 9 months ago

I have tried everything in the past week to make this work but still get 401 errors. Only direct responces API works:

What we’ve checked so far:
• Headers policy: true none (no OpenAI-Project/OpenAI-Organization), project-only, project+org, and org-only. ✔️
• Config hygiene: API‑key mode, wire_api="responses", correct TOML mapping. ✔️
• CLI versions: 0.40.0 → 0.43.0‑alpha.2, each pinned with npx. ✔️
• Base URLs: both root and v1 variants to detect path vs. auth issues. ✔️
• Controls: direct Responses API (sync + SSE) succeed. ✔️

This is exactly the right isolation sequence. It shows the problem is specific to the CLI’s streaming endpoint authorization, not key or project.

If anyone finds the solution please let me know

Bl4ckh34d · 9 months ago

Same problem here but no solution so far.

scottjs · 9 months ago

I was having this issue when trying to wire this up with a github action, this I had to run codex login first by piping the API key.

This is how I've fixed it:

      - name: Prepare Codex home
        run: |
          export CODEX_HOME="${{ runner.temp }}/.codex"
          echo "CODEX_HOME=$CODEX_HOME" >> $GITHUB_ENV
          mkdir -p "$CODEX_HOME"
          touch "$CODEX_HOME/config.toml"

      - name: Codex login
        env:
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
        run: |
          printf '%s' "$OPENAI_API_KEY" | codex login --with-api-key
          codex login status

      - name: Run Codex CLI
        run: |
          set -e
          codex --full-auto exec -s workspace-write -- <<'PROMPT'
          Implement JIRA ticket ${{ inputs.issue_key }}: ${{ inputs.issue_summary }}.

          ${{ inputs.issue_description }}

          Requirements:
          - Follow repository conventions.
          - Do not modify CI workflows.
          - You are running in CI/CD mode.
          PROMPT

This was originally inspired by: https://cookbook.openai.com/examples/codex/jira-github

If you're just trying to use your standard ChatGPT account (and not use the API) the resetting your local env and re-logging in also seems to help.

mahmutsalman · 9 months ago

I am having the same issue, too. Although I haven't used it and I have a usage limit, this error still occurs. After i log out and log in again it resolved for now.

naillizard · 9 months ago

I'm having this issue also, if I login with chatgpt plus it just works, I then logout from chatgpt and use an apikey from openai with full access and I start getting these errors:

stream error: exceeded retry limit, last status: 401 Unauthorized, request id: ********-AKL; retrying....

Funny thing is, using opencode with the gpt-5-codex works!

<img width="607" height="295" alt="Image" src="https://github.com/user-attachments/assets/baa6628d-8d81-48ac-b72d-df84a9181fa0" />

naillizard · 9 months ago
I'm having this issue also, if I login with chatgpt plus it just works, I then logout from chatgpt and use an apikey from openai with full access and I start getting these errors: `` stream error: exceeded retry limit, last status: 401 Unauthorized, request id: ********-AKL; retrying.... `` Funny thing is, using opencode with the gpt-5-codex works! <img alt="Image" width="607" height="295" src="https://private-user-images.githubusercontent.com/1164234/502315125-baa6628d-8d81-48ac-b72d-df84a9181fa0.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NjA2NTcwOTYsIm5iZiI6MTc2MDY1Njc5NiwicGF0aCI6Ii8xMTY0MjM0LzUwMjMxNTEyNS1iYWE2NjI4ZC04ZDgxLTQ4YWMtYjcyZC1kZjg0YTkxODFmYTAucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MTAxNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTEwMTZUMjMxOTU2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OTIxOWE3MmNkODAxNzRmNzIyY2Y0YzY3NWVkMThkMjY4YWRjMjllYzkzMDNiZGY0MTRmZDMyMzZkNWNhZjE5MCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.RFa-bJELpobycJ02fUBxLnxWCOjN9aUR_NVjOAeNtnE">

never mind, I resolved it, missed an important step

codex --config preferred_auth_method="apikey"

https://developers.openai.com/codex/pricing#use-your-api-key-with-codex-cli

etraut-openai contributor · 8 months ago

This was a problem with token refresh. It has been fixed in more recent versions, so I'm going to close this issue. If you're seeing other stream errors with the latest version of codex, please open a new issue.