| 点击您的 Gemini API 提供商,以查看此页面上特定于提供商的内容和代码。 | 
Google 的生成式 AI 模型可在特定区域使用。
在代码中初始化 Vertex AI Gemini API 后端服务时,您可以选择性指定要在请求中访问的模型的位置。如果您未指定位置,则默认值为 us-central1。
请参阅本页稍后提供的可用位置列表。
了解 global 位置信息
如需访问 Gemini 2.0 和 Gemini 2.5 模型,Vertex AI Gemini API 支持 global 位置,这意味着您的请求将由全球池中任何可用的模型处理。将请求的位置设置为 global 可以提高整体可用性,同时减少资源耗尽 (429) 错误。
此外,2025 年 6 月之后发布的 Gemini 2.5 预览版和实验性模型通常只能在 global 位置访问。
代码示例
请注意,这些示例展示了如何访问 Gemini 模型,但您也可以在访问 Imagen 模型时指定位置。
将 LOCATION 替换为本页稍后列出的可用位置中的位置代码(例如 europe-west4)。
Swift
// ...
// Initialize the Vertex AI Gemini API backend service
// Specify the location for where you want to access the model
let ai = FirebaseAI.firebaseAI(backend: .vertexAI(location: "LOCATION"))
// Create a `GenerativeModel` instance with a model that supports your use case
let model = ai.generativeModel(modelName: "MODEL_NAME")
// ...
Kotlin
// ...
// Initialize the Vertex AI Gemini API backend service
// Specify the location for where you want to access the model
val model = Firebase.ai(backend = GenerativeBackend.vertexAI(location = "LOCATION"))
                        .generativeModel("MODEL_NAME")
// ...
Java
// ...
// Initialize the Vertex AI Gemini API backend service
// Specify the location for where you want to access the model
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.vertexAI("LOCATION"))
        .generativeModel("MODEL_NAME");
GenerativeModelFutures model = GenerativeModelFutures.from(ai);
// ...
Web
// ...
// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);
// Initialize the Vertex AI Gemini API backend service
// Specify the location for where you want to access the model
const ai = getAI(firebaseApp, { backend: new VertexAIBackend('LOCATION') });
// Create a `GenerativeModel` instance with a model that supports your use case
const model = getGenerativeModel(ai, { model: 'MODEL_NAME' });
// ...
Dart
// ...
// Initialize the Vertex AI Gemini API backend service
// Specify the location for where you want to access the model
final ai = await FirebaseAI.vertexAI(location: 'LOCATION');
// Create a `GenerativeModel` instance with a model that supports your use case
final model = ai.generativeModel(model: 'MODEL_NAME');
// ...
Unity
// ...
// Initialize the Vertex AI Gemini API backend service
// Specify the location for where you want to access the model
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.VertexAI(location: "LOCATION"));
// Create a `GenerativeModel` instance with a model that supports your use case
var model = ai.GetGenerativeModel(modelName: "MODEL_NAME");
// ...
可用位置
Google Cloud 使用区域。 Google Cloud 仅在您为 Vertex AI 上的生成式 AI 的所有正式版功能指定的区域中存储客户数据。
Vertex AI 上的生成式 AI 可在以下区域使用。 Vertex AI部分型号和/或特定版本可能无法在所有地区使用(如需详细了解各地区的供应情况,请参阅 Google Cloud 文档)。
Gemini 2.0 和 Gemini 2.5 模型(Gemini 2.0 Flash Live 除外)还可在 global 位置使用。对于 Imagen 模型,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)