Menentukan lokasi untuk mengakses model

Klik penyedia Gemini API untuk melihat konten khusus penyedia dan kode di halaman ini.


Model AI generatif Google tersedia di region tertentu.

Saat melakukan inisialisasi layanan backend Vertex AI Gemini API dalam kode Anda, Anda dapat menentukan lokasi untuk model yang Anda akses dalam permintaan Anda. Lihat daftar lokasi yang tersedia di halaman ini.

Untuk mengakses hampir semua Gemini model, Vertex AI Gemini API mendukung lokasi global, yang berarti permintaan Anda akan ditangani oleh model yang tersedia di mana saja dalam kumpulan global. Menetapkan lokasi ke global untuk permintaan Anda dapat membantu Anda menghindari batas kapasitas untuk model dan mengurangi error "layanan kelebihan beban" (503).

Bergantung pada modelnya, Anda mungkin harus menetapkan lokasi ini:

  • Gemini pratinjau model: Anda harus menetapkan lokasi ke global is required (kecuali untuk Live API model pratinjau).

  • Gemini 3.x model: Anda harus menetapkan lokasi ke global saat menggunakan Firebase AI Logic.

  • model: Anda dapat menetapkan lokasi secara opsional.Gemini 2.5 Jika Anda tidak menentukan lokasi, lokasi default-nya adalah us-central1.

  • Gemini Live API model: Anda dapat menetapkan lokasi secara opsional. Jika Anda tidak menentukan lokasi, lokasi default-nya adalah us-central1. Perhatikan bahwa lokasi global tidak didukung.

Berikut beberapa fakta penting dan praktik terbaik terkait lokasi:

  • Batas kapasitas adalah per model, per region, per menit.

  • Untuk menghindari batas kapasitas yang tidak terduga, pertimbangkan untuk menetapkan lokasi ke global (jika model Anda mendukung lokasi global).

  • Jika menetapkan lokasi ke global tidak berlaku atau tidak didukung untuk kasus penggunaan Anda, pertimbangkan untuk mendistribusikan secara eksplisit tempat Anda mengakses model. Misalnya, Anda dapat menetapkan lokasi berdasarkan lokasi pengguna akhir Anda menggunakan Firebase Remote Config.

Contoh kode

Perhatikan bahwa contoh ini menunjukkan cara mengakses model Gemini, tetapi Anda juga dapat menentukan lokasi saat mengakses model Imagen.

Ganti LOCATION dengan kode lokasi (misalnya, global atau europe-west4) dari daftar lokasi yang tersedia di halaman ini.

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");

// ...

Perhatikan bahwa jika Anda menentukan lokasi tempat model tidak tersedia, Anda akan mendapatkan error 404 yang menyatakan bahwa model was not found or your project does not have access to it.

Lokasi yang tersedia

Google Cloud menggunakan region. Google Cloud hanya menyimpan data pelanggan di region yang Anda tentukan untuk semua fitur AI Generatif di Vertex AI yang tersedia secara umum.

AI Generatif di Vertex AI tersedia di region berikut. Beberapa model dan/atau versi tertentu mungkin tidak tersedia di semua lokasi (untuk mengetahui ketersediaan lokasi secara mendetail, lihat Google Cloud dokumentasi).

Perhatikan hal berikut:

  • Untuk semua Gemini model pratinjau (kecuali model Live API), satu-satunya lokasi yang didukung adalah global.

  • Saat menggunakan Firebase AI Logic untuk mengakses model Gemini 3.x, satu-satunya lokasi yang didukung adalah global.

  • Untuk semua Live API model dan semua Imagen model, global lokasi tidak didukung.

Global

  • global

Amerika Serikat

  • Columbus, Ohio (us-east5)
  • Dallas, Texas (us-south1)
  • Iowa (us-central1)
  • Las Vegas, Nevada (us-west4)
  • Moncks Corner, South Carolina (us-east1)
  • Northern Virginia (us-east4)
  • Oregon (us-west1)

Kanada

  • Montréal (northamerica-northeast1)

Amerika Selatan

  • Sao Paulo, Brasil (southamerica-east1)

Eropa

  • Belgia (europe-west1)
  • Finlandia (europe-north1)
  • Frankfurt, Jerman (europe-west3)
  • London, Inggris Raya (europe-west2)
  • Madrid, Spanyol (europe-southwest1)
  • Milan, Italia (europe-west8)
  • Belanda (europe-west4)
  • Paris, Prancis (europe-west9)
  • Warsawa, Polandia (europe-central2)
  • Zürich, Swiss (europe-west6)

Asia Pasifik

  • Changhua County, Taiwan (asia-east1)
  • Hong Kong, China (asia-east2)
  • Mumbai, India (asia-south1)
  • Seoul, Korea (asia-northeast3)
  • Singapura (asia-southeast1)
  • Sydney, Australia (australia-southeast1)
  • Tokyo, Jepang (asia-northeast1)

Timur Tengah

  • Dammam, Arab Saudi (me-central2)
  • Doha, Qatar (me-central1)
  • Tel Aviv, Israel (me-west1)