Country, Region, or Territory Not Supported: Proxy for OpenAI, Claude and Gemini APIs
Why the OpenAI API returns 403 Country, region, or territory not supported and Gemini returns User location is not supported, which proxy to use, and how to set it in Python, Node.js and CLI tools.
Key takeaways
From Russian addresses the OpenAI API returns 403 Country, region, or territory not supported, and the Anthropic API returns 403 Request not allowed. Both refuse before checking the key.
The Gemini API returns 400 User location is not supported for the API use, and it checks the country only after the key.
From China, connections to api.openai.com and the Gemini API timed out, and api.anthropic.com returned 403 Request not allowed.
For OpenAI and Anthropic a datacenter proxy in a supported country is enough. For Gemini we recommend an ISP proxy.
The Python libraries, Codex CLI, Gemini CLI and Claude Code read HTTPS_PROXY. Node.js reads it only with NODE_USE_ENV_PROXY=1.
With a proxy the account and the key stay yours, and the connection is encrypted all the way to the API.
Quick comparison
| Factor | OpenAI | Anthropic (Claude) | Google (Gemini) |
|---|---|---|---|
| From Russia, no key | 403, country not supported | 403 Request not allowed | 403, the same as from Germany |
| From China, no key | TCP connection timed out | 403 Request not allowed | TCP connection timed out |
| From Germany, no key | 401, key required | 401, key required | 403 PERMISSION_DENIED |
| Checked first | Country | Country | Key |
| Proxy in Python | HTTPS_PROXY or DefaultHttpxClient | HTTPS_PROXY or DefaultHttpxClient | HTTPS_PROXY or HttpOptions |
| Proxy in Node.js | NODE_USE_ENV_PROXY or undici | NODE_USE_ENV_PROXY or undici | NODE_USE_ENV_PROXY |
| Proxy in the CLI | HTTPS_PROXY (Codex) | HTTPS_PROXY (Claude Code) | HTTPS_PROXY (Gemini CLI) |
What the APIs return from Russia and China
On 15 November 2026 we sent the same requests to the OpenAI, Anthropic and Google APIs from hosting providers in Moscow and Saint Petersburg, from networks in Shanghai, Chengdu and Wuhan, and for comparison from a server in Germany. The requests carried no key, so the answer shows what each service does with the address before it looks at an account.
OpenAI answers Russian addresses with 403 and the error unsupported_country_region_territory. From Germany the same request gets 401 and a request for the key. The country is checked first.
Anthropic answers Russian and Chinese addresses with 403 and the message Request not allowed. From Germany the answer is 401, asking for the x-api-key header.
Google checks the key first. With no key, or with an invalid one, the answers from Russia and from Germany are identical, so an address for Gemini can only be tested with a request that carries a working key.
From Russia the connection is established and the refusal comes from the API itself. From China the connections to api.openai.com and generativelanguage.googleapis.com timed out before a connection was established, so there the network path fails before any check by the API.
HTTP/1.1 403 Forbidden
{
"error": {
"code": "unsupported_country_region_territory",
"message": "Country, region, or territory not supported",
"param": null,
"type": "request_forbidden"
}
}HTTP/1.1 403 Forbidden
{
"error": {
"type": "forbidden",
"message": "Request not allowed"
}
}“OpenAI and Anthropic check the country of the request address before the key. That is why a 403 arrives even on a request that carries no key.”
Country, region, or territory not supported and User location is not supported
Country, region, or territory not supported, with the code unsupported_country_region_territory, is OpenAI's answer when the request address is in an unsupported country. It arrives before the key is checked, so a new key or another account does not change it. Codex CLI prints the API's answers as a line of the form unexpected status 403 Forbidden, followed by the same text.
User location is not supported for the API use, with code 400 FAILED_PRECONDITION, is the Gemini API's answer. Google checks the key first, so this error only comes back on requests that carry a working key.
Request not allowed, with code 403, is the Anthropic API's answer.
The errors also appear on servers in supported countries. The service looks at the address the request leaves from, and that address can be in a different country from the server itself. Check the server's outgoing address before changing any code.
For Gemini, Google's developer forum describes a server in France that gets User location is not supported, although France is on Google's list and the Anthropic API works from the same server.
What a proxy changes, and what it does not
A proxy changes the address a request reaches the API from. When that address is in a country on the provider's list, the request goes on to the key check. The key, the account, the payment method and phone verification stay as they are.
Each provider publishes a list of countries. OpenAI states on its supported countries page that accessing its services outside the listed countries and territories may result in the account being blocked or suspended. Anthropic's supported regions policy is written around where the user and the organisation are located. Google publishes the list of countries where the Gemini API and AI Studio are available. Russia, mainland China and Hong Kong are not on any of the three lists.
Read the terms of the provider you work with before connecting. Proxya cannot promise how a provider will assess a particular account.
OpenAI supported countriesAnthropic supported regionsGemini API available regions
Proxy or API reseller
Access to AI APIs from unsupported regions is also sold by resellers. A reseller takes payment in local currency, issues its own key and sends requests to the provider from its own account.
With a proxy the account and the key stay yours, and the provider bills you directly. The connection is encrypted all the way from your server to the API: the proxy carries an encrypted stream and sees neither the key nor the text of the requests.
To put its own key on your requests, a reseller has to receive them in readable form on its servers. The choice depends on whether you have an account with the provider and a way to pay it.
Which proxy to choose
For the API one thing matters: an address in a country on the provider's list.
Datacenter proxies, from $1.70/proxy/mo, suit OpenAI and Anthropic. In our test a request from a hosting address in Germany got 401 from both, which means the address was accepted and the API moved on to the key.
ISP proxies, from $2.50/proxy/mo, are what we recommend for Gemini. The address is registered to an internet provider rather than a hosting company, held for you for the whole term, with unmetered traffic. They also suit using the same address in the web versions: ChatGPT, claude.ai and Google AI Studio.
Residential proxies, from $2.40/GB, rotate addresses and are billed per gigabyte. The API does not need them.
Keep the requests of one account on one address and in one country. For several accounts, use separate addresses.
Test a proxy with one command
Before changing any code, test the proxy address with curl. A 401 means the API accepted the address and expects a key. A 403 with a country error means the address is in an unsupported region.
For SOCKS5 use the socks5h scheme. The proxy then resolves api.openai.com, not your own DNS server.
This test does not work for Gemini: without a key the answer is the same from any country. Test it with a request that carries a key, from your code.
# 401: the address is accepted and the API expects a key
# 403 with a country error: the address is in an unsupported region
curl -x http://USER:PASS@HOST:PORT https://api.openai.com/v1/models
curl -x http://USER:PASS@HOST:PORT https://api.anthropic.com/v1/models
# SOCKS5: the proxy resolves the host name
curl -x socks5h://USER:PASS@HOST:PORT https://api.openai.com/v1/modelsPython: OpenAI, Anthropic and Gemini
All three official libraries read the HTTPS_PROXY variable when the client is created. This is the shortest route, and the code stays as it is.
When only the API requests should go through the proxy and the rest of the application should not, set the address in the client itself. OpenAI and Anthropic provide DefaultHttpxClient for this, and Google takes the client_args parameter in HttpOptions. For the asynchronous Gemini client, pass the same address in async_client_args.
We ran both routes on the current versions of the libraries through a local proxy that logs connections. All three libraries pass the host name to the proxy, so the DNS lookup is done by the proxy.
# The variable applies to the whole process
export HTTPS_PROXY=http://USER:PASS@HOST:PORT
python app.py# For the current window
$env:HTTPS_PROXY = "http://USER:PASS@HOST:PORT"
python app.py# Only these clients go through the proxy
from openai import OpenAI, DefaultHttpxClient
from anthropic import Anthropic, DefaultHttpxClient as AnthropicHttpxClient
from google import genai
from google.genai import types
PROXY = "http://USER:PASS@HOST:PORT"
openai_client = OpenAI(http_client=DefaultHttpxClient(proxy=PROXY))
claude_client = Anthropic(http_client=AnthropicHttpxClient(proxy=PROXY))
gemini_client = genai.Client(
http_options=types.HttpOptions(client_args={"proxy": PROXY}),
)Node.js
The built-in fetch in Node.js ignores HTTPS_PROXY by default. It reads the variable when NODE_USE_ENV_PROXY=1 is set, or when node runs with the --use-env-proxy flag. Support is in Node.js 24, and in Node.js 22 from 22.21.
The OpenAI, Anthropic and Google libraries use that fetch, so the variables are enough for all three.
The second route sets the proxy in the client through the undici package, taking fetch and ProxyAgent from it together. Passed a ProxyAgent without the fetch from the same package, the OpenAI library reports a connection error.
Use one route for the whole process. In our test, once the undici package was loaded, the built-in fetch stopped reading the proxy variables, and requests from the Gemini library went out directly.
# Node.js 24, or 22.21 and later
export NODE_USE_ENV_PROXY=1
export HTTPS_PROXY=http://USER:PASS@HOST:PORT
node app.js// fetch and ProxyAgent from the same package
import OpenAI from "openai";
import Anthropic from "@anthropic-ai/sdk";
import { fetch, ProxyAgent } from "undici";
const dispatcher = new ProxyAgent("http://USER:PASS@HOST:PORT");
const openai = new OpenAI({ fetch, fetchOptions: { dispatcher } });
const claude = new Anthropic({ fetch, fetchOptions: { dispatcher } });Codex, Gemini CLI, Claude Code and programs with no proxy settings
Codex CLI and Gemini CLI read the HTTPS_PROXY variable. In our test all of their connections went through the proxy: for Codex to api.openai.com, chatgpt.com and github.com, for Gemini CLI to generativelanguage.googleapis.com and play.googleapis.com. The proxy parameter in the Gemini CLI settings did not redirect any traffic in our test, so use the variable.
Claude Code reads HTTPS_PROXY as well and does not support SOCKS proxies. The full setup, including SOCKS5 through a local port, is in a separate guide.
For programs that have no proxy settings, use Proxya Desktop in tunnel mode. It sends all of the computer's traffic through the proxy, and the program connects as it normally does.
# Codex CLI, Gemini CLI and Claude Code read the same variable
export HTTPS_PROXY=http://USER:PASS@HOST:PORT
codex
gemini
claudeOn a server
Set the proxy in the API client when other services run on the same server. HTTPS_PROXY applies to the whole process, including requests to other external services.
When you use the variable, list the addresses that should go direct in NO_PROXY: localhost, internal domains and private network addresses.
Answers from reasoning models can take several minutes. If the connection drops on long requests, turn on streaming so that data keeps moving over the connection.
Keep the proxy address with its login and password alongside the API keys, in environment variables or a secrets manager, not in the code.
Frequently asked
OpenAI has placed the address the request came from in an unsupported country. The answer comes with code 403 and the code unsupported_country_region_territory, before the key is checked. If the server is in a supported country, check its outgoing address.
The service looks at the address the request leaves from, not at where the server stands, and the two can differ. Check the server's outgoing address. If it is in an unsupported country, send the API requests through a proxy in a supported one.
It is the Gemini API's answer, with code 400 FAILED_PRECONDITION, to a request from an unsupported region. It only comes back on requests with a working key. Developers also report it from server addresses in supported countries, which is why we recommend an ISP proxy for Gemini.
No. From Russian addresses the API returns 403 with the error unsupported_country_region_territory. The answer comes before the key is checked, so a new key changes nothing.
It is the Anthropic API's answer to a request from an unsupported region. In our test it came back with code 403 on requests from Russian and Chinese addresses. From an address in a supported country the same request gets 401 when no key is sent.
An ISP proxy in a country on Google's list. The address is registered to an internet provider rather than a hosting company and does not change for the whole term.
A datacenter or ISP proxy in a country on OpenAI's list. For requests from a server a datacenter proxy is enough. An ISP proxy suits when the same address is also used for the ChatGPT site.
With a proxy you use your own account and key, the provider bills you, and the connection is encrypted all the way to the API. A reseller sells access through its own account and receives your requests on its servers.
Proxya proxies work over HTTP and SOCKS5. For the SDKs and the CLI tools, HTTP is simpler: every library in this guide accepts it with no extra packages, and Claude Code does not support SOCKS.
Google checks the key before the country. API key not valid means the key is wrong and says nothing about the address. Check the key, then send a request with a working key through the proxy.
Providers tie access to the country where the user is located. OpenAI states that access from outside its list may result in the account being blocked or suspended. We cannot promise how a provider will assess a particular account.
In our test, connections from Chinese networks to api.openai.com and generativelanguage.googleapis.com timed out, and api.anthropic.com returned 403 Request not allowed. Through a proxy the request reaches the API from the proxy's address, provided the proxy itself is reachable from your network.