指定存取模型的位置

按一下 Gemini API 供應商,即可在這個頁面查看供應商專屬內容和程式碼。


Google 的生成式 AI 模型僅適用於特定區域。

在程式碼中初始化 Vertex AI Gemini API 後端服務時,您可以指定要在要求中存取的模型位置。請參閱本頁稍後的可用位置清單。

如要存取幾乎所有 Gemini 模型,Vertex AI Gemini API 支援 global 位置,也就是說,系統會從全球集區中選取可用模型來處理要求。將要求的位置設為 global,有助於避免達到模型容量上限,並減少「服務過載」(503) 錯誤。

視機型而定,你可能需要設定這個位置:

  • Gemini 預覽模型:必須將位置設為 global (Live API 預覽模型除外)。

  • Gemini 3.x 模型:使用 Firebase AI Logic 時,必須將位置設為 global

  • Gemini 2.5 型號:設定位置資訊為選用項目。如未指定位置,預設值為 us-central1

  • Gemini Live API 模型:設定位置為選用。如未指定位置,預設為 us-central1。請注意,global 位置受支援。

以下是關於地點的幾項重點和最佳做法:

  • 容量限制是依模型、依區域和依分鐘計算。

  • 為避免意外達到容量上限,建議將位置設為 global (如果模型支援 global 位置)。

  • 如果設定位置為 global 不適用於您的用途或不支援,請考慮明確分配您存取模型的地區。舉例來說,您可以使用 Firebase Remote Config,根據使用者的位置設定位置。

程式碼範例

請注意,這些範例顯示存取 Gemini 模型,但您也可以在存取 Imagen 模型時指定位置。

LOCATION 替換為這個頁面稍後列出的可用位置代碼 (例如 globaleurope-west4)。

Swift

// ...

// Initialize the Vertex AI Gemini API backend service
// Specify a supported 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 a supported 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 a supported 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 a supported 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 a supported 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 a supported 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");

// ...

請注意,如果您指定模型無法使用的位置,系統會顯示 404 錯誤,指出模型was not found or your project does not have access to it

服務地區

Google Cloud 使用區域Google Cloud 只會在您為 Vertex AI 上所有正式發布的生成式 AI 功能指定的區域中,儲存客戶資料。

下列區域可使用 Vertex AI 的生成式 AI 功能。 部分機型和/或特定版本可能僅適用於部分地區 (如要瞭解各機型/版本的適用地區,請參閱 Google Cloud 說明文件)。

注意事項:

  • 對於所有Gemini 預覽模型 (Live API 模型除外),唯一支援的位置是 global

  • 使用 Firebase AI Logic 存取 Gemini 3.x 模型時,唯一支援的位置是 global

  • 所有 Live APIImagen 型號均支援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)