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

# Anthropic Provider

> Claude 4, Sonnet, Opus, and extended thinking models

The Anthropic provider supports all Claude models including Claude 4, Sonnet, Opus, Haiku, and extended thinking.

## Configuration

<ParamField path="provider" type="string" required>
  Set to `"anthropic"`
</ParamField>

<ParamField path="api_key" type="string" required>
  Anthropic API key. Get yours at [console.anthropic.com](https://console.anthropic.com)
</ParamField>

<ParamField path="base_url" type="string">
  Custom base URL for proxies (defaults to `https://api.anthropic.com`)
</ParamField>

<ParamField path="model" type="string" required>
  Model name: `claude-sonnet-4`, `claude-opus-4`, etc.
</ParamField>

<ParamField path="temperature" type="number">
  Sampling temperature (0.0-1.0). Defaults to `0.7`.
</ParamField>

<ParamField path="max_tokens" type="number">
  Maximum output tokens. Defaults to `8192`.
</ParamField>

## Example Configuration

```json theme={null}
{
  "provider": "anthropic",
  "model": "claude-sonnet-4",
  "api_key": "sk-ant-...",
  "temperature": 0.7
}
```

## OAuth Setup Tokens

Anthropic supports OAuth setup tokens (from `anthropic.com/setup`):

```json theme={null}
{
  "provider": "anthropic",
  "model": "claude-sonnet-4",
  "api_key": "sk-ant-oat01-..."
}
```

OAuth tokens use Bearer authentication instead of x-api-key:

```
Authorization: Bearer sk-ant-oat01-...
```

## Supported Models

* **Claude 4**: `claude-sonnet-4`, `claude-opus-4`, `claude-haiku-4`
* **Claude 3.5**: `claude-3-5-sonnet-20241022`, `claude-3-5-haiku-20241022`
* **Claude 3**: `claude-3-opus-20240229`, `claude-3-sonnet-20240229`, `claude-3-haiku-20240307`
* **Extended thinking**: Models with reasoning capabilities (thinking content)

## Capabilities

| Feature          | Support                        |
| ---------------- | ------------------------------ |
| Streaming        | Yes                            |
| Function Calling | Yes                            |
| Vision (images)  | Yes                            |
| System Messages  | Yes (top-level `system` field) |
| Tool Calls       | Yes (native)                   |

## Authentication

The Anthropic provider supports two authentication methods:

### 1. Standard API Key

```
x-api-key: sk-ant-api-...
anthropic-version: 2023-06-01
```

### 2. OAuth Setup Token

```
Authorization: Bearer sk-ant-oat01-...
anthropic-version: 2023-06-01
anthropic-beta: oauth-2025-04-20
```

API keys are read from:

1. `api_key` field in config
2. `ANTHROPIC_API_KEY` environment variable

## Message Format

Anthropic uses a different message format than OpenAI:

* System messages go in top-level `system` field (not in messages array)
* Roles are `user` and `assistant` (tool messages use `user` role)
* Messages are objects with `role` and `content`

```json theme={null}
{
  "model": "claude-sonnet-4",
  "max_tokens": 8192,
  "system": "You are a helpful assistant",
  "messages": [
    {"role": "user", "content": "Hello"},
    {"role": "assistant", "content": "Hi there!"}
  ]
}
```

## Tool Calls

Anthropic uses a native `tool_use` content block format:

```json theme={null}
{
  "content": [
    {"type": "text", "text": "Let me check that"},
    {"type": "tool_use", "id": "call_1", "name": "shell", "input": {"cmd": "ls"}}
  ]
}
```

## Vision Support

Claude supports image input via `content_parts`:

```json theme={null}
{
  "role": "user",
  "content": [
    {"type": "text", "text": "What's in this image?"},
    {"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "iVBOR..."}}
  ]
}
```

## Custom Base URL

For proxies or self-hosted endpoints:

```json theme={null}
{
  "provider": "anthropic",
  "model": "claude-sonnet-4",
  "api_key": "sk-ant-...",
  "base_url": "https://proxy.example.com"
}
```

Or use `anthropic-custom:` prefix:

```json theme={null}
{
  "provider": "anthropic-custom:https://proxy.example.com",
  "model": "claude-sonnet-4",
  "api_key": "sk-ant-..."
}
```

## Code Example

From `src/providers/anthropic.zig`:

```zig theme={null}
pub const AnthropicProvider = struct {
    credential: ?[]const u8,
    base_url: []const u8,
    allocator: std.mem.Allocator,

    const DEFAULT_BASE_URL = "https://api.anthropic.com";
    const API_VERSION = "2023-06-01";

    pub fn init(allocator: std.mem.Allocator, api_key: ?[]const u8, base_url: ?[]const u8) AnthropicProvider {
        const url = if (base_url) |u| trimTrailingSlash(u) else DEFAULT_BASE_URL;
        return .{
            .credential = api_key,
            .base_url = url,
            .allocator = allocator,
        };
    }
};
```

## Error Handling

The provider classifies common Anthropic API errors:

* `error.RateLimited` — 429 rate limit exceeded
* `error.InvalidApiKey` — Authentication failed
* `error.ApiError` — Generic API error
* `error.NoResponseContent` — Empty response

## Related

* [Providers Overview](/providers/overview)
* [OpenAI Provider](/providers/openai)
* [OpenRouter Provider](/providers/openrouter)
