モデルにアクセスする場所を指定する

Gemini API プロバイダをクリックして、このページでプロバイダ固有のコンテンツとコードを表示します。


Google の生成 AI モデルは、特定のリージョンで利用できます。

コードで Vertex AI Gemini API バックエンド サービスを初期化するときに、 リクエストでアクセスするモデルのロケーションを 必要に応じて 指定できます。 利用可能なロケーションのリストについては、このページの後半をご覧ください。

ロケーションに関する重要なポイントとベスト プラクティスは次のとおりです。

  • 容量上限は、モデルごと、リージョンごと、分ごとに設定されます。

  • ロケーションを指定しない場合、デフォルトは us-central1 です。

  • 容量上限に予期せず達しないようにするには、ロケーション を global に設定することを検討してください(モデルが global ロケーションをサポートしている場合)。

  • ユースケースでロケーションを global に設定できない場合や、サポートされていない場合は、モデルにアクセスする場所を明示的に分散することを検討してください。たとえば、 Firebase Remote Config を使用して、エンドユーザーのロケーションに基づいてロケーションを設定できます。 Firebase Remote Config

global ロケーションについて

ほぼすべての Gemini モデルにアクセスする場合、 Vertex AI Gemini APIglobal ロケーションをサポートしています。つまり、 リクエストはグローバル プール内の利用可能なモデルによって処理されます。 リクエストのロケーションを global に設定すると、モデルの容量上限に達することを回避し、リソース不足(429)エラーを減らすことができます。

コードサンプル

これらのサンプルでは Gemini モデルへのアクセスを示していますが、 Imagen モデルにアクセスするときにロケーションを指定することもできます。

LOCATION は、このページの後半にある利用可能なロケーションのリストからロケーション コード(europe-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");

// ...

モデルが利用できないロケーションを指定すると、 モデル was not found or your project does not have access to itが見つからないことを示す 404 エラーが発生します。

利用できるロケーション

Google Cloud では リージョンを使用します。 Google Cloud は、生成 AI のすべての一般提供機能について、お客様が指定したリージョンにのみ顧客データを保存します。Vertex AI

Vertex AI の生成 AI は、次のリージョンで利用できます。 一部のモデルや特定のバージョンは、すべてのロケーションで利用できるとは限りません。 (ロケーションの可用性の詳細については、 Google Cloud ドキュメントをご覧ください)。

すべての Gemini モデル(Gemini Live API モデルを除く)は、 global ロケーションでも利用できます。すべての Live API モデルとすべての 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