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

# Anthropic

> Track Anthropic Messages usage in sync and async Python applications.

Start with the [Python quickstart](https://docs.brello.app/sdk/python/quickstart.md). Set `ANTHROPIC_API_KEY` and choose a Claude model your project can use for `ANTHROPIC_MODEL`.

## Track a Messages call

```python theme={null}
import os

from anthropic import Anthropic
from brello import Brello

brello = Brello()
with brello.wrap(Anthropic()) as client:
    message = client.messages.create(
        model=os.environ["ANTHROPIC_MODEL"],
        max_tokens=256,
        messages=[{"role": "user", "content": "Summarize the release notes."}],
    )

brello.flush()
```

Brello observes `messages.create()`, including `stream=True`, `messages.parse()` for structured outputs, and `messages.stream()`. The same methods are supported on `client.beta.messages`. Your existing tools and message handlers continue to receive the provider's results.

## Track async Messages streaming

```python theme={null}
import asyncio
import os

from anthropic import AsyncAnthropic
from brello import Brello


async def main():
    brello = Brello()
    async with brello.wrap(AsyncAnthropic()) as client:
        async with client.messages.stream(
            model=os.environ["ANTHROPIC_MODEL"],
            max_tokens=256,
            messages=[{"role": "user", "content": "Summarize the release notes."}],
        ) as stream:
            async for text in stream.text_stream:
                print(text, end="")
            message = await stream.get_final_message()

    await brello.aflush()


asyncio.run(main())
```

Brello uses Anthropic's cumulative stream usage to record one event per observed request. It records Anthropic's `request-id` header when available. If the connection ends before Brello sees `message_stop`, Brello records an error with `usage: null`. Closing the stream early records a cancellation.

Total input includes uncached input, cache reads, and cache creation. Brello estimates five-minute and one-hour cache writes separately at standard tier. A cache write the SDK cannot classify produces `usage: null`. For Priority Tier and Fast mode, Brello records the reported tokens and leaves the cost estimate unavailable.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.