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

# Anthropic Integration Guide

> Complete guide to using Muxx with Anthropic Claude.

This guide covers integrating Muxx with Anthropic's Claude models.

## Quick Start

### Gateway

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

client = Anthropic(
    base_url="https://gateway.muxx.dev/v1",
    default_headers={
        "X-Muxx-Api-Key": "muxx_sk_live_xxxxxxxxxxxx"
    }
)

response = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello!"}]
)
```

### SDK

```python theme={null}
from muxx import Muxx
from anthropic import Anthropic

muxx = Muxx()
client = muxx.wrap(Anthropic())

response = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello!"}]
)
```

## Claude Models

| Model             | Best For            | Cost   |
| ----------------- | ------------------- | ------ |
| claude-3-5-sonnet | General use, coding | Medium |
| claude-3-5-haiku  | Fast, simple tasks  | Low    |
| claude-3-opus     | Complex reasoning   | High   |

## Common Patterns

### With System Prompt

```python theme={null}
@trace("claude-chat")
def chat(user_message: str) -> str:
    response = client.messages.create(
        model="claude-3-5-sonnet-20241022",
        max_tokens=1024,
        system="You are a helpful coding assistant.",
        messages=[{"role": "user", "content": user_message}]
    )
    return response.content[0].text
```

### Multi-turn Conversation

```python theme={null}
@trace("conversation")
def conversation():
    messages = []

    messages.append({"role": "user", "content": "What is Python?"})
    response = client.messages.create(
        model="claude-3-5-sonnet-20241022",
        max_tokens=1024,
        messages=messages
    )
    messages.append({"role": "assistant", "content": response.content[0].text})

    messages.append({"role": "user", "content": "Show me an example"})
    response = client.messages.create(
        model="claude-3-5-sonnet-20241022",
        max_tokens=1024,
        messages=messages
    )

    return response.content[0].text
```

### Tool Use

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

response = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    tools=tools,
    messages=[{"role": "user", "content": "Weather in Paris?"}]
)

# Tool calls are logged automatically
```

## Streaming

```python theme={null}
with client.messages.stream(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a poem"}]
) as stream:
    for text in stream.text_stream:
        print(text, end="")
```
