Skip to content

Codex Token Exchange Failed: Fix "error sending request for url" at Sign-In

Sign-in could not be completed or Login server error? Codex itself cannot reach OpenAI. Check its proxy, the Windows app's proxy, firewall, then network.

•••18 min read•OpenAI Codex
Codex token exchange failed: the Codex process on your computer gets no answer from auth.openai.com because of a proxy, firewall, VPN or DNS problem, so the first check is the proxy Codex uses

Codex shows one of these messages when sign-in or a saved session fails:

text
# Browser page after you sign in (served by Codex on 127.0.0.1:1455)
Sign-in could not be completed
Token exchange failed: error sending request for url (https://auth.openai.com/oauth/token )
Error code token_exchange_failed

# Codex app or IDE extension
Sign-in failed: Login server error: Token exchange failed: error sending request for url (https://auth.openai.com/oauth/token )

# CLI, app or IDE after a session that used to work
Your access token could not be refreshed. Please log out and sign in again.

In the first two, error sending request for url means the Codex process on your computer never got an answer from auth.openai.com: a proxy, firewall, VPN, DNS or certificate problem on that machine, not a wrong password or a blocked account. Start with three checks:

  1. Proxy variables in the terminal that runs Codex (or the one that launched your editor): a HTTP_PROXY or HTTPS_PROXY that points at a proxy which is no longer running breaks Codex while the browser keeps working.
  2. Sign in again on a different network, such as a phone hotspot. If it works there, the original network path is the cause.
  3. On a remote or headless machine, use codex login --device-auth. If device code fails with the same error sending request for url, the network path is still the problem.

The commands for each step are in the checks below. If the terminal signs in but the Codex desktop app on Windows still fails, the app may not be using the proxy you set; that case has its own section. The third message is different: it means a stored session could not be renewed, and signing out and in again is the fix. If you are already signed in and see Connection failed: error sending request under Reconnecting... waiting for network, the failing connection is the model stream to chatgpt.com, not sign-in; see Codex keeps reconnecting: what “waiting for network” and 5/5 mean.

Token exchange failed and Your access token could not be refreshed both concern Codex authentication, but they describe different phases. An exchange error appears while Codex is trying to turn a browser authorization result into usable tokens. A refresh error appears after a session already existed and could not be renewed. OpenAI does not publish an exhaustive table that maps either line to one root cause.

A browser page saying sign-in completed is not the final proof. The process running Codex must receive the local loopback callback, reach the token endpoint, store the new credentials, and use them. Start by identifying that process and the last observable step; only then decide whether logout, device authentication, port forwarding, or network/TLS work is relevant.

Read the tail of the error before changing anything

Token exchange failed: error sending request for url (https://auth.openai.com/oauth/token ), token endpoint returned status 403 and Your access token could not be refreshed fail at different points, and the last part of the message tells you which one you have. Keep the full message, but redact secrets. Its tail narrows the boundary:

Observable signalWhat it establishesFirst useful check
error sending request for url (.../oauth/token), timeout, or connection failureThe Codex process did not complete a request to the token endpointTest network, proxy, and TLS from that process host, not just from the browser
token endpoint returned status 403The endpoint received the request and rejected itPreserve the status and sanitized context; verify account, workspace, and managed policy without guessing a regional cause
Browser finishes while CLI keeps waitingThe local loopback callback may not have reached CodexCheck whether the CLI or IDE extension host is inside WSL, SSH, a container, or another remote runtime
access token could not be refreshedA previously stored session could not renewInspect auth status on the execution host, then rebuild stored credentials through supported commands
CERTIFICATE_VERIFY_FAILED or an explicit CA errorThe process does not trust the certificate chain it seesUse a trusted corporate CA bundle only when that network condition is known

These are routing signals, not automatic diagnoses. In particular, a 403 proves rejection—not whether the account, workspace, proxy, region, or subscription caused it. When the 403 line ends with a reason such as Country, region, or territory not supported, the reason is part of the message; the 403 section explains it.

Codex sign-in sequence from browser sign-in to the local callback on port 1455, the token request to auth.openai.com/oauth/token and later session renewal, with four error messages marked where each one stops and the first check for each

Codex token exchange failed with "error sending request for url": checks in order

As of November 14, 2026, OpenAI has not named one root cause or a fixed version for this error: the main GitHub report, openai/codex#26764, has been open since June 6, 2026 without a maintainer fix, and newer reports about the Windows desktop app (October 5 to November 4, 2026) are open too. The checks below come from OpenAI support replies on the community forum and from causes users confirmed in that issue. Run them on the machine where Codex runs, one at a time, and retry sign-in after each.

1. Look at the proxy variables Codex inherits. On macOS or Linux:

bash
env | grep -i -E '^(http|https|all|no)_proxy='
echo "$SSL_CERT_FILE"
cat ~/.codex/.env 2>/dev/null

In PowerShell on Windows:

powershell
Get-ChildItem Env: | Where-Object Name -match '^(HTTPS?|ALL|NO)_PROXY$|^SSL_CERT_FILE$'
[Environment]::GetEnvironmentVariable('HTTPS_PROXY', 'User')
Get-Content "$HOME\.codex\.env" -ErrorAction SilentlyContinue

OpenAI support suggested starting from a clean terminal session and checking for conflicting HTTP_PROXY, HTTPS_PROXY, http_proxy or https_proxy values (forum reply, September 21, 2026). In issue #26764, users traced the error to an HTTPS_PROXY left pointing at 127.0.0.1:6850 after their proxy client moved to another port, and to a stale proxy port in ~/.codex/.env. Codex loads that .env file at startup (source), so a value there applies even when your shell shows none. Another Windows user found a stale SSL_CERT_FILE; Codex uses that variable as its CA bundle when CODEX_CA_CERTIFICATE is not set.

You can also ask Codex what it sees. codex doctor includes a network check that lists which proxy variables are present in the Codex process (including any loaded from ~/.codex/.env) and warns when CODEX_CA_CERTIFICATE or SSL_CERT_FILE points at a file it cannot read (source). A Windows user in #26764 found their stale SSL_CERT_FILE this way. On macOS, when a system proxy is configured but Codex is not using it, the same check suggests turning on the experimental System proxy setting described in the desktop app section.

bash
codex doctor

Fix what you find: point the variable at a proxy that is actually listening, or remove it for this session (unset HTTP_PROXY HTTPS_PROXY or Remove-Item Env:HTTPS_PROXY). If you need a proxy to reach OpenAI, keep localhost, 127.0.0.1 and ::1 in NO_PROXY so the browser's callback to Codex stays local. Then restart the editor or app, because it keeps the environment it was launched with. Codex CLI 0.156.0 (September 22, 2026) added a retry through the system proxy when the direct token request cannot connect (release notes), so check codex --version and update an older build.

2. Pause security software that filters traffic. OpenAI support suggested temporarily disabling VPN, antivirus web filtering, DNS filtering and corporate or security proxy tools, then trying again (forum reply, May 26, 2026). Open reports describe Windows desktop updates changing the codex.exe path so an existing firewall exception no longer matches (#50022), and an antivirus restricting new Codex runtimes (#48441). If pausing a tool fixes sign-in, turn it back on and add an exception for the current Codex executable rather than leaving protection off.

3. Try another network, then another OS user. Both OpenAI support replies suggest a different network such as a mobile hotspot, and signing in from a new user profile on the same computer. A hotspot success points at the original network (corporate proxy, DNS filter, firewall). A new-user success points at something in your account: environment variables, ~/.codex, or per-user proxy settings.

4. Sign in once with the CLI, then restart the editor. Community members on the forum and in #26764 got the IDE extension or the app working this way; it is not an OpenAI instruction. The CLI and IDE extension share cached login details, according to OpenAI's authentication guide:

bash
npm install -g @openai/codex
codex login

Complete the browser flow, then fully quit and reopen VS Code or the app. If codex login fails with the same message, go back to steps 1–3: the terminal shares the same network path.

5. Use device-code login when the browser callback cannot reach Codex. Run codex login --device-auth, open the link and enter the one-time code. Device code login is in beta and must be enabled in your ChatGPT security settings or by your workspace admin. It avoids the local callback on port 1455, but it still has to reach auth.openai.com. In both forum threads where OpenAI support replied, device code failed alongside the browser login with:

text
Error logging in with device code: error sending request for url (https://auth.openai.com/api/accounts/deviceauth/usercode )

The app reports the same failure as account/login/start failed: failed to request device code: error sending request for url (…). Either form means the network checks above still apply.

Corporate TLS proxy or private root CA: CODEX_CA_CERTIFICATE

For a corporate TLS proxy, the official auth guide documents CODEX_CA_CERTIFICATE for a trusted PEM bundle. Set it before logging in; when it is unset, Codex falls back to SSL_CERT_FILE. A certificate-chain error that names the CA explicitly is covered in the Codex self-signed certificate guide.

bash
export CODEX_CA_CERTIFICATE=/path/to/corporate-root-ca.pem
codex login

Read codex-login.log before you retry again

A direct codex login also writes a dedicated codex-login.log under the configured log directory. Use that log to identify callback, certificate, or browser-login failures, but redact tokens, email addresses, workspace identifiers, and private paths before sharing it.

The log normally says only that the request failed. To see which proxy Codex actually connected to, one user in #26764 (macOS, CLI 0.146.1, September 17, 2026) turned on the HTTP client's debug output for one login attempt:

bash
RUST_LOG='warn,reqwest=debug,hyper_util=debug,rustls=debug' codex login
tail -n 100 "${CODEX_HOME:-$HOME/.codex}/log/codex-login.log"

Their log showed proxy(http://127.0.0.1:7897/ ) intercepts 'https://auth.openai.com/' while the working proxy listened on 7890; the old port came from ~/.codex/.env. Look for the same kind of line and compare the port with the one your proxy client uses now.

Codex desktop app on Windows: the terminal signs in, the app does not

In the Windows app the same failure reads Sign-in failed: Login server error: Token exchange failed: error sending request for url (https://auth.openai.com/oauth/token ), or the browser shows the Sign-in could not be completed page, and on some builds the next attempt fails with workspace routing discovery timed out instead. A common pattern in GitHub reports from October and November 2026 is that codex login in a terminal succeeds and codex login status says you are logged in, yet the app keeps failing: the app is not sending its request through the proxy that works for your browser and terminal. As of November 14, 2026, OpenAI has not replied on any of these reports, so the steps below are what worked for the people who filed them.

Set the proxy at Windows user level, not only in a terminal. On app 26.1007.2314.0, adding the proxy to %USERPROFILE%\.codex\.env did not change the app, but setting the variables for the Windows user account did (#53261, October 14, 2026). An earlier report on 26.930.3930.0 saw codex.exe connect straight to port 443 despite the .env file (#50994). In PowerShell, with the port your proxy client actually uses:

powershell
$proxy = "http://127.0.0.1:7890"   # replace 7890 with your proxy's HTTP or mixed port
[Environment]::SetEnvironmentVariable("HTTP_PROXY", $proxy, "User")
[Environment]::SetEnvironmentVariable("HTTPS_PROXY", $proxy, "User")
[Environment]::SetEnvironmentVariable("NO_PROXY", "localhost,127.0.0.1,::1", "User")

Then quit the app completely, including from the system tray, and start it again so it reads the new environment. These variables apply to every program you start from then on. If you later change the proxy port or stop using the proxy, update or delete them ([Environment]::SetEnvironmentVariable("HTTPS_PROXY", $null, "User")); a forgotten user-level variable pointing at a dead port is one of the causes in step 1.

Turn on the System proxy setting. Codex has an experimental respect_system_proxy feature, off by default, that makes Codex requests follow the macOS or Windows system proxy settings, including PAC files, before proxy variables (feature definition). The reporter of #55826 (app 26.1013.4894.0, October 21, 2026), whose sign-in alternated between token_exchange_failed and workspace routing discovery timed out, got the app to sign in after adding this to %USERPROFILE%\.codex\config.toml and restarting:

toml
[features]
respect_system_proxy = true

From a terminal, codex features enable respect_system_proxy is the command Codex's own diagnostics suggest for the same setting. It is experimental: if your organization manages Codex settings, ask the administrator first.

If you recently changed your proxy client's port, try the old one. In #54839 (app 26.1013.3656.0, October 17, 2026) the app kept connecting to the port the previous proxy client used after Windows had been switched to a new one, with no stale variable anywhere. Setting the new proxy client to listen on the old port made sign-in work at once. A second user reported the same on 26.1016.8622.0 on November 4.

If none of this helps, sign in with the CLI as in step 4 of the checks, then reopen the app. That did not fix #59439 (26.1029.7803.0, behind a VPN, November 4), which is still open.

Reported causes and fixes by build, as of November 14, 2026

Each row is one user's report, with the build they ran. None has an OpenAI-confirmed fix version.

Where it failedWhat the reporter foundWhat worked for themReport and status
CLI 0.146.1, macOS~/.codex/.env still pointed at port 7897 after the proxy moved to 7890Correct the port in .env#26764, September 17; issue open
CLI and app, WindowsAn old SSL_CERT_FILE left over from another projectRemove the variable from the user (and, if present, system) environment#26764, September 14; issue open
App 26.930.3930.0, Windows, corporate proxyProxy in .codex\.env ignored; direct connections to port 443Start Codex with the proxy variables set; one user said a Store update fixed it, another said it did not#50994, October 5; open
App 26.1007.2314.0, Windows, local proxy client.codex\.env ignored while the bundled CLI was already logged inProxy variables at Windows user level#53261, October 14; open
App 26.1013.3656.0 and 26.1016.8622.0, WindowsThe app kept the proxy port from before a proxy-client switchSet the proxy client back to the old port#54839, October 17 and November 4; open
App 26.1013.4894.0, WindowsAlternated with workspace routing discovery timed outrespect_system_proxy = true#55826, October 21; open
App 26.1016.8120.0, Windows, authenticated corporate proxyThe proxy answered 407 (it wants NTLM or Kerberos sign-in)None reported#50994, October 23; open
App 26.1029.7803.0, Windows, VPNThe app fails while npm CLI 0.162.1 signs inNone yet#59439, November 4; open
CLI 0.160.1, Linux, Cloudflare WARPWARP's local DNS-over-HTTPS resolver; curl worked, Codex's lookup gave upwarp-cli disconnect, then codex login#51405, October 6; open
App, Windows, firewall or antivirusA desktop update moved codex.exe, so the firewall exception no longer matched; an antivirus restricted new Codex runtimesRe-add the exception for the current executable#50022, #48441; open

"token endpoint returned status 403": the request arrived and was rejected

Token exchange failed: token endpoint returned status 403 Forbidden: … is not a network failure. The request reached a server and came back with an HTTP 403 refusal, and Codex prints the reason it received after the colon (source). Proxy and firewall changes from the checks above will not change this answer unless they change where the request comes from.

When the reason reads Country, region, or territory not supported, OpenAI's error-code guide says the request is coming from a country, region, or territory OpenAI does not support. Compare your location with the supported countries list. If you are in a supported country, the request may be leaving through a VPN, proxy or company gateway located somewhere else; that is an inference from the wording, not something the message states. The reverse also follows: if your browser reaches OpenAI through a proxy but Codex does not use that proxy (the desktop app problems above), the token request leaves from your real location. That is again an inference, not something OpenAI has confirmed, but it is why fixing the app's proxy is worth trying before anything else when this 403 appears only in Codex.

A 403 with any other reason has no public OpenAI explanation. openai/codex#10466, opened February 3, 2026, is still open; the fix one user reported there was keeping localhost, 127.0.0.1 and ::1 in NO_PROXY. Keep the full status line and the request id if one is printed for the support message described at the end.

Browser says signed in but Codex keeps waiting: WSL, SSH, containers and port 1455

If the browser flow finishes but Codex never receives new credentials, the callback did not reach it. Repeating logout will not repair a blocked callback.

For a remote or headless CLI, OpenAI recommends device-code authentication when the normal browser flow cannot return to the local callback endpoint:

bash
codex login --device-auth

The option may need to be enabled by the personal account or workspace administrator. Follow the link and enter the one-time code; never share that code.

If you keep the standard browser flow and the CLI runs on a host reachable by SSH, OpenAI documents a local loopback callback on port 1455. Codex listens on 127.0.0.1:1455 on the host where it runs (port 1457 if 1455 stays busy). Forward the port from your local machine, then run login inside that SSH session:

bash
ssh -L 1455:localhost:1455 user@remote
codex login

Do not expose port 1455 publicly, and do not add forwarding when Codex already runs locally. This tunnel only closes the browser-to-remote-CLI callback path; it cannot repair an endpoint 403 or a certificate failure. The same applies inside WSL, a dev container or a VM: the callback has to reach port 1455 in the environment where Codex runs, so forward that port (VS Code Remote lists forwarded ports in its Ports panel) or use device code.

Managed environments can enforce ChatGPT versus API-key login and can restrict ChatGPT login to a specific workspace. If the freshly selected account is immediately rejected or logged out, stop rotating local credentials and ask the workspace administrator to confirm membership, provisioning, the required sign-in method, and the expected workspace.

Workload identity is another exception. OpenAI's auth documentation says user-driven codex login and codex logout are rejected when the process environment supplies workload identity. In that case, the identity provider, federation rule, and runtime environment own the repair.

Preserve the work before changing authentication

Before you sign out to clear Your access token could not be refreshed, or end Codex processes to retry a failed sign-in, save what the current session holds. An authentication error does not erase uncommitted files, but closing several clients and starting duplicate tasks can make the recovery confusing. Before signing out:

  • inspect the repository for changes that already landed;
  • copy any unsent prompt or useful error text to a safe note, with secrets removed;
  • record the local time, Codex surface, client version, project path, and last successful action;
  • stop retrying the same task in several windows.

Do not paste an access token, API key, OTP, Cookie, or the contents of auth.json into a ticket or chat. OpenAI's authentication documentation says file-based auth.json contains access tokens and should be treated like a password.

Find the surface that owns the failed session

The same sign-in or refresh error can come from the desktop app, the CLI, an IDE extension or a remote host, and the fix only works on the machine where the failing process runs. The visible screen and the executing process are not always on the same machine. A VS Code window on your laptop may run its extension host over Remote SSH. A terminal may be inside WSL or a container. A third-party harness may hold its own Codex OAuth profile even though the standalone CLI is healthy.

Where the error appearsCredential boundary to inspect firstWhat does not prove it is clear
Codex App on the local computerThe active App profile and local Codex credential storeLogging out of an unrelated browser profile
Codex CLIThe user and CODEX_HOME of that shell environmentA successful ChatGPT web session
VS Code or another IDEThe extension host; local or remoteReinstalling only the editor UI
WSL, SSH, dev container, or VMThe home directory or keyring inside that environmentLogging out on the laptop host
A separate agent or gatewayThat tool's own auth profile, if it has oneA healthy standalone Codex CLI session

OpenAI documents that the Codex CLI and IDE extension can share cached login details. Those details may be stored in ~/.codex/auth.json or in an operating-system credential store. That is why deleting a guessed file is a poor first move: there may be no file, the file may belong to another user, or the failing process may use a keyring.

Where Codex runs and which proxy it reads: the CLI uses shell variables and ~/.codex/.env, the IDE extension the environment the editor was launched with, the Windows app user-level variables, and a remote host its own environment, each with one check or fix

Clear and rebuild the CLI or IDE session

Your access token could not be refreshed. Please log out and sign in again. is fixed by clearing the saved session and signing in again on the host that shows it. The message comes in several versions, and each one tells you why the saved session could not be renewed (source):

End of the messageWhat it means
Your access token could not be refreshed. Please log out and sign in again.The renewal failed without a more specific reason
…because your refresh token has expired.The saved session is too old to renew
…because your refresh token was already used.The same saved session was renewed somewhere else first, for example when one auth.json is copied to several machines or containers
…because your refresh token was revoked.The saved session was revoked on OpenAI's side; the message does not say why
…because you have since logged out or signed in to another account. Please sign in again.The credential store now holds a different login than the one this running client started with

The message can also appear after a prefix such as failed to read configuration layers:, error loading configuration: or error running remote compact task:. The prefix only tells you which step needed a fresh token; the fix is the same.

On the machine where the failing Codex process runs, first inspect the current method:

bash
codex login status

This reports whether credentials are present and which authentication mode is active. It does not prove that the next model request will work, but it catches a common mismatch: the user expects ChatGPT subscription access while the process is using an API key, or the shell belongs to a different OS user than the editor.

For stored CLI authentication, use the supported logout command:

bash
codex logout
codex login

Complete the browser flow with the intended ChatGPT account and workspace. Then check the method again:

bash
codex login status

OpenAI's current authentication guide documents codex login, codex login status, and codex logout. Because CLI and IDE can share the cache, close and reopen the IDE after the new login instead of letting an old extension process keep stale state.

For the desktop app, use its profile menu to confirm the active account or API-key status, log out there, fully quit the app, reopen it, and sign in through the intended method. Do not assume that logging out of chatgpt.com in one browser profile clears the app's local credential store.

Still there after a fresh sign-in: an older Codex process holds the old session

If codex login status shows the new login but the CLI or app keeps saying …because you have since logged out or signed in to another account or …because your refresh token was revoked, a Codex process started before you signed in again may still be running with the old session. Two reports point this way:

  • On Linux with CLI 0.166.0, the "another account" message survived repeated logouts and logins and went away after the user ended all their codex processes (#56721, November 4, 2026).
  • With the Windows app working on a project over SSH, the "revoked" message stayed after signing in again on both machines. The user found older Codex app-server processes on the remote server, started before a CLI update, and ending them fixed it (#48112, September 25, 2026).

Ending Codex processes stops any task that is still running, so save your work first (see Preserve the work before changing authentication). On macOS, Linux or a remote host:

bash
ps -eo pid,lstart,args | grep '[c]odex'   # the start time shows which ones predate your sign-in
pkill -u "$USER" -x codex

On Windows, quit the app from the system tray and check Task Manager for codex.exe processes that are left behind; the Codex app-server guide has a PowerShell command that ends them all (it also ends IDE sessions that use Codex). Then sign in once more.

If the desktop app still shows …refresh token was revoked after all this, you are not alone: the same report on macOS (#48619, September 27) and Windows (#51327, October 6) is open without a fix or OpenAI reply as of November 14, 2026. Send it to support with the details listed at the end of this page.

Verify recovery instead of trusting the login screen

A clean result has three pieces of evidence:

  1. codex login status shows the intended authentication method.
  2. The app or IDE profile shows the intended account and workspace where that surface exposes them.
  3. One small, low-risk task completes in the same project and execution environment that originally failed.

Use a read-only or harmless task, such as asking Codex to summarize one non-sensitive file. Do not resume a large write immediately. If the small task works, reopen the original task and inspect the existing repository changes before continuing.

If status is correct but the small task still fails, preserve the exact new message. HTTP 429 belongs in the separate Codex rate-limit diagnostic. A stalled connection or tool call belongs in the Codex timeout diagnostic. A first-login phone or MFA prompt belongs in the Codex verification guide. Those are different problems even when they appear immediately after reauthentication.

Still failing: what to send OpenAI support

OpenAI support asks people who still see the token-exchange error on the latest version to email support@openai.com with the exact error, the Codex version, and the time and time zone it happened (forum reply, October 24, 2026).

If a fresh supported login on the correct host still produces the same refresh error, prepare a small support packet:

  • the redacted error text and timestamp with timezone;
  • App, CLI, or IDE surface and its version;
  • operating system plus local, WSL, SSH, container, or VM context;
  • active authentication method, without the token or full account identifier;
  • whether logout completed and whether the new browser or device flow returned successfully;
  • the result of one small verification task;
  • a sanitized excerpt from codex-login.log only if the new login failed.

Do not attach auth.json, access or refresh tokens, API keys, OTPs, Cookies, a full HAR file, or unredacted screenshots. The useful outcome is not merely a different login screen. It is a fresh credential on the correct execution host, tied to the intended account and method, that can complete a bounded Codex task.

Found an error, or hit a problem this article does not cover? Send the article URL and what you saw to hi@laozhang.ai. We check it and update the article.