This page shows you how to quickly start sending requests to the Vertex AI Gemini API by using the Google Cloud console, a programming language SDK, or the REST API.
New to Google Cloud
Get set up on Google Cloud
If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers get $300 in free credits to run, test, and deploy workloads. The setup process is only three short steps:
Use the following button to create an account. After you're done, return to this page to complete this beginner tutorial. To use all features available on this site, sign in using your account.
Create an accountFor more information on getting set up on Google Cloud, see Get set up on Google Cloud.
Send a request to the Vertex AI Gemini API
To see the instructions for sending a request to the Vertex AI Gemini API, select one of the following tabs:
Python
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
In Cloud Shell, install or update the Vertex AI SDK for Python by running the following command:
pip install "google-cloud-aiplatform>=1.38"
Send a prompt request. Replace PROJECT_ID with the ID of your Google Cloud project.
To learn how to install or update the Vertex AI SDK for Python, see Install the Vertex AI SDK for Python. For more information, see the Vertex AI SDK for Python API reference documentation.
Node.js
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
In Cloud Shell, install or update the Vertex AI SDK for Node.js by running the following command:
npm install @google-cloud/vertexai
Send a prompt request. Replace PROJECT_ID with the ID of your Google Cloud project.
For more information on installing and using the Vertex AI Node.js SDK, see the Vertex AI SDK for Node.js reference documentation.
Java
- Set up your Java Development Environment.
Authenticate by running the following command. Replace PROJECT_ID with your Google Cloud project ID and ACCOUNT with your Google Cloud username.
gcloud config set project PROJECT_ID && gcloud auth login ACCOUNT
Add
google-cloud-vertexai
as your dependency:<!--If you are using Maven with BOM, add the following in your pom.xml--> <dependencyManagement> <dependencies> <dependency> <groupId>com.google.cloud</groupId> <artifactId>libraries-bom</artifactId> <version>26.32.0</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>com.google.cloud</groupId> <artifactId>google-cloud-vertexai</artifactId> </dependency> </dependencies> <!--If you are using Maven without BOM, add the following to your pom.xml--> <dependency> <groupId>com.google.cloud</groupId> <artifactId>google-cloud-vertexai</artifactId> <version>0.4.0</version> </dependency> <!--If you are using Gradle without BOM, add the following to your build.gradle--> implementation 'com.google.cloud:google-cloud-vertexai:0.4.0'
Send a prompt request. Set projectID
to your Google Cloud project ID.
For more information on installing and using the Vertex AI Java Development Kit (JDK), see the Vertex AI JDK reference documentation.
Go
- Prepare your environment for Go development.
Review the available Vertex AI API Go packages to determine which package best meets your project's needs:
Package cloud.google.com/go/vertexai (recommended)
vertexai
is a human authored package that provides access to common capabilities and features.This package is recommended as the starting point for most developers building with the Vertex AI API. To access capabilities and features not yet covered by this package, use the auto-generated
aiplatform
instead.Package cloud.google.com/go/aiplatform
aiplatform
is an auto-generated package.This package is intended for projects that require access to Vertex AI API capabilities and features not yet provided by the human authored
vertexai
package.
Install the desired Go package based on your project's needs by running one of the following commands:
# Human authored package. Recommended for most developers. go get cloud.google.com/go/vertexai
# Auto-generated package. go get cloud.google.com/go/aiplatform
Send a prompt request. Replace PROJECT_ID with the ID of your Google Cloud project.
For more information on installing and using the Vertex AI SDK for Go, see the Vertex AI SDK for Go reference documentation.
C#
Before trying this sample, follow the C# setup instructions in the Vertex AI quickstart using client libraries. For more information, see the Vertex AI C# API reference documentation.
To authenticate to Vertex AI, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
REST
-
In the Google Cloud console, activate Cloud Shell.
Configure environment variables by entering the following. Replace PROJECT_ID with the ID of your Google Cloud project.
MODEL_ID="gemini-1.0-pro-vision" PROJECT_ID="PROJECT_ID"
Provision the endpoint:
gcloud beta services identity create --service=aiplatform.googleapis.com --project=PROJECT_ID
Send a prompt request by entering the following curl command:
curl \ -X POST \ -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \ -H "Content-Type: application/json" \ https://us-central1-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/us-central1/publishers/google/models/${MODEL_ID}:streamGenerateContent -d \ $'{ "contents": { "role": "user", "parts": [ { "fileData": { "mimeType": "image/jpeg", "fileUri": "gs://generativeai-downloads/images/scones.jpg" } }, { "text": "Describe this picture." } ] } }'
If asked to authorize Cloud Shell, click Authorize.
The model returns a response. Note that the response is generated in sections with each section separately evaluated for safety.
Console
Use Vertex AI Studio to quickly design and iterate on your prompts. After your prompt is ready, you can get the code for your prompt in any of the supported programming languages.
In the Google Cloud console, go to the Vertex AI Studio page.
Click Multimodal.
Under Sample prompts, locate the prompt titled Extract text from images, and click Open.
The prompt page opens and the prompt is populated in the Prompt field.
Submit the prompt by clicking Submit.
The model returns a response.
View the code equivalent of this prompt request by clicking
Get code.
What's next
- Learn more about the Vertex AI Gemini API.
- Learn how to design multimodal prompts.
- See the in-depth guides on the Vertex AI Gemini API:
- See the Vertex AI Gemini API reference.
- See the Vertex AI Gemini API Python SDK reference.