Google Gen AI SDKs

The new Google Gen AI SDK provides a unified interface to Gemini 2.0 through both the Gemini Developer API and the Gemini Enterprise API ( Vertex AI). With a few exceptions, code that runs on one platform will run on both. 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:

Or try out the Getting Started notebook.

To learn more, see the Python SDK reference (opens in a new tab).

Quickstart

1. Install SDK bash pip install google-genai

2. Import libraries

from google import genai
from google.genai import types

3. Create a client

client = genai.Client(api_key='GEMINI_API_KEY')

4. Generate content

response = client.models.generate_content(
    model='gemini-1.5-flash', contents='How does RLHF work?'
)
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{
    APIKey:   apiKey,
    Backend:  genai.BackendGoogleAI,
})

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)