Registry /
gcp / google-ai-generativelanguage
Install & Compatibility
Where this runs
tested against v0.12.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 2.296s · 83.9MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 6.2s · import 1.452s · 82MB
83MB installed
● package 83MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
GenerativeServiceClient
✓ from google.ai.generativelanguage_v1beta import GenerativeServiceClient
✗ from google.ai import generativelanguage_v1beta as glm
This quickstart demonstrates how to instantiate the `GenerativeServiceClient` and use it to generate text with the Gemini Pro model. It highlights the typical setup for authentication using Application Default Credentials (ADC), suitable for Google Cloud environments.
import os
from google.ai import generativelanguage_v1beta as glm
# Initialize the client. This client will attempt to ascertain credentials
# from the environment, e.g., via Application Default Credentials (ADC).
# For local development, consider `gcloud auth application-default login`.
# For API Key-based authentication (e.g., from Google AI Studio), the `google-genai`
# library (pip install google-genai) is generally recommended.
client = glm.GenerativeServiceClient()
model_name = "models/gemini-pro" # Or another supported model like "models/text-bison-001"
# Prepare the content for generation
content = glm.Content(
parts=[glm.Part(text="Write a short poem about a cat sitting by a window.")]
)
try:
# Make the generate content request
response = client.generate_content(model=model_name, contents=[content])
# Extract the generated text
if response.candidates:
print(response.candidates[0].content.parts[0].text)
else:
print("No content generated.")
except Exception as e:
print(f"An error occurred: {e}")
print("Ensure you have enabled the Generative Language API in your Google Cloud project and set up authentication.")
# It's good practice to explicitly close the client when done to release resources.
client.close()
Debug
Known issues
breakingThe `google-generativeai` library (also known as the Google AI Python SDK for the Gemini API) was officially deprecated on November 30, 2025, in favor of the newer `google-genai` library. While `google-ai-generativelanguage` is the low-level GAPIC client, users migrating from `google-generativeai` might mistakenly try to use it as a direct replacement. Ensure you are using the correct library for your needs, preferably `google-genai` for high-level API access.fixMigrate to the `google-genai` library (for the high-level SDK) or confirm `google-ai-generativelanguage` is the intended low-level client.
affects: <=0.8.6 of google-generativeai
gotchaThis library (`google-ai-generativelanguage`) is a low-level GAPIC client, offering direct interaction with the Generative Language API. For simpler interactions with Gemini models (especially Gemini 2.0+ via AI Studio), the `google-genai` library offers a higher-level, more unified API that simplifies many common use cases. Using `google-ai-generativelanguage` directly requires more explicit handling of API requests/responses.fixFor ease of use and most common Gemini API interactions, consider using `pip install google-genai` and its corresponding API (`from google import genai`). Use `google-ai-generativelanguage` when fine-grained control or integration within a broader Google Cloud client ecosystem is required.
affects: All versions
gotchaAuthentication for `google-ai-generativelanguage` typically relies on Application Default Credentials (ADC), which are automatically discovered in Google Cloud environments or set up locally via `gcloud auth application-default login`. If you intend to use an API key (e.g., from Google AI Studio) for direct access, you should generally use the `google-genai` library, which is designed for API key-based authentication via the `GEMINI_API_KEY` environment variable.fixFor ADC, ensure `gcloud auth application-default login` is run or `GOOGLE_APPLICATION_CREDENTIALS` environment variable points to a service account key. For API key, switch to `google-genai` and set `GEMINI_API_KEY`.
affects: All versions
deprecatedThis library requires Python 3.9 or newer. Python versions 3.8 and older are no longer supported.fixUpgrade your Python environment to 3.9 or later.
affects: All versions
Upgrade
Version history
0.12.0latest on PyPI · released Jun 3, 2026
Audit
Dependencies
pythonrequiredRequired Python version
google-authrequiredDirect dependency for authentication