指定访问模型的位置

点击您的 Gemini API 提供商,以查看此页面上特定于提供商的内容和代码。


Google 的生成式 AI 模型可在特定区域使用。您可以根据法规遵从、延迟时间、可用性和耐用性要求,选择要在哪些位置访问模型。

使用 Firebase AI Logic 时,您使用 Agent Platform Gemini API (formerly Vertex AI) 的每个请求都可以选择性地包含位置信息,以便访问模型。Firebase AI Logic 具有默认位置信息设置。

  • 使用新的“Agent Platform”初始化语法时:global
  • 使用旧版“Vertex AI”初始化语法时:us-central1

对于几乎所有 Gemini 模型,Agent Platform Gemini API (formerly Vertex AI) 支持 global 位置,这意味着您的请求将由全球池中任何可用的模型处理。为请求使用 global 位置有助于避免达到模型容量限制,并减少“服务过载”(503) 错误。此外,根据型号的不同,使用 global 位置信息可能是必需的

何时需要明确设置位置信息?

Firebase AI Logic 具有位置信息的自动默认值(例如,使用“Agent Platform”初始化语法时为 global)。不过,如果您需要或想要使用其他位置,则需要在代码中初始化 Agent Platform Gemini API (formerly Vertex AI) 后端服务时显式指定位置。

根据模型,可能需要明确设置位置。 如果您的请求尝试访问某个位置中不可用的模型,则会收到 404 错误,指出该模型 was not found or your project does not have access to it

  • Gemini 预览版实验版模型:仅在 global 位置提供(Live API 模型除外 - 请参阅下文)。

  • Gemini 3.x 型号:仅在 global 位置使用 Firebase AI Logic 时可用。 Firebase AI Logic 尚不支持 useu 位置。

  • Gemini 2.5 型号在许多地区均可使用

  • Gemini Live API 型号:仅在us-central1地区提供。global 位置受支持。

如需查看所有可用位置的列表,请参阅本页面的后续内容。

一般事实和最佳实践

以下是有关位置信息的一些关键事实和最佳实践:

  • 容量限制是按模型、按区域、按分钟设置的。

  • 为避免意外达到容量限制,请考虑使用位置 global(如果您的模型支持 global 位置)。

  • 不妨考虑使用 Firebase Remote Config 来控制访问模型的位置。这样一来,您无需发布应用的新版本即可更改位置。

  • 如果使用 global 的位置信息不适用于或不支持您的使用情形,请考虑明确分配您访问模型的位置。例如,您可以使用 Firebase Remote Config 根据最终用户的位置设置位置。

代码示例

Firebase AI Logic 具有位置信息的自动默认值(例如,使用“Agent Platform”初始化语法时为 global)。不过,如果您需要或想要使用其他位置,则需要在代码中初始化 Agent Platform Gemini API (formerly Vertex AI) 后端服务时显式指定位置。

LOCATION 替换为本页稍后列出的可用位置中的位置代码(例如 globaleurope-west4)。

Agent Platform 语法

Swift

// ...

// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the `agentPlatform` syntax, the default location is `global`, so
// specifying a location is usually optional since most models are supported in `global`.
let ai = FirebaseAI.firebaseAI(backend: .agentPlatform(location: "LOCATION"))

// ...

Kotlin

// ...

// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the `agentPlatform` syntax, the default location is `global`, so
// specifying a location is usually optional since most models are supported in `global`.
val ai = Firebase.ai(backend = GenerativeBackend.agentPlatform(location = "LOCATION"))

// ...

Java

// ...

// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the `agentPlatform` syntax, the default location is `global`, so
// specifying a location is usually optional since most models are supported in `global`.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.agentPlatform("LOCATION"));

// ...

Web

// ...

// Initialize FirebaseApp

// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the `AgentPlatformBackend` syntax, the default location is `global`, so
// specifying a location is usually optional since most models are supported in `global`.
const ai = getAI(firebaseApp, { backend: new AgentPlatformBackend('LOCATION') });

// ...

Dart

// ...

// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the `agentPlatform` syntax, the default location is `global`, so
// specifying a location is usually optional since most models are supported in `global`.
final ai = await FirebaseAI.agentPlatform(location: 'LOCATION');

// ...

Unity

// ...

// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the `AgentPlatform` syntax, the default location is `global`, so
// specifying a location is usually optional since most models are supported in `global`.
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.AgentPlatform(location: "LOCATION"));

// ...

Vertex AI 语法

Swift

// ...

// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the legacy `vertexai` syntax, the default location is `us-central`, so
// specifying a location is usually required since most models are *not* supported in `us-central`.
let ai = FirebaseAI.firebaseAI(backend: .vertexai(location: "LOCATION"))

// ...

Kotlin

// ...

// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the legacy `vertexAI` syntax, the default location is `us-central`, so
// specifying a location is usually required since most models are *not* supported in `us-central`.
val ai = Firebase.ai(backend = GenerativeBackend.vertexAI(location = "LOCATION"))

// ...

Java

// ...

// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the legacy `vertexAI` syntax, the default location is `us-central`, so
// specifying a location is usually required since most models are *not* supported in `us-central`.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.vertexAI("LOCATION"));

// ...

Web

// ...

// Initialize FirebaseApp

// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the legacy `VertexAIBackend` syntax, the default location is `us-central`, so
// specifying a location is usually required since most models are *not* supported in `us-central`.
const ai = getAI(firebaseApp, { backend: new VertexAIBackend('LOCATION') });

// ...

Dart

// ...

// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the legacy `vertexAI` syntax, the default location is `us-central`, so
// specifying a location is usually required since most models are *not* supported in `us-central`.
final ai = await FirebaseAI.vertexAI(location: 'LOCATION');

// ...

Unity

// ...

// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the legacy `VertexAI` syntax, the default location is `us-central`, so
// specifying a location is usually required since most models are *not* supported in `us-central`.
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.VertexAI(location: "LOCATION"));

// ...

请注意,如果您指定了模型不可用的位置,系统会返回 404 错误,指出模型 was not found or your project does not have access to it

可用位置

Google Cloud 使用区域Google Cloud 仅在您为 Agent Platform 上的生成式 AI 的所有正式版功能指定的区域中存储客户数据。

Agent Platform 上的生成式 AI 可在以下区域使用。 部分型号和/或特定版本可能无法在所有地区使用(如需详细了解地区可用性,请参阅 Google Cloud 文档)。

请注意以下几点:

  • Firebase AI Logic 默认为 us-central1 位置。

  • 对于所有 Gemini 预览版模型(Live API 模型除外),唯一受支持的位置是 global

  • 使用 Firebase AI Logic 访问 Gemini 3.x 模型时,唯一支持的位置是 globalFirebase AI Logic 尚不支持 useu 位置。

  • 对于所有 Live API 模型和所有 Imagen 模型,global 位置信息不受支持。

全球

  • global

美国

  • 俄亥俄州哥伦布 (us-east5)
  • 德克萨斯州达拉斯 (us-south1)
  • 爱荷华 (us-central1)
  • 内华达州,拉斯维加斯 (us-west4)
  • 南卡罗来纳州蒙克斯科纳 (us-east1)
  • 北弗吉尼亚 (us-east4)
  • 俄勒冈 (us-west1)

加拿大

  • 蒙特利尔 (northamerica-northeast1)

南美洲

  • 巴西圣保罗 (southamerica-east1)

欧洲

  • 比利时 (europe-west1)
  • 芬兰 (europe-north1)
  • 德国法兰克福 (europe-west3)
  • 英国伦敦 (europe-west2)
  • 西班牙马德里 (europe-southwest1)
  • 意大利米兰 (europe-west8)
  • 荷兰 (europe-west4)
  • 法国巴黎 (europe-west9)
  • 波兰华沙 (europe-central2)
  • 瑞士苏黎世 (europe-west6)

亚太地区

  • 中国台湾彰化 (asia-east1)
  • 中国香港 (asia-east2)
  • 印度孟买 (asia-south1)
  • 韩国首尔 (asia-northeast3)
  • 新加坡 (asia-southeast1)
  • 澳大利亚悉尼 (australia-southeast1)
  • 日本东京 (asia-northeast1)

中东

  • 沙特阿拉伯达曼 (me-central2)
  • 卡塔尔多哈 (me-central1)
  • 以色列特拉维夫 (me-west1)