> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pandaprobe.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Anthropic

> Auto-trace Anthropic Messages API calls

### Installation

<Tabs>
  <Tab title="pip">
    ```bash theme={null}
    pip install "pandaprobe[anthropic]"
    ```
  </Tab>

  <Tab title="uv">
    ```bash theme={null}
    uv add "pandaprobe[anthropic]"
    ```
  </Tab>

  <Tab title="npm">
    ```bash theme={null}
    npm install pandaprobe @anthropic-ai/sdk
    ```
  </Tab>

  <Tab title="yarn">
    ```bash theme={null}
    yarn add pandaprobe @anthropic-ai/sdk
    ```
  </Tab>

  <Tab title="pnpm">
    ```bash theme={null}
    pnpm add pandaprobe @anthropic-ai/sdk
    ```
  </Tab>
</Tabs>

### Setup

<Tabs>
  <Tab title="Python">
    ```python title="Python" theme={null}
    from pandaprobe.wrappers import wrap_anthropic
    from anthropic import Anthropic

    client = wrap_anthropic(Anthropic())
    ```
  </Tab>

  <Tab title="TypeScript">
    ```ts title="TypeScript" theme={null}
    import Anthropic from "@anthropic-ai/sdk";
    import { wrapAnthropic } from "pandaprobe/wrappers/anthropic";

    const client = wrapAnthropic(new Anthropic());
    ```
  </Tab>
</Tabs>

<Note>
  PandaProbe traces both synchronous and asynchronous Python clients, plus the Promise-based TypeScript client.
</Note>

## Messages API

Span name: `"anthropic-messages"`, SpanKind: `LLM`

```python title="Python" theme={null}
response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    system="You are a helpful assistant.",
    messages=[{"role": "user", "content": "Explain quantum computing."}],
)
```

```ts title="TypeScript" theme={null}
const response = await client.messages.create({
  model: "claude-sonnet-5",
  max_tokens: 1024,
  system: "You are a helpful assistant.",
  messages: [{ role: "user", content: "Explain quantum computing." }],
});
```

**What gets traced**

* Input: system prompt (from top-level `system` kwarg) plus messages, normalized to a standard format
* Output: text content blocks
* Model name
* Token usage
* Model parameters: `temperature`, `top_p`, `top_k`, `max_tokens`, `stop_sequences`, thinking configuration
* Extended thinking or reasoning blocks stored in metadata as `reasoning_summary`

### Streaming

<CodeGroup>
  ```python title="Python — stream=True" theme={null}
  response = client.messages.create(
      model="claude-sonnet-4-6",
      max_tokens=1024,
      messages=[{"role": "user", "content": "Hello!"}],
      stream=True,
  )
  for event in response:
      if hasattr(event, "delta") and hasattr(event.delta, "text"):
          print(event.delta.text, end="")
  ```

  ```python title="Python — messages.stream context manager" theme={null}
  with client.messages.stream(
      model="claude-sonnet-4-6",
      max_tokens=1024,
      messages=[{"role": "user", "content": "Hello!"}],
  ) as stream:
      for text in stream.text_stream:
          print(text, end="")
  ```
</CodeGroup>

Both streaming patterns are fully supported with time-to-first-token tracking.

In TypeScript, both `messages.create({stream: true, ...})` and `messages.stream(...)` are instrumented:

```ts title="TypeScript" theme={null}
const stream = await client.messages.create({
  model: "claude-sonnet-5",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello!" }],
  stream: true,
});
for await (const event of stream) {
  if (event.type === "content_block_delta" && event.delta.type === "text_delta") {
    process.stdout.write(event.delta.text);
  }
}
```

## Extended thinking

When using Anthropic's extended thinking feature, thinking blocks are automatically extracted and stored in the span metadata under the `reasoning_summary` key. Thinking content is stripped from the visible output.

## Token usage mapping

| Anthropic Field | PandaProbe Field |
| - | - |
| `input_tokens` | `prompt_tokens` |
| `output_tokens` | `completion_tokens` |
| `cache_read_input_tokens` | `cache_read_tokens` |
| `cache_creation_input_tokens` | `cache_creation_tokens` |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.