Skip to main content
Google Vertex is a service that exposes all foundation models available in Google Cloud, like gemini-2.5-pro, gemini-2.5-flash, etc. It also provides some non-Google models such as Anthropic’s Claude. This will help you getting started with ChatVertexAI chat models. For detailed documentation of all ChatVertexAI features and configurations head to the API reference.
This library will be deprecatedThis library will be replaced by the ChatGoogle library. New implementations should use the ChatGoogle library instead and existing implementations should consider migrating.

Overview

Integration details

Model features

See the links in the table headers below for guides on how to use specific features. Note that while logprobs are supported, Gemini has fairly restricted usage of them.

Setup

LangChain.js supports two different authentication methods based on whether you’re running in a Node.js environment or a web environment. It also supports the authentication method used by Vertex AI Express Mode using either package. To access ChatVertexAI models you’ll need to setup Google VertexAI in your Google Cloud Platform (GCP) account, save the credentials file, and install the @langchain/google-vertexai integration package. On Node.js, that package uses @langchain/google-gauth for authentication (you do not need to install it separately).

Credentials

Head to your GCP account and generate a credentials file. Once you’ve done this set the GOOGLE_APPLICATION_CREDENTIALS environment variable:
Alternatively, on your local machine you can run gcloud auth application-default login to use Application Default Credentials. If running in a web environment, install the @langchain/google-vertexai-web package (which uses @langchain/google-webauth for authentication). Set service account JSON in GOOGLE_WEB_CREDENTIALS:
GOOGLE_VERTEX_AI_WEB_CREDENTIALS is also supported but deprecated. If you are using Vertex AI Express Mode, you can install either the @langchain/google-vertexai or @langchain/google-vertexai-web package. You can then go to the Express Mode API Key page and set your API Key in the GOOGLE_API_KEY environment variable:
If you want to get automated tracing of your model calls you can also set your LangSmith API key by uncommenting below:

Installation

The LangChain ChatVertexAI integration lives in the @langchain/google-vertexai package:
Or if using in a web environment like a Vercel Edge function:

Instantiation

Now we can instantiate our model object and generate chat completions:

Invocation

Tool calling with Google search retrieval

It is possible to call the model with a Google search tool which you can use to ground content generation with real-world information and reduce hallucinations. Grounding is currently not supported by gemini-2.0-flash-exp. You can choose to either ground using Google Search or by using a custom data store. Here are examples of both:

Google search retrieval

Grounding example that uses Google Search:

Google search retrieval with data store

First, set up your data store (this is a schema of an example data store): Then, use this data store in the example provided below: (Note that you have to use your own variables for projectId and datastoreId)
You should now get results that are grounded in the data from your provided data store.

Context caching

Vertex AI offers context caching functionality, which helps optimize costs by storing and reusing long blocks of message content across multiple API requests. This is particularly useful when you have lengthy conversation histories or message segments that appear frequently in your interactions. To use this feature, first create a context cache by following this official guide. Once you’ve created a cache, you can pass its id in as a runtime param as follows:
You can also bind this field directly onto the model instance:
Note that not all models currently support context caching.

API reference

For detailed documentation of all ChatVertexAI features and configurations head to the API reference.