# Google Gen AI | Sentry for JavaScript

This integration works in the Node.js, Cloudflare Workers, Vercel Edge Functions, and browser runtimes. It requires SDK version `10.14.0` or higher.

*Import name: `Sentry.googleGenAIIntegration`*

The `googleGenAIIntegration` adds instrumentation for the `@google/genai` SDK to capture spans by automatically wrapping Google Gen AI client calls and recording LLM interactions with configurable input/output recording.

For browser applications, you need to manually instrument the Google Gen AI client using the `instrumentGoogleGenAIClient` helper:

```javascript
import * as Sentry from "@sentry/browser";
import { GoogleGenAI } from "@google/genai";

const genAI = new GoogleGenAI(process.env.API_KEY);
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!");
```

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

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

*Type: `boolean`*

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

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

```javascript
Sentry.init({
  integrations: [Sentry.googleGenAIIntegration({ recordInputs: true })],
});
```

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

*Type: `boolean`*

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

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

```javascript
Sentry.init({
  integrations: [Sentry.googleGenAIIntegration({ recordOutputs: true })],
});
```

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

By default this integration adds tracing support to Google Gen AI SDK method calls including:

* `models.generateContent()` - Make an API request to generate content with a given model.
* `models.generateContentStream()` - Make an API request to generate content with a given model and yields the response in chunks.
* `chats.create()` - Create chat sessions.
* `sendMessage()` - Send messages in chat sessions.
* `sendMessageStream()` - Stream messages in chat sessions.

The integration will automatically detect streaming vs non-streaming requests and handle them appropriately.

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

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