|
点击您的 Gemini API 提供商,以查看此页面上特定于提供商的内容和代码。 |
Google 的生成式 AI 模型可在特定区域使用。您可以根据法规遵从、延迟时间、可用性和耐用性要求,选择要在哪些位置访问模型。
使用 Firebase AI Logic 时,您使用 Agent Platform Gemini API (formerly Vertex AI) 的每个请求都可以选择性地包含位置信息,以便访问模型。Firebase AI Logic 具有默认位置信息设置。
- 使用新的“Agent Platform”初始化语法时:
global - 使用旧版“Vertex AI”初始化语法时:
us-central1
关于 global 位置信息
对于几乎所有 Gemini 模型,Agent Platform Gemini API (formerly Vertex AI) 提供 global 位置,这意味着您的请求将由全球池中任何可用的模型处理。
为请求使用 global 位置有助于避免达到模型容量上限,并减少“服务过载”(503) 错误。此外,根据模型的不同,使用 global 位置可能是必需的,因为它是该模型唯一可用的位置(例如,预览版 Gemini 模型)。
何时需要明确设置位置信息?
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位置提供。Gemini 3.x 稳定模型:可在
global位置使用,通常也可在us和eu位置使用。Gemini 2.5 型号: 在许多地区均可使用。 请注意,Gemini Live API 2.5 模型在
global中不可用。
如需查看所有可用位置的列表,请参阅本页面的后续内容。
一般事实和最佳实践
以下是有关位置信息的一些关键事实和最佳实践:
容量限制是按模型、按区域和按分钟设置的。
为避免意外达到容量上限,请考虑使用
global位置(如果模型在global位置可用)。不妨考虑使用 Firebase Remote Config 来控制访问模型的位置。这样一来,您无需发布应用的新版本即可更改位置。
如果使用
global位置信息不适用于您的使用情形,请考虑明确指定访问模型的位置(如果模型在global以外的位置提供)。例如,您可以使用 Firebase Remote Config 根据最终用户的位置信息设置位置。
代码示例
Firebase AI Logic 具有位置信息的自动默认值(例如,使用“Agent Platform”初始化语法时为 global)。不过,如果您需要或想要使用其他位置,则需要在代码中初始化 Agent Platform Gemini API (formerly Vertex AI) 后端服务时显式指定位置。
将 LOCATION 替换为本页稍后列出的可用位置中的位置代码(例如 global 或 us-central1)。
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 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 默认为以下位置:
- 使用新的“Agent Platform”初始化语法时:
global - 使用旧版“Vertex AI”初始化语法时:
us-central1
- 使用新的“Agent Platform”初始化语法时:
Gemini 预览版和实验版模型:仅在
global位置提供。Gemini 3.x 稳定模型:可在
global位置使用,通常也可在us和eu位置使用。Gemini 2.5 型号: 在许多地区均可使用。 请注意,Gemini Live API 2.5 模型在
global中不可用。
Gemini 3.x 及更高版本的型号
使用 Gemini 3.x 及更高版本的模型时,Firebase AI Logic 支持以下位置:
globaluseu
如需详细了解每种型号的可用位置,请参阅 Google Cloud 文档。
旧版模型
使用旧版 Gemini 模型(例如 2.5 模型)时,Firebase AI Logic 支持以下位置:
全球
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)
请注意,Gemini Live API 2.5 模型在 global 中不可用。
如需详细了解每种型号的可用位置,请参阅 Google Cloud 文档。
之前提供此功能但现在已停用的地区列表:
- 尚未拒绝任何地点