Registry / gcp / google-ai-generativelanguage

google-ai-generativelanguage

JSON →
library0.12.0pypypi✓ verified 24d ago

The `google-ai-generativelanguage` library is the low-level Python client for the Google Generative Language API. It provides programmatic access to Google's generative AI models, such as Gemini, allowing developers to perform tasks like text generation, multimodal content understanding, and more. Maintained by Google, it is currently at version 0.11.0 and is compatible with Python 3.9 and newer. While functional for direct API interaction, for a higher-level and more unified experience with Gemini models, the `google-genai` library is often recommended.

pip install google-ai-generativelanguage
INSTALL
IMPORT
SIG · GOOGLE-AI-GENERATI
G
google-ai-generativelanguage
gcppythonv0.12.0
Install
6.2s avg
Import
1874ms
Disk
83MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 2.296s · 83.9MB
glibc
py 3.103.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.
fix
Migrate 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.
fix
For 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.
fix
For 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.
fix
Upgrade 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
Agent activity
50 hits · last 30 days
node
44
OpenAI (training)
1
Resources
google-ai-generativelanguage — pip install google-ai-generativelanguage · libregistry