Codex CLI: failed to refresh token: 403 country, region, or territory not supported
This error means OpenAI's geographic restriction fired while Codex CLI was signing in with your OpenAI or ChatGPT account: at the token exchange after login, or when Codex tried to refresh an existing token. The refusal comes from OpenAI, not from your config and not from Codex itself. Retrying and re-running codex login repeat the same check against the same signals. The way out is to stop depending on the account login: point Codex CLI at a custom model provider and authenticate with an API key. go2llm publishes POST /v1/responses, the endpoint Codex CLI needs, and the setup is below.
Written 2026-10-26.
What the error looks like
Two wordings show up, depending on the step that failed:
failed to refresh token: 403 Forbidden: Country, region, or territory not supported
token exchange failed: token endpoint returned status 403 Forbidden: Country, region, or territory not supported
The first appears when a token you already had stops refreshing. The second appears during the login itself. Both end with the same sentence, and it is the same refusal that OpenAI's API returns as unsupported_country_region_territory, described on the 403 region not supported page.
Why it happens
Codex CLI's account login talks to OpenAI's own token endpoint. If the request comes from a country OpenAI does not serve, the endpoint answers 403 and the login stops there. Nothing about your key, balance or Codex version matters at that point.
Why a VPN is not a fix
OpenAI infers location from more than one signal: the request IP, the country of the billing card, the phone number used at signup, and the account's history. A VPN changes only the first. A login that passes today can fail on the next refresh, when the exit node changes or a check runs against a signal the VPN never touched. Regular IP changes inside one account can also end with the account being blocked at the vendor, which is worse than the 403.
This is a terms-of-service position of the vendor. There is no flag or setting in Codex CLI that overrides it, and go2llm does not promise to bypass it.
Fix: use a custom model provider with an API key
Codex CLI can send requests to a provider other than OpenAI. For that it needs a model_providers entry in ~/.codex/config.toml and a key in an environment variable. The request then goes to go2llm.tech with your go2llm key, and the OpenAI account login is not part of that path.
# ~/.codex/config.toml
[model_providers.go2llm]
name = "go2llm"
base_url = "https://api.go2llm.tech/v1"
env_key = "GO2LLM_API_KEY"
wire_api = "responses"
Fallback address: https://go2llm.tech/v1 — same key, same models. Switch to it if api.go2llm.tech does not open or a non-streaming response takes longer than 100 seconds.
Set the key in the shell that runs Codex:
export GO2LLM_API_KEY=YOUR_API_KEY
Then select the go2llm provider and a model from the published list (GET https://api.go2llm.tech/v1/models, no key needed). Keep wire_api = "responses": current Codex CLI rejects "chat" with "no longer supported", and base_url must end in /v1. The reasons are on the 404 on /v1/responses page.
What was checked and what was not
Checked on 2026-09-14: Codex CLI 0.151.0, codex exec through /v1/responses with wire_api = "responses" on the qwen3-8-flash model. It read a file in a test project, ran tools and made a real edit.
Not checked: other models (the endpoint serves the same models as chat.completions, but that is not a claim that every model works in Codex), the interactive codex TUI, and how Codex behaves if an old login state from a failed attempt is still on the machine. If the same 403 keeps appearing after you switch providers, the request is still reaching OpenAI's login: check which provider is selected.
The full config, the limits of the test run and the details of the endpoint are on the Codex API page. The documentation covers keys, balance and the other clients.
Related errors
- 404 on /v1/responses in Codex CLI: the
wire_apirules for custom providers. - 403 unsupported_country_region_territory: the same refusal on the API side, and the four gateway 403 codes.
- The full error reference.
FAQ
Why does Codex CLI say country, region, or territory not supported? Because OpenAI's token endpoint refused the request on geographic grounds while Codex was exchanging or refreshing your account token. It is a vendor-side restriction tied to location signals such as IP, billing country and phone number, not a broken Codex install.
Can I use Codex CLI without logging in to OpenAI? Yes, with a custom model provider. Configure model_providers.go2llm in ~/.codex/config.toml with wire_api = "responses" and put the key in the variable named by env_key. This was checked with codex exec 0.151.0 on qwen3-8-flash.
Does a VPN fix "403 country, region, or territory not supported"? Not reliably. A VPN changes the request IP, but OpenAI also looks at the billing country, the signup phone and the account history, and a changed exit node can break a login that worked a day earlier.
Does go2llm bypass the OpenAI restriction? No. go2llm is a separate gateway with its own catalog and prices, and it has no affiliation with OpenAI. You sign in to go2llm with its own key, so Codex does not use the OpenAI account login on this path.
Get a key and make your first request in 3 minutes → go2llm.tech. Registration credits $1 to your balance. Per-model prices are on the pricing page.