---
title: "Anthropic"
description: "Manually instrument the Anthropic SDK in React Native to capture spans and LLM interactions."
url: https://docs.sentry.io/platforms/react-native/integrations/anthropic/
---

# Anthropic | Sentry for React Native

*Import name: `Sentry.instrumentAnthropicAiClient`*

The `instrumentAnthropicAiClient` helper adds instrumentation for the [`@anthropic-ai/sdk`](https://www.npmjs.com/package/@anthropic-ai/sdk) by wrapping an Anthropic client instance and recording LLM interactions with configurable input/output capture. The OpenTelemetry-based automatic integration available for Node.js does not work in React Native, so wrapping the client manually is the only supported path.

## [Usage](https://docs.sentry.io/platforms/react-native/integrations/anthropic.md#usage)

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

const anthropic = new Anthropic({
  // Warning: API keys included in your app bundle will be visible to anyone who
  // inspects the bundle. Proxy LLM calls through your own backend whenever possible.
  apiKey: "your-api-key",
});

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!" }],
});
```

Make sure [tracing is enabled](https://docs.sentry.io/platforms/react-native/tracing.md) for the spans produced by this integration to be captured.

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

### [Options](https://docs.sentry.io/platforms/react-native/integrations/anthropic.md#options)

The following options control what data is captured from Anthropic SDK calls:

#### [`recordInputs`](https://docs.sentry.io/platforms/react-native/integrations/anthropic.md#recordinputs)

*Type: `boolean` (optional)*

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

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

#### [`recordOutputs`](https://docs.sentry.io/platforms/react-native/integrations/anthropic.md#recordoutputs)

*Type: `boolean` (optional)*

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

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

## [Supported Operations](https://docs.sentry.io/platforms/react-native/integrations/anthropic.md#supported-operations)

By default, tracing support is added to the following Anthropic SDK calls:

* `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

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

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

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