Vertex AI API

The Google Cloud client library for the Vertex AI API.

Tip

Flutter applications should use Firebase AI Logic.

The Vertex AI API is meant for Dart command-line, cloud, and server applications. For mobile and web applications, see instead Firebase AI Logic, which provides client-side access to both the Gemini Developer API and Vertex AI.

Note

This package is currently experimental and published under the labs.dart.dev pub publisher in order to solicit feedback.

For packages in the labs.dart.dev publisher we generally plan to either graduate the package into a supported publisher (dart.dev, tools.dart.dev) after a period of feedback and iteration, or discontinue the package. These packages have a much higher expected rate of API and breaking changes.

Your feedback is valuable and will help us evolve this package. For general feedback, suggestions, and comments, please file an issue in the bug tracker.

What's this?

The Google Cloud client library for the Vertex AI API.

Train high-quality custom machine learning models with minimal machine learning expertise and effort.

Quickstart

This quickstart shows you how to install the package and make your first Vertex API request.

Before you begin

You must create and configure a Google Cloud project before using the Vertex AI API.

You can find complete details in this before you begin guide.

Installing the package into your application

Tip

You can create a skeleton application by running the terminal command: dart create myapp

Run the terminal command:

dart pub add google_cloud_aiplatform_v1beta1

Make your first request

Here is an example that uses the generateContent method to send a request to the Vertex API using the Gemini 2.5 Flash model.

Before running the example, you must login with the gcloud CLI:

$ gcloud auth application-default login

Note

Model names must be in the form "projects/{projectId}/locations/{location}/publishers/{publisher}/models/{model}".

For example, if the Google Cloud project id were "happycat", then this would be a valid model: "projects/happycat/locations/global/publishers/google/models/gemini-2.5-flash".

import 'package:google_cloud_aiplatform_v1beta1/aiplatform.dart';
import 'package:googleapis_auth/auth_io.dart' as auth;

void main() async {
  const projectId = ''; // Enter your projectId here.
  if (projectId.isEmpty) {
    print('Please provide a project ID in the `projectId` constant.');
    return;
  }

  final client = await auth.clientViaApplicationDefaultCredentials(
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  );
  final service = PredictionService(client: client);

  final request = GenerateContentRequest(
    model:
        'projects/$projectId/locations/global/'
        'publishers/google/models/gemini-2.5-flash',
    contents: [
      Content(
        parts: [Part(text: "Explain how AI works in a few words")],
        role: "user",
      ),
    ],
  );

  final result = await service.generateContent(request);
  final parts = result.candidates?[0].content?.parts;
  if (parts == null) {
    print('<No textual response>');
  } else {
    print(parts.map((p) => p.text ?? '').join(''));
  }

  service.close();
}

Libraries

aiplatform
The Google Cloud client for the Vertex AI API.