Registry / llm-agents / llama-index-llms-google-genai

llama-index-llms-google-genai

JSON →
library0.9.5pypypi✓ verified 86d ago

This library provides the official integration for connecting LlamaIndex applications with Google's Generative AI models, including Gemini and Vertex AI. It allows LlamaIndex to leverage Google's LLMs for tasks such as text completion, chat interactions, function calling, and structured prediction. As of version 0.9.1, it is actively maintained with a regular release cadence, often aligning with updates to the core LlamaIndex framework.

pip install llama-index-llms-google-genai
INSTALL
IMPORT
SIG · LLAMA-INDEX-LLMS-G
L
llama-index-llms-google-genai
llm-agentspythonv0.9.5
Install
24.4s avg
Import
8949ms
Disk
452MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.5 · 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.920 runs
installs and imports cleanly · install 0.0s · import 7.450s · 423.6MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 24.4s · import 6.869s · 417MB
452MB installed
● package 452MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GoogleGenAI
from llama_index.llms.google_genai import GoogleGenAI
from llama_index.llms.gemini import Gemini
The 'llama-index-llms-gemini' package has been discontinued and replaced. Always use 'llama-index-llms-google-genai'.

This quickstart demonstrates how to initialize the GoogleGenAI LLM and perform a basic text completion. It assumes the `GOOGLE_API_KEY` environment variable is set. Replace `YOUR_GOOGLE_API_KEY_HERE` with your actual key for testing if not using environment variables.

import os from llama_index.llms.google_genai import GoogleGenAI # Ensure your Google API key is set as an environment variable # Or pass it directly: api_key="YOUR_API_KEY" os.environ["GOOGLE_API_KEY"] = os.environ.get('GOOGLE_API_KEY', 'YOUR_GOOGLE_API_KEY_HERE') llm = GoogleGenAI(model="gemini-pro") # Or use 'gemini-1.5-flash', 'gemini-1.5-pro', etc. response = llm.complete("What is the capital of France?") print(response)
Debug
Known issues
breakingThe `llama-index-llms-gemini` package has been discontinued since version 0.6.2 and replaced by `llama-index-llms-google-genai`. Direct imports from `llama_index.llms.gemini` will fail.
fix
Migrate your code to use the `llama-index-llms-google-genai` package and update import statements to `from llama_index.llms.google_genai import GoogleGenAI`.
affects: <0.6.2 (for gemini package), all (for google-genai package if using old imports)
gotchaAuthentication requires setting the `GOOGLE_API_KEY` environment variable. For Vertex AI, additional configurations like `GOOGLE_GENAI_USE_VERTEXAI`, `region`, and `project_id` (either as environment variables or `vertexai_config` parameters) are necessary. Incorrect setup will lead to authentication errors.
fix
Ensure `GOOGLE_API_KEY` is correctly set in your environment. For Vertex AI, configure `GOOGLE_GENAI_USE_VERTEXAI=True` and provide `project_id` and `location` (region) either via environment variables or in the `GoogleGenAI` constructor.
affects: All
gotchaAPI rate limiting from Google GenAI can lead to `google.api_core.exceptions.ResourceExhausted` (HTTP 429) errors.
fix
Implement retry logic with exponential backoff around your LLM calls. Consider checking and potentially increasing your Google Cloud project quotas if these errors persist.
affects: All
gotchaToken usage metrics (promptTokens, completionTokens) might not be accurately populated or reported in some tracing and observability tools (e.g., Langfuse) for synchronous calls due to how the underlying Google GenAI SDK reports usage metadata.
fix
Check the documentation of your specific observability tool for updates or workarounds. This is often an issue with the integration layer rather than the LLM integration itself. Manual parsing of `usage_metadata` might be required in some cases.
affects: Early versions (0.1.7 observed, potentially others)
Errors
Common errors & fixes
ImportError: cannot import name 'Gemini' from 'llama_index.llms' (unknown location)
Attempting to import the `Gemini` class from the old, deprecated `llama_index.llms.gemini` path instead of the new `llama_index.llms.google_genai` path.
fix
Update your import statement to `from llama_index.llms.google_genai import GoogleGenAI` and ensure `llama-index-llms-google-genai` is installed.
google.api_core.exceptions.PermissionDenied: 403 Permission denied. Your application has insufficient authentication credentials to access this API. Please check the 'Authentication' section in the API documentation.
The `GOOGLE_API_KEY` environment variable is either not set, incorrect, or expired. Or, for Vertex AI, the `project_id` or `location` (region) are not correctly configured.
fix
Set the `GOOGLE_API_KEY` environment variable with a valid API key obtained from Google AI Studio. For Vertex AI, verify that `GOOGLE_GENAI_USE_VERTEXAI=True` and that `project_id` and `location` are correctly specified.
google.api_core.exceptions.ResourceExhausted: 429 Resource has been exhausted (e.g. check your plan and billing).
You have exceeded the allowed API request rate limit or quota for Google Generative AI models.
fix
Implement a retry mechanism with exponential backoff in your application to handle transient rate limit errors. Review your Google Cloud project's API quotas and consider requesting an increase if your usage consistently exceeds limits.
Upgrade
Version history
0.9.5latest on PyPI · released May 19, 2026
Audit
Dependencies
llama-index-corerequiredThis is a LlamaIndex integration and requires the core LlamaIndex library to function.
google-generativeairequiredThis package is a wrapper around the Google Generative AI Python SDK.
Agent activity
31 hits · last 30 days
node
28
OpenAI (training)
1
Resources
llama-index-llms-google-genai — pip install llama-index-llms-google-genai · libregistry