{"id":9084,"library":"llama-index-llms-google-genai","title":"Google GenAI LLM Integration for LlamaIndex","description":"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.","status":"active","version":"0.9.1","language":"en","source_language":"en","source_url":"https://github.com/run-llama/llama_index","tags":["LLM","Google GenAI","Gemini","Vertex AI","LlamaIndex","AI","integration"],"install":[{"cmd":"pip install llama-index-llms-google-genai","lang":"bash","label":"Install only Google GenAI LLM integration"},{"cmd":"pip install llama-index google-generativeai llama-index-llms-google-genai","lang":"bash","label":"Install with LlamaIndex core and Google Generative AI SDK"}],"dependencies":[{"reason":"This is a LlamaIndex integration and requires the core LlamaIndex library to function.","package":"llama-index-core","optional":false},{"reason":"This package is a wrapper around the Google Generative AI Python SDK.","package":"google-generativeai","optional":false}],"imports":[{"note":"The 'llama-index-llms-gemini' package has been discontinued and replaced. Always use 'llama-index-llms-google-genai'.","wrong":"from llama_index.llms.gemini import Gemini","symbol":"GoogleGenAI","correct":"from llama_index.llms.google_genai import GoogleGenAI"}],"quickstart":{"code":"import os\nfrom llama_index.llms.google_genai import GoogleGenAI\n\n# Ensure your Google API key is set as an environment variable\n# Or pass it directly: api_key=\"YOUR_API_KEY\"\nos.environ[\"GOOGLE_API_KEY\"] = os.environ.get('GOOGLE_API_KEY', 'YOUR_GOOGLE_API_KEY_HERE')\n\nllm = GoogleGenAI(model=\"gemini-pro\") # Or use 'gemini-1.5-flash', 'gemini-1.5-pro', etc.\n\nresponse = llm.complete(\"What is the capital of France?\")\nprint(response)\n","lang":"python","description":"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."},"warnings":[{"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`.","message":"The `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.","severity":"breaking","affected_versions":"<0.6.2 (for gemini package), all (for google-genai package if using old imports)"},{"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.","message":"Authentication 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.","severity":"gotcha","affected_versions":"All"},{"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.","message":"API rate limiting from Google GenAI can lead to `google.api_core.exceptions.ResourceExhausted` (HTTP 429) errors.","severity":"gotcha","affected_versions":"All"},{"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.","message":"Token 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.","severity":"gotcha","affected_versions":"Early versions (0.1.7 observed, potentially others)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Update your import statement to `from llama_index.llms.google_genai import GoogleGenAI` and ensure `llama-index-llms-google-genai` is installed.","cause":"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.","error":"ImportError: cannot import name 'Gemini' from 'llama_index.llms' (unknown location)"},{"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.","cause":"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.","error":"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."},{"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.","cause":"You have exceeded the allowed API request rate limit or quota for Google Generative AI models.","error":"google.api_core.exceptions.ResourceExhausted: 429 Resource has been exhausted (e.g. check your plan and billing)."}]}