Fixing OpenAI and Codex 403 “unsupported_country_region_territory”
Why OpenAI and Codex return 403 unsupported_country_region_territory, how to fix false positives on VPNs or cloud IPs, and compliant alternatives.


What the error means
HTTP 403 with code: "unsupported_country_region_territory" (and type: "request_forbidden") means OpenAI's edge rejected your request because the IP address it saw geolocated to a country, region, or territory outside OpenAI's supported list. It can happen on direct OpenAI API calls, inside Codex CLI sessions, or during ChatGPT OAuth login (auth.openai.com/oauth/token).
{
"error": {
"code": "unsupported_country_region_territory",
"message": "Country, region, or territory not supported",
"param": null,
"type": "request_forbidden"
}
}What you should do next depends on one factual check: are you physically operating from a country on OpenAI's official supported list (platform.openai.com/docs/supported-countries), or not?
If you are in a supported country (false positives)
OpenAI enforces regional eligibility based on the egress IP that actually reaches its servers, not the billing address on your account. Even when you are in a supported country, four network setups commonly trigger a false positive.
| Cause | How to check | Fix |
|---|---|---|
| Corporate VPN, proxy, or split tunnel | Check HTTPS_PROXY / ALL_PROXY / NO_PROXY and inspect your current public egress IP | Route OpenAI traffic directly from your local supported-region network or fix corporate proxy egress |
| Cloud server, CI runner, or container IP | Confirm the cloud region of your VM, GitHub Actions runner, or NAT gateway | Move the workload or NAT egress to a cloud region in OpenAI's supported list |
| IPv6 vs. IPv4 geolocation mismatch | Compare your IPv4 and IPv6 exit addresses (curl -4 vs. curl -6 on an IP lookup service) | Ask your ISP or network admin to fix the IPv6 routing/geolocation, or use your verified IPv4 path |
Custom openai_base_url or LLM gateway | Run codex login status and check [model_providers.*] or OPENAI_BASE_URL | Confirm the gateway itself runs in a supported region, or clear stale proxy/base-URL env vars |
# Check whether shell proxy or custom base URL overrides are set
env | grep -iE 'proxy|openai_base_url'
# Check active Codex authentication method
codex login statusIf your home or office ISP IP is genuinely in a supported country and no VPN, proxy, or cloud relay is involved, the IP block was likely recently reassigned and carries stale geolocation data. Restarting your router to draw a fresh ISP lease sometimes resolves it; if the same block keeps returning 403, contact OpenAI Support (help.openai.com) with your public IP and ISP details.
If your country or region is not supported
Instead of fighting 403 blocks on OpenAI endpoints, pick a coding setup that runs locally on your own hardware or uses model providers that officially support your region:
- Run local models with Ollama or
mlx-lm: your code and prompts stay on your own machine with no external region check. Codex CLI itself supports open-weight local models viaollama launch codexorcodex --oss -m <model>, and Claude Code, OpenCode, and Pi also work with local endpoints. - Use coding agents and providers available in your region: DeepSeek Harness (
dsh), Kimi Code, Qwen Code, OpenCode, and Pi let you work with DeepSeek, Kimi, Qwen, GLM, or other models offered directly in your area. - Check enterprise cloud regions where available: teams running on Amazon Bedrock, Google Cloud Vertex AI, or Microsoft Foundry use their cloud provider's regional endpoints and billing rather than consumer OpenAI logins.
Article · Running Claude Code and Codex with Ollama: local models, 64k context, and setup → Running Codex and Claude Code on local models with Ollama (`ollama launch`, `codex --oss`, 64k context).
Article · DeepSeek Harness (DSH) in Mirasim: on any desktop, next to your other agents → DeepSeek Harness (DSH): open-source coding agent on Mac, Windows and Linux.
Article · Kimi Code in Mirasim: a desktop app for Kimi Code CLI, next to your other agents → Kimi Code: setup, models, and using it alongside other coding agents.
Article · Qwen Code in Mirasim: Alibaba's open-source coding agent, next to your other agents → Qwen Code: open-source CLI agent with Qwen models or any OpenAI-compatible endpoint.
Switching agents or local models in Mirasim
When a Codex session stops on a regional 403 or a provider you can't reach from your current network, you don't have to throw away the thread or rewrite your setup.
- Switch agent in the same pane: Mirasim's desktop app runs eleven coding agents on macOS, Windows, and Linux — including DeepSeek Harness, Kimi Code, Qwen Code, OpenCode, Pi, Claude Code, and Codex — and carries the conversation history when you hand a session over to another agent.
- Connect local models or regional API keys: add Ollama,
mlx-lm(on Apple silicon Mac), or any OpenAI-compatible provider available in your region under Settings › Models › Model providers, then pick it per session. Running on your own API keys or local models on your own computer uses zero Mirasim credit.
Chapter 16 · Models, accounts and quota › Local models → Running local models (Ollama and mlx-lm) inside Mirasim.
Questions
- Why did Codex work yesterday and suddenly return unsupported_country_region_territory today?
- Usually because your egress IP changed — you connected to a corporate VPN, switched Wi-Fi or mobile hotspot, moved to a different cloud/CI runner region, or your ISP assigned an IP range whose geolocation record is stale. Check your current IPv4 and IPv6 exit addresses and proxy environment variables first.
- Does switching from ChatGPT login to an OpenAI API key remove the region check?
- No. Both ChatGPT OAuth (
auth.openai.com/oauth/token) and OpenAI API requests enforce OpenAI's supported countries and territories list. - Can I still use Codex CLI with a local model if OpenAI's API is unavailable in my region?
- Yes. Codex CLI supports local open-weight models through Ollama (
ollama launch codexorcodex --oss -m <model>) or any OpenAI-compatible local server configured in~/.codex/config.toml, without calling OpenAI's hosted endpoints. - Is my OpenAI API key invalid when I see 403 request_forbidden?
- No. An invalid or revoked key returns HTTP 401. HTTP 403 with
unsupported_country_region_territoryis specifically a geographic restriction on the network egress reaching OpenAI.
Article · Codex login: sign in with ChatGPT or an API key, sign in on a server, and fix login problems → Codex login methods, credential storage, and other OAuth errors.
Article · Codex “stream disconnected before completion”: what it means and how to fix it → Fixing Codex “stream disconnected before completion” and network drops.
Article · Using an API key with Claude Code and Codex: setup, custom endpoints, and switching back → Using API keys and custom OpenAI-compatible endpoints with Codex and Claude Code.
Article · Configuring Claude Code and Codex behind a proxy, firewall, or custom CA certificate → Configuring HTTPS_PROXY, NO_PROXY and custom CA certificates for corporate networks.
Article · Running Claude Code and Codex on Amazon Bedrock, Vertex AI, and Microsoft Foundry → Running coding agents on Amazon Bedrock, Google Cloud Vertex AI, or Microsoft Foundry.
Sources
Checked on November 30, 2026 against OpenAI's Supported countries and territories documentation (platform.openai.com/docs/supported-countries), OpenAI API error code guidance (help.openai.com), and Ollama's Codex integration docs (docs.ollama.com/integrations/codex). Supported regions can change over time; check OpenAI's official list for current availability.
Keep reading

Running Claude Code and Codex on Amazon Bedrock, Vertex AI, and Microsoft Foundry
Connect Claude Code and Codex to Amazon Bedrock, Vertex AI, and Microsoft Foundry: env vars, config.toml, auth, model pinning, and limits.

Using Claude Code with Chrome and Codex Browser: live debugging, Playwright, and previews
How to connect Claude Code to Chrome (extension, console logs, login limits) and use Codex Browser or Playwright, plus live dev-server previews in Mirasim.

Cutting Claude Code and Codex token usage: /context, /compact, prompt caching, and model routing
How to cut Claude Code and Codex token spend and stretch usage limits: /context, /compact, /clear, prompt caching, subagents, and local usage tracking.