Login failed — token exchange failed: error sending request to URL (https://auth.openai.com/oauth/token)
Open 💬 20 comments Opened Jun 6, 2026 by liuhongwei56
💡 Likely answer: A maintainer (etraut-openai, contributor)
responded on this thread — see the highlighted reply below.
What version of the Codex App are you using (From “About Codex” dialog)?
最新版本
What subscription do you have?
plus
What platform is your computer?
windows
What issue are you seeing?
错误代码
token_exchange_failed
细节
Token exchange failed: error sending request for url (https://auth.openai.com/oauth/token)
What steps can reproduce the bug?
无法登入codex,网页版可以正常使用
What is the expected behavior?
_No response_
Additional information
_No response_
20 Comments
macOS 26.5.1
Apple Silicon
Codex CLI 0.139.0
Same issue.
Web ChatGPT works.
Desktop login fails.
CLI login fails.
Device auth fails.
Token exchange failed:
error sending request for url
https://auth.openai.com/oauth/token
Same issue.
macOS 26.5.1
Apple Silicon
Codex CLI 0.139.0
Desktop login fails
CLI login fails
Device Auth fails
curl auth.openai.com works
curl chatgpt.com/backend-api returns cf-mitigated: challenge
English translation:
What version of the Codex App are you using (From “About Codex” dialog)?
Latest version
What subscription do you have?
plus
What platform is your computer?
windows
What issue are you seeing?
Error code
token_exchange_failed
Details
Token exchange failed: error sending request for url (https://auth.openai.com/oauth/token)
What steps can reproduce the bug?
Unable to log in to Codex; the web version works normally
What is the expected behavior?
_No response_
Additional information
_No response_
<!-- codex-issue-translator -->
same for here.... any idea?
same for my MacBook.
can any add some info? thanks
After deleting the dir "~/.codex", I could log in successfully finally. But I don't think this is a good way to solve this issue.
I can reproduce the same issue, but only when running the ChatGPT extension inside WSL Remote.
Environment
Behavior
Windows VS Code authenticates successfully.
The same account fails only when VS Code is connected to WSL Remote.
The browser login completes, but the callback page shows:
Running the bundled CLI directly produces the same result:
fails with:
and
also fails with:
Additional troubleshooting
curl https://auth.openai.com/oauth/tokensucceeds (HTTP 405 as expected).curl -4also succeeds.codexbinary is statically linked.This suggests the issue is specific to the Linux/WSL bundled Codex CLI rather than general network connectivity.
hi @etraut-openai , can you please add some update about this issue , thanks in advance
Codex Remote Login Troubleshooting
localhostRefused to ConnectAfter logging in, the browser may show:
localhost refused to connectCodex is running on the remote server, but the OAuth callback uses
localhost:1455. In VS Code Remote SSH, open the PORTS panel and forward remote port1455to the local machine. Then restart the Codex login process.Token Exchange Failed
After port forwarding, Codex may show:
Token exchange failed: error sending request for urlThis usually means the remote server cannot connect to the authentication service. Enable TUN mode for the proxy on both the local machine and the remote server, then restart the login process.
The issue is now resolved in my environment.
Previously, login failed with:
After updating, login succeeds with:
I did not change my WSL, proxy, network, CA certificate, or authentication settings.
Current environment:
So the issue may have been resolved by a recent VS Code, ChatGPT extension, or bundled Codex CLI update.
@sunny2eastgo i use the codex extension for Vs code, my VScode version is the last (1.129) and the version of the codex is the 26.5715. i already try update and change version several time but still get the same error every time.... and we dont have any answer about this.... i think is serious... please can some one add some info... thanks in advance
Resolved in my case. The root cause was a stale per-user proxy environment variable, not the Codex app itself.
My browser worked normally because it used the Windows system proxy, but Codex inherited old environment variables:
Port
6850was no longer listening. My actual proxy client was listening on127.0.0.1:7892. Because Codex was trying to use the dead port, it failed with:Before the login failure, I also saw repeated streaming errors:
What fixed it
7892with your own real port:To remove stale user variables instead:
ChatGPT.exeandcodex.exeprocess, then start the app again. Environment-variable changes only apply to newly started processes.After correcting the port and restarting all Codex/ChatGPT processes, both OAuth login and streaming worked immediately.
This is worth checking especially when browser login works but the Windows desktop app fails, and reinstalling the app does not help, because user environment variables survive an app reinstall.
I'm seeing the same issue on Arch Linux with codex-cli 0.145.0.
Environment
npm install -g @openai/codexReproduction
Diagnostics
codex doctorreports:Network checks
The OAuth endpoint itself is reachable.
Running:
returns the expected response:
Additional checks performed:
curl -I https://auth.openai.com/oauth/tokenreturnsHTTP/2 405(expected for a GET request).curl -4 -I https://chatgpt.comreaches Cloudflare normally.I've ruled out local networking, proxy configuration, and basic connectivity to
auth.openai.com.I'm happy to provide additional diagnostics or test a debug build if that would help.
I had the same issue, and I resolved it by following your instructions.
My device: Macbook Air, MacOS Sequoia 15.7.4
I had the same issue, solved by following instruction
症状:
token_exchange_failed
Token exchange failed: error sending request for url (https://auth.openai.com/oauth/token)
或者在登录失败之前反复出现:
stream disconnected before completion: error sending request for url (https://chatgpt.com/backend-api/codex/responses)
根本原因
问题的本质是:系统中残留了指向旧端口的代理环境变量(
HTTP_PROXY/HTTPS_PROXY),而你的代理软件早已切换到了新端口。HTTP_PROXY/HTTPS_PROXY来决定要不要走代理、走哪个端口。这个变量一旦被设置过,不会随着代理软件重启或换端口而自动更新,会一直"卡"在旧值上。解决方案
Say 7897 is the proxy we are using, 7890 is the old proxy.
(Make sure you know the proxy your VPN is using. May check it in the setting of VPN)
停用并保留备份:
清掉当前终端里的失效代理:
然后:
确认结果中不再出现
127.0.0.1:7890。Important
注意大小写代理“用途相似,但彼此不同“。特别注意大小写都要检查
在 macOS/Linux 中,环境变量区分大小写:
它们不会自动同步,删除小写也不会影响大写。不同程序读取规则也不同:
curl通常优先使用小写变量。curl出于安全原因只认http_proxy,不认HTTP_PROXY。i dont use any proxy, so that solutions for me don`t work :(
I am experiencing the same
token_exchange_failederror on Windows, but unlike the original report, I do not have a proxy configured.Environment
Error
The browser authentication step completes, but the Codex CLI fails during the OAuth code-to-token exchange.
Important context
Codex authentication was working correctly on the same machine, network and account before I ran
codex logout.After logout, I have been unable to authenticate again.
Before logout, Codex CLI 0.146.0 still recognized my ChatGPT Plus account, although the
codex_appsMCP connection was reporting an HTTP transport error.Troubleshooting already performed
auth.openai.comresolves correctly.HTTP_PROXY,HTTPS_PROXYorALL_PROXYenvironment variables are configured.codex login --device-auth.Additional observation
Both of these Codex-originated HTTPS operations failed:
codex_appsMCP connection to the ChatGPT backend.auth.openai.com/oauth/token.Browser and PowerShell HTTPS access work normally on the same machine.
This suggests that the failure may be specific to the HTTP/TLS client used internally by Codex on Windows, rather than a general network or browser connectivity problem.
Please let me know which Codex logs or diagnostic commands would be useful. I can provide sanitized output without authentication tokens or personal account information.
i just for add some news, now i can logging succesfully, but when i try to start a chat, never get a response..
<img width="426" height="204" alt="Image" src="https://github.com/user-attachments/assets/e4088b80-2f56-4450-a1df-c434fd15d84e" />
It’s very frustrating... I’m using an enterprise account paid for by my company, and after contacting support, they told me the problem is with OpenAI, not them... it’s unbelievable.
SOLVED / WORKAROUND FOUND on Windows 11 with Codex CLI 0.147.0 and Codex Desktop.
I was seeing the same login failures:
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)
Web authentication itself worked normally, and curl could reach the OpenAI auth endpoints successfully.
Workaround
What fixed both Codex CLI and Codex Desktop for me was configuring the proxy in Codex’s own dotenv file:
C:\Users\<username>\.codex\.env
with:
HTTP_PROXY=http://127.0.0.1:8888
HTTPS_PROXY=http://127.0.0.1:8888
NO_PROXY=localhost,127.0.0.1,::1
In my setup, 127.0.0.1:8888 is a local HTTP proxy forwarded through an SSH tunnel to a remote HTTP proxy.
After saving the file and restarting Codex:
codex login --device-authcompleted successfullyWhy this works
This is not just an arbitrary dotenv workaround.
In Codex 0.147.0, the startup code explicitly loads environment variables from:
~/.codex/.env
before creating the main runtime.
The source contains a dedicated
load_dotenv()path for this file, and normal environment variables such as HTTP_PROXY, HTTPS_PROXY and NO_PROXY are allowed to be loaded from it.So placing the proxy variables in
~/.codex/.envgives Codex itself access to those values at process startup, instead of relying only on environment variables inherited from the shell.I also verified this at the network level: the proxy logs showed Codex issuing:
CONNECT auth.openai.com:443
through the configured proxy.
One useful diagnostic detail: during testing, my SSH tunnel temporarily dropped and Codex immediately returned the same generic:
error sending request for url (...)
After restoring the tunnel, authentication succeeded again.
So for anyone seeing this Windows login error while browser login and curl still work:
~/.codex/.env.This worked for both CLI and Desktop in my environment.
Since Codex already has an explicit startup path for loading
~/.codex/.env, it may be useful to document this proxy configuration method in the official Windows authentication troubleshooting guide.