Quickstart: Generate text using the Vertex AI Gemini API (original) (raw)
Get started
- Send a text prompt to the Gemini API without an account
- Generate an image and verify its watermark using Imagen
- Generate text using the Gemini API
- Send text prompts to Gemini using Vertex AI Studio
- Deploy your Vertex AI Studio prompt as a web application
- Vertex AI in express mode
- Overview
- Console tutorial
- API tutorial
Select models
- Model Garden
- Try it: Test model capabilities using Playspaces
- Overview of Model Garden
- Use models in Model Garden
- Supported models
- Google Models
- Overview
- Gemini
* Gemini 2.5 Flash
* Gemini 2.5 Pro
* Gemini 2.0 Flash
* Gemini 2.0 Flash-Lite
* Vertex AI Model Optimizer
* Migrate to Gemini 2
* SDKs - Imagen
* Imagen 3.0 Generate 002
* Imagen 3.0 Generate 001
* Imagen 3.0 Fast Generate 001
* Imagen 3.0 Capability 001
* Imagen 4.0 Generate Preview 06-06
* Imagen 4.0 Fast Generate Preview 06-06
* Imagen 4.0 Ultra Generate Preview 06-06
* Migrate to Imagen 3 - Veo
* Veo 2 Generate 001
* Veo 3 Generate 001 Preview - Model versions
- Managed partner models
- Model as a Service (MaaS) overview
- Claude
* Overview
* Request predictions
* Batch predictions
* Prompt caching
* Count tokens
* Model details
* Claude Opus 4
* Claude Sonnet 4
* Claude 3.7 Sonnet
* Claude 3.5 Sonnet v2
* Claude 3.5 Haiku
* Claude 3 Opus
* Claude 3 Haiku
* Claude 3.5 Sonnet - Llama
* Overview
* Request predictions
* Batch predictions
* Model details
* Llama 4 Maverick
* Llama 4 Scout
* Llama 3.3
* Llama 3.2
* Llama 3.1 405b
* Llama 3.1 70b
* Llama 3.1 8b - Mistral AI
* Overview
* Model details
* Mistral OCR (25.05)
* Mistral Small 3.1 (25.03)
* Mistral Large (24.11)
* Mistral Nemo
* Codestral (25.01) - Model as a Service (MaaS) deprecations
- Self-deployed models
- Overview
- Llama
- Use Hugging Face Models
- Hex-LLM
- Comprehensive guide to vLLM for Text and Multimodal LLM Serving (GPU)
- xDiT
- Tutorial: Deploy Llamma 3 models with SpotVM and Reservations
Build
- Agents
- Overview
- Agent Engine
* Overview
* Quickstart
* Set up the environment
* Evaluate an agent
* Deploy an agent
* Getting help
* Troubleshoot setting up the environment
* Troubleshoot developing an agent
* Troubleshoot deploying an agent
* Troubleshoot using an agent
* Troubleshoot managing deployed agents
* Get support - Agent Tools
* Built-in tools
* Google Cloud tools
* Model Context Protocol (MCP) tools
* MCP Toolbox for Databases
* Ecosystem tools
* RAG Engine
* RAG Overview
* RAG quickstart for Python
* Use RAG in multimodal live
* Data ingestion
* Use Vertex AI Search with RAG
* Reranking for RAG
* Manage your RAG corpus
* RAG quotas - Prompt design
- Introduction to prompting
- Prompting strategies
* Overview
* Give clear and specific instructions
* Use system instructions
* Include few-shot examples
* Add contextual information
* Structure prompts
* Instruct the model to explain its reasoning
* Break down complex tasks
* Experiment with parameter values
* Prompt iteration strategies - Capabilities
- Text and code generation
* Text generation
* System instructions
* Function calling
* Controlled generation
* Content generation parameters
* Code execution
* Thinking
* Live API
* Safety
* Responsible AI
* System instructions for safety
* Configure content filters
* Gemini for safety filtering and content moderation
* Abuse monitoring
* Process blocked responses
* Medical text - Image generation
* Gemini
* Generate images with Gemini
* Imagen
* Imagen overview
* Generate images using text prompts
* Edit images
* Edit using inpainting (insert or remove objects)
* Edit using outpainting
* Use product image editing
* Edit using Personalization
* Edit images (mask-free)
* Upscale an image
* Prompt and image attribute guide
* Base64 encode and decode files
* Responsible AI and usage guidelines for Imagen
* Legacy features
* Migrate to Imagen 3
* Text-to-Live images prompt guide
* Create live images from text
* Get image descriptions using visual captioning
* Use Visual Question Answering
* Get video descriptions using Imagen - Analyze
* Image understanding
* Video understanding
* Audio understanding
* Document understanding
* Bounding box detection - Grounding
* Overview
* Grounding with Google Search
* Grounding with Google Maps
* Grounding with Vertex AI Search
* Grounding with your search API
* Grounding responses using RAG
* Grounding with Elasticsearch
* Web Grounding for Enterprise
* Use Google Search suggestions - Translation
- Generate speech from text
- Transcribe speech
- Development tools
- Model tuning
- Introduction to tuning
- Tuning recommendations with LoRA and QLoRA
- Migrate
- Migrate from Google AI to Vertex AI
Evaluate
- Overview
- Tutorial: Perform evaluation using the Python SDK
- Define your evaluation metrics
- Prepare your evaluation dataset
- Run an evaluation
- Interpret evaluation results
- Templates for model-based metrics
- Evaluate agents
- Customize judge models
- Evaluate a judge model
- Prompting for judge model customization
- Configure a judge model
- Alternative evaluation methods
- Run AutoSxS pipeline
- Run a computation-based evaluation pipeline
Deploy
- Overview
- Optimize cost, latency, and performance
- Deployment best practices
- Batch prediction
- Provisioned Throughput
- Provisioned Throughput overview
- Supported models
- Calculate Provisioned Throughput requirements
- Purchase Provisioned Throughput
- Use Provisioned Throughput
- Troubleshooting error code 429
- Pay-as-you-go
- Quotas and system limits
- Dynamic shared quota
Administer
Go to Vertex AI documentation
Stay organized with collections Save and categorize content based on your preferences.
In this quickstart, you send the following multimodal requests to the Vertex AI Gemini API and view the responses:
- A text prompt
- A prompt and an image
- A prompt and a video file (with an audio track)
You can complete this quickstart by using a programming language SDK in your local environment or the REST API.
Prerequisites
Completing this quickstart requires you to:
- Set up a Google Cloud project and enable the Vertex AI API
- On your local machine:
- Install, initialize, and authenticate with the Google Cloud CLI
- Install the SDK for your language
Set up a Google Cloud project
Set up your Google Cloud project and enable the Vertex AI API.
- 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.
- In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Go to project selector - Make sure that billing is enabled for your Google Cloud project.
- Enable the Vertex AI API.
Enable the API - In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Go to project selector - Make sure that billing is enabled for your Google Cloud project.
- Enable the Vertex AI API.
Enable the API
Set up the Google Cloud CLI
On your local machine, set up and authenticate with the Google Cloud CLI. If you are familiar with the Gemini API in Google AI Studio, note that the Vertex AI Gemini API uses Identity and Access Management instead of API keys to manage access.
- Install and initialize the Google Cloud CLI.
- If you previously installed the gcloud CLI, ensure your
gcloud
components are updated by running this command.
gcloud components update - To authenticate with the gcloud CLI, generate a local Application Default Credentials (ADC) file by running this command. The web flow launched by the command is used to provide your user credentials.
gcloud auth application-default login
For more information, see Set up Application Default Credentials.
Set up the SDK for your programming language
On your local machine, click one of the following tabs to install the SDK for your programming language.
Gen AI SDK for Python
Install and update the Gen AI SDK for Python by running this command.
pip install --upgrade google-genai
Gen AI SDK for Go
Install and update the Gen AI SDK for Go by running this command.
go get google.golang.org/genai
Gen AI SDK for Node.js
Install and update the Gen AI SDK for Node.js by running this command.
npm install @google/genai
Gen AI SDK for Java
Install and update the Gen AI SDK for Java:
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>
C#
Install the Google.Cloud.AIPlatform.V1
package from NuGet. Use your preferred method of adding packages to your project. For example, right-click the project in Visual Studio and choose Manage NuGet Packages....
REST
- Configure your environment variables by entering the following. Replace
PROJECT_ID
with the ID of your Google Cloud project.
MODEL_ID="gemini-2.0-flash-001"
PROJECT_ID="PROJECT_ID" - Use Google Cloud CLI to provision the endpoint by running this command.
gcloud beta services identity create --service=aiplatform.googleapis.com --project=${PROJECT_ID}
Send a prompt to the Vertex AI Gemini API
Use the following code to send a prompt to the Vertex AI Gemini API. This sample returns a list of possible namesfor a specialty flower store.
You can run the code from the command line, by using an IDE, or by including the code in your application.
Gen AI SDK for Python
Install
pip install --upgrade google-genai
To learn more, see the SDK reference documentation.
Set environment variables to use the Gen AI SDK with Vertex AI:
Replace the GOOGLE_CLOUD_PROJECT
and GOOGLE_CLOUD_LOCATION
values
with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
Gen AI SDK for Go
Learn how to install or update the Gen AI SDK for Go.
To learn more, see the SDK reference documentation.
Set environment variables to use the Gen AI SDK with Vertex AI:
Replace the GOOGLE_CLOUD_PROJECT
and GOOGLE_CLOUD_LOCATION
values
with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
Gen AI SDK for Node.js
Install
npm install @google/genai
To learn more, see the SDK reference documentation.
Set environment variables to use the Gen AI SDK with Vertex AI:
Replace the GOOGLE_CLOUD_PROJECT
and GOOGLE_CLOUD_LOCATION
values
with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
Gen AI SDK for Java
Learn how to install or update the Gen AI SDK for Java.
To learn more, see the SDK reference documentation.
Set environment variables to use the Gen AI SDK with Vertex AI:
Replace the GOOGLE_CLOUD_PROJECT
and GOOGLE_CLOUD_LOCATION
values
with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
C#
To send a prompt request, create a C# file (.cs
) and copy the following code into the file. Set your-project-id
to your Google Cloud project ID. After updating the values, run the code.
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 "Authorization: Bearer $(gcloud auth print-access-token)"
-H "Content-Type: application/json"
https://aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/global/publishers/google/models/${MODEL_ID}:generateContent -d
$'{
"contents": {
"role": "user",
"parts": [
{
"text": "What's a good name for a flower shop that specializes in selling bouquets of dried flowers?"
}
]
}
}'
The model returns a response. Note that the response is generated in sections with each section separately evaluated for safety.
Send a prompt and an image to the Vertex AI Gemini API
Use the following code to send a prompt that includes text and an image to the Vertex AI Gemini API. This sample returns a description of theprovided image(image for Java sample).
Gen AI SDK for Python
Install
pip install --upgrade google-genai
To learn more, see the SDK reference documentation.
Set environment variables to use the Gen AI SDK with Vertex AI:
Replace the GOOGLE_CLOUD_PROJECT
and GOOGLE_CLOUD_LOCATION
values
with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
Gen AI SDK for Go
Learn how to install or update the Gen AI SDK for Go.
To learn more, see the SDK reference documentation.
Set environment variables to use the Gen AI SDK with Vertex AI:
Replace the GOOGLE_CLOUD_PROJECT
and GOOGLE_CLOUD_LOCATION
values
with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
Gen AI SDK for Node.js
Install
npm install @google/genai
To learn more, see the SDK reference documentation.
Set environment variables to use the Gen AI SDK with Vertex AI:
Replace the GOOGLE_CLOUD_PROJECT
and GOOGLE_CLOUD_LOCATION
values
with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
Gen AI SDK for Java
Learn how to install or update the Gen AI SDK for Java.
To learn more, see the SDK reference documentation.
Set environment variables to use the Gen AI SDK with Vertex AI:
Replace the GOOGLE_CLOUD_PROJECT
and GOOGLE_CLOUD_LOCATION
values
with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
Node.js
Before trying this sample, follow the Node.js setup instructions in theVertex AI quickstart using client libraries. For more information, see theVertex AI Node.js API reference documentation.
To authenticate to Vertex AI, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.
Java
Before trying this sample, follow the Java setup instructions in theVertex AI quickstart using client libraries. For more information, see theVertex AI Java API reference documentation.
To authenticate to Vertex AI, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.
C#
To send a prompt request, create a C# file (.cs
) and copy the following code into the file. Set your-project-id
to your Google Cloud project ID. After updating the values, run the code.
REST
You can send this prompt request from from your IDE, or you can embed the REST call into your application where appropriate.
curl -X POST
-H "Authorization: Bearer $(gcloud auth print-access-token)"
-H "Content-Type: application/json"
https://aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/global/publishers/google/models/${MODEL_ID}:generateContent -d
$'{
"contents": {
"role": "user",
"parts": [
{
"fileData": {
"mimeType": "image/jpeg",
"fileUri": "gs://generativeai-downloads/images/scones.jpg"
}
},
{
"text": "Describe this picture."
}
]
}
}'
The model returns a response. Note that the response is generated in sections with each section separately evaluated for safety.
Send a prompt and a video to the Vertex AI Gemini API
Use the following code to send a prompt that includes text, audio, and video to the Vertex AI Gemini API. This sample returns a description of theprovided video, including anything important from the audio track.
You can send this prompt request by using the command line, using your IDE, or by including the REST call in your application.
Gen AI SDK for Python
Install
pip install --upgrade google-genai
To learn more, see the SDK reference documentation.
Set environment variables to use the Gen AI SDK with Vertex AI:
Replace the GOOGLE_CLOUD_PROJECT
and GOOGLE_CLOUD_LOCATION
values
with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
Gen AI SDK for Go
Learn how to install or update the Gen AI SDK for Go.
To learn more, see the SDK reference documentation.
Set environment variables to use the Gen AI SDK with Vertex AI:
Replace the GOOGLE_CLOUD_PROJECT
and GOOGLE_CLOUD_LOCATION
values
with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
Gen AI SDK for Node.js
Install
npm install @google/genai
To learn more, see the SDK reference documentation.
Set environment variables to use the Gen AI SDK with Vertex AI:
Replace the GOOGLE_CLOUD_PROJECT
and GOOGLE_CLOUD_LOCATION
values
with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
Gen AI SDK for Java
Learn how to install or update the Gen AI SDK for Java.
To learn more, see the SDK reference documentation.
Set environment variables to use the Gen AI SDK with Vertex AI:
Replace the GOOGLE_CLOUD_PROJECT
and GOOGLE_CLOUD_LOCATION
values
with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT export GOOGLE_CLOUD_LOCATION=global export GOOGLE_GENAI_USE_VERTEXAI=True
Node.js
Before trying this sample, follow the Node.js setup instructions in theVertex AI quickstart using client libraries. For more information, see theVertex AI Node.js API reference documentation.
To authenticate to Vertex AI, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.
Java
Before trying this sample, follow the Java setup instructions in theVertex AI quickstart using client libraries. For more information, see theVertex AI Java API reference documentation.
To authenticate to Vertex AI, set up Application Default Credentials. For more information, seeSet up authentication for a local development environment.
C#
To send a prompt request, create a C# file (.cs
) and copy the following code into the file. Set your-project-id
to your Google Cloud project ID. After updating the values, run the code.
REST
curl -X POST
-H "Authorization: Bearer $(gcloud auth print-access-token)"
-H "Content-Type: application/json"
https://aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/global/publishers/google/models/${MODEL_ID}:generateContent -d
$'{
"contents": {
"role": "user",
"parts": [
{
"fileData": {
"mimeType": "video/mp4",
"fileUri": "gs://cloud-samples-data/generative-ai/video/pixel8.mp4"
}
},
{
"text": "Provide a description of the video. The description should also contain anything important which people say in the video."
}
]
}
}'
The model returns a response. Note that the response is generated in sections with each section separately evaluated for safety.
What's next
- Learn more about the Vertex AI Gemini API.
- Explore the Google Gen AI SDK reference.
- Learn about calling Vertex AI models by using the OpenAI library.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-06-11 UTC.