> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-5e9cc07a-preview-update-1770920925-e15dbde.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Google integrations

> Integrate with Google using LangChain JavaScript.

Functionality related to [Google Cloud Platform](https://cloud.google.com/)
and [AI Studio](https://aistudio.google.com/)

## Chat models

### Gemini models

Access Gemini models such as `gemini-2.5-pro` and `gemini-2.0-flex` through the [`ChatGoogleGenerativeAI`](/oss/javascript/integrations/chat/google_generative_ai),
or if using VertexAI, via the [`ChatVertexAI`](/oss/javascript/integrations/chat/google_vertex_ai) class.

<Tip>
  See [this section for general instructions on installing LangChain packages](/oss/javascript/langchain/install).
</Tip>

<Tabs>
  <Tab title="GenAI">
    ```bash npm theme={null}
    npm install @langchain/google-genai @langchain/core
    ```

    Configure your API key.

    ```
    export GOOGLE_API_KEY=your-api-key
    ```

    ```typescript theme={null}
    import { ChatGoogleGenerativeAI } from "@langchain/google-genai";

    const model = new ChatGoogleGenerativeAI({
      model: "gemini-pro",
      maxOutputTokens: 2048,
    });

    // Batch and stream are also supported
    const res = await model.invoke([
      [
        "human",
        "What would be a good company name for a company that makes colorful socks?",
      ],
    ]);
    ```

    More recent Gemini models support image inputs:

    ```typescript theme={null}
    const visionModel = new ChatGoogleGenerativeAI({
      model: "gemini-2.5-flash-lite",
      maxOutputTokens: 2048,
    });
    const image = fs.readFileSync("./hotdog.jpg").toString("base64");
    const input2 = [
      new HumanMessage({
        content: [
          {
            type: "text",
            text: "Describe the following image.",
          },
          {
            type: "image_url",
            image_url: `data:image/png;base64,${image}`,
          },
        ],
      }),
    ];

    const res = await visionModel.invoke(input2);
    ```

    <Tip>
      **Click [here](/oss/javascript/integrations/chat/google_generative_ai) for the `@langchain/google-genai` specific integration docs**
    </Tip>
  </Tab>

  <Tab title="VertexAI">
    ```bash npm theme={null}
    npm install @langchain/google-vertexai @langchain/core
    ```

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

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

    or as a file path:

    ```
    GOOGLE_VERTEX_AI_WEB_CREDENTIALS_FILE=/path/to/your/credentials.json
    ```

    ```typescript theme={null}
    import { ChatVertexAI } from "@langchain/google-vertexai";
    // Or, if using the web entrypoint:
    // import { ChatVertexAI } from "@langchain/google-vertexai-web";

    const model = new ChatVertexAI({
      model: "gemini-2.5-pro",
      maxOutputTokens: 2048,
    });

    // Batch and stream are also supported
    const res = await model.invoke([
      [
        "human",
        "What would be a good company name for a company that makes colorful socks?",
      ],
    ]);
    ```

    Gemini vision models support image inputs when providing a single human message. For example:

    ```typescript theme={null}
    const visionModel = new ChatVertexAI({
      model: "gemini-pro-vision",
      maxOutputTokens: 2048,
    });
    const image = fs.readFileSync("./hotdog.png").toString("base64");
    const input2 = [
      new HumanMessage({
        content: [
          {
            type: "text",
            text: "Describe the following image.",
          },
          {
            type: "image_url",
            image_url: `data:image/png;base64,${image}`,
          },
        ],
      }),
    ];

    const res = await visionModel.invoke(input2);
    ```

    <Tip>
      Click [here](/oss/javascript/integrations/chat/google_vertex_ai) for the `@langchain/google-vertexai` specific integration docs
    </Tip>
  </Tab>
</Tabs>

The value of `image_url` must be a base64 encoded image (e.g., `data:image/png;base64,abcd124`).

### Gemma

Access the `gemma-3-27b-it` model through AI Studio using the `ChatGoogle` class.
(This class is a superclass of the [`ChatVertexAI`](/oss/javascript/integrations/chat/google_vertex_ai)
class that works with both Vertex AI and the AI Studio APIs.)

<Tip>
  **Since Gemma is an open model, it may also be available from other platforms** including [Ollama](/oss/javascript/integrations/chat/ollama/).
</Tip>

```bash npm theme={null}
npm install @langchain/google-gauth @langchain/core
```

Configure your API key.

```
export GOOGLE_API_KEY=your-api-key
```

```typescript theme={null}
import { ChatGoogle } from "@langchain/google-gauth";

const model = new ChatGoogle({
  model: "gemma-3-27b-it",
});

const res = await model.invoke([
  {
    role: "user",
    content:
      "What would be a good company name for a company that makes colorful socks?",
  },
]);
```

### Third party models

See above for setting up authentication through Vertex AI to use these models.

[Anthropic](/oss/javascript/integrations/chat/anthropic) Claude models are also available through
the [Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude)
platform. See [here](https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude)
for more information about enabling access to the models and the model names to use.

PaLM models are no longer supported.

## Vector store

### Vertex AI vector search

> [Vertex AI Vector Search](https://cloud.google.com/vertex-ai/docs/matching-engine/overview),
> formerly known as Vertex AI Matching Engine, provides the industry's leading high-scale
> low latency vector database. These vector databases are commonly
> referred to as vector similarity-matching or an approximate nearest neighbor (ANN) service.

```typescript theme={null}
import { MatchingEngine } from "@langchain/community/vectorstores/googlevertexai";
```

### Postgres vector store

The [PostgresVectorStore](/oss/javascript/integrations/vectorstores/google_cloudsql_pg) module from the
[`@langchain/google-cloud-sql-pg`](https://www.npmjs.com/package/@langchain/google-cloud-sql-pg) package provides a way to use the CloudSQL for PostgresSQL to store
vector embeddings using the class.

```bash theme={null}
$ yarn add @langchain/google-cloud-sql-pg
```

Set your environment variables:

```bash theme={null}
PROJECT_ID="your-project-id"
REGION="your-project-region"
INSTANCE_NAME="your-instance"
DB_NAME="your-database-name"
DB_USER="your-database-user"
PASSWORD="your-database-password"
```

Create a DB connection through the PostgresEngine class:

```typescript theme={null}
const engine: PostgresEngine = await PostgresEngine.fromInstance(
  process.env.PROJECT_ID ?? "",
  process.env.REGION ?? "",
  process.env.INSTANCE_NAME ?? "",
  process.env.DB_NAME ?? "",
  peArgs
);
```

Initialize the vector store table:

```typescript theme={null}
await engine.initVectorstoreTable(
  "my_vector_store_table",
  768,
  vectorStoreArgs
);
```

Create a vector store instance:

```typescript theme={null}
const vectorStore = await PostgresVectorStore.initialize(
  engine,
  embeddingService,
  "my_vector_store_table",
  pvectorArgs
);
```

## Tools

### Google search

* Set up a Custom Search Engine, following [these instructions](https://stackoverflow.com/questions/37083058/programmatically-searching-google-in-python-using-custom-search)
* Get an API Key and Custom Search Engine ID from the previous step, and set them as environment variables `GOOGLE_API_KEY` and `GOOGLE_CSE_ID` respectively

There exists a `GoogleCustomSearch` utility which wraps this API. To import this utility:

```typescript theme={null}
import { GoogleCustomSearch } from "@langchain/community/tools/google_custom_search";
```

We can easily load this wrapper as a Tool (to use with an Agent). We can do this with:

```typescript theme={null}
const tools = [new GoogleCustomSearch({})];
// Pass this variable into your agent.
```

***

<Callout icon="pen-to-square" iconType="regular">
  [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/javascript/integrations/providers/google.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
</Callout>

<Tip icon="terminal" iconType="regular">
  [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
</Tip>
