Get a Google Cloud API key

This guide shows how to get a Google Cloud API key to use Gemini on Vertex AI, covering the following topics:

Authentication Options

To use Gemini on Vertex AI, you need to authenticate. The following table compares the two primary authentication methods.

Method Description Pros Cons Best for
Google Cloud API Key A simple encrypted string that grants access to Google Cloud APIs. Easy and fast to set up. Less secure; requires careful management to prevent exposure. Quickstarts, prototyping, and initial development.
Application Default Credentials (ADC) A strategy that finds credentials automatically based on the application environment. More secure; credentials are not hardcoded. Manages credential rotation automatically. Requires more initial setup and understanding of IAM. Production and security-sensitive environments.

We recommend using an API key for initial testing and using Application Default Credentials for production. This page shows you how to get a Google Cloud API key based on whether you already have a Google Cloud account.

Select whether you have a Google Cloud account:


Create a Google Cloud API key

If you already have a Google Cloud account, use the following instructions to get a standard Google Cloud API key.

Before you begin

Concepts

  • Service Account: A special type of Google account intended to represent a non-human user that needs to authenticate and be authorized to access data in Google APIs.
  • API Key: A simple encrypted string that identifies a Google project for purposes of quota, billing, and monitoring.
  • IAM (Identity and Access Management): Defines who (identity) has what access (role) for which resource.

Prerequisites

Make your first API request

After getting an API key, learn how to use your API key to make your first request in the API quickstart.

Optional: Set up your API key locally

For initial testing, you can hard code an API key, but this is not secure and should only be temporary. The following instructions show how to set up your API key locally as an environment variable.