Google GenAI Python SDK

raw JSON →
1.69.0 verified Tue May 12 auth: no python install: stale quickstart: stale

The Google GenAI Python SDK provides an interface for developers to integrate Google's generative models into their Python applications. Current version: 1.69.0, released on March 27, 2026. The SDK is actively maintained with regular updates, typically on a monthly basis.

pip install google-genai
error ModuleNotFoundError: No module named 'google.generativeai'
cause This error often occurs because developers are attempting to import the older `google.generativeai` package, which has been superseded by the `google-genai` SDK, or the package is not correctly installed in the current environment.
fix
Ensure you have installed the correct and latest google-genai SDK using pip install -U google-genai and update your imports to import google.generativeai as genai (if using the older SDK, ensure it's installed and the Python version is compatible) or from google import genai for the newer unified SDK.
error AttributeError: module 'google.genai' has no attribute 'GenerativeModel'
cause This error typically arises when using the newer `google-genai` SDK with syntax from the older `google.generativeai` SDK, where `GenerativeModel` was a direct top-level class. In the current `google-genai` SDK, models are accessed via a client object.
fix
For the google-genai SDK, instantiate a client first and then access models through it. For example: import google.generai as genai; client = genai.Client(api_key='YOUR_API_KEY'); model = client.models.GenerativeModel('gemini-pro').
error 401 UNAUTHENTICATED. {'error': {'code': 401, 'message': 'API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials.'}
cause This specific 401 error indicates that you are trying to use an API key in a context or with an endpoint that requires OAuth2 authentication (e.g., certain Vertex AI APIs) rather than a simple API key, or your API key is invalid/blocked.
fix
If working with Vertex AI, ensure you are using Application Default Credentials (ADC) or OAuth2 for authentication. If you are intending to use a simple API key, ensure it is correct, active, and that the Generative Language API is enabled for your Google Cloud project. Verify if your API key has been reported as leaked and generate a new one if necessary.
error ValueError: Missing key inputs argument! To use the Google AI API, provide (api_key) arguments.
cause This error means that the `google-genai` library was initialized or an API call was made without a properly provided `api_key` argument, which is essential for authentication with Google AI Studio.
fix
Pass your Google AI Studio API key explicitly during client instantiation or configure it via an environment variable. Example: import google.generativeai as genai; genai.configure(api_key='YOUR_API_KEY') or client = genai.Client(api_key='YOUR_API_KEY') or ensure os.environ['GOOGLE_API_KEY'] is set.
error 429 Quota exceeded for quota metric 'Generate Content API requests per minute'
cause You have exceeded the allocated rate limits (requests per minute, tokens per minute, or requests per day) for your project or usage tier in the Gemini API. This is common for free tier users or during periods of high usage.
fix
Implement exponential backoff and retry logic in your code. Check your project's quotas in Google AI Studio, consider upgrading your usage tier, or request a quota increase if your application requires higher limits.
breaking Breaking change in Interactions API: Refactored TextContent annotations to use specific citation types in version 1.68.0.
fix Update your code to use the new citation types as per the latest API documentation.
breaking Breaking change in Interactions API: Renamed ContentDelta unions in version 1.68.0.
fix Modify your code to accommodate the new union names as specified in the updated API.
breaking The 'google.generativeai' library is not found. This typically means the package is not installed in the environment where the script is executed.
fix Install the 'google-generativeai' package using pip: `pip install google-generativeai`.
breaking The script failed with `ModuleNotFoundError: No module named 'google.generativeai'`, indicating that the required Python package is not installed in the environment.
fix Install the 'google-generativeai' package using pip: `pip install google-generativeai`.
python os / libc status wheel install import disk
3.10 alpine (musl) - - - -
3.10 slim (glibc) - - - -
3.11 alpine (musl) - - - -
3.11 slim (glibc) - - - -
3.12 alpine (musl) - - - -
3.12 slim (glibc) - - - -
3.13 alpine (musl) - - - -
3.13 slim (glibc) - - - -
3.9 alpine (musl) - - - -
3.9 slim (glibc) - - - -

This script demonstrates how to configure the Google GenAI SDK with your API key and generate text using the 'gemini-1.5-flash' model.

import google.generativeai as genai

# Configure the API key
api_key = os.environ.get('GENAI_API_KEY')
genai.configure(api_key=api_key)

# Generate content using a model
model = genai.GenerativeModel(model='gemini-1.5-flash')
response = model.generate_text(prompt='Once upon a time')
print(response.text)