Token exchange failed appears at the end of a ChatGPT login: you have already signed in in the browser, but Codex itself couldn’t get a token from auth.openai.com. Either it couldn’t reach that address, or the address answered with a 403. The browser and Codex use the network in different ways, so “everything opens in the browser” doesn’t prove much. You can fix the network and proxy with the steps below — or skip the login: with a key from RuAPI (an independent API gateway that works from Russia), Codex needs neither a ChatGPT account nor a VPN.
Which error do you have
In the app, the same sign-in error may be called
token_exchange_failed. The texts were checked against the Codex source code (server.rs, oauth/error.rs, protocol/error.rs) on 25 November 2026.
Why it happens
- Codex requests the token, not the browser. The login opens in the browser, but the last step — exchanging the code for a token — is done by Codex. If your proxy settings apply only to the browser, the browser part succeeds and Codex gets an error.
- Old proxy settings are still there. The proxy changed its port or is off, but
HTTP_PROXY/HTTPS_PROXYstill point to the old address. That’s what happened to users in this GitHub thread. - The proxy intercepts localhost. After the login, the browser returns to a local address on your computer, and that request must not go through a proxy: in a similar thread, excluding localhost helped some users. A Codex developer suspected there that the remaining cases mostly involve proxies and VPNs.
- The country is not supported. OpenAI doesn’t work in every country. The list for the API is on Supported countries and territories; the same page warns that access from other countries may get the account blocked.
What to try
1
Update Codex
codex update installs the latest version (if Codex was installed by the RuAPI command, update it as described here). codex doctor checks the installation, configuration and login.2
Remove old proxy settings
Check the
HTTP_PROXY, HTTPS_PROXY and ALL_PROXY variables and the ~/.codex/.env file: delete addresses that no longer work.3
Keep localhost out of the proxy
Add the variable
NO_PROXY=localhost,127.0.0.1,::1 and start the login in a new terminal window. If NO_PROXY is already set, don’t replace it; append these addresses after a comma.4
Check certificates
If your antivirus or work network inspects HTTPS, Codex may not trust the replaced certificate. Turn inspection off during the login, or check whether
SSL_CERT_FILE points to an outdated file.5
Sign in from the terminal
If the error is in the app, run
codex login in a terminal and return to the app: it helped one user.Codex without a ChatGPT login
Codex CLI can be connected with an API key, and then the token exchange step doesn’t exist. With RuAPI, requests go tohttps://www.ruapi.ai/v1, no VPN is needed, and you pay per token.
1
Account and key
Sign up at www.ruapi.ai with email, Google or Yandex. Key: Console → API Keys → Create API key.
2
Balance
Console → Wallet: USDT or USDC, from 5 USDT. No USDT yet? Buy it with rubles via SBP. Cards from foreign banks (Visa / Mastercard) are accepted too.
3
Codex
With one command or manually in
config.toml — see Codex CLI. Then start codex: it won’t ask you to sign in any more.FAQ
The browser login worked. Why does Codex show an error?
The browser login worked. Why does Codex show an error?
Because Codex itself requests the token, and its network settings may differ from the browser’s.
I get “unexpected status 403 Forbidden”, but I'm already signed in
I get “unexpected status 403 Forbidden”, but I'm already signed in
That is a request error, not a login error. Read the text after the colon: for example, the account may have no access to the selected workspace. If Codex is connected to RuAPI, a 403 usually means the balance is too low or the key isn’t allowed to use the model — see Error codes.
Will a new ChatGPT account help?
Will a new ChatGPT account help?
If the cause is the network, a proxy or the country, a new account will get the same error.
Can I sign in to Codex with an OpenAI key?
Can I sign in to Codex with an OpenAI key?
Yes, but that takes an OpenAI API key with a paid balance and access to OpenAI’s servers from your address. If the request is rejected because of the country, you’ll get unsupported_country_region_territory.
Next
Codex CLI setup
With one command or config.toml.
Codex: stream disconnected
The reply breaks off midway.