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="")
Metadata
Release files for llama-index-llms-google-genai 0.11.3
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.3.tar.gz | 15.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llama_index_llms_google_genai-0.11.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.6 kB
Release files / llama_index_llms_google_genai-0.11.3.tar.gz
| Download URL | llama_index_llms_google_genai-0.11.3.tar.gz |
|---|---|
| Size | 15.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2fdf9355fbde7b922fa264263f27cff762fa990a3027e735eec83d68a522f2a2
|
|
BLAKE2b-256 checksum How to use checksums |
dad7a484343c1473b5b164ba0b78d48f53071f7013cbde8df1034beb697c1d40
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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.3-py3-none-any.whl
| Download URL | llama_index_llms_google_genai-0.11.3-py3-none-any.whl |
|---|---|
| Size | 15.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fbdbc19fc826e5c9830e0186edd84f4ccda44f39d959a275e49a00a7994ef1c0
|
|
BLAKE2b-256 checksum How to use checksums |
dd6cf45a0175d40dcbe87e9f85476e4fe27706de52b887893481ba5f60b4ee1e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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}
|