Installing the Vertex AI client libraries

Client libraries provide an optimized developer experience for calling the Vertex AI API. The client libraries use each supported language's natural conventions and reduce boilerplate code that you have to write. The following guide explains how to install them.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Enable the Vertex AI API.

    Enable the API

  4. Create a service account:

    1. In the Cloud Console, go to the Create service account page.

      Go to Create service account
    2. Select a project.
    3. In the Service account name field, enter a name. The Cloud Console fills in the Service account ID field based on this name.

      In the Service account description field, enter a description. For example, Service account for quickstart.

    4. Click Create.
    5. Click the Select a role field.

      Under Quick access, click Basic, then click Owner.

    6. Click Continue.
    7. Click Done to finish creating the service account.

      Do not close your browser window. You will use it in the next step.

  5. Create a service account key:

    1. In the Cloud Console, click the email address for the service account that you created.
    2. Click Keys.
    3. Click Add key, then click Create new key.
    4. Click Create. A JSON key file is downloaded to your computer.
    5. Click Close.
  6. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path of the JSON file that contains your service account key. This variable only applies to your current shell session, so if you open a new session, set the variable again.

Client libraries

Vertex AI provides client libraries for the following languages. Select the language that you want to use.

Java

If you are using Maven, add the following to your dependencies:

<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud-aiplatform</artifactId>
  <version>0.4.0</version>
</dependency>

If you are using Gradel, add the following to your dependencies:

compile 'com.google.cloud:google-cloud-aiplatform:0.4.0'

If you are using sbt, add the following to your dependencies:

libraryDependencies += "com.google.cloud" % "google-cloud-aiplatform" % "0.4.0"

Try code samples

To view or get individual code samples, go to the java-aiplatform GitHub repository.

Client library documentation

For more information, view the Vertex AI client library for Java documentation.

Node.js

Before installing the library, prepare your environment for Node.js development.

Run the following command in your environment to install the client library:

npm install @google-cloud/aiplatform

Client library documentation

For more information, view the Vertex AI client library for Node.js documentation.

Python

Vertex SDK for Python

The Python client library for Vertex AI is now called the Vertex SDK for Python. With the release of version 0.7 (Preview), the Vertex SDK for Python provides two levels of support. The high-level aiplatform library is designed to simplify common data science workflows by using wrapper classes and opinionated defaults. The lower-level aiplatform.gapic library remains available for those times when you need more flexibility or control, or for those methods that are not supported by the high-level library.

When you install the Vertex SDK for Python, you can use both levels of support. If you mix aiplatform and aiplatform.gapic calls in the same workflow, be aware that the two approaches use different initialization procedures; you must initialize for each one separately.

Before you install

Before you install the Vertex SDK for Python, we recommend creating an isolated Python environment for each project. Activate a venv environment or use another method to create an isolated Python environment.

Learn more about setting up a Python development environment to work with Google Cloud.

Another option is to create an Notebooks instance for this project. If you are working in a notebook, install the Vertex SDK for Python on your notebook instance or environment.

Install and initialize the Vertex SDK for Python

Run the following command in your virtual environment to install the Vertex SDK for Python:

YOUR_ENVIRONMENT/bin/pip install google-cloud-aiplatform

The following code sample shows how to initialize the library in your Python code:

def init_sample(
    project: Optional[str] = None,
    location: Optional[str] = None,
    experiment: Optional[str] = None,
    staging_bucket: Optional[str] = None,
    credentials: Optional[auth_credentials.Credentials] = None,
    encryption_spec_key_name: Optional[str] = None,
):
    aiplatform.init(
        project=project,
        location=location,
        experiment=experiment,
        staging_bucket=staging_bucket,
        credentials=credentials,
        encryption_spec_key_name=encryption_spec_key_name,
    )

Try code samples

Some of the tutorials in the form of Jupyter notebooks show how to use the Vertex SDK for Python as part of a larger workflow.

To view or get individual code samples, go to the python-aiplatform GitHub repository.

Client library documentation

For more information, view the Vertex SDK for Python documentation.