# Codex "Token exchange failed: error sending request": What to Check

- URL: https://www.aifreehelp.com/en/posts/codex-token-exchange-failed
- Published: 2026-12-05
- Updated: 2026-12-05
- AI Free Help Editorial Team

> **Short answer:** "Token exchange failed: error sending request for url (https://auth.openai.com/oauth/token)" in Codex means Codex sent its own sign-in request and got no answer, so the cause is a proxy, DNS, certificate or security-software setting on your computer. It is not a blocked account or an OpenAI outage, because only OpenAI's own sign-in page with a request ID points to a problem on OpenAI's side. If you have used a proxy or VPN app, first remove proxy settings that still point to an old port, including ~/.codex/.env, and otherwise check DNS on Linux or WSL, security software and "Run Codex in WSL" on Windows, or ask IT on a company network, where OpenAI documents CODEX_CA_CERTIFICATE and respect_system_proxy. There is no evidence that device code sign-in, a localhost proxy exception or waiting helps, and every codex login attempt signs out your current login first.

**Based on:** public user threads (2025–2026) · 7 official pages · counted December 5, 2026 · [How we word this](https://www.aifreehelp.com/en/editorial-policy#how-we-word-user-reports)

What this Codex sign-in error means, why the browser and curl still work, and which setting on your computer to check for your setup.

**Matching interface messages:**

- “Token exchange failed: error sending request for url (https://auth.openai.com/oauth/token)”
- “Sign-in failed: Login server error: Token exchange failed: error sending request for url (https://auth.openai.com/oauth/token)”
- “Error logging in with device code: error sending request for url (https://auth.openai.com/api/accounts/deviceauth/usercode)”

Signing in to Codex with ChatGPT has two parts. First you sign in on the OpenAI page in your browser. Then Codex itself sends the code from that page to auth.openai.com and gets your tokens back. "Token exchange failed: error sending request for url (https://auth.openai.com/oauth/token)" means the second part failed: Codex sent the request and got no HTTP response. That is why ChatGPT in the browser and a `curl` test can work while Codex fails. Codex uses its own proxy, DNS and certificate settings, and they can differ from your browser's and your terminal's.

OpenAI's documentation does not mention "Token exchange failed: error sending request for url". This page is based on OpenAI's Codex documentation, the public [openai/codex source code](https://github.com/openai/codex) and replies from OpenAI staff. This site is not affiliated with OpenAI.

## What "Token exchange failed" means, and the messages that look like it

"Token exchange failed: error sending request for url" in Codex means the token request never got an answer. The connection failed before any reply came back: the proxy port didn't answer, the name didn't resolve, the certificate check failed, or security software cut the connection. Codex hides the exact reason. When OpenAI's server does answer and refuses, the same line reads "token endpoint returned status …" instead ([Codex source: how the message is built](https://github.com/openai/codex/blob/97df242212f7239998ebab201e570a3d585afac4/codex-rs/login/src/server.rs#L491-L500)).

| What you see | What it means | What to do |
|---|---|---|
| `Token exchange failed: error sending request for url (https://auth.openai.com/oauth/token)` | No answer reached Codex. The problem is on your computer or network. | [Check your setup](#fix-it-check-the-setting-that-matches-your-setup) |
| `Token exchange failed: token endpoint returned status 403 Forbidden` (or another status) | OpenAI's server, or the service in front of it, answered and refused. If the text after it is `unsupported_country_region_territory`, your location is not on OpenAI's list of supported countries and regions. | A different case. The text after the status gives the reason. |
| An OpenAI page: "Authentication error", "Login failed. Please start the sign-in process again", `error_code: token_exchange_failed`, `request_id: …` | The exchange failed on OpenAI's side, not in Codex on your computer. | [Retry, then contact OpenAI with the request ID](#is-it-an-openai-outage-or-a-blocked-account) |
| `Error logging in with device code: error sending request for url (https://auth.openai.com/api/accounts/deviceauth/usercode)` | The same cause. Device code sign-in hits it one step earlier. | [Check your setup](#fix-it-check-the-setting-that-matches-your-setup) |
| "Sign-in completed but credentials could not be saved locally" (`persist_failed`) | The token exchange worked. Saving the login on your computer failed. | A different error |
| The browser shows "localhost refused to connect" or never comes back | The browser never got back to Codex on your computer. | A different error. See [Login on headless devices](https://learn.chatgpt.com/docs/auth#login-on-headless-devices). |

Each Codex app words it differently. The CLI prints "Token exchange error: …" and then "Error logging in: Token exchange failed: …". The browser page says "Sign-in could not be completed" with the error code `token_exchange_failed`. The desktop app shows "Sign-in failed: Login server error: Token exchange failed: …". These are all the same error.

If you are already signed in and see "[Your access token could not be refreshed](https://www.aifreehelp.com/en/posts/codex-access-token-could-not-be-refreshed)", or the sign-in finishes and then fails with "[workspace routing discovery failed](https://www.aifreehelp.com/en/posts/codex-workspace-routing-discovery-failed)", those are later steps with their own fixes.

## Fix it: check the setting that matches your setup

To fix "Token exchange failed: error sending request" in Codex, find the setting on your computer that stops Codex from reaching auth.openai.com. Don't keep running `codex login` to test each change. Every `codex login` signs out the saved login before it starts, so a failed attempt can also sign out a CLI or editor extension that still worked ([Codex source: login signs out first](https://github.com/openai/codex/blob/97df242212f7239998ebab201e570a3d585afac4/codex-rs/cli/src/login.rs#L130-L155)). Check first, then sign in once.

1. **Everyone: run `codex doctor` and read the network lines.**

   ```bash
   codex doctor
   ```

   The "network" line lists which proxy variables are set (names only), the macOS system proxy mode, and any `CODEX_CA_CERTIFICATE` or `SSL_CERT_FILE` file. The "reachability" line tests chatgpt.com, not auth.openai.com, but it uses the same proxy, DNS and certificate settings. "connect failed" points to a proxy, DNS or firewall problem. "TLS handshake or certificate validation failed" points to certificates or security software. If you only have the macOS desktop app, run its own copy: `"/Applications/ChatGPT.app/Contents/Resources/codex-cli/CodexCLI.app/Contents/MacOS/codex" doctor`.

   If you signed in with `codex login`, also open `~/.codex/log/codex-login.log`. OpenAI's [Authentication](https://learn.chatgpt.com/docs/auth#login-diagnostics) page says direct `codex login` runs write this file. A line with `oauth token exchange transport failure` and `is_connect=true` means Codex could not connect at all.

2. **If you use, or once used, a proxy or VPN app: remove proxy settings that point to a port nothing listens on.** Old proxy settings are a common cause for people with proxy apps. The app moved to a new port, and the old value stayed behind. Your browser follows the system settings, but Codex reads proxy variables such as `HTTPS_PROXY` and `ALL_PROXY` first. Look in three places:
   - Your terminal: `env | grep -i proxy` on macOS or Linux, or `Get-ChildItem Env: | Where-Object Name -like '*proxy*'` in PowerShell. On Windows, also search for "Edit environment variables for your account".
   - The file `~/.codex/.env` (on Windows `%USERPROFILE%\.codex\.env`). Every Codex app loads this file when it starts. Its values replace the same variables from your terminal, so a clean terminal does not rule it out ([Codex source: how .env is loaded](https://github.com/openai/codex/blob/97df242212f7239998ebab201e570a3d585afac4/codex-rs/arg0/src/lib.rs#L270-L303)).
   - Your shell profile (`~/.zshrc`, `~/.bashrc`), if an old `export` line sets these variables.

   Delete the lines for a proxy you no longer run. Then quit Codex completely, including the desktop app and the editor, and open it again. Since Codex 0.156.0, on macOS and Windows, the browser sign-in tries once more through the system proxy settings after a connection failure. On Linux and in WSL, that second try uses the same variables again. Device code sign-in has no second try.

3. **If you use Windows with antivirus or a firewall app: allow Codex in it.** HTTPS scanning and per-app rules can block Codex while the browser works. Allowing Codex, or turning off the HTTPS scanning feature, often fixes it. Pausing protection may not be enough. A desktop app update may also run `codex.exe` from a new folder, so a rule for the old path can stop working after an update.

4. **If you use Codex in VS Code or the desktop app on Windows with WSL: try with "Run Codex in WSL" turned off.** The extension setting is **Run Codex In Windows Subsystem For Linux** (`chatgpt.runCodexInWindowsSubsystemForLinux`, off by default, see [Codex IDE extension settings](https://learn.chatgpt.com/docs/ide/settings)). In the desktop app, open **Settings**, set **Agent environment** to **Windows native**, and restart the app. The change takes effect only after a restart ([ChatGPT desktop app for Windows](https://learn.chatgpt.com/docs/windows/windows-app#windows-subsystem-for-linux-wsl)). Turning WSL off often fixes this error. The reason is WSL's own network: its DNS, IPv6 route or proxy address can fail where Windows works. For example, a proxy at `127.0.0.1` on Windows is not reachable at that address from inside WSL. If you need WSL, fix its DNS in the next step instead.

5. **If you use Linux or WSL: check DNS.** DNS problems are a common cause on Linux and WSL.
   - Run `cat /etc/resolv.conf` and check that it lists a nameserver that works.
   - Run `getent hosts auth.openai.com`. If it returns only IPv6 addresses and your network has no working IPv6, Codex can fail while `curl` works.
   - Tools that take over DNS, such as Tailscale or Cloudflare WARP, can leave a resolver behind that Codex can't use. Disconnect them once and sign in again.

6. **If you set certificate variables, or your company inspects HTTPS: fix the certificate settings.**
   - Check for an `SSL_CERT_FILE` you don't need (`echo $SSL_CERT_FILE`, or `$env:SSL_CERT_FILE` in PowerShell). An old project or tool setup can leave one behind. When it is set, Codex trusts that file instead of your system's certificates. Remove it, then restart Codex from a fresh terminal.
   - On a company network that inspects HTTPS, OpenAI says to set `CODEX_CA_CERTIFICATE` to a PEM bundle before logging in ([Authentication: custom CA bundles](https://learn.chatgpt.com/docs/auth#custom-ca-bundles)). Set it in your shell or system, not in `~/.codex/.env`. Codex skips variables that start with `CODEX_` in that file.
   - In a Dev Container, install the `ca-certificates` package in the image before the extension starts.

7. **If your network only works through a company proxy or PAC file: use OpenAI's system proxy setting, or ask IT.** OpenAI's [Managed configuration](https://learn.chatgpt.com/docs/enterprise/managed-configuration#use-the-system-proxy-for-native-client-requests) page describes the experimental `respect_system_proxy` setting, which makes Codex use the macOS or Windows proxy settings. Turn it on with `codex features enable respect_system_proxy`, then restart Codex. On a managed computer, ask your administrator first. IT can also allow the domains in [OpenAI's network recommendations](https://help.openai.com/en/articles/9247338-network-recommendations-for-chatgpt-errors-on-web-and-apps), which include `*.openai.com` and `*.chatgpt.com`.

8. **If only the desktop app or the extension fails and the CLI signs in: update the app, then try one sign-in from another Codex app.** Updating the desktop app or the extension often works, but not for everyone. Signing in once from the CLI or another Codex app and then reopening the desktop app or the extension works for some people and not others. The desktop app may run its own copy of Codex, or run it inside WSL.

9. **If it still fails: use an API key for now and contact OpenAI.** [OpenAI staff on the forum: API key login is "probably the best workaround for now"](https://community.openai.com/t/1381736/3). OpenAI bills API key usage at standard API rates ([Authentication](https://learn.chatgpt.com/docs/auth)). When you contact OpenAI support, include the details OpenAI staff ask for: [OpenAI staff on the forum: send the exact error, your Codex version, and the time and time zone it happened](https://community.openai.com/t/1376953/4). Don't share `auth.json`, cookies or tokens.

## Is it an OpenAI outage or a blocked account?

"Token exchange failed: error sending request for url" in Codex is neither an OpenAI outage nor a blocked account. A blocked account or a server refusal sends an answer, and Codex then shows "token endpoint returned status …". The recent sign-in incidents in [OpenAI's status history](https://status.openai.com/history) do not mention this message, and there is no evidence that waiting clears it.

OpenAI's own sign-in page with `error_code: token_exchange_failed` and a `request_id` is different. That page comes from OpenAI's servers. On August 31, 2026, OpenAI Support said a failure on this page came from the Google sign-in token exchange, and later that day said the issue was fixed ([OpenAI staff on the forum: "it looks like this issue has already been resolved"](https://community.openai.com/t/1393787/12)). If you see that page, retry from a fresh browser tab. If it still fails, send the new request ID to OpenAI support.

## Fixes that don't hold up

Several common tips for Codex "Token exchange failed" are fixes for other sign-in failures. Skip these, or use them only as tests:

- **`codex login --device-auth`**: device code sign-in connects to the same auth.openai.com from the same computer, with the same proxy, DNS and certificates. It fails with the same "error sending request". OpenAI's [Login on headless devices](https://learn.chatgpt.com/docs/auth#login-on-headless-devices) recommends it for remote machines and for a blocked localhost callback, which is a different problem.
- **Excluding localhost, 127.0.0.1 and ::1 from your proxy, or freeing port 1455**: by the time Codex shows "Token exchange failed: error sending request", your browser has already reached Codex's local sign-in page on 127.0.0.1:1455. These changes fix a callback that never arrives.
- **Deleting `auth.json`**: it helps only in rare cases. `codex login` already clears the saved login before it starts. Deleting the whole `.codex` folder helps when the cause is a stale `.env` or an old setting inside it, but the folder also holds your local chats and settings. Check `.env` instead.
- **Waiting an hour or two**: this applies only to the OpenAI page with a request ID. See [the outage section above](#is-it-an-openai-outage-or-a-blocked-account).
- **Switching to a phone hotspot, reinstalling, repairing or resetting the app**: nobody reports these clearing it. A hotspot is still a useful test. If Codex fails the same way there, the cause is on your computer, not your home network.
- **Changing proxy modes or protocols**: removing settings that point to a dead port (step 2) and OpenAI's `respect_system_proxy` (step 7) are the supported checks.

## Sources

- [Authentication](https://learn.chatgpt.com/docs/auth) — Checked 2026-12-05
- [Managed configuration](https://learn.chatgpt.com/docs/enterprise/managed-configuration) — Checked 2026-12-05
- [Codex IDE extension settings](https://learn.chatgpt.com/docs/ide/settings) — Checked 2026-12-05
- [Environment variables](https://learn.chatgpt.com/docs/config-file/environment-variables) — Checked 2026-12-05
- [Network recommendations for ChatGPT errors on web and apps](https://help.openai.com/en/articles/9247338-network-recommendations-for-chatgpt-errors-on-web-and-apps) — Checked 2026-12-05
- [ChatGPT desktop app for Windows](https://learn.chatgpt.com/docs/windows/windows-app) — Checked 2026-12-05
- [OpenAI Status: incident history](https://status.openai.com/history) — Checked 2026-12-05
