This quickstart shows you how to install the Google Gen AI SDK for your language of choice and then make your first API request.
Requirements
The requirements for getting started with Vertex AI depend on your Google Cloud workflow. You need to:
- New Google Cloud users and express mode users:
- Have a valid
@gmail.comGoogle Account - Sign up for express mode
- Have an express mode API key
- Enable the Vertex AI API in the console
- Have a valid
- Existing users:
- Have a valid
@gmail.comGoogle Account and Google Cloud project - Enable billing
- Enable the Vertex AI API in the console
- Have set up a method of authentication, either:
- Application default credentials (ADC), or
- An API key that's bound to a service account
- Have a valid
Choose your authentication method:
Before you begin
If you don't already have an API key, you need to obtain one before continuing. If you already have an API key, skip to the next step.
Google Cloud offers two types of API keys: express mode API keys, and API keys that are bound to your service account. Which API key you should obtain for this quickstart depends on whether or not you have an existing Google Cloud project:
- If you're new to Google Cloud or you use express mode: Create an express mode API key. If you're new to express mode, you need to sign up first.
- If you already have a Google Cloud project: Create a standard Google Cloud API key that's bound to a service account. Binding an API key to a service account is possible only if it's enabled in the organization policy settings. If you can't enable this setting, use ADC instead.
If you have already configured ADC, skip to the next step.
To configure ADC, do the following:
Configure your project
Select a project, enable billing, enable the Vertex AI API, and install the gcloud CLI:
-
Sign in to your Google Account.
If you don't already have one, sign up for a new account.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles. -
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles. -
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
Create local authentication credentials
Create local authentication credentials for your user account:
gcloud auth application-default login
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
Set up required roles
If you're using a standard API key or ADC, your project also needs to be granted the appropriate Identity and Access Management permissions for Vertex AI. If you're using an express mode API key, you can skip to the next step.
To get the permissions that
you need to use Vertex AI,
ask your administrator to grant you the
Vertex AI User (roles/aiplatform.user)
IAM role on your project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
You might also be able to get the required permissions through custom roles or other predefined roles.
Install the SDK and set up your environment
On your local machine, click one of the following tabs to install the SDK for your programming language.
Python
Install and update the Gen AI SDK for Python by running this command.
pip install --upgrade google-genai
Set environment variables:
# Replace the `GOOGLE_CLOUD_PROJECT_ID` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT_ID export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
Go
Install and update the Gen AI SDK for Go by running this command.
go get google.golang.org/genai
Set environment variables:
# Replace the `GOOGLE_CLOUD_PROJECT_ID` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT_ID export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
Node.js
Install and update the Gen AI SDK for Node.js by running this command.
npm install @google/genai
Set environment variables:
# Replace the `GOOGLE_CLOUD_PROJECT_ID` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT_ID export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
Java
Install and update the Gen AI SDK for Java by running this command.
Maven
Add the following to your pom.xml:
<dependencies> <dependency> <groupId>com.google.genai</groupId> <artifactId>google-genai</artifactId> <version>0.7.0</version> </dependency> </dependencies>
Set environment variables:
# Replace the `GOOGLE_CLOUD_PROJECT_ID` and `GOOGLE_CLOUD_LOCATION` values # with appropriate values for your project. export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT_ID export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
REST
Set environment variables:
GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT_ID GOOGLE_CLOUD_LOCATION="global" API_ENDPOINT="https://aiplatform.googleapis.com" MODEL_ID="gemini-2.5-flash" GENERATE_CONTENT_API="generateContent"
Replace GOOGLE_CLOUD_PROJECT_ID with your Google Cloud project ID.
Make your first request
Use the
generateContent
method to send a request to the Gemini API in Vertex AI:
Python
Go
Node.js
Java
C#
REST
To send this prompt request, run the curl command from the command line or include the REST call in your application.
curl \ -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "${API_ENDPOINT}/v1/projects/${GOOGLE_CLOUD_PROJECT}/locations/${GOOGLE_CLOUD_LOCATION}/publishers/google/models/${MODEL_ID}:${GENERATE_CONTENT_API}" -d \ $'{ "contents": { "role": "user", "parts": { "text": "Explain how AI works in a few words" } } }'
The model returns a response. Note that the response is generated in sections with each section separately evaluated for safety.
Generate images
Gemini can generate and process images conversationally. You can prompt Gemini with text, images, or a combination of both to achieve various image-related tasks, such as image generation and editing. The following code demonstrates how to generate an image based on a descriptive prompt:
You must include responseModalities: ["TEXT", "IMAGE"] in your
configuration. Image-only output is not supported with these models.
Python
Go
Node.js
Java
Image understanding
Gemini can understand images as well. The following code uses the image generated in the previous section and uses a different model to infer information about the image:
Python
Go
Node.js
Java
Code execution
The Gemini API in Vertex AI code execution feature enables the model to generate and run Python code and learn iteratively from the results until it arrives at a final output. Vertex AI provides code execution as a tool, similar to function calling. You can use this code execution capability to build applications that benefit from code-based reasoning and that produce text output. For example:
Python
Go
Node.js
Java
For more examples of code execution, check out the code execution documentation.
What's next
Now that you made your first API request, you might want to explore the following guides that show how to set up more advanced Vertex AI features for production code:
Access Gemini models using OpenAI libraries
Learn how to use OpenAI libraries to implement and call Gemini models in Vertex AI.
Get started with Gemini 3
Learn about Gemini 3, our most intelligent model family to date, built on a foundation of state-of-the-art reasoning.
Explore Google models
Explore the latest Google models supported in Vertex AI, including Gemini, Imagen, Veo, and Gemma.