If you see an error like FAILED_PRECONDITION: User location is not supported when trying to log in to Gemini CLI or use the Gemini Code Assist extension in VS Code, the issue is not with your account or the code. Google AI Studio and the Gemini API are rolled out unevenly across countries, and some regions are simply excluded from the supported list. This can be resolved by setting up a proxy with an IP address from a permitted country — and we will discuss how to do this correctly in the terminal, in VS Code, and at the environment variable level.
What is Gemini CLI and Gemini Code Assist
Gemini CLI is a console tool from Google that allows you to interact with Gemini models directly from the terminal: write code, generate commands, analyze project files, and perform agent tasks without leaving your working environment. It accesses the API on the domains generativelanguage.googleapis.com or through Vertex AI, depending on which authorization method you use — either a Google AI Studio key or a Google Cloud account.
Gemini Code Assist is an extension for VS Code (as well as for JetBrains IDEs) that integrates suggestions, autocompletion, and chat with the model directly into the code editor. Essentially, it is the same API, but called from the IDE via an extension rather than from the command line. Both tools use the same backend, so the issue of regional blocking manifests similarly in both cases — the extension simply cannot establish a session or returns an error on the first request to the model.
An important nuance: both tools make network requests not only to the generation API itself but also to Google’s authorization services (OAuth, Identity Toolkit). If the proxy is set up only for one endpoint, authorization may succeed while generation fails, or vice versa. Therefore, the proxy needs to be defined at the system environment variable level, not just in one specific place.
Why Gemini is unavailable in your region
Google traditionally rolls out new AI products in stages: first the USA and parts of Europe, then other countries. For Gemini, this is expressed in geographical restrictions at the API level — the server checks the IP address of the incoming request (and sometimes the billing address of the Google account) and compares it to the list of allowed locations. If the country is not on the list, the request is terminated with a precondition error or simply times out without a clear explanation.
This is not a block in the usual sense — your country's provider is not cutting anything; it is specifically a geo-filter on Google's side. Accordingly, a VPN with a shared IP often does not help: such addresses are widely used by thousands of people, and Google marks them as suspicious, either requiring a CAPTCHA or still cutting off based on geo if the IP range is formally registered in the wrong country. You need an address that looks like a regular home or mobile IP from a supported region — that is, the task is exactly the same as what residential and mobile proxies solve.
Which proxy to choose for working with the Gemini API
For development tools like Gemini CLI, the key proxy parameters are session stability (to avoid connection drops in the middle of generating a long response), speed, and how "clean" the IP looks to Google’s anti-fraud systems. Here’s a comparison of three types:
| Proxy Type | Speed | Risk of Geo-Blocking | When to Use |
|---|---|---|---|
| Datacenter Proxies | High | Medium-High | Fast tests, one-off API requests |
| Residential Proxies | Medium-High | Low | Daily work with Gemini CLI and Code Assist |
| Mobile Proxies | Medium | Minimal | When residential IP is still blocked by geo-filter |
In practice, for daily developer work, the most convenient option is residential proxies tied to a specific country and preferably with a sticky session lasting 10-30 minutes — this is enough to avoid OAuth authorization drops and to keep the terminal session intact during code generation. Datacenter proxies are cheaper and faster, but some of Google’s ranges are already known and sometimes require additional account verification when logging in through such an IP. It’s wise to keep mobile proxies on hand — if a residential address unexpectedly ends up on the suspicious list, the mobile network of the operator usually passes the geo-check without issues.
Setting up a proxy in the terminal: Linux, macOS, Windows
Gemini CLI, like most console utilities on Node.js (which it is written in), respects the standard environment variables HTTP_PROXY and HTTPS_PROXY. This is sufficient to route all CLI traffic through the proxy without modifying application configs.
For macOS and Linux (bash/zsh), add to the current session:
export HTTP_PROXY="http://login:password@proxy_host:port"
export HTTPS_PROXY="http://login:password@proxy_host:port"
export NO_PROXY="localhost,127.0.0.1"
gemini --version
To make the proxy apply permanently, not just in the current terminal session, add these same lines to ~/.zshrc or ~/.bashrc and restart the terminal with the command source ~/.zshrc.
For Windows in PowerShell, set the variables like this:
$env:HTTP_PROXY = "http://login:password@proxy_host:port"
$env:HTTPS_PROXY = "http://login:password@proxy_host:port"
gemini --version
If you want the variables to persist after restarting PowerShell, use [System.Environment]::SetEnvironmentVariable("HTTPS_PROXY", "http://login:password@proxy_host:port", "User") — the variable will be written to the Windows user profile.
If your proxy requires separate authentication without a login in the URL (for example, via IP whitelist), simply remove the login and password from the connection string and add the IP of your server or workstation to the whitelist on the proxy provider’s panel.
Setting up a proxy in VS Code for Code Assist
VS Code has its own proxy settings that are not automatically inherited from system environment variables unless the corresponding option is enabled. Open settings.json (Ctrl+Shift+P → "Preferences: Open User Settings (JSON)") and add:
{
"http.proxy": "http://login:password@proxy_host:port",
"http.proxyStrictSSL": false,
"http.proxySupport": "override"
}
The parameter http.proxySupport: "override" is important: without it, VS Code may continue to use the system proxy or completely ignore the setting for individual extensions. After editing the settings, restart VS Code completely (not just reload the window), because the Gemini Code Assist extension initializes the network client once when the application starts.
If the extension still does not see the proxy, check the http.proxyAuthorization setting — in rare cases, corporate builds of VS Code block the transmission of login and password in the proxy URL for security reasons, and then credentials need to be passed through the Proxy-Authorization header in base64.
Another point — temporarily disable diagnostic extensions like corporate VPN clients and antivirus software with traffic interception (SSL inspection). They often replace the certificate on the fly, and Gemini Code Assist, which strictly checks Google’s certificate chain, will break the connection with a TLS error that can easily be mistaken for a proxy issue.
Setting up a proxy in Gemini CLI itself
In addition to environment variables, you can set a proxy in Gemini CLI through the project configuration file or global user settings — this is convenient if you want to use different proxies for different projects without touching system variables. The config is usually stored in ~/.gemini/settings.json or in a .env file inside the project directory:
# .env in the project root
GEMINI_API_KEY=your_key
HTTPS_PROXY=http://login:password@proxy_host:port
HTTP_PROXY=http://login:password@proxy_host:port
If you are authenticating through a Google Cloud account (Vertex AI) rather than through an AI Studio key, you will additionally need to ensure that the proxy is also used by the gcloud utility, through which the OAuth flow occurs. For it, the proxy is set separately:
gcloud config set proxy/type http
gcloud config set proxy/address proxy_host
gcloud config set proxy/port port
gcloud config set proxy/username login
gcloud config set proxy/password password
If after this gcloud auth login still opens the browser with the real (non-proxied) IP for login confirmation, note that the OAuth page itself opens in your system browser directly, and if the browser is not set to the same proxy, the final authorization session may receive a token tied to your real IP. For full consistency, it is advisable to set up the proxy in the browser you use to confirm the login — for example, through a proxy extension or system network settings during authorization.
Testing the connection: curl and Python
Before figuring out why Gemini CLI is not working, ensure that the proxy is generally passing traffic to the Google API. The fastest way is a direct request via curl:
curl -x http://login:password@proxy_host:port \
"https://generativelanguage.googleapis.com/v1beta/models?key=YOUR_API_KEY"
If a JSON response comes back with a list of models (gemini-1.5-flash, gemini-1.5-pro, and so on) — the proxy is working and the region is supported. If you see 403 or FAILED_PRECONDITION — the issue is at the geo-filter level, and you need to change the proxy country.
For more detailed diagnostics, it is convenient to use Python with an explicit proxy for the session:
import requests
proxies = {
"http": "http://login:password@proxy_host:port",
"https": "http://login:password@proxy_host:port",
}
url = "https://generativelanguage.googleapis.com/v1beta/models"
params = {"key": "YOUR_API_KEY"}
response = requests.get(url, params=params, proxies=proxies, timeout=15)
print(response.status_code)
print(response.text[:500])
This script is handy to keep on hand as a quick check before starting a full session in the CLI or IDE — it quickly shows whether the issue lies with the network, the key, or the IP region itself.
Common errors and their solutions
Error "User location is not supported" even after connecting a proxy usually means that the proxy server's IP is either in an unsupported country or Google has identified it as a datacenter IP and applied additional checks. The solution is to switch to a residential or mobile IP from the USA or another fully supported country for Gemini.
Timeouts when generating long responses are most often related to an unstable proxy session — the IP changes in the middle of a request, and the connection drops. A sticky session is needed for a duration exceeding the typical request (usually 10-15 minutes with a buffer is enough even for large code generations).
SSL/TLS handshake failed error almost always indicates traffic interception by antivirus software, a corporate firewall, or incorrectly configured proxyStrictSSL in VS Code. Check if there is SSL inspection software on the machine and temporarily disable it for diagnostics.
CLI works, but the extension in VS Code does not (or vice versa) means that environment variables are not passed to the VS Code process. This is a common situation in Linux and macOS if VS Code is launched not from the terminal where the variables were exported, but from an icon in the system menu. In this case, the variables need to be set through settings.json, as described above, rather than relying on inheritance from the shell.
IP binding to the API key region and security
A separate nuance that is often forgotten: if the API key or Google Cloud project was created with binding to a specific billing region, changing the proxy IP may lead to a mismatch between the expected and actual location, and Google sometimes requires re-verification via SMS or email. To reduce the frequency of such checks, try to use proxies with a constant (non-rotating for each request) IP from the same country — this appears to Google’s protection systems as normal user behavior, as if someone simply lives in that country, rather than as suspicious activity.
If you are working with multiple projects or keys simultaneously and using an anti-detect browser like Dolphin Anty or AdsPower to isolate profiles (relevant if testing Gemini integrations in different browser environments), bind a separate proxy with a fixed geolocation to each profile — this reduces the risk that one project will "drag" suspicions due to mixed IPs from another.
Also, do not use the same free or shared proxy for Gemini and at the same time for other high-load tasks — a large number of parallel sessions from one IP increases the chance of hitting a rate limit or temporary block at the Google level, which looks just like a regional issue, although the cause is entirely different.
Conclusion
The regional limitation of Gemini CLI and Gemini Code Assist is resolved at the network level: the proxy needs to be specified simultaneously in the system environment variables, in the VS Code settings, and, when using Google Cloud, in the gcloud config — only then will all three entry points (CLI, IDE extension, and OAuth authorization) work through the same IP without desynchronization. Always check the connection with a simple curl request before full operation — this saves hours on diagnostics when the problem is actually not in the code, but in the proxy country.
For stable daily work with Gemini CLI, the best fit is residential proxies with fixed geolocation and a long sticky session — they look like a regular home IP and rarely trigger additional checks from Google. If the residential address still falls under the geo-filter, it’s worth trying mobile proxies, and for quick one-off API tests without a long session, datacenter proxies will suffice.