LlamaIndex Llms Integration: Google GenAI
Installation
-
Install the required Python packages:
%pip install llama-index-llms-google-genai
-
Set the Google API key as an environment variable:
%env GOOGLE_API_KEY=your_api_key_here
Usage
Basic Content Generation
To generate a poem using the Gemini model, use the following code:
from llama_index.llms.google_genai import GoogleGenAI
llm = GoogleGenAI(model="gemini-3-flash-preview")
resp = llm.complete("Write a poem about a magic backpack")
print(resp)
Chat with Messages
To simulate a conversation, send a list of messages:
from llama_index.core.llms import ChatMessage
from llama_index.llms.google_genai import GoogleGenAI
messages = [
ChatMessage(role="user", content="Hello friend!"),
ChatMessage(role="assistant", content="Yarr what is shakin' matey?"),
ChatMessage(
role="user", content="Help me decide what to have for dinner."
),
]
llm = GoogleGenAI(model="gemini-3-flash-preview")
resp = llm.chat(messages)
print(resp)
Streaming Responses
To stream content responses in real-time:
from llama_index.llms.google_genai import GoogleGenAI
llm = GoogleGenAI(model="gemini-3-flash-preview")
resp = llm.stream_complete(
"The story of Sourcrust, the bread creature, is really interesting. It all started when..."
)
for r in resp:
print(r.text, end="")
To stream chat responses:
from llama_index.core.llms import ChatMessage
from llama_index.llms.google_genai import GoogleGenAI
llm = GoogleGenAI(model="gemini-3-flash-preview")
messages = [
ChatMessage(role="user", content="Hello friend!"),
ChatMessage(role="assistant", content="Yarr what is shakin' matey?"),
ChatMessage(
role="user", content="Help me decide what to have for dinner."
),
]
resp = llm.stream_chat(messages)
Specific Model Usage
To use a specific model, you can configure it like this:
from llama_index.llms.google_genai import GoogleGenAI
llm = GoogleGenAI(model="gemini-3-flash-preview")
resp = llm.complete("Write a short, but joyous, ode to LlamaIndex")
print(resp)
Asynchronous API
To use the asynchronous completion API:
from llama_index.llms.google_genai import GoogleGenAI
llm = GoogleGenAI(model="gemini-3-flash-preview")
resp = await llm.acomplete("Llamas are famous for ")
print(resp)
For asynchronous streaming of responses:
resp = await llm.astream_complete("Llamas are famous for ")
async for chunk in resp:
print(chunk.text, end="")
Release files for llama-index-llms-google-genai 0.11.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| llama_index_llms_google_genai-0.11.2.tar.gz | 14.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llama_index_llms_google_genai-0.11.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.2 kB
Release files / llama_index_llms_google_genai-0.11.2.tar.gz
| Download URL | llama_index_llms_google_genai-0.11.2.tar.gz |
|---|---|
| Size | 14.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
939d99030b0fa45c0f11ec8b0c3a2f44ce68b347818073c6d39086794e37b308
|
|
BLAKE2b-256 checksum How to use checksums |
6a5d59d9ded5b75ce5f0115c5292d3b7e8707c15abf258ba46357bf51b514591
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / llama_index_llms_google_genai-0.11.2-py3-none-any.whl
| Download URL | llama_index_llms_google_genai-0.11.2-py3-none-any.whl |
|---|---|
| Size | 15.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
61c4517f3d5799cad50cf84d14be6236510de4a8f501288d21237baf23252269
|
|
BLAKE2b-256 checksum How to use checksums |
193cf52a38b1905ddae417d05aaae874e9076882e1b3df63452cb3aafe85d0fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|