Anthropic
Route your Anthropic API calls through AI SpendOps for automatic usage tracking and cost attribution.
Configuration
| Setting | Value |
|---|---|
| Route | /v1/anthropic/* |
| Upstream | https://api.anthropic.com |
| Auth header | x-api-key: sk-ant-... |
| Streaming usage | Native (message_start + message_delta events) |
SDK base URL
https://proxy.aispendops.com/v1/anthropic
Example
curl https://proxy.aispendops.com/v1/anthropic/v1/messages \
-H "x-api-key: sk-ant-your-anthropic-key" \
-H "X-ASO-API-Key: aso_k_yourkey.secret" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{"model":"claude-sonnet-4-20250514","max_tokens":1024,"messages":[{"role":"user","content":"Hello"}]}'
Python SDK
import anthropic
client = anthropic.Anthropic(
api_key="sk-ant-your-anthropic-key",
base_url="https://proxy.aispendops.com/v1/anthropic",
default_headers={"X-ASO-API-Key": "aso_k_yourkey.secret"},
)
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
print(message.content[0].text)
Usage fields
| Field | Description |
|---|---|
input_tokens | Non-cached input tokens (excludes cache tokens) |
output_tokens | Output tokens |
cache_read_input_tokens | Tokens served from prompt cache |
cache_creation_input_tokens | Tokens written to prompt cache (all TTL tiers) |
cache_creation.ephemeral_1h_input_tokens | The 1-hour-TTL portion of the above |
server_tool_use.web_search_requests | Number of web search tool invocations |
Cache token accounting
Anthropic reports input_tokens, cache_read_input_tokens and
cache_creation_input_tokens as three separate, non-overlapping categories that
sum to the total input. AI SpendOps charges each at its own rate and does not
subtract anything.
This is the opposite of most other providers. OpenAI and Google Gemini report cached tokens as a breakdown inside the prompt token total, so AI SpendOps subtracts the cached portion there before pricing to avoid charging it twice.
Cache writes are also tiered by TTL. Anthropic charges a 5-minute cache write at 1.25x the base input rate and a 1-hour cache write at 2x, so AI SpendOps tracks the 1-hour portion separately and prices the two tiers apart.
Notes
- Use the native
/v1/messagesendpoint for accurate streaming usage. The OpenAI-compatible endpoint does not return streaming usage data. - Anthropic uses
x-api-keyinstead ofAuthorization: Bearerfor authentication.