This package contains resources to access Google AI/ML models and other Google services via Vertex AI. Authorization to these services use either an API Key or service account credentials that are included in an environment variable.
If you are running this on the Google Cloud Platform, or in a way where service account credentials can be stored on a file system, consider using the @langchain/google-vertexai package instead. You do not need to use both packages. See the section on Authorization below.
$ pnpm install @langchain/google-vertexai-web
Authorization is done through a Google Cloud Service Account.
To handle service accounts, this package uses the google-auth-library
package, and you may wish to consult the documentation for that library
about how it does so. But in short, classes in this package will use
credentials from the first of the following that apply:
apiKey attributeauthInfo attributeAPI_KEYGOOGLE_WEB_CREDENTIALSGOOGLE_VERTEX_AI_WEB_CREDENTIALS (deprecated)Set LANGSMITH_GATEWAY=true and LANGSMITH_GATEWAY_API_KEY to route
ChatVertexAI through the gateway's /vertex endpoint. The gateway key falls
back to LANGSMITH_API_KEY. Set LANGSMITH_GATEWAY to a custom gateway root URL
to use a different host or path prefix.
import { ChatVertexAI } from "@langchain/google-vertexai-web";
const model = new ChatVertexAI({ model: "gemini-2.5-flash" });
const response = await model.invoke("Hello!");
console.log(response.content);
Vertex Express requests do not require Google web credentials when a gateway API
key is configured. Passing your own credentials (authOptions or apiKey) or an
explicit endpoint opts out of gateway routing and sends requests straight to
Vertex AI.
Keep gateway API keys in trusted server or edge runtimes, not public browser bundles.
Integration with Google Vertex AI chat models in web environments.
Setup:
Install @langchain/google-vertexai-web and set your stringified
Vertex AI credentials as an environment variable named `GOO
Integration with a Google Vertex AI LLM using the "@langchain/google-webauth" package for auth.
Integration with a Google Vertex AI embeddings model using the "@langchain/google-webauth" package for auth.