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 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).
| 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 |
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 |
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 |
"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. |
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", or the sign-in finishes and then fails with "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). Check first, then sign in once.
-
Everyone: run
codex doctorand read the network lines.bashcodex doctorThe "network" line lists which proxy variables are set (names only), the macOS system proxy mode, and any
CODEX_CA_CERTIFICATEorSSL_CERT_FILEfile. 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 page says directcodex loginruns write this file. A line withoauth token exchange transport failureandis_connect=truemeans Codex could not connect at all. -
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_PROXYandALL_PROXYfirst. Look in three places:- Your terminal:
env | grep -i proxyon macOS or Linux, orGet-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). - Your shell profile (
~/.zshrc,~/.bashrc), if an oldexportline 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.
- Your terminal:
-
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.exefrom a new folder, so a rule for the old path can stop working after an update. -
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). 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). 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 at127.0.0.1on Windows is not reachable at that address from inside WSL. If you need WSL, fix its DNS in the next step instead. -
If you use Linux or WSL: check DNS. DNS problems are a common cause on Linux and WSL.
- Run
cat /etc/resolv.confand 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 whilecurlworks. - 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.
- Run
-
If you set certificate variables, or your company inspects HTTPS: fix the certificate settings.
- Check for an
SSL_CERT_FILEyou don't need (echo $SSL_CERT_FILE, or$env:SSL_CERT_FILEin 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_CERTIFICATEto a PEM bundle before logging in (Authentication: custom CA bundles). Set it in your shell or system, not in~/.codex/.env. Codex skips variables that start withCODEX_in that file. - In a Dev Container, install the
ca-certificatespackage in the image before the extension starts.
- Check for an
-
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 page describes the experimental
respect_system_proxysetting, which makes Codex use the macOS or Windows proxy settings. Turn it on withcodex 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, which include*.openai.comand*.chatgpt.com. -
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.
-
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". OpenAI bills API key usage at standard API rates (Authentication). 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. 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 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"). 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 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 loginalready clears the saved login before it starts. Deleting the whole.codexfolder helps when the cause is a stale.envor an old setting inside it, but the folder also holds your local chats and settings. Check.envinstead. - Waiting an hour or two: this applies only to the OpenAI page with a request ID. See the outage section above.
- 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.






