Skip to main content
The AnthropicAdapter extracts telemetry from Anthropic Message responses — model name, input and output token counts, and cost in USD — and passes them directly into agentvista.record() or a traced run. Cost is calculated automatically from the model name using AgentVista’s built-in pricing table; no manual configuration is required.

Setup

1

Install the SDK with the Anthropic extra

This installs agentvista along with the anthropic package.
2

Initialize AgentVista

Call agentvista.init() once at application startup with your API key.
3

Import the adapter

Usage examples

Use adapter.extract() on any anthropic.types.Message response and unpack the result directly into agentvista.record().
adapter.extract() returns a dict with any of these keys present:

Supported models

Cost calculation is automatic for the following Claude models. If your model is not listed, cost_usd will be absent from the extracted telemetry; all other fields (tokens, model name) are still captured.Models with prompt caching enabled (Opus 4.6, Sonnet 4.6, Sonnet 4.5, Haiku 4.5) also track cache_creation_input_tokens and cache_read_input_tokens from the Anthropic response and apply the correct cached read and cache write rates automatically.The adapter matches both full versioned IDs (e.g. claude-sonnet-4-6-20260205) and short aliases (e.g. claude-sonnet-4-6).