Metadata-Version: 2.4
Name: chatsee-anthropic
Version: 0.1.0
Summary: ChatSee connector for the Anthropic Messages API — capture every turn with one line.
Maintainer-email: ChatSee <contact@chatsee.ai>
License: MIT
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: chatsee-ai>=0.14.0
Requires-Dist: anthropic>=0.40.0
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: chatsee-connector-testing; extra == "dev"

# chatsee-anthropic

ChatSee connector for the Anthropic Messages API.

```bash
pip install chatsee-anthropic
```

```python
from anthropic import Anthropic
from chatsee_anthropic import instrument_anthropic

client = Anthropic(api_key="...")
instrument_anthropic(client, agent_id="...", tenant_id="...")
```

That is the whole integration. Your agent code does not change —
`client.messages.create(...)` still returns exactly what it returned before.
`chatsee-ai` is installed for you as a dependency.

## What it captures

Per turn: the user's question, the assistant's answer, the system prompt,
every tool call with its arguments and result, and **one model call per model
call** with the tokens Anthropic reported for it.

## Three backends, one connector

`Anthropic`, `AnthropicBedrock` and `AnthropicVertex` (and the Async variants)
all expose the same Messages resource. The connector detects which one you
built and labels the provider `anthropic`, `bedrock` or `vertex` — it never
assumes. Streaming via `messages.stream(...)` is captured too.

## The part worth knowing

`messages.create` fires once per **loop step**, not once per turn. A
tool-using turn calls it at least twice — once to ask for the tool, once to
answer — and each call reports its own usage.

So the connector accumulates model calls across the steps of a turn and emits
when the turn ends, which is the step whose `stop_reason` is not `tool_use`.
Capturing only the final response would silently drop the first step's tokens
and every tool-using turn would look cheaper than it was.

## Guarantees

* **Fails open.** A failure inside capture is logged and swallowed. ChatSee
  can never break your agent.
* **Idempotent.** Instrumenting the same client twice is a no-op.
* **Concurrency-safe.** Turns are keyed per conversation, so one client
  serving several users at once does not mix them up.

All three are enforced by the contract suite, not just intended.

## Tests

No network, no API key, no dev tenant — the Anthropic SDK is stubbed, ChatSee
is not.

```bash
pip install -e python/connectors/_shared
pip install -e python/connectors/ai_sdk/anthropic
pytest python/connectors/ai_sdk/anthropic/tests -q
```
