Skip to main content

LlamaIndex Llms Integration: Google GenAI

Installation

  1. Install the required Python packages:

    %pip install llama-index-llms-google-genai
    
  2. 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.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llama-index-llms-google-genai 0.12.0
File Size Uploaded Provenance Actions
llama_index_llms_google_genai-0.12.0.tar.gz 15.1 kB Without provenance Details for llama_index_llms_google_genai-0.12.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llama-index-llms-google-genai 0.12.0
File Interpreter ABI Platform Actions
llama_index_llms_google_genai-0.12.0-py3-none-any.whl Python 3 none any Details for llama_index_llms_google_genai-0.12.0-py3-none-any.whl

Total release size: 30.6 kB

Release files / llama_index_llms_google_genai-0.12.0.tar.gz

Download URL llama_index_llms_google_genai-0.12.0.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
fd2b7bc2fe1f65212477004ca4f1407e796ef544c8c963e4a3e1f311d3b31a1d
BLAKE2b-256 checksum
How to use checksums
3245d8e5f79bd725767a1d3cb01fe02d72d6b993f176a74c27ff437c04135739
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","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.12.0-py3-none-any.whl

Download URL llama_index_llms_google_genai-0.12.0-py3-none-any.whl
Size 15.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9da09cdcd6fff30b242bd8e04e5120531d06e84166eab6f2d795f8c9c1a752e8
BLAKE2b-256 checksum
How to use checksums
9fa9ad7168175c7799bd75b166bcf0fe1c1703350f465241bbc028cc155c1ee4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for llama-index-llms-google-genai 0.12.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.12.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page