Registry / llm-agents / langchain-google-vertexai

langchain-google-vertexai

JSON →
library3.2.4pypypi✓ verified 25d ago

This package provides LangChain integrations for Google Cloud generative models via the Vertex AI Platform. It enables access to foundational models (like Gemini) and third-party models available on Vertex AI Model Garden, along with services like Vector Search. The current version is 3.2.2, with active development and frequent releases to support new features and address issues.

pip install langchain-google-vertexai
INSTALL
IMPORT
SIG · LANGCHAIN-GOOGLE-V
L
langchain-google-vertexai
llm-agentspythonv3.2.4
Install
24.5s avg
Import
14875ms
Disk
546MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.2.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 19.604s · 545.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 24.5s · import 10.146s · 521MB
546MB installed
● package 546MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ChatVertexAI
from langchain_google_vertexai import ChatVertexAI
from langchain.llms import VertexAI or from langchain.chat_models import ChatVertexAI (for older LangChain versions)
The primary chat model class for Vertex AI. As of v3.2.0, this is deprecated in favor of `ChatGoogleGenerativeAI` from `langchain-google-genai` for unified Gemini API access, but remains for Vertex AI platform-specific features. [9, 22]
VertexAI
from langchain_google_vertexai import VertexAI
from langchain.llms import VertexAI (for older LangChain versions)
The primary LLM class for Vertex AI completion models. As of v3.2.0, this is deprecated in favor of `GoogleGenerativeAI` from `langchain-google-genai` for unified Gemini API access, but remains for Vertex AI platform-specific features. [9, 22]
VertexAIEmbeddings
from langchain_google_vertexai import VertexAIEmbeddings
from langchain.embeddings import VertexAIEmbeddings (for older LangChain versions)
The embeddings class for Vertex AI. As of v3.2.0, this is deprecated in favor of `GoogleGenerativeAIEmbeddings` from `langchain-google-genai` for unified Gemini API access, but remains for Vertex AI platform-specific features. [9, 20, 22]
ChatAnthropicVertex
from langchain_google_vertexai import ChatAnthropicVertex
For integrating with Anthropic's Claude models hosted on Vertex AI. [9]

This quickstart demonstrates how to instantiate and use the `ChatVertexAI` model for text generation. It also shows an example of multimodal input (commented out) using a vision-capable model. Ensure your Google Cloud project and location are configured, and that you are authenticated to Google Cloud, typically via Application Default Credentials (e.g., `gcloud auth application-default login`) or by setting `GOOGLE_APPLICATION_CREDENTIALS`.

import os from langchain_core.messages import HumanMessage from langchain_google_vertexai import ChatVertexAI # Ensure your Google Cloud Project ID and location are set # or use GOOGLE_APPLICATION_CREDENTIALS for authentication. # For example, by running 'gcloud auth application-default login' # os.environ["GOOGLE_CLOUD_PROJECT"] = os.environ.get("GOOGLE_CLOUD_PROJECT", "your-gcp-project-id") # os.environ["GOOGLE_CLOUD_LOCATION"] = os.environ.get("GOOGLE_CLOUD_LOCATION", "us-central1") # Initialize the chat model # Note: ChatVertexAI is deprecated in favor of ChatGoogleGenerativeAI from langchain_google_genai # for most Gemini models, but can still be used for Vertex AI specific deployments. llm = ChatVertexAI(model="gemini-pro") # or "gemini-2.5-flash", "chat-bison", etc. # Invoke the model with a message response = llm.invoke("What is the capital of France?") print(response.content) # Example with multimodal input (requires a vision model like "gemini-pro-vision") # from langchain_core.messages import HumanMessage # llm_vision = ChatVertexAI(model="gemini-pro-vision") # message_with_image = HumanMessage( # content=[ # {"type": "text", "text": "What's in this image?"}, # {"type": "image_url", "image_url": {"url": "https://picsum.photos/seed/picsum/200/300"}}, # ] # ) # response_vision = llm_vision.invoke([message_with_image]) # print(response_vision.content)
Debug
Known issues
deprecatedClasses `ChatVertexAI`, `VertexAI`, and `VertexAIEmbeddings` are officially deprecated in `langchain-google-vertexai` version 3.2.0 and will be removed in 4.0.0. [8, 9, 20]
fix
Migrate to `ChatGoogleGenerativeAI`, `GoogleGenerativeAI`, and `GoogleGenerativeAIEmbeddings` respectively, from the `langchain-google-genai` package for most Gemini API interactions. `langchain-google-vertexai` remains supported for Vertex AI platform-specific features (Model Garden, Vector Search, etc.). [8, 9, 22]
affects: >=3.2.0
gotchaAuthentication to Google Cloud Vertex AI typically requires Application Default Credentials (ADC). Incorrect or missing authentication setup is a common source of errors. [2, 3, 6, 7]
fix
Ensure you are authenticated via `gcloud auth application-default login` or by setting the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the path of a service account JSON key file. Project ID and location might also need to be specified in the model constructor or environment variables. [2, 3, 6, 20]
affects: All
gotchaThere can be confusion between `langchain-google-vertexai` and `langchain-google-genai`. While both offer Google LLM integrations, `langchain-google-vertexai` focuses on Vertex AI platform-specific features (e.g., Model Garden, Vector Search, Anthropic models on Vertex AI), whereas `langchain-google-genai` is for direct Google Generative AI (Gemini API) access. [2, 7, 22, 33, 34]
fix
For general Gemini model access (Gemini API), use `langchain-google-genai`. For integrations requiring Vertex AI platform features or third-party models deployed on Vertex AI, use `langchain-google-vertexai`. Refer to the official LangChain Google documentation for guidance on which package to use. [22]
affects: All
gotchaWhen using tools with Gemini models through Vertex AI, certain Zod schema features (e.g., discriminated unions, union types, positive refinements) are not supported or are automatically converted, potentially leading to unexpected behavior or errors. [3, 19]
fix
Use simple, flat object structures for tool schemas, replace discriminated unions with enums and optional fields, and prefer `min()` over `positive()` for number constraints. Test your tool schemas thoroughly. [3, 19]
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'langchain_google_vertexai'
The 'langchain-google-vertexai' package is not installed, or the Python environment where the code is being run does not have it installed.
fix
Install the package using pip: `pip install langchain-google-vertexai`. Ensure this is run in the same Python environment used by your application.
AttributeError: 'TextGenerationResponse' object has no attribute 'candidates'
This error typically occurs with older versions of LangChain or 'langchain-google-vertexai' when the internal structure of the response object from Vertex AI models has changed, making the 'candidates' attribute unavailable or deprecated.
fix
Update 'langchain-google-vertexai' to a compatible version with your LangChain installation (`pip install --upgrade langchain-google-vertexai`). You may need to adjust your code to access the generated text directly, often via `response.text` instead of `response.candidates`.
ValueError: Could not resolve project_id
This indicates an authentication failure with Google Cloud's Vertex AI. It often means that the Google Cloud project ID is not correctly identified, which can happen if `GOOGLE_APPLICATION_CREDENTIALS` is not set, or if the environment (e.g., Cloud Run) is not correctly configured for application default credentials.
fix
Ensure the `GOOGLE_APPLICATION_CREDENTIALS` environment variable points to a valid service account JSON key file. Alternatively, ensure you are authenticated via `gcloud auth application-default login` for local development. When initializing `ChatVertexAI`, explicitly pass `project` and `location` parameters.
ValueError: Cannot get the Candidate text. Response candidate content part has no text.
This error arises from an incompatibility between the installed version of `langchain-google-vertexai` and `google-cloud-aiplatform`, especially when using tool-calling features.
fix
Upgrade `langchain-google-vertexai` to version 1.0.2 or later to ensure compatibility with the `google-cloud-aiplatform` SDK's tool-calling updates: `pip install --upgrade langchain-google-vertexai`.
Upgrade
Version history
3.2.4latest on PyPI · released Jun 9, 2026
Audit
Dependencies
google-cloud-aiplatformrequiredRequired for interacting with Google Vertex AI services.
langchain-corerequiredCore LangChain functionalities.
httpxrequiredUsed for making HTTP requests.
pydanticrequiredUsed for data validation and settings management.
Agent activity
58 hits · last 30 days
node
52
OpenAI (training)
1
Resources
langchain-google-vertexai — pip install langchain-google-vertexai · libregistry