The new Google Gen AI SDK provides a unified interface to Gemini 2.0 through both the Gemini Developer API and the Gemini API on Vertex AI. With a few exceptions, code that runs on one platform will run on both. This means that you can prototype an application using the Developer API and then migrate the application to Vertex AI without rewriting your code.
The Gen AI SDK also supports the Gemini 1.5 models.
Python
The Google Gen AI SDK for Python is available on PyPI and GitHub:
To learn more, see the Python SDK reference (opens in a new tab).
Quickstart
1. Import the library
from google import genai
2. Create a client
Choose one of the following options, depending on whether you're using Vertex AI in express mode or not.
Create a client for Vertex AI (with all Google Cloud capabilities and services)
Specify the project ID and location while creating the client.
client = genai.Client( vertexai=True, project='your-project-id', location='us-central1' )
Create a client for Vertex AI in express mode
If you're using Vertex AI in express mode, you must first create an API key. Specify your API key while creating the client.
client = genai.Client( vertexai=True, api_key='your-api-key' )
3. Generate content
response = client.models.generate_content(
model='gemini-1.5-pro-002', contents='What is your name?'
)
print(response.text)
Go
The Google Gen AI SDK for Go is available on go.dev and GitHub:
Quickstart
1. Import libraries
import "google.golang.org/genai"
2. Create a client
client, err := genai.NewClient(ctx, &genai.ClientConfig{
Project: project,
Location: location,
Backend: genai.BackendVertexAI,
})
3. Generate content
// Call the GenerateContent method
result, err := client.Models.GenerateContent(ctx, "gemini-2.0-flash-exp", genai.Text("Tell me about New York?"), nil)