An integration package connecting Google VertexAI and LangChain
Project Links
Meta
Requires Python: <4.0.0,>=3.10.0
Classifiers
langchain-google-vertexai
This package contains the LangChain integrations for Google Cloud generative models.
Contents
Installation
pip install -U langchain-google-vertexai
Chat Models
ChatVertexAI
class exposes models such as gemini-pro
and other Gemini variants.
To use, you should have a Google Cloud project with APIs enabled, and configured credentials. Initialize the model as:
from langchain_google_vertexai import ChatVertexAI
llm = ChatVertexAI(model_name="gemini-2.5-flash")
llm.invoke("Sing a ballad of LangChain.")
Multimodal inputs
Gemini supports image inputs when providing a single chat message. Example:
from langchain_core.messages import HumanMessage
from langchain_google_vertexai import ChatVertexAI
llm = ChatVertexAI(model_name="gemini-2.0-flash-001")
message = HumanMessage(
content=[
{
"type": "text",
"text": "What's in this image?",
},
{
"type": "image_url",
"image_url": {"url": "https://picsum.photos/seed/picsum/200/300"}
},
]
)
response = llm.invoke([message])
The value of image_url
can be:
- A public image URL
- An accessible Google Cloud Storage (GCS) file (e.g.,
"gcs://path/to/file.png"
) - A base64 encoded image (e.g.,
"data:image/png;base64,abcd124"
)
Multimodal Outputs
Gemini supports image output. Example:
from langchain_core.messages import HumanMessage
from langchain_google_vertexai import ChatVertexAI, Modality
llm = ChatVertexAI(model_name="imagen-3.0-generate-002",
response_modalities = [Modality.TEXT, Modality.IMAGE])
message = HumanMessage(
content=[
{
"type": "text",
"text": "Generate an image of a cat.",
},
]
)
response = llm.invoke([message])
Embeddings
Google Cloud embeddings models can be used as:
from langchain_google_vertexai import VertexAIEmbeddings
embeddings = VertexAIEmbeddings()
embeddings.embed_query("hello, world!")
LLMs
Use Google Cloud's generative AI models as old-style LangChain LLMs:
from langchain_core.prompts import PromptTemplate
from langchain_google_vertexai import ChatVertexAI
template = """Question: {question}
Answer: Let's think step by step."""
prompt = PromptTemplate.from_template(template)
llm = ChatVertexAI(model_name="gemini-2.5-flash")
chain = prompt | llm
question = "Who was the president of the USA in 1994?"
print(chain.invoke({"question": question}))
Code Generation
You can use Gemini models for code generation tasks to generate code snippets, functions, or scripts in various programming languages.
Example: Generate a Python function
from langchain_google_vertexai import ChatVertexAI
llm = ChatVertexAI(model_name="gemini-2.5-flash", temperature=0.3, max_output_tokens=1000)
prompt = "Write a Python function that checks if a string is a valid email address."
generated_code = llm.invoke(prompt)
print(generated_code)
Example: Generate JavaScript code
from langchain_google_vertexai import ChatVertexAI
llm = ChatVertexAI(model_name="gemini-2.5-flash", temperature=0.3, max_output_tokens=1000)
prompt_js = "Write a JavaScript function that returns the factorial of a number."
print(llm.invoke(prompt_js))
Notes
- Adjust
temperature
to control creativity (higher values increase randomness). - Use
max_output_tokens
to limit the length of the generated code. - Gemini models are well-suited for code generation tasks with advanced understanding of programming concepts.
Oct 17, 2025
3.0.0
Oct 16, 2025
3.0.0rc1
Sep 16, 2025
2.1.2
Sep 15, 2025
2.1.1
Sep 12, 2025
2.1.0
Aug 04, 2025
2.0.28
Jun 30, 2025
2.0.27
Jun 20, 2025
2.0.26
Jun 11, 2025
2.0.25
May 16, 2025
2.0.24
May 08, 2025
2.0.23
May 07, 2025
2.0.22
Apr 24, 2025
2.0.21
Apr 11, 2025
2.0.20
Apr 04, 2025
2.0.19
Mar 27, 2025
2.0.18
Mar 25, 2025
2.0.17
Mar 21, 2025
2.0.16
Mar 10, 2025
2.0.15
Feb 26, 2025
2.0.14
Feb 03, 2025
2.0.13
Jan 24, 2025
2.0.12
Jan 14, 2025
2.0.11
Jan 07, 2025
2.0.10
Dec 12, 2024
2.0.9
Nov 27, 2024
2.0.8
Oct 31, 2024
2.0.7
Oct 29, 2024
2.0.6
Oct 11, 2024
2.0.5
Oct 07, 2024
2.0.4
Oct 01, 2024
2.0.3
Oct 01, 2024
2.0.2
Sep 18, 2024
2.0.1
Sep 13, 2024
2.0.0
Sep 09, 2024
2.0.0.dev1
Aug 22, 2024
1.0.10
Aug 21, 2024
1.0.9
Jul 31, 2024
1.0.8
Jul 22, 2024
1.0.7
Jun 25, 2024
1.0.6
Jun 05, 2024
1.0.5
May 17, 2024
1.0.4
May 01, 2024
1.0.3
Apr 26, 2024
1.0.2
Apr 12, 2024
1.0.1
Apr 11, 2024
0.1.3
Mar 26, 2024
0.1.2
Mar 15, 2024
0.1.1
Feb 27, 2024
0.1.0
Feb 27, 2024
0.0.7
Feb 26, 2024
0.0.6
Feb 26, 2024
0.0.6rc0
Feb 08, 2024
0.0.5
Jan 26, 2024
0.0.3
Jan 18, 2024
0.0.2
Jan 12, 2024
0.0.1.post1
Jan 06, 2024
0.0.1
Jan 05, 2024
0.0.1rc0
Wheel compatibility matrix
Files in release
Extras:
Dependencies:
(<2.0.0,>=1.0.0)
langchain-core
(<2.0.0,>=1.97.0)
google-cloud-aiplatform
(<3.0.0,>=2.18.0)
google-cloud-storage
(<1.0.0,>=0.28.0)
httpx
(<1.0.0,>=0.4.0)
httpx-sse
(<3.0.0,>=2.9.0)
pydantic
(<1.0.0,>=0.22.0)
validators
(<2.0.0,>=1.4.0)
bottleneck
(<3.0.0,>=2.8.6)
numexpr
(<22.0.0,>=19.0.1)
pyarrow