This quickstart shows you how to install the Google Gen AI SDK for your language of choice and then make your first API request. It covers the following topics:
- Install the SDK and set up your environment: Set up your development environment for Python, Go, Node.js, Java, or REST.
- Make your first request: Use the
generateContent
method to send a text prompt and receive a response. - Generate images: Create an image from a descriptive text prompt.
- Image understanding: Provide an image as input to the model and ask questions about it.
- Code execution: Enable the model to generate and run Python code to solve problems.
Authentication Method | Description | Use Case |
---|---|---|
API key | A simple encrypted string that you can use to call the Gemini API in Vertex AI. | Best for quick prototyping and development when you don't need to access Google Cloud resources. |
Application Default Credentials (ADC) | A strategy that finds credentials automatically based on the application environment, without needing to modify application code. | Recommended for most production applications, especially those running on Google Cloud, as it provides more robust and secure authentication. |
Choose your authentication method:
Before you begin
Concepts
- API key: A simple encrypted string that identifies your project when calling the API, suitable for quick prototyping.
- Application Default Credentials (ADC): A method that automatically finds and uses service account credentials in a Google Cloud environment, recommended for production applications.
Prerequisites
Configure application default credentials if you haven't yet.
The following diagram summarizes the overall workflow:
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.
Gen AI SDK for 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` 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
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` 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 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` 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
To install the Gen AI SDK for Java, add the following dependency to your Maven pom.xml
file:
<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` 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
REST
Set environment variables:
GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT GOOGLE_CLOUD_LOCATION=global API_ENDPOINT=YOUR_API_ENDPOINT MODEL_ID="gemini-2.5-flash" GENERATE_CONTENT_API="generateContent"
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: