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

# Anthropic SDK

> Use Raptor with the official Anthropic SDK

# Anthropic Integration

Works with both Python and TypeScript. Your existing Claude code stays the same—just change the base URL.

## Setup

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

    client = Anthropic(
        api_key="sk-ant-your-key",
        base_url="https://proxy.raptordata.dev",
        default_headers={
            "X-Raptor-Api-Key": "rpt_your-key",
            "X-Raptor-Workspace-Id": "your-workspace-id"
        }
    )
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    import Anthropic from '@anthropic-ai/sdk';

    const client = new Anthropic({
      apiKey: 'sk-ant-your-key',
      baseURL: 'https://proxy.raptordata.dev',
      defaultHeaders: {
        'X-Raptor-Api-Key': 'rpt_your-key',
        'X-Raptor-Workspace-Id': 'your-workspace-id'
      }
    });
    ```
  </Tab>
</Tabs>

<Note>
  Anthropic uses `https://proxy.raptordata.dev` (no `/v1`). OpenAI uses `https://proxy.raptordata.dev/v1`.
</Note>

## Messages

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    message = client.messages.create(
        model="claude-sonnet-4-20250514",
        max_tokens=1024,
        messages=[{"role": "user", "content": "Hello!"}]
    )
    print(message.content[0].text)
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    const message = await client.messages.create({
      model: 'claude-sonnet-4-20250514',
      max_tokens: 1024,
      messages: [{ role: 'user', content: 'Hello!' }]
    });
    console.log(message.content[0].text);
    ```
  </Tab>
</Tabs>

## With System Prompt

```python theme={null}
message = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    system="You are a helpful assistant.",
    messages=[{"role": "user", "content": "Hello!"}]
)
```

## Streaming

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    with client.messages.stream(
        model="claude-sonnet-4-20250514",
        max_tokens=1024,
        messages=[{"role": "user", "content": "Tell me a story"}]
    ) as stream:
        for text in stream.text_stream:
            print(text, end="")
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    const stream = client.messages.stream({
      model: 'claude-sonnet-4-20250514',
      max_tokens: 1024,
      messages: [{ role: 'user', content: 'Tell me a story' }]
    });

    stream.on('text', (text) => process.stdout.write(text));
    await stream.finalMessage();
    ```
  </Tab>
</Tabs>

## Tools

```python theme={null}
tools = [{
    "name": "get_weather",
    "description": "Get weather for a location",
    "input_schema": {
        "type": "object",
        "properties": {"location": {"type": "string"}},
        "required": ["location"]
    }
}]

message = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    tools=tools,
    messages=[{"role": "user", "content": "Weather in Paris?"}]
)
```

## Vision

```python theme={null}
message = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[{
        "role": "user",
        "content": [
            {"type": "image", "source": {"type": "url", "url": "https://..."}},
            {"type": "text", "text": "What's in this image?"}
        ]
    }]
)
```

## Response Headers

| Header                         | Description                |
| ------------------------------ | -------------------------- |
| `X-Raptor-Cache`               | `hit` or `miss`            |
| `X-Raptor-Latency-Ms`          | Total Raptor overhead      |
| `X-Raptor-Upstream-Latency-Ms` | Time waiting for Anthropic |
| `X-Raptor-Request-Id`          | Unique ID for debugging    |

## Error Handling

```python theme={null}
from anthropic import APIError

try:
    message = client.messages.create(...)
except APIError as e:
    if e.status_code == 403:
        print("Blocked by Raptor firewall")
    else:
        raise
```

<Note>
  All Claude features work: Claude 3.5 Sonnet, Claude 3 Opus, vision, tools, and more.
</Note>
