Documentation Anthropic AI Wrapper
5 min read | June 29, 2026
Tutorial

Anthropic AI Wrapper

The Astralog Anthropic wrapper transparently monitors all your interactions with the Anthropic API. It captures token usage, prompts, completions, and latency.

View on GitHub

Installation

pip install astralog-anthropic astralog anthropic

Setup

# agent.py
import anthropic
from astralog import Client
from astralog_anthropic import track_anthropic

astralog_client = Client(api_key="ast_sk_live_xxxxxxxxxxxxx")
anthropic_client = anthropic.Anthropic(api_key="sk-ant-...")

# Seamlessly wrap the Anthropic client
tracked_anthropic = track_anthropic(anthropic_client, astralog_client)

# Use it normally. The wrapper will automatically extract:
# - Total tokens consumed
# - Model used
# - Call latency
# - Full prompts and responses
response = tracked_anthropic.messages.create(
    model="claude-3-haiku-20240307",
    max_tokens=100,
    messages=[{"role": "user", "content": "Hello!"}]
)

Cost Control & Visibility

By wrapping your LLM clients, Astralog generates specific ai_inference events in ClickHouse. You can use our Query Interface to instantly calculate your total token usage costs by model and detect prompt injections or hallucination anomalies.