Google Generative AI SDK (Gemini)

raw JSON →
0.8.6 verified Tue May 12 auth: no python install: verified quickstart: verified deprecated

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.

pip install google-genai
error ModuleNotFoundError: No module named 'google.generativeai'
cause The `google-generativeai` package is either not installed, installed in a different Python environment, or there's a typo in the import statement.
fix
Ensure the package is installed in your active Python environment: pip install -U google-generativeai. Verify your Python version is supported (Python 3.9+ is generally required for recent versions).
error AttributeError: module 'google.generativeai' has no attribute 'GenerativeModel'
cause You are likely using an outdated version of the `google-generativeai` library, or the `GenerativeModel` class has been renamed/moved in your specific version. This error is also common when migrating from `google-generativeai` to the newer `google-genai` SDK, where the client initialization and model access patterns differ.
fix
Update the library to the latest version: pip install --upgrade google-generativeai. If this doesn't resolve it, verify the correct API usage for your installed version, or consider migrating to the google-genai SDK where model instantiation is typically handled differently (e.g., genai.GenerativeModel('model_name') might be replaced by client.models.get('model_name') in the new SDK).
error ImportError: cannot import name 'get_default_text_client' from 'google.generativeai.client'
cause The `get_default_text_client` function was a component of older versions of the `google-generativeai` library, often used for the deprecated PaLM API, and has since been removed or is not available in newer versions or the `google-genai` SDK.
fix
Update to the latest google-generativeai version and adjust your code to use current methods for client initialization (e.g., genai.configure(api_key=...) and genai.GenerativeModel(...)). For new projects or if this persists, migrate to the google-genai SDK which has a different client and model instantiation approach.
error 403 Request had insufficient authentication scopes. [reason: "ACCESS_TOKEN_SCOPE_INSUFFICIENT"]
cause This error indicates that the API key or service account used for authentication does not have the necessary permissions (scopes) to access the requested Generative AI API or that the API key is missing/invalid.
fix
Ensure your Google API key is correctly set (e.g., via genai.configure(api_key="YOUR_API_KEY") or as an environment variable GOOGLE_API_KEY). If using Google Cloud credentials, verify that the service account has roles like 'Vertex AI User' or 'AI Platform Developer' enabled, and that the Vertex AI API is enabled for your project.
error google.api_core.exceptions.FailedPrecondition: 400 User location is not supported for the API use.
cause The Google Generative AI API might not be available in your geographical region or the specific model you are trying to use has regional restrictions.
fix
Check the official Google Generative AI documentation for supported regions. If your region is not supported, you may need to use a proxy or configure your environment to route requests through a supported region, potentially using the Vertex AI SDK which allows specifying locations.
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.
fix pip install google-genai and migrate. Full migration guide at ai.google.dev/gemini-api/docs/libraries
breaking google-cloud-aiplatform generative AI module deprecated June 24, 2026. SDK releases after that date will not include generative AI modules.
fix Use google-genai with vertexai=True for Vertex AI access.
breaking API surface completely changed. genai.configure() removed. GenerativeModel class removed. New SDK uses Client() instance with client.models.generate_content().
fix Replace genai.configure(api_key=...) with client = genai.Client(api_key=...). Replace model.generate_content() with client.models.generate_content(model=..., contents=...).
breaking GenerationConfig renamed to GenerateContentConfig and moved to google.genai.types.
fix from google.genai import types; types.GenerateContentConfig(temperature=0.1)
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.
fix Set GEMINI_API_KEY for AI Studio usage. Use gcloud auth application-default login for Vertex AI mode.
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.
fix Always verify generated Gemini code uses 'from google import genai' not 'import google.generativeai as genai'.
pip install google-generativeai
python os / libc variant status wheel install import disk
3.10 alpine (musl) google-genai - - 3.27s 125.1M
3.10 alpine (musl) google-generativeai - - - -
3.10 slim (glibc) google-genai - - 2.28s 195M
3.10 slim (glibc) google-generativeai - - - -
3.11 alpine (musl) google-genai - - 5.43s 137.1M
3.11 alpine (musl) google-generativeai - - - -
3.11 slim (glibc) google-genai - - 4.37s 207M
3.11 slim (glibc) google-generativeai - - - -
3.12 alpine (musl) google-genai - - 4.11s 127.2M
3.12 alpine (musl) google-generativeai - - - -
3.12 slim (glibc) google-genai - - 4.19s 197M
3.12 slim (glibc) google-generativeai - - - -
3.13 alpine (musl) google-genai - - 3.90s 123.7M
3.13 alpine (musl) google-generativeai - - - -
3.13 slim (glibc) google-genai - - 3.99s 196M
3.13 slim (glibc) google-generativeai - - - -
3.9 alpine (musl) google-genai - - 2.37s 118.7M
3.9 alpine (musl) google-generativeai - - - -
3.9 slim (glibc) google-genai - - 2.02s 189M
3.9 slim (glibc) google-generativeai - - - -

Minimal Gemini call using the new google-genai SDK 1.x.

# 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)