Skip to content
86% off$349 $48.86code BF2026

Guides

Codex CLI 401 Unauthorized: "exceeded retry limit" fix

Codex CLI stops with "exceeded retry limit, last status: 401 Unauthorized" after Reconnecting 1/5 to 5/5. Fixes in order, plus what to send OpenAI.

TroubleshootingUpdated 6 min read

On this page

You send a prompt in Codex CLI and see "Reconnecting... 1/5", then 2/5, up to 5/5. Then it gives up:

text
exceeded retry limit, last status: 401 Unauthorized, request id: 99927d40789dcbd0-MAD

The request id differs on every failure. Everything else is the same string.

Why it happens

A 401 means the server did not accept the credentials Codex sent. The "Reconnecting" counter is Codex retrying the same rejected request until it runs out of attempts, so the retries cannot fix it. The cause is on the credentials side.

The public report this article is based on (an OpenAI Codex GitHub issue from November 2025, macOS on Apple silicon) has no confirmed fix. Its related-issue list includes reports titled along the lines of "logout and login can't fix" and "Your refresh token has already been used". The causes below are ordered by how often they fit that pattern. They are our reading of those reports, not something OpenAI has confirmed.

Likely causeWhat you seeFix
Stale or already-used saved loginWorked for days, then every prompt failsFix 1
Damaged state in the login folderRe-login "succeeds" but 401 returnsFix 2
Two sessions sharing one loginFails after using Codex elsewhereFix 3
Custom provider or API key in config401 even right after a fresh loginFix 4
Old CLI versionReports from late 2025, no recent updateFix 5

Step-by-step fixes

Fix 1: Log out, then log in again

  1. Quit every running Codex session.

  2. Sign out completely:

    bash
    codex logout
  3. Sign in again:

    bash
    codex login
  4. Finish the sign-in in the browser, start codex, and send a short prompt.

On a machine without a usable browser (for example over SSH), try codex login --device-auth.

OpenAI's help center says that the first time you run Codex you choose Sign in with ChatGPT or another available sign-in method. Pick the same method you used before, so you can tell whether the method or the saved login is the problem.

Fix 2: Test with a fresh login folder

If Fix 1 changed nothing, this shows whether the old saved login state is the problem. Codex reads its config and login from ~/.codex by default, and an automation can point it elsewhere with CODEX_HOME. OpenAI's own docs mention that if your automation sets CODEX_HOME, you use $CODEX_HOME/config.toml instead.

  1. Log in with an empty folder:

    bash
    mkdir -p "$HOME/.codex-fresh"
    CODEX_HOME="$HOME/.codex-fresh" codex login
  2. Run Codex against the same folder:

    bash
    CODEX_HOME="$HOME/.codex-fresh" codex
  3. If prompts work, the old login state was the problem. Keep setting CODEX_HOME the same way, or move back to ~/.codex after clearing it.

  4. If you still get 401, the saved login is not the cause. Go to Fix 4.

To undo, delete ~/.codex-fresh. Your default folder is untouched.

Fix 3: Look for a second session using the same login

Use this if the error comes and goes, or appears after you used Codex on another machine, in a container, or in a second terminal that shares the login. The "refresh token has already been used" reports point at this pattern. We have not confirmed that it triggers the 401.

  • Close other Codex sessions that use the same login.
  • Run codex login once, in one place.
  • If you need several sessions at once, give each its own CODEX_HOME and its own login.

Fix 4: Check config and credentials storage

A fresh login can't help if Codex is not sending it.

  1. Open ~/.codex/config.toml (or $CODEX_HOME/config.toml).
  2. Look for a custom model_provider or a [model_providers...] section. Microsoft's Azure guide lists 401 Unauthorized or 403 Forbidden as a symptom when the API key environment variable is not exported correctly, so a leftover provider block with a dead key produces the same error.
  3. Comment out the provider settings, save, and run codex again.
  4. In the same shell, check for a stale key: env | grep -i openai. If an old key shows up, unset it and retry.
  5. If you use a ChatGPT subscription through a gateway, note that Databricks documents that an API key sign-in doesn't work with a ChatGPT subscription model provider service. Match the sign-in method to the provider.

OpenAI also documents a cli_auth_credentials_store setting that can keep CLI credentials in the secure OS keyring. If your config sets it, a login can live in the Keychain instead of a file in the login folder, so deleting files alone won't reset it.

Fix 5: Update Codex

The reports date from late 2025 and Codex ships releases often. Update it the same way you installed it, then repeat Fix 1. OpenAI's help center describes the standalone installer for macOS and Linux as the documented route. Check codex --version before and after, and note it for any bug report.

Fix 6: Try a different sign-in method

Codex can sign in with a ChatGPT account or an API key. If the ChatGPT login keeps returning 401, an API key shows whether the problem is tied to that login path. API-key use is billed separately through the OpenAI API, so check the cost first. OpenAI's help article on signing in with your ChatGPT account covers the ChatGPT path.

Checklist before you try again

  • No other Codex session is running with the same login.
  • You ran codex logout, then codex login, once.
  • config.toml has no leftover custom provider.
  • No stale OPENAI_API_KEY in your shell.
  • codex --version is current.
  • You tested once with a fresh CODEX_HOME.

If nothing works

This one needs OpenAI. Add your details to the GitHub issue for the original report, or open a new issue in the Codex repository. If you sign in with ChatGPT, the OpenAI help center is the other route. Include the full error line with its request id, your Codex version, macOS version and chip, your sign-in method, and what Fix 1 and Fix 2 did. Remove API keys and tokens from anything you paste.

text
Codex CLI fails every prompt with: "Reconnecting... 1/5" through "5/5", then
"exceeded retry limit, last status: 401 Unauthorized, request id: <your id>".

Codex version: <output of codex --version>
macOS: <version>, <chip>
Sign-in method: ChatGPT account / API key
Tried: codex logout + codex login; fresh CODEX_HOME folder; removed custom
provider from config.toml; updated Codex.
Other Codex sessions using this login: yes / no
Result: still 401.

Where Sledbot helps, and where it doesn't

Sledbot does not repair an expired or rejected token, and it can't change what OpenAI's server accepts. It helps in one case: you run Codex under more than one login and they overwrite each other. Each account you add in Settings ▸ Accounts (Add account…, then Subscription (CLI login), with Agent set to Codex) gets its own CODEX_HOME folder. Settings ▸ Agents also has Log in… and Update… buttons for Codex. If one Codex login in Terminal is all you use, the steps above are enough. See the accounts and fallback doc or Sledbot.

Common questions

Does the 1/5 to 5/5 counter mean my connection is bad?

Not here. The counter shows retries of a request the server rejected with 401. A network problem would normally look different, such as a timeout or a failed connection.

Is the request id useful?

Yes. It identifies that specific failed request, so include it when you contact OpenAI.

Will deleting ~/.codex fix it?

Sometimes, but Fix 2 gets the same answer without risking your config. If you do clear it, back it up first.

Could this be a usage limit?

A usage limit would normally say so rather than return 401. A 401 points at credentials, not quota.

Every app.
One purchase.