# wrap_anthropic

> **Function** in `langsmith`

📖 [View in docs](https://reference.langchain.com/python/langsmith/wrappers/_anthropic/wrap_anthropic)

Patch the Anthropic client to make it traceable.

## Signature

```python
wrap_anthropic(
    client: C,
    *,
    tracing_extra: Optional[TracingExtra] = None,
    chat_name: str = 'ChatAnthropic',
    completions_name: str = 'Anthropic',
) -> C
```

## Description

**Example:**

```python
import anthropic
from langsmith import wrappers

client = wrappers.wrap_anthropic(anthropic.Anthropic())

# Use Anthropic client same as you normally would:
system = "You are a helpful assistant."
messages = [
    {
        "role": "user",
        "content": "What physics breakthroughs do you predict will happen by 2300?",
    }
]
completion = client.messages.create(
    model="claude-3-5-sonnet-latest",
    messages=messages,
    max_tokens=1000,
    system=system,
)
print(completion.content)

# With raw response to access headers:
raw_response = client.messages.with_raw_response.create(
    model="claude-3-5-sonnet-latest",
    messages=messages,
    max_tokens=1000,
    system=system,
)
print(raw_response.headers)  # Access HTTP headers
message = raw_response.parse()  # Get parsed response

# You can also use the streaming context manager:
with client.messages.stream(
    model="claude-3-5-sonnet-latest",
    messages=messages,
    max_tokens=1000,
    system=system,
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
    message = stream.get_final_message()
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `client` | `C` | Yes | The client to patch. |
| `tracing_extra` | `Optional[TracingExtra]` | No | Extra tracing information. (default: `None`) |
| `chat_name` | `str` | No | The run name for the messages endpoint. (default: `'ChatAnthropic'`) |
| `completions_name` | `str` | No | The run name for the completions endpoint. (default: `'Anthropic'`) |

## Returns

`C`

The patched client.

---

[View source on GitHub](https://github.com/langchain-ai/langsmith-sdk/blob/fcda9320ff067c3d3857e9e3d088fc1eb0643fc4/python/langsmith/wrappers/_anthropic.py#L475)