|
点击您的 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 具有自动默认位置(例如,
global 使用“Agent Platform”初始化语法时)。但是,如果您需要或想要使用其他位置,则需要在代码中初始化
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 模型:使用 Firebase AI Logic 时,仅在
global位置可用。Firebase AI Logic 尚不 支持us和eu位置。Gemini 2.5 模型: 在许多位置可用。
Gemini Live API 模型:仅在
us-central1位置可用。不 支持global位置。
请参阅本页稍后部分列出的所有可用位置。
一般事实和最佳实践
以下是有关位置的一些关键事实和最佳实践:
容量限制是按模型、按区域、按分钟计算的。
为避免意外达到容量限制,请考虑使用
global位置(如果您的模型支持global位置)。考虑使用 Firebase Remote Config 来控制访问模型的位置。这样,您就可以更改位置,而无需发布应用的新版本。
如果使用
global位置不适用于您的用例或不受支持,请考虑明确分配访问模型的位置。例如, 您可以使用 Firebase Remote Config根据最终用户的位置设置位置。
代码示例
Firebase AI Logic 具有自动默认位置(例如,
global 使用“Agent Platform”初始化语法时)。但是,如果您需要或想要使用其他位置,则需要在代码中初始化
Agent Platform Gemini API (formerly Vertex AI)后端服务时明确指定位置。
将 LOCATION 替换为本页稍后部分列出的 可用位置列表中的位置代码(例如 global 或
europe-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 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 模型时, 唯一 支持的位置是
global。Firebase AI Logic 尚 不 支持us和eu位置。对于所有 Live API 模型和所有 Imagen 模型,均
global不 支持 location。
全球
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)