Skip to main content

Anthropic

Route your Anthropic API calls through AI SpendOps for automatic usage tracking and cost attribution.

Configuration

SettingValue
Route/v1/anthropic/*
Upstreamhttps://api.anthropic.com
Auth headerx-api-key: sk-ant-...
Streaming usageNative (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

FieldDescription
input_tokensNon-cached input tokens (excludes cache tokens)
output_tokensOutput tokens
cache_read_input_tokensTokens served from prompt cache
cache_creation_input_tokensTokens written to prompt cache (all TTL tiers)
cache_creation.ephemeral_1h_input_tokensThe 1-hour-TTL portion of the above
server_tool_use.web_search_requestsNumber 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/messages endpoint for accurate streaming usage. The OpenAI-compatible endpoint does not return streaming usage data.
  • Anthropic uses x-api-key instead of Authorization: Bearer for authentication.