Skip to content

langchain-google-genai uses older google-ai-generativelanguage, not the newer google-genai #980

Description

@t-dsai

Hi,
My setup is based on Python 3.13, with the following libraries

google-genai==1.19.0
langchain==0.3.25
langchain-core==0.3.64
langchain-community==0.3.24
langchain-google-genai==2.1.5
langchain-google-community==2.0.7

I tried using langchain-google-genai library as follows:

from langchain_google_genai import ChatGoogleGenerativeAI
llm = ChatGoogleGenerativeAI(
    model="gemini-2.0-flash",
    api_key=my_api_key,
    temperature=0.5,
    )
result = llm.invoke("Sing a ballad of LangChain.")
print(result.content)

However, it threw me an error, with google.ai module not found.

Upon going through chat_models.py in langchain_google_genai directory, I found usage of the following library.
google.ai.generativelanguage_v1beta

Upon installing google-ai-generativelanguage, the issue was resolved. However, Google recommends migrating from old Gemini SDK to the new Gemini SDK [https://ai.google.dev/gemini-api/docs/migrate]

With the naming langchain-google-genai, it hints that the underlying library is using the new Gemini SDK.

Is it planned to move to new Gemini SDK soon? If not, would it be a good idea to highlight this requirement somewhere prominently.

My apologies if I overlooked/missed this requirement of langchain-google-genai.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions