---
title: "Google Gen AI"
description: "Adds instrumentation for Google Gen AI SDK."
url: https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/integrations/google-genai/
---

# Google Gen AI | Sentry for Next.js

For meta-framework applications running on both client and server, we recommend **setting up the integration manually** using the [`instrumentGoogleGenAIClient` wrapper](https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/integrations/google-genai.md#manual-instrumentation) to ensure consistent instrumentation across all runtimes.

## [Automatic Instrumentation](https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/integrations/google-genai.md#automatic-instrumentation)

*Import name: `Sentry.googleGenAIIntegration`*

If you are using a different runtime (like Bun, Cloudflare Workers or a Browser) or experiencing missing spans, you need to use **[Manual Instrumentation](https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/integrations/google-genai.md#manual-instrumentation)** to explicitly wrap your AI client instance instead.

The `googleGenAIIntegration` adds instrumentation for the [`@google/genai`](https://www.npmjs.com/package/@google/genai) SDK to capture spans by wrapping Google Gen AI SDK calls and recording LLM interactions.

In Node.js runtimes, this integration is enabled by default and automatically captures spans for Google Gen AI SDK calls (requires Sentry SDK version `10.28.0` or higher).

To customize what data is captured (such as inputs and outputs), see the [Options](https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/integrations/google-genai.md#options) in the Configuration section.

## [Manual Instrumentation](https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/integrations/google-genai.md#manual-instrumentation)

*Import name: `Sentry.instrumentGoogleGenAIClient`*

The `instrumentGoogleGenAIClient` helper adds instrumentation for the [`@google/genai`](https://www.npmjs.com/package/@google/genai) SDK to capture spans by wrapping Google Gen AI SDK calls and recording LLM interactions with configurable input/output recording. You need to manually wrap your Google Gen AI client instance with this helper.

See example below:

```javascript
import { GoogleGenAI } from "@google/genai";

const genAI = new GoogleGenAI({
  apiKey: "your-api-key", // Warning: API key will be exposed in browser!
});

const client = Sentry.instrumentGoogleGenAIClient(genAI, {
  recordInputs: true,
  recordOutputs: true,
});

// Use the wrapped client instead of the original genAI instance
const result = await client.models.generateContent("Hello!");
```

To customize what data is captured (such as inputs and outputs), see the [Options](https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/integrations/google-genai.md#options) in the Configuration section.

## [Configuration](https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/integrations/google-genai.md#configuration)

### [Options](https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/integrations/google-genai.md#options)

The following options control what data is captured from Google Gen AI SDK calls:

#### [`recordInputs`](https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/integrations/google-genai.md#recordinputs)

*Type: `boolean` (optional)*

Records inputs to Google Gen AI SDK calls (such as prompts and messages).

Defaults to `true` if `sendDefaultPii` is `true`.

#### [`recordOutputs`](https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/integrations/google-genai.md#recordoutputs)

*Type: `boolean` (optional)*

Records outputs from Google Gen AI SDK calls (such as generated text and responses).

Defaults to `true` if `sendDefaultPii` is `true`.

**Usage**

Using the `googleGenAIIntegration` integration for **automatic instrumentation**:

```javascript
Sentry.init({
  dsn: "____PUBLIC_DSN____",
  // Tracing must be enabled for agent monitoring to work
  tracesSampleRate: 1.0,
  integrations: [
    Sentry.googleGenAIIntegration({
      // your options here
    }),
  ],
});
```

Using the `instrumentGoogleGenAIClient` wrapper for **manual instrumentation**:

```javascript
const client = Sentry.instrumentGoogleGenAIClient(genAI, {
  // your options here
});
```

## [Supported Operations](https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/integrations/google-genai.md#supported-operations)

By default, tracing support is added to the following Google Gen AI SDK calls:

* `models.generateContent()` - Generate content with a given model
* `models.generateContentStream()` - Stream content generation with a given model
* `chats.create()` - Create chat sessions
* `sendMessage()` - Send messages in chat sessions
* `sendMessageStream()` - Stream messages in chat sessions

Streaming and non-streaming requests are automatically detected and handled appropriately.

## [Supported Versions](https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/integrations/google-genai.md#supported-versions)

* `@google/genai`: `>=0.10.0 <2`
