Setting Up Google Cloud Platform Project and Credentials to use Vertex AI

Google Cloud Setup to use Vertex AI

This post outlines the steps you will need to take to use Google Cloud and Vertex AI for your own projects, and authenticate the credential in your local Jupyter Notebook.

Create a Google Cloud Project

Google Cloud projects form the basis for creating, enabling, and using all Google Cloud services including managing APIs, enabling billing, adding and removing collaborators, and managing permissions for Google Cloud resources.

Your usage of Google Cloud tools is always associated with a project.

You will be prompted to create a new project the first time you visit the Cloud Console.

Note that you can create a free project which includes a 90-day $300 Free Trial.

Learn more about projects here.

Set up Billing

A Cloud Billing account is used to define who pays for a given set of resources, and it can be linked to one or more projects. Project usage is charged to the linked Cloud Billing account.

Within your project, you can configure billing by selecting “Billing” in the menu on the left.

Make sure that billing is enabled for your Google Cloud project, click here to learn how to confirm that billing is enabled.

Enable APIs

Once you have a project set up with a billing account, you will need to enable any services you want to use.

Click here to enable the APIs in your Google Cloud project. For example, you might need:

  • Vertex AI
  • BigQuery
  • IAM

You can search for the APIs you need to enable in the search bar.

Create Service Account

A service account is a special kind of account typically used by an application or compute workload, such as a Compute Engine instance, rather than a person. A service account is identified by its email address, which is unique to the account. To learn more, check out this intro video.

You will need to create a service account and give it access to the Google Cloud services you want to use.

  1. Go to the Create Service Account page and select your project
  2. Give the account a name (you can pick anything)

  1. Select the Roles / Permissions you’d want for this project (examples are in the screenshot below)

Create Service Account key

Once you have created your service account, you need to create a key.

  1. Select your newly created service account then click. ADD KEY → create new key.
  2. Select JSON key type and click create.

Clicking Create downloads a service account key file. After you download the key file, you cannot download it again.

Create Credentials

To use Vertex AI services, you will need to authenticate with your credentials.

Using the json file you just downloaded, you will create a credentials object.

from google.auth.transport.requests import Request
from google.oauth2.service_account import Credentials
# Path to your service account key file
key_path = 'your_key.json' #Path to the json key associated with your service account from google cloud
# Create credentials object

credentials = Credentials.from_service_account_file(
    key_path,
    scopes=['https://www.googleapis.com/auth/cloud-platform'])

if credentials.expired:
    credentials.refresh(Request())

Connect to Vertex

Once you have a project and your credentials, you can use Vertex AI tools.

Copy your project ID and paste it in the PROJECT_ID field below.

PROJECT_ID = 'your_project_ID'
REGION = 'us-central1'
import vertexai

# initialize vertex
vertexai.init(project = PROJECT_ID, location = REGION, credentials = credentials)
2 Likes