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

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


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

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

以下に、ロケーションに関する重要なポイントとベスト プラクティスを紹介します。

  • 容量上限は、モデルごと、リージョンごと、1 分あたりの上限です。

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

  • 容量上限に予期せず達しないように、リクエストでロケーションを global に設定することをおすすめします。

  • ユースケースでロケーションを global に設定できない場合は、モデルにアクセスする場所を明示的に分散することを検討してください。たとえば、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 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");

// ...

モデルが使用できないロケーションを指定すると、モデル was not found or your project does not have access to it という 404 エラーが表示されます。

利用できるロケーション

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

Vertex AI の生成 AI は、次のリージョンで利用できます。一部のモデルや特定のバージョンは、地域によってはご利用いただけない場合があります(地域ごとの利用可否の詳細については、Google Cloud ドキュメントをご覧ください)。

すべての Gemini モデル(Gemini 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