|
点击您的 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 4.x 和 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
agentPlatform 语法从 SDK v12.17.0 及更高版本开始提供。
// ...
// 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
agentPlatform 语法适用于 v17.15.0 及更高版本的 SDK 以及 v34.17.0 及更高版本的 Firebase Android BoM。
// ...
// 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
agentPlatform 语法适用于 v17.15.0 及更高版本的 SDK 以及 v34.17.0 及更高版本的 Firebase Android BoM。
// ...
// 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
AgentPlatformBackend 语法从 Firebase JS SDK v12.17.0+ 开始提供。
// ...
// 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
vertexAI 语法已在 SDK v13.0.0 中移除。
// ...
// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the legacy `vertexAI` syntax, the default location is `us-central1`, so
// specifying a location is usually required since most models are *not* supported in `us-central1`.
let ai = FirebaseAI.firebaseAI(backend: .vertexAI(location: "LOCATION"))
// ...
Kotlin
vertexAI 语法已在 SDK 的 v18.0.0 和 BoM 的 v35.0.0 中移除。
// ...
// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the legacy `vertexAI` syntax, the default location is `us-central1`, so
// specifying a location is usually required since most models are *not* supported in `us-central1`.
val ai = Firebase.ai(backend = GenerativeBackend.vertexAI(location = "LOCATION"))
// ...
Java
vertexAI 语法已在 SDK 的 v18.0.0 和 BoM 的 v35.0.0 中移除。
// ...
// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the legacy `vertexAI` syntax, the default location is `us-central1`, so
// specifying a location is usually required since most models are *not* supported in `us-central1`.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.vertexAI("LOCATION"));
// ...
Web
VertexAIBackend 语法已在 SDK v13.0.0 中移除。
// ...
// Initialize FirebaseApp
// Initialize the Agent Platform Gemini API backend service (formerly branded Vertex AI).
// For the legacy `VertexAIBackend` syntax, the default location is `us-central1`, so
// specifying a location is usually required since most models are *not* supported in `us-central1`.
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-central1`, so
// specifying a location is usually required since most models are *not* supported in `us-central1`.
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-central1`, so
// specifying a location is usually required since most models are *not* supported in `us-central1`.
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 4.x 和 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 文档。
之前可用但现已停用的位置列表:
- 尚未拒绝任何地点