!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}return t}()||function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}(),document.documentElement.setAttribute("data-announcement-bar-initially-dismissed",function(){try{return"true"===localStorage.getItem("docusaurus.announcement.dismiss")}catch(t){}return!1}())

[Skip to main content](#__docusaurus_skipToContent_fallback)

LangChain v0.2 is coming soon! Preview the new docs [here](/v0.2/docs/introduction/).

[

![🦜️🔗 Langchain](/v0.1/img/brand/wordmark.png)![🦜️🔗 Langchain](/v0.1/img/brand/wordmark-dark.png)

](/v0.1/)[Docs](/v0.1/docs/get_started/introduction/)[Use cases](/v0.1/docs/use_cases/)[Integrations](/v0.1/docs/integrations/platforms/)[API Reference](https://api.js.langchain.com)

[More](#)

*   [People](/v0.1/docs/people/)
*   [Community](/v0.1/docs/community/)
*   [Tutorials](/v0.1/docs/additional_resources/tutorials/)
*   [Contributing](/v0.1/docs/contributing/)

[v0.1](#)

*   [v0.2](https://js.langchain.com/v0.2/docs/introduction)
*   [v0.1](/v0.1/docs/get_started/introduction/)

[🦜🔗](#)

*   [LangSmith](https://smith.langchain.com)
*   [LangSmith Docs](https://docs.smith.langchain.com)
*   [LangChain Hub](https://smith.langchain.com/hub)
*   [LangServe](https://github.com/langchain-ai/langserve)
*   [Python Docs](https://python.langchain.com/)

[Chat](https://chatjs.langchain.com)[](https://github.com/langchain-ai/langchainjs)

Search

*   [Providers](/v0.1/docs/integrations/platforms/)
    
    *   [Providers](/v0.1/docs/integrations/platforms/)
    *   [Anthropic](/v0.1/docs/integrations/platforms/anthropic/)
    *   [AWS](/v0.1/docs/integrations/platforms/aws/)
    *   [Google](/v0.1/docs/integrations/platforms/google/)
    *   [Microsoft](/v0.1/docs/integrations/platforms/microsoft/)
    *   [OpenAI](/v0.1/docs/integrations/platforms/openai/)
*   [Components](/v0.1/docs/integrations/components/)
    
    *   [LLMs](/v0.1/docs/integrations/llms/)
        
    *   [Chat models](/v0.1/docs/integrations/chat/)
        
        *   [Chat models](/v0.1/docs/integrations/chat/)
        *   [Alibaba Tongyi](/v0.1/docs/integrations/chat/alibaba_tongyi/)
        *   [Anthropic](/v0.1/docs/integrations/chat/anthropic/)
        *   [Anthropic Tools](/v0.1/docs/integrations/chat/anthropic_tools/)
        *   [Azure OpenAI](/v0.1/docs/integrations/chat/azure/)
        *   [Baidu Wenxin](/v0.1/docs/integrations/chat/baidu_wenxin/)
        *   [Bedrock](/v0.1/docs/integrations/chat/bedrock/)
        *   [Cloudflare Workers AI](/v0.1/docs/integrations/chat/cloudflare_workersai/)
        *   [Cohere](/v0.1/docs/integrations/chat/cohere/)
        *   [Fake LLM](/v0.1/docs/integrations/chat/fake/)
        *   [Fireworks](/v0.1/docs/integrations/chat/fireworks/)
        *   [Friendli](/v0.1/docs/integrations/chat/friendli/)
        *   [Google GenAI](/v0.1/docs/integrations/chat/google_generativeai/)
        *   [(Legacy) Google PaLM/VertexAI](/v0.1/docs/integrations/chat/google_palm/)
        *   [Google Vertex AI](/v0.1/docs/integrations/chat/google_vertex_ai/)
        *   [Groq](/v0.1/docs/integrations/chat/groq/)
        *   [Llama CPP](/v0.1/docs/integrations/chat/llama_cpp/)
        *   [Minimax](/v0.1/docs/integrations/chat/minimax/)
        *   [Mistral AI](/v0.1/docs/integrations/chat/mistral/)
        *   [NIBittensorChatModel](/v0.1/docs/integrations/chat/ni_bittensor/)
        *   [Ollama](/v0.1/docs/integrations/chat/ollama/)
        *   [Ollama Functions](/v0.1/docs/integrations/chat/ollama_functions/)
        *   [OpenAI](/v0.1/docs/integrations/chat/openai/)
        *   [PremAI](/v0.1/docs/integrations/chat/premai/)
        *   [PromptLayer OpenAI](/v0.1/docs/integrations/chat/prompt_layer_openai/)
        *   [TogetherAI](/v0.1/docs/integrations/chat/togetherai/)
        *   [WebLLM](/v0.1/docs/integrations/chat/web_llm/)
        *   [YandexGPT](/v0.1/docs/integrations/chat/yandex/)
        *   [ZhipuAI](/v0.1/docs/integrations/chat/zhipuai/)
    *   [Document loaders](/v0.1/docs/integrations/document_loaders/)
        
    *   [Document transformers](/v0.1/docs/integrations/document_transformers/)
        
    *   [Document compressors](/v0.1/docs/integrations/document_compressors/)
        
    *   [Text embedding models](/v0.1/docs/integrations/text_embedding/)
        
    *   [Vector stores](/v0.1/docs/integrations/vectorstores/)
        
    *   [Retrievers](/v0.1/docs/integrations/retrievers/)
        
    *   [Tools](/v0.1/docs/integrations/tools/)
        
    *   [Agents and toolkits](/v0.1/docs/integrations/toolkits/)
        
    *   [Chat Memory](/v0.1/docs/integrations/chat_memory/)
        
    *   [Stores](/v0.1/docs/integrations/stores/)
        

*   [](/v0.1/)
*   [Components](/v0.1/docs/integrations/components/)
*   [Chat models](/v0.1/docs/integrations/chat/)
*   (Legacy) Google PaLM/VertexAI

On this page

ChatGooglePaLM
==============

note

This integration does not support `gemini-*` models. Check Google [GenAI](/v0.1/docs/integrations/chat/google_generativeai/) or [VertexAI](/v0.1/docs/integrations/chat/google_vertex_ai/).

The [Google PaLM API](https://developers.generativeai.google/products/palm) can be integrated by first installing the required packages:

tip

See [this section for general instructions on installing integration packages](/v0.1/docs/get_started/installation/#installing-integration-packages).

*   npm
*   Yarn
*   pnpm

    npm install google-auth-library @google-ai/generativelanguage @langchain/community

    yarn add google-auth-library @google-ai/generativelanguage @langchain/community

    pnpm add google-auth-library @google-ai/generativelanguage @langchain/community

tip

We're unifying model params across all packages. We now suggest using `model` instead of `modelName`, and `apiKey` for API keys.

Create an **API key** from [Google MakerSuite](https://makersuite.google.com/app/apikey). You can then set the key as `GOOGLE_PALM_API_KEY` environment variable or pass it as `apiKey` parameter while instantiating the model.

    import { ChatGooglePaLM } from "@langchain/community/chat_models/googlepalm";import {  AIMessage,  HumanMessage,  SystemMessage,} from "@langchain/core/messages";export const run = async () => {  const model = new ChatGooglePaLM({    apiKey: "<YOUR API KEY>", // or set it in environment variable as `GOOGLE_PALM_API_KEY`    temperature: 0.7, // OPTIONAL    model: "models/chat-bison-001", // OPTIONAL    topK: 40, // OPTIONAL    topP: 1, // OPTIONAL    examples: [      // OPTIONAL      {        input: new HumanMessage("What is your favorite sock color?"),        output: new AIMessage("My favorite sock color be arrrr-ange!"),      },    ],  });  // ask questions  const questions = [    new SystemMessage(      "You are a funny assistant that answers in pirate language."    ),    new HumanMessage("What is your favorite food?"),  ];  // You can also use the model as part of a chain  const res = await model.invoke(questions);  console.log({ res });};

#### API Reference:

*   [ChatGooglePaLM](https://api.js.langchain.com/classes/langchain_community_chat_models_googlepalm.ChatGooglePaLM.html) from `@langchain/community/chat_models/googlepalm`
*   [AIMessage](https://api.js.langchain.com/classes/langchain_core_messages.AIMessage.html) from `@langchain/core/messages`
*   [HumanMessage](https://api.js.langchain.com/classes/langchain_core_messages.HumanMessage.html) from `@langchain/core/messages`
*   [SystemMessage](https://api.js.langchain.com/classes/langchain_core_messages.SystemMessage.html) from `@langchain/core/messages`

ChatGooglePaLM
==============

LangChain.js supports Google Vertex AI chat models as an integration. It supports two different methods of authentication based on whether you're running in a Node environment or a web environment.

Setup[​](#setup "Direct link to Setup")
---------------------------------------

### Node[​](#node "Direct link to Node")

To call Vertex AI models in Node, you'll need to install [Google's official auth client](https://www.npmjs.com/package/google-auth-library) as a peer dependency.

You should make sure the Vertex AI API is enabled for the relevant project and that you've authenticated to Google Cloud using one of these methods:

*   You are logged into an account (using `gcloud auth application-default login`) permitted to that project.
*   You are running on a machine using a service account that is permitted to the project.
*   You have downloaded the credentials for a service account that is permitted to the project and set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the path of this file.

tip

See [this section for general instructions on installing integration packages](/v0.1/docs/get_started/installation/#installing-integration-packages).

*   npm
*   Yarn
*   pnpm

    npm install google-auth-library @langchain/community

    yarn add google-auth-library @langchain/community

    pnpm add google-auth-library @langchain/community

### Web[​](#web "Direct link to Web")

To call Vertex AI models in web environments (like Edge functions), you'll need to install the [`web-auth-library`](https://github.com/kriasoft/web-auth-library) pacakge as a peer dependency:

*   npm
*   Yarn
*   pnpm

    npm install web-auth-library

    yarn add web-auth-library

    pnpm add web-auth-library

Then, you'll need to add your service account credentials directly as a `GOOGLE_VERTEX_AI_WEB_CREDENTIALS` environment variable:

    GOOGLE_VERTEX_AI_WEB_CREDENTIALS={"type":"service_account","project_id":"YOUR_PROJECT-12345",...}

You can also pass your credentials directly in code like this:

    import { ChatGoogleVertexAI } from "@langchain/community/chat_models/googlevertexai";const model = new ChatGoogleVertexAI({  authOptions: {    credentials: {"type":"service_account","project_id":"YOUR_PROJECT-12345",...},  },});

Usage[​](#usage "Direct link to Usage")
---------------------------------------

Several models are available and can be specified by the `model` attribute in the constructor. These include:

*   code-bison (default)
*   code-bison-32k

The ChatGoogleVertexAI class works just like other chat-based LLMs, with a few exceptions:

1.  The first `SystemMessage` passed in is mapped to the "context" parameter that the PaLM model expects. No other `SystemMessages` are allowed.
2.  After the first `SystemMessage`, there must be an odd number of messages, representing a conversation between a human and the model.
3.  Human messages must alternate with AI messages.

    import { ChatGoogleVertexAI } from "@langchain/community/chat_models/googlevertexai";// Or, if using the web entrypoint:// import { ChatGoogleVertexAI } from "@langchain/community/chat_models/googlevertexai/web";const model = new ChatGoogleVertexAI({  temperature: 0.7,});

#### API Reference:

*   [ChatGoogleVertexAI](https://api.js.langchain.com/classes/langchain_community_chat_models_googlevertexai.ChatGoogleVertexAI.html) from `@langchain/community/chat_models/googlevertexai`

### Streaming[​](#streaming "Direct link to Streaming")

ChatGoogleVertexAI also supports streaming in multiple chunks for faster responses:

    import { ChatGoogleVertexAI } from "@langchain/community/chat_models/googlevertexai";// Or, if using the web entrypoint:// import { ChatGoogleVertexAI } from "@langchain/community/chat_models/googlevertexai/web";const model = new ChatGoogleVertexAI({  temperature: 0.7,});const stream = await model.stream([  ["system", "You are a funny assistant that answers in pirate language."],  ["human", "What is your favorite food?"],]);for await (const chunk of stream) {  console.log(chunk);}/*AIMessageChunk {  content: ' Ahoy there, matey! My favorite food be fish, cooked any way ye ',  additional_kwargs: {}}AIMessageChunk {  content: 'like!',  additional_kwargs: {}}AIMessageChunk {  content: '',  name: undefined,  additional_kwargs: {}}*/

#### API Reference:

*   [ChatGoogleVertexAI](https://api.js.langchain.com/classes/langchain_community_chat_models_googlevertexai.ChatGoogleVertexAI.html) from `@langchain/community/chat_models/googlevertexai`

### Examples[​](#examples "Direct link to Examples")

There is also an optional `examples` constructor parameter that can help the model understand what an appropriate response looks like.

    import { ChatGoogleVertexAI } from "@langchain/community/chat_models/googlevertexai";import {  AIMessage,  HumanMessage,  SystemMessage,} from "@langchain/core/messages";// Or, if using the web entrypoint:// import { ChatGoogleVertexAI } from "@langchain/community/chat_models/googlevertexai/web";const examples = [  {    input: new HumanMessage("What is your favorite sock color?"),    output: new AIMessage("My favorite sock color be arrrr-ange!"),  },];const model = new ChatGoogleVertexAI({  temperature: 0.7,  examples,});const questions = [  new SystemMessage(    "You are a funny assistant that answers in pirate language."  ),  new HumanMessage("What is your favorite food?"),];// You can also use the model as part of a chainconst res = await model.invoke(questions);console.log({ res });

#### API Reference:

*   [ChatGoogleVertexAI](https://api.js.langchain.com/classes/langchain_community_chat_models_googlevertexai.ChatGoogleVertexAI.html) from `@langchain/community/chat_models/googlevertexai`
*   [AIMessage](https://api.js.langchain.com/classes/langchain_core_messages.AIMessage.html) from `@langchain/core/messages`
*   [HumanMessage](https://api.js.langchain.com/classes/langchain_core_messages.HumanMessage.html) from `@langchain/core/messages`
*   [SystemMessage](https://api.js.langchain.com/classes/langchain_core_messages.SystemMessage.html) from `@langchain/core/messages`

* * *

#### Help us out by providing feedback on this documentation page:

[

Previous

Google GenAI

](/v0.1/docs/integrations/chat/google_generativeai/)[

Next

Google Vertex AI

](/v0.1/docs/integrations/chat/google_vertex_ai/)

*   [Setup](#setup)
    *   [Node](#node)
    *   [Web](#web)
*   [Usage](#usage)
    *   [Streaming](#streaming)
    *   [Examples](#examples)

Community

*   [Discord](https://discord.gg/cU2adEyC7w)
*   [Twitter](https://twitter.com/LangChainAI)

GitHub

*   [Python](https://github.com/langchain-ai/langchain)
*   [JS/TS](https://github.com/langchain-ai/langchainjs)

More

*   [Homepage](https://langchain.com)
*   [Blog](https://blog.langchain.dev)

Copyright © 2024 LangChain, Inc.