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
Usage examples
- Basic
- With tracing
- Streaming
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:| Key | Type | Description |
|---|---|---|
model | str | Model ID returned by the API (e.g. "claude-sonnet-4-6-20260205") |
input_tokens | int | Prompt tokens plus any cache creation and cache read tokens |
output_tokens | int | Completion tokens |
total_tokens | int | Sum of input and output tokens |
cost_usd | float | Total cost in USD, rounded to 6 decimal places |
Supported models
Cost calculation is automatic for the following Claude models. If your model is not listed,
Models with prompt caching enabled (Opus 4.6, Sonnet 4.6, Sonnet 4.5, Haiku 4.5) also track
cost_usd will be absent from the extracted telemetry; all other fields (tokens, model name) are still captured.| Model | Input (per M tokens) | Output (per M tokens) |
|---|---|---|
claude-opus-4-6 | $5.00 | $25.00 |
claude-sonnet-4-6 | $3.00 | $15.00 |
claude-sonnet-4-5 | $3.00 | $15.00 |
claude-haiku-4-5 | $1.00 | $5.00 |
claude-opus-4-0 | $15.00 | $75.00 |
claude-haiku-3-5 | $0.80 | $4.00 |
claude-3-haiku | $0.25 | $1.25 |
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).