# Anthropic | Sentry for JavaScript

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

*Import name: `Sentry.anthropicAIIntegration`*

The `anthropicAIIntegration` adds instrumentation for the `@anthropic-ai/sdk` to capture spans by automatically wrapping Anthropic client calls and recording LLM interactions with configurable input/output recording.

For browser applications, you need to manually instrument the Anthropic client using the `instrumentAnthropicAiClient` helper:

```javascript
import * as Sentry from "@sentry/browser";
import Anthropic from "@anthropic-ai/sdk";

const anthropic = new Anthropic();
const client = Sentry.instrumentAnthropicAiClient(anthropic, {
  recordInputs: true,
  recordOutputs: true,
});

// Use the wrapped client instead of the original anthropic instance
const response = await client.messages.create({
  model: "claude-3-5-sonnet-20241022",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello!" }],
});
```

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

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

*Type: `boolean`*

Records inputs to Anthropic API method calls (such as prompts and messages).

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

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

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

*Type: `boolean`*

Records outputs from Anthropic API method calls (such as generated text and responses).

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

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

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

By default this integration adds tracing support to Anthropic API method calls including:

* `messages.create()` - Create messages with Claude models
* `messages.stream()` - Stream messages with Claude models
* `messages.countTokens()` - Count tokens for messages
* `models.get()` - Get model information
* `completions.create()` - Create completions (legacy)
* `models.retrieve()` - Retrieve model details
* `beta.messages.create()` - Beta messages API

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

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

* `@anthropic-ai/sdk`: `>=0.19.2 <1.0.0`
