> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ruapi.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Gemini API 报错「User location is not supported for the API use」：什么意思、怎么解决

> Gemini API 报 400 FAILED_PRECONDITION「User location is not supported for the API use」：为什么 Google 会按所在位置拒绝请求，为什么连云服务器上也会出现，以及怎么接入 Gemini 不再报这个错——换密钥和地址就行。

**先说结论**：这个错误是 Google 自己返回的：发往 Gemini API 的请求来自它地区名单以外的地方，就会报这个错。检查的是请求从哪个地址发出，而不是密钥：换新密钥、建新项目都没用。要让这个错误消失，请求就不能从你的地址发到 Google。用 RuAPI 的密钥正是这样：你在代码里换掉密钥和地址，Gemini 模型还是原来那些，不用 VPN。

## 报错长什么样

```json theme={null}
{
  "error": {
    "code": 400,
    "message": "User location is not supported for the API use.",
    "status": "FAILED_PRECONDITION"
  }
}
```

在 SDK 里，它会以异常的形式出现，状态码 400，文字一样：`User location is not supported for the API use.`

## 为什么会这样

* **Google 会检查请求从哪里来**。如果地址属于 [Available regions for Google AI Studio and Gemini API](https://ai.google.dev/gemini-api/docs/available-regions) 名单以外的地区，请求还没到模型就被拒绝了。
* **在支持的国家的服务器上也会出现**。Google 开发者论坛上有人反映过这种情况（[示例](https://discuss.ai.google.dev/t/gemini-api-returns-failed-precondition-user-location-is-not-supported-for-the-api-use/190618)）。
* **用 VPN 绕过不靠谱**。很多 VPN 地址 Google 也不放行，而且让跑着需要 Gemini 的程序的服务器一直挂 VPN，也很麻烦。

## 可以怎么办

| 情况 | 怎么办 |
| - | - |
| 服务器在支持的国家，但还是报错 | 查一下服务器地址被识别在哪里（`curl ipinfo.io`），换云服务的地域或出网线路 |
| 你本人所在的地区不在 Google 的名单里 | 通过 RuAPI 接入 Gemini，步骤见下 |
| 代码已经按 google-genai 写好了 | 什么都不用重写：同一个 RuAPI 密钥也支持 Google 格式，只要改 `api_key` 和 `base_url` |

## 通过 RuAPI 接入 Gemini

**1. 注册**

在 [www.ruapi.ai](https://www.ruapi.ai/?lng=zh-CN\&utm_source=docs\&utm_campaign=zh-gemini-user-location-not-supported) 注册，邮箱、Google 或 Yandex 都行。

**2. 充值**

控制台 →「**钱包管理**」：USDT 或 USDC（TRC20 / BEP20 / Polygon；USDT 还可以走 TON），5 USDT 起。还没有 USDT 的话，[用 SBP 拿卢布买](https://docs.ruapi.ai/zh/buy-usdt.md)。外国银行的卡（Visa / Mastercard）也收。

**3. 密钥**

控制台 →「**令牌管理**」→「**添加令牌**」，拿到一串 `sk-...`。

**4. 改代码**

换掉密钥和地址，其他代码保持不变。

```python google-genai（原来接 Google 的） theme={null}
from google import genai

client = genai.Client(
    api_key="sk-你的RuAPI密钥",
    http_options={"base_url": "https://www.ruapi.ai"},  # 不要加 /v1beta
)

response = client.models.generate_content(
    model="gemini-3.8-flash",
    contents="你好！",
)
print(response.text)
```

```python OpenAI SDK theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="sk-你的RuAPI密钥",
    base_url="https://www.ruapi.ai/v1",
)

resp = client.chat.completions.create(
    model="gemini-3.8-flash",
    messages=[{"role": "user", "content": "你好！"}],
)
print(resp.choices[0].message.content)
```

```bash curl theme={null}
curl "https://www.ruapi.ai/v1beta/models/gemini-3.8-flash:generateContent" \
  -H "x-goog-api-key: sk-你的RuAPI密钥" \
  -H "Content-Type: application/json" \
  -d '{ "contents": [{ "parts": [{ "text": "你好！" }] }] }'
```

选哪个 Gemini 模型（Argon、Flash、Flash-Lite、Pro），见 [Gemini API 指南](https://docs.ruapi.ai/zh/gemini-api.md)。

## 常见问题

> [accordion] 在 AI Studio 换新密钥或新建项目有用吗？
>
> 没用。Google 检查的不是密钥，而是请求从哪个地址发出。从同一个地址，新密钥也会报同样的错。

> [accordion] 这和 AI Studio 里的「not available in your region」是同一个错误吗？
>
> 原因一样，只是出现的地方不同：在 AI Studio 里是页面上的提示，在 API 里是 400 响应。AI Studio 另有一篇文章：[Google AI Studio：not available in your region](https://docs.ruapi.ai/zh/google-ai-studio-russia.md)。

> [accordion] 是原版 Gemini 吗？
>
> 是。都是 Google 的原版模型，比如 gemini-4-argon、gemini-3.8-flash，不掉包，不降质量。

## 接下来

> [card] [不用 VPN 用 Gemini API](https://docs.ruapi.ai/zh/gemini-api-russia.md)
>
> 三步接入，附 Python 和 curl 示例。

> [card] [RuAPI 错误码](https://docs.ruapi.ai/zh/errors.md)
>
> 400、401、403、429 是什么意思、怎么解决。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.