aboutsummaryrefslogtreecommitdiffstats
path: root/packages/multillm-anthropic/README.md
blob: e3bd82306fc0de6f1b4c58eab490cd9e54eccacb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# multillm-anthropic

Anthropic provider for [multillm](../multillm).

## Installation

```bash
pip install multillm-anthropic
```

## Usage

```python
import asyncio
import multillm

async def main():
    client = multillm.Client()

    # Simple query
    answer = await client.single("anthropic/claude-sonnet-4-20250514", "Hello!")
    print(answer)

    # Chat completion
    response = await client.chat_complete("anthropic/claude-sonnet-4-20250514", [
        {"role": "user", "content": "What is Python?"}
    ])
    print(response.text)

    # Streaming
    async for chunk in client.chat_complete_stream("anthropic/claude-sonnet-4-20250514", messages):
        print(chunk, end="")

asyncio.run(main())
```

## Configuration

Choose one of the following methods (priority: direct config > env var > config file):

**Option 1: Config file** (recommended)

Create `~/.config/multillm/providers/anthropic.json`:

```json
{
  "api_key": "sk-ant-..."
}
```

Set permissions:
```bash
chmod 600 ~/.config/multillm/providers/anthropic.json
```

**Option 2: Environment variable**

```bash
export ANTHROPIC_API_KEY=sk-ant-...
```

**Option 3: Direct config**

```python
client = multillm.Client({
    "anthropic": {"api_key": "sk-ant-..."}
})
```

### Config File Fields

| Field | Required | Description |
|-------|----------|-------------|
| `api_key` | Yes | Your Anthropic API key |

## Models

Use Anthropic model names after the provider prefix:

- `anthropic/claude-sonnet-4-20250514`
- `anthropic/claude-opus-4-20250514`
- `anthropic/claude-3-5-haiku-20241022`