The package you want is google-genai
The official Python SDK is google-genai (pip name with a hyphen, import name with a dot). It replaces the legacy google-generativeai package, which reached end-of-life in November 2025. If a tutorial uses import google.generativeai as genai, it's pre-EOL and the surface has changed underneath it.
Install
One main package; one optional extra for faster async via aiohttp:
Three imports you'll use everywhere
from google import genai— the client factory.from google.genai import types— config dataclasses (GenerateContentConfig,Tool,Part,HarmCategory, etc.).from google.genai import errors— exception classes (APIError,ClientError,ServerError).
Client construction patterns
Three common shapes:
- Implicit env —
genai.Client()readsGEMINI_API_KEYorGOOGLE_API_KEY. - Explicit key —
genai.Client(api_key='...'). Useful in tests or when juggling multiple keys. - Vertex AI —
genai.Client(vertexai=True, project='...', location='...').
One client instance handles both sync and async — the async surface lives at client.aio.models and client.aio.chats.