Skip to main content
The Google Gen AI Python SDK provides a unified interface for Google’s generative AI models through both the Gemini Developer API and Vertex AI.

Requirements

Python 3.10 or higher is required.

Install with pip

Install the SDK using pip:
pip install google-genai

Install with uv

For faster installation, you can use uv:
uv pip install google-genai

Optional Dependencies

The SDK includes optional dependencies for enhanced functionality:

aiohttp (Faster Async Performance)

By default, the SDK uses httpx for both sync and async operations. For improved async performance, install with aiohttp support:
pip install google-genai[aiohttp]
The SDK configures trust_env=True to match httpx’s default behavior. You can pass additional aiohttp.ClientSession.request() arguments through HttpOptions:
from google import genai
from google.genai import types

http_options = types.HttpOptions(
    async_client_args={'cookies': ..., 'ssl': ...},
)

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

local-tokenizer (Local Token Counting)

For local token counting and computation without API calls, install with tokenizer support:
pip install google-genai[local-tokenizer]
This enables the LocalTokenizer class:
from google import genai

tokenizer = genai.LocalTokenizer(model_name='gemini-2.5-flash')
result = tokenizer.count_tokens("What is your name?")
print(result)

Verify Installation

Verify your installation by checking the SDK version:
import google.genai
print(google.genai.__version__)

Core Dependencies

The SDK automatically installs these core dependencies:
  • anyio>=4.8.0, <5.0.0 - Async I/O support
  • google-auth[requests]>=2.47.0, <3.0.0 - Google authentication
  • httpx>=0.28.1, <1.0.0 - HTTP client
  • pydantic>=2.9.0, <3.0.0 - Data validation and typing
  • requests>=2.28.1, <3.0.0 - HTTP library
  • tenacity>=8.2.3, <9.2.0 - Retry logic
  • websockets>=13.0.0, <17.0 - WebSocket support
  • typing-extensions>=4.11.0, <5.0.0 - Type hints backport

Next Steps

Quickstart

Get started with your first API call

Authentication

Configure API keys and credentials

Build docs developers (and LLMs) love