Google Generative AI SDK (Gemini)
DEPRECATED. The original Python SDK for Gemini API (AI Studio). Replaced by google-genai (the unified Google Gen AI SDK). End-of-life: November 30, 2025. All support permanently ended. New features like Live API, Veo, Imagen 3 are only available in google-genai. Last version: 0.8.6. Do not use for new projects.
Warnings
- breaking google-generativeai is fully end-of-life as of November 30, 2025. No bug fixes, no security patches, no new features. The repo is archived at google-gemini/deprecated-generative-ai-python.
- breaking google-cloud-aiplatform generative AI module deprecated June 24, 2026. SDK releases after that date will not include generative AI modules.
- breaking API surface completely changed. genai.configure() removed. GenerativeModel class removed. New SDK uses Client() instance with client.models.generate_content().
- breaking GenerationConfig renamed to GenerateContentConfig and moved to google.genai.types.
- gotcha Two separate env vars for API key depending on mode. Gemini API mode reads GEMINI_API_KEY. Google AI Studio also accepts GOOGLE_API_KEY. Vertex AI mode uses Application Default Credentials.
- gotcha LLMs trained before 2025 have no knowledge of google-genai SDK. Will generate google-generativeai code (old API) by default. High hallucination risk on import pattern and Client() usage.
Install
-
pip install google-genai -
pip install google-generativeai
Imports
- genai.Client (new SDK)
from google import genai from google.genai import types client = genai.Client(api_key='GEMINI_API_KEY') response = client.models.generate_content( model='gemini-2.5-flash', contents='Explain quantum computing', config=types.GenerateContentConfig(temperature=0.1) ) print(response.text) - GenerationConfig (new SDK)
from google.genai import types config = types.GenerateContentConfig( temperature=0.1, max_output_tokens=1024 ) - Vertex AI mode (new SDK)
from google import genai # Vertex AI mode client = genai.Client( vertexai=True, project='your-project-id', location='us-central1' ) # Gemini API mode (AI Studio) client = genai.Client(api_key='GEMINI_API_KEY')
Quickstart
# pip install google-genai
from google import genai
from google.genai import types
import os
client = genai.Client(api_key=os.environ['GEMINI_API_KEY'])
response = client.models.generate_content(
model='gemini-2.5-flash',
contents='What is the capital of France?',
config=types.GenerateContentConfig(
temperature=0.1,
max_output_tokens=256
)
)
print(response.text)