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.
概述
集成详情
模型功能
请参阅下表标题中的链接,了解如何使用特定功能。
Note that while logprobs are supported, Gemini has fairly restricted usage of them.
设置
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. 要访问ChatVertexAI models,你需要setup Google VertexAI in your Google Cloud Platform (GCP) account, save the credentials file, and install the @langchain/google-vertexai integration package.
凭证
Head to your GCP account and generate a credentials file. Once you’ve done this set theGOOGLE_APPLICATION_CREDENTIALS environment variable:
GOOGLE_VERTEX_AI_WEB_CREDENTIALS environment variable as a JSON stringified object, and install the @langchain/google-vertexai-web package:
@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:
安装
LangChain 的ChatVertexAI 集成位于 @langchain/google-vertexai 包中:
实例化
现在我们可以实例化模型对象并生成聊天补全:调用
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 bygemini-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)
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:API 参考
有关所有ChatVertexAI 功能和配置的详细文档,请前往 API 参考。
将这些文档连接到 Claude、VSCode 等工具,通过 MCP 获取实时答案。

