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

# Anthropic Integration

ActGuard patches Anthropic request paths and tracks usage for Messages API calls.

## Requirements

| Requirement     | Version    |
| --------------- | ---------- |
| `anthropic` SDK | `>=0.83.0` |
| Python          | `>=3.9`    |

```bash theme={null}
pip install "anthropic>=0.83.0"
```

## Patched methods

* `anthropic._base_client.SyncAPIClient.request`
* `anthropic._base_client.AsyncAPIClient.request`

Only `/v1/messages` requests are budget-tracked.

## Usage with ActGuard runtime

```python theme={null}
import actguard
import anthropic

client = actguard.Client.from_env()
ant = anthropic.Anthropic()

with client.run(user_id="alice", run_id="run-anthropic"):
    with client.budget_guard(usd_limit=0.10) as guard:
        message = ant.messages.create(
            model="claude-3-5-sonnet-latest",
            max_tokens=256,
            messages=[{"role": "user", "content": "Hello"}],
        )

print(guard.tokens_used, guard.usd_used)
```

Streaming responses are supported; usage is read from `message_start` and `message_delta` events.
