Skip to content

Vertex AI plugin

The Vertex AI plugin provides access to Google’s Gemini models through Vertex AI using Google Cloud authentication.

To use this plugin, add the genkit_vertexai package to your project:

Terminal window
dart pub add genkit_vertexai

Then, you can use vertexAI plugin in the Genkit initializer:

import 'package:genkit/genkit.dart';
import 'package:genkit_vertexai/genkit_vertexai.dart';
void main() {
final ai = Genkit(
plugins: [vertexAI()],
);
}

The plugin requires you to specify your Google Cloud project ID, the region to which you want to make Vertex API requests, and your Google Cloud project credentials.

  • By default, vertexAI gets your Google Cloud project ID from the GCLOUD_PROJECT environment variable.

    You can also pass this value directly:

vertexAI(projectId: 'my-project-id')
  • By default, vertexAI gets the Vertex AI API location from the GCLOUD_LOCATION environment variable.

    You can also pass this value directly:

vertexAI(location: 'us-central1')
  • To provide API credentials, you need to set up Google Cloud Application Default Credentials.

    1. To specify your credentials:

      • If you’re running your flow from a Google Cloud environment (Cloud Functions, Cloud Run, and so on), this is set automatically.

      • On your local dev environment, do this by running:

Terminal window
gcloud auth application-default login
  1. In addition, make sure the account is granted the Vertex AI User IAM role (roles/aiplatform.user). See the Vertex AI access control docs.

To get a reference to a supported model, specify its identifier to vertexAI method:

final model = vertexAI.gemini('gemini-2.5-flash');
final ai = Genkit(
plugins: [vertexAI()],
);
final response = await ai.generate(
model: vertexAI.gemini('gemini-2.5-flash'),
prompt: 'Tell me a joke.',
);
print(response.text);

See Generating content with AI models for more information.

The Vertex AI plugin provides access to Google Cloud’s enterprise-grade AI platform, offering advanced features beyond basic model access. Use this for enterprise applications that need grounding, Vector Search, Model Garden, or evaluation capabilities.

Accessing Google GenAI Models via Vertex AI

Section titled “Accessing Google GenAI Models via Vertex AI”

All languages support accessing Google’s generative AI models (Gemini, Imagen, etc.) through Vertex AI with enterprise authentication and features.