← Blog

How-to5 min read

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.

Mirasim's agent and model picker for switching a session to local models or available regional coding agentsMirasim's agent and model picker for switching a session to local models or available regional coding agents

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).

Typical 403 response payload from OpenAI's API
{
  "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.

CauseHow to checkFix
Corporate VPN, proxy, or split tunnelCheck HTTPS_PROXY / ALL_PROXY / NO_PROXY and inspect your current public egress IPRoute OpenAI traffic directly from your local supported-region network or fix corporate proxy egress
Cloud server, CI runner, or container IPConfirm the cloud region of your VM, GitHub Actions runner, or NAT gatewayMove the workload or NAT egress to a cloud region in OpenAI's supported list
IPv6 vs. IPv4 geolocation mismatchCompare 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 gatewayRun codex login status and check [model_providers.*] or OPENAI_BASE_URLConfirm the gateway itself runs in a supported region, or clear stale proxy/base-URL env vars
Quick shell checks for proxy variables and Codex login status
# 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 status

If 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 via ollama launch codex or codex --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.

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.

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 codex or codex --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_territory is specifically a geographic restriction on the network egress reaching OpenAI.

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