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

# Trace Anthropic SDK with BotGauge

> Trace Anthropic SDK calls with BotGauge in code or zero-code. Verified versions, install line, and a tested messages sample.

Records Anthropic SDK LLM calls with model, input and output, and token counts. If your framework calls the Anthropic SDK underneath, this extra traces those LLM calls without the framework's own steps.

| | |
| - | - |
| Extra | `[anthropic]` |
| Verified framework versions | anthropic 1.8.0 and 1.15.0 |
| Instrumentor installed by the extra | `openinference-instrumentation-anthropic 3.0.3` |
| Zero-code run | Traced |

Also verified: anthropic 1.8.0 with instrumentor 2.1.6. The extra no longer installs that older instrumentor. See [supported frameworks](https://www.botgauge.com/docs/integrations/overview.md) for how verification works.

## In code

Call `tracing.init()`, attach the framework instrumentor to the provider it returns, and wrap the work in `tracing.turn()` and `tracing.agent()`.

**1. Install**

```bash terminal theme={null}
pip install "botgauge[anthropic]" anthropic==1.15.0
```

**2. Add the code**

```python app.py theme={null}
import os

from botgauge import tracing
from anthropic import Anthropic
from openinference.instrumentation.anthropic import AnthropicInstrumentor

provider = tracing.init()
AnthropicInstrumentor().instrument(tracer_provider=provider)

client = Anthropic()

with tracing.turn(session_id="ses_anthropic"), tracing.agent("anthropic-agent"):
    reply = client.messages.create(
        model=os.environ["ANTHROPIC_MODEL"],
        max_tokens=128,
        messages=[{"role": "user", "content": "In one sentence, what is OpenTelemetry?"}],
    )
print(reply.content[0].text)

tracing.shutdown()
```

**3. Run**

```bash terminal theme={null}
python app.py
```

Needs `BOTGAUGE_API_KEY`, `ANTHROPIC_API_KEY`, `ANTHROPIC_MODEL`. Set `ANTHROPIC_BASE_URL` too if your LLM isn't api.anthropic.com.

## Zero-code

Leave your app unchanged and start it with `botgauge instrument`. The sample still wraps the work in `tracing.turn()` and `tracing.agent()` so spans carry session and agent ids.

**1. Install**

```bash terminal theme={null}
pip install "botgauge[anthropic]" anthropic==1.15.0
```

**2. Add the code**

```python app.py theme={null}
import os

from botgauge import tracing
from anthropic import Anthropic

client = Anthropic()

with tracing.turn(session_id="ses_anthropic"), tracing.agent("anthropic-agent"):
    reply = client.messages.create(
        model=os.environ["ANTHROPIC_MODEL"],
        max_tokens=128,
        messages=[{"role": "user", "content": "In one sentence, what is OpenTelemetry?"}],
    )
print(reply.content[0].text)
```

**3. Run**

```bash terminal theme={null}
botgauge instrument python app.py
```

Needs `BOTGAUGE_API_KEY`, `ANTHROPIC_API_KEY`, `ANTHROPIC_MODEL`. Set `ANTHROPIC_BASE_URL` too if your LLM isn't api.anthropic.com.

View Anthropic spans liveWatch your Anthropic messages with token counts appear in [BotGauge](https://cloud.botgauge.com).

[Try BotGauge →](https://cloud.botgauge.com)

## Related

See [versions not verified](https://www.botgauge.com/docs/integrations/versions-not-verified.md) if you run a different version, [capture and redaction](https://www.botgauge.com/docs/tracing/capture-and-redaction.md) to control exported content, and [troubleshooting](https://www.botgauge.com/docs/tracing/troubleshooting.md) if spans are missing.


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