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

# Anthropic

> Using Moda with Anthropic Claude

## Overview

Moda automatically tracks your Anthropic Claude API calls. Messages, streaming, extended thinking, tool use, and content blocks are all captured with no additional code required.

## Setup

<CodeGroup>
  ```bash Python theme={"dark"}
  pip install moda-ai anthropic
  ```

  ```bash Node.js theme={"dark"}
  npm install moda-ai @anthropic-ai/sdk
  ```
</CodeGroup>

<CodeGroup>
  ```python Python theme={"dark"}
  import moda
  from anthropic import Anthropic

  moda.init("YOUR_MODA_API_KEY")

  client = Anthropic()
  response = client.messages.create(
      model="claude-sonnet-4-20250514",
      max_tokens=1024,
      messages=[{"role": "user", "content": "Hello!"}]
  )

  moda.flush()
  ```

  ```typescript Node.js theme={"dark"}
  import { Moda } from 'moda-ai';
  import Anthropic from '@anthropic-ai/sdk';

  await Moda.init('YOUR_MODA_API_KEY');

  const client = new Anthropic();
  const response = await client.messages.create({
    model: 'claude-sonnet-4-20250514',
    max_tokens: 1024,
    messages: [{ role: 'user', content: 'Hello!' }]
  });

  await Moda.flush();
  ```
</CodeGroup>

## Supported Features

| Feature                       | Captured                                                    |
| ----------------------------- | ----------------------------------------------------------- |
| Messages                      | Yes                                                         |
| Streaming (`messages.stream`) | Yes                                                         |
| Extended thinking             | Yes (captured as `thinking` content blocks)                 |
| Tool use                      | Yes (captured as `tool_use` / `tool_result` content blocks) |
| System prompts                | Yes                                                         |
| Content blocks (text, image)  | Yes                                                         |
| Token usage                   | Yes (input, output, reasoning tokens)                       |
| Model name                    | Yes (request and response)                                  |

## Extended Thinking

When using extended thinking, reasoning tokens and thinking content blocks are automatically captured.

<CodeGroup>
  ```python Python theme={"dark"}
  response = client.messages.create(
      model="claude-sonnet-4-20250514",
      max_tokens=16000,
      thinking={
          "type": "enabled",
          "budget_tokens": 10000,
      },
      messages=[{"role": "user", "content": "Explain quantum computing"}]
  )
  ```

  ```typescript Node.js theme={"dark"}
  const response = await client.messages.create({
    model: 'claude-sonnet-4-20250514',
    max_tokens: 16000,
    thinking: {
      type: 'enabled',
      budget_tokens: 10000,
    },
    messages: [{ role: 'user', content: 'Explain quantum computing' }]
  });
  ```
</CodeGroup>

Moda captures:

* The thinking content as `thinking` content blocks
* Reasoning token count for cost tracking
* The final text response

## Tool Use

Anthropic tool use is automatically captured with full request/response details:

<CodeGroup>
  ```python Python theme={"dark"}
  response = client.messages.create(
      model="claude-sonnet-4-20250514",
      max_tokens=1024,
      tools=[{
          "name": "get_weather",
          "description": "Get the weather for a location",
          "input_schema": {
              "type": "object",
              "properties": {
                  "location": {"type": "string"}
              }
          }
      }],
      messages=[{"role": "user", "content": "What's the weather in London?"}]
  )
  ```

  ```typescript Node.js theme={"dark"}
  const response = await client.messages.create({
    model: 'claude-sonnet-4-20250514',
    max_tokens: 1024,
    tools: [{
      name: 'get_weather',
      description: 'Get the weather for a location',
      input_schema: {
        type: 'object',
        properties: {
          location: { type: 'string' }
        }
      }
    }],
    messages: [{ role: 'user', content: "What's the weather in London?" }]
  });
  ```
</CodeGroup>

## Streaming

Streaming is fully supported:

<CodeGroup>
  ```python Python theme={"dark"}
  with client.messages.stream(
      model="claude-sonnet-4-20250514",
      max_tokens=1024,
      messages=[{"role": "user", "content": "Count to 5"}]
  ) as stream:
      for text in stream.text_stream:
          print(text, end="")
  ```

  ```typescript Node.js theme={"dark"}
  const stream = client.messages.stream({
    model: 'claude-sonnet-4-20250514',
    max_tokens: 1024,
    messages: [{ role: 'user', content: 'Count to 5' }]
  });

  for await (const event of stream) {
    if (event.type === 'content_block_delta' && event.delta.type === 'text_delta') {
      process.stdout.write(event.delta.text);
    }
  }
  ```
</CodeGroup>

## Troubleshooting

**Data not appearing?**

* Ensure `moda.init()` is called before creating the Anthropic client
* Call `moda.flush()` (Python) or `await Moda.flush()` (Node.js) before exit
* Verify your API key is correct

**Extended thinking not captured?**

* Ensure you're using a model that supports extended thinking
* Check that the `thinking` parameter is properly configured

<Info>
  For full SDK documentation, see the [Python SDK](/ingestion/moda-sdk) or [Node.js SDK](/ingestion/moda-sdk-node) guides.
</Info>
