Arthur + Anthropic SDK
How does a developer instrument an Anthropic SDK application with Arthur in under 10 minutes? You install the Arthur Observability SDK with the Anthropic extra, initialize an Arthur instance pointed at your engine, call instrument_anthropic(), and every Claude API call is automatically traced — no changes to your Anthropic code required.
Overview
Arthur provides first-class instrumentation for the Anthropic Python SDK. Once enabled, every call to client.messages.create() (and other Anthropic endpoints) is captured as an OpenInference-compatible trace and exported to your Arthur GenAI Engine instance. You get full visibility into:
- Prompts and completions — every message sent and received
- Model parameters — model name, max tokens, token counts
- Latency and errors — per-call timing and failure tracking
- Session and user context — group traces by conversation or end-user
sequenceDiagram
participant App as Your Application
participant SDK as Arthur SDK
participant Anthropic as Anthropic API
participant Engine as Arthur GenAI Engine
App->>SDK: arthur.instrument_anthropic()
Note over SDK: Auto-instrumentation enabled
App->>Anthropic: client.messages.create(...)
Anthropic-->>App: Response
SDK->>Engine: Trace (spans, attributes)
Note over Engine: Traces visible in dashboard
Prerequisites:
- Python 3.10+
- An Arthur GenAI Engine instance (cloud or local)
- An Arthur API key — see API Keys to create one
Installation
Install the Arthur Observability SDK with the anthropic extra:
pip install "arthur-observability-sdk[anthropic]"This pulls in the core SDK, the Anthropic OpenInference instrumentor, and all required OpenTelemetry dependencies.
Initialize Arthur
Create a single Arthur instance at application startup.
from arthur_observability_sdk import Arthur
arthur = Arthur(
api_key="your-api-key", # or set ARTHUR_API_KEY env var
base_url="https://your-arthur-engine-instance", # or set ARTHUR_BASE_URL env var
task_id="<your-task-uuid>", # Arthur task UUID
service_name="my-anthropic-app",
)| Parameter | Description |
|---|---|
api_key | Your Arthur Engine API key. Falls back to ARTHUR_API_KEY env var. |
base_url | Base URL of your Arthur GenAI Engine. Falls back to ARTHUR_BASE_URL env var, then http://localhost:3030. |
task_id | Arthur task UUID for associating traces with a specific task. |
service_name | OpenTelemetry service.name resource attribute. Used to identify your application in the Arthur dashboard. Creates a new task based on service_name if task_id isn't specified. |
At least one oftask_idorservice_namemust be provided. A new task with theservice_namewill be created iftask_idis not specified.
Use environment variables for secrets. SetARTHUR_API_KEYandARTHUR_BASE_URLas environment variables (e.g., in a.envfile) rather than hardcoding them in your application.
Instrument Anthropic
A single method call patches the Anthropic SDK so all subsequent API calls are traced automatically:
import anthropic
from arthur_observability_sdk import Arthur
arthur = Arthur(
api_key="your-api-key", # or set ARTHUR_API_KEY env var
base_url="https://your-arthur-engine-instance", # or set ARTHUR_BASE_URL env var
task_id="<your-task-uuid>", # Arthur task UUID
service_name="my-anthropic-app",
)
arthur.instrument_anthropic()
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello, Claude!"}],
)
print(response.content[0].text)
arthur.shutdown()Key points:
- Call
arthur.instrument_anthropic()before creating youranthropic.Anthropic()client. - Every call to
client.messages.create()is automatically captured — no decorator or wrapper needed. - Call
arthur.shutdown()when your application exits to flush any remaining trace spans.
Add Session and User Context
To attribute traces to specific sessions or users, wrap your Anthropic calls with arthur.attributes(). This context manager attaches session_id and user_id as OpenInference span attributes on every span created within its scope.
with arthur.attributes(session_id="sess-1", user_id="user-42"):
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}],
)This is especially useful for:
- Multi-turn conversations — trace an entire chat session end-to-end
- Per-user analytics — understand how individual users interact with your application
- Debugging — filter traces in the Arthur dashboard by session or user
You can nest context managers or use them across multiple calls:
with arthur.attributes(session_id="onboarding-flow", user_id="user-99"):
# First turn
r1 = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "What can you help me with?"}],
)
# Second turn
r2 = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[
{"role": "user", "content": "What can you help me with?"},
{"role": "assistant", "content": r1.content[0].text},
{"role": "user", "content": "Tell me more about the first option."},
],
)Verify in Arthur
After running your instrumented application, traces appear in the Arthur GenAI Engine within seconds.

Traces viewed on the Arthur Engine UI
What to look for in the dashboard:
- Trace list — each
messages.createcall appears as a trace with input messages, output completion, model name, and latency - Session grouping — if you used
arthur.attributes(session_id=...), traces are grouped by session - User filtering — filter by
user_idto see a specific user's interactions - Token usage — input and output token counts are captured automatically
You can also query traces programmatically:
curl -X GET "${ARTHUR_BASE_URL}/api/v1/traces?task_ids=${ARTHUR_TASK_ID}" \
-H "Authorization: Bearer ${ARTHUR_API_KEY}"Troubleshooting
| Symptom | Fix |
|---|---|
| No traces appearing | Verify ARTHUR_API_KEY and ARTHUR_BASE_URL are correct and your Arthur Engine is reachable from your application. |
| Traces delayed | Traces are exported asynchronously via BatchSpanProcessor; allow a few seconds, or call arthur.shutdown() to flush. |
ImportError on instrument | Run pip install "arthur-observability-sdk[anthropic]" to install the required extra. |
Next Steps
Now that you have Anthropic instrumentation running, explore these capabilities:
- Prompt Management — version and manage your Claude prompts in Arthur, then fetch them at runtime with
arthur.get_prompt() - Continuous Evaluations — set up automated quality checks that run against your traced Claude interactions
- LangChain Integration — if you use LangChain with Anthropic models, Arthur can instrument the full chain with
arthur.instrument_langchain() - Agentic Experiments — run structured experiments against your Claude-powered agents and compare results across prompt versions
- Read our Best Practices for Building Agents Blog Series — observability and tracing fundamentals for building production agents
flowchart LR
A[Instrument Anthropic] --> B[View Traces]
B --> C[Add Evaluations]
B --> D[Manage Prompts]
C --> E[Set Up Continuous Evals]
D --> F[A/B Test Prompts]
E --> G[Production Monitoring]
F --> GUpdated about 22 hours ago