Monitor your Anthropic API usage and costs in real-time by collecting detailed metrics and logs with a custom OpenTelemetry collector. This integration provides comprehensive visibility into token consumption, feature usage, and cost attribution across models, workspaces, and API keys.
The Anthropic Usage & Cost Monitoring integration uses an OpenTelemetry receiver to collect detailed usage metrics and cost data from the Anthropic Admin API, transforming them into structured telemetry for monitoring and cost tracking in Honeycomb.
What’s Collected:
The Anthropic Usage Receiver is designed to be integrated into a custom OpenTelemetry Collector using the OpenTelemetry Collector Builder (OCB).
Download the appropriate OCB binary for your platform:
# For Linux/macOS (adjust version and platform as needed)
curl -L -O https://github.com/open-telemetry/opentelemetry-collector/releases/download/cmd%2Fbuilder%2Fv0.131.0/ocb_0.131.0_linux_amd64
chmod +x ocb_0.131.0_linux_amd64
mv ocb_0.131.0_linux_amd64 ocb
Create a builder-config.yaml
file that includes the Anthropic Usage Receiver:
dist:
name: otelcol-anthropic
description: Custom OpenTelemetry Collector with Anthropic Usage Receiver
output_path: ./dist
otelcol_version: 0.131.0
exporters:
- gomod: go.opentelemetry.io/collector/exporter/debugexporter v0.131.0
- gomod: go.opentelemetry.io/collector/exporter/otlpexporter v0.131.0
- gomod: go.opentelemetry.io/collector/exporter/otlphttpexporter v0.131.0
processors:
- gomod: go.opentelemetry.io/collector/processor/batchprocessor v0.131.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourceprocessor v0.131.0
receivers:
- gomod: go.opentelemetry.io/collector/receiver/otlpreceiver v0.131.0
- gomod: github.com/honeycombio/anthropic-usage-receiver/anthropicusagereceiver v0.1.0
extensions:
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension v0.131.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage/filestorage v0.131.0
./ocb --config builder-config.yaml
This generates a custom collector binary in the ./dist
directory.
For environments where persistence isn’t required (e.g., short-lived containers, testing):
receivers:
anthropicusage:
admin_api_key: ${env:ANTHROPIC_ADMIN_API_KEY}
endpoint: https://api.anthropic.com
collection_interval: 1m
usage:
enabled: true
bucket_width: 1m
group_by: [model, service_tier, context_window, workspace_id, api_key_id]
cost:
enabled: true
collection_interval: 24h
bucket_width: 1d
group_by: [workspace_id, description]
exporters:
otlp:
endpoint: https://api.honeycomb.io:443
headers:
"x-honeycomb-team": "${env:HONEYCOMB_API_KEY}"
service:
pipelines:
metrics:
receivers: [anthropicusage]
processors: [batch]
exporters: [otlp]
logs:
receivers: [anthropicusage]
processors: [batch]
exporters: [otlp]
For production environments where checkpoint persistence is important to prevent data loss during restarts:
extensions:
file_storage:
directory: /var/lib/otel/anthropic-storage
timeout: 10s
receivers:
anthropicusage:
admin_api_key: ${env:ANTHROPIC_ADMIN_API_KEY}
endpoint: https://api.anthropic.com
collection_interval: 1m
storage: file_storage # Enable checkpoint persistence
usage:
enabled: true
bucket_width: 1m
group_by: [model, service_tier, context_window, workspace_id, api_key_id]
cost:
enabled: true
collection_interval: 24h
bucket_width: 1d
group_by: [workspace_id, description]
retry_on_failure:
enabled: true
initial_interval: 5s
max_interval: 60s
max_elapsed_time: 5m
exporters:
otlp:
endpoint: https://api.honeycomb.io:443
headers:
"x-honeycomb-team": "${env:HONEYCOMB_API_KEY}"
processors:
batch:
timeout: 10s
send_batch_size: 512
service:
extensions: [file_storage]
pipelines:
metrics:
receivers: [anthropicusage]
processors: [batch]
exporters: [otlp]
logs:
receivers: [anthropicusage]
processors: [batch]
exporters: [otlp]
Stateful vs Stateless:
export ANTHROPIC_ADMIN_API_KEY="sk-ant-admin-..."
export HONEYCOMB_API_KEY="your-honeycomb-api-key"
./dist/otelcol-anthropic --config=config.yaml
Once your data is flowing into Honeycomb, use the pre-built Anthropic Usage & Cost Monitoring Board Template to instantly visualize your usage and costs:
The template includes pre-configured visualizations for:
Metric | Description |
---|---|
anthropic.usage.input_tokens |
Number of uncached input tokens consumed |
anthropic.usage.output_tokens |
Number of output tokens generated |
anthropic.usage.cache_creation.ephemeral_1h |
Tokens used for 1-hour ephemeral cache creation |
anthropic.usage.cache_creation.ephemeral_5m |
Tokens used for 5-minute ephemeral cache creation |
anthropic.usage.cache_read_input_tokens |
Input tokens read from cache |
anthropic.usage.web_search_requests |
Number of web search requests |
Metric | Description |
---|---|
anthropic.cost.amount |
Cost amount in minor currency units (e.g., fractional cents for USD) |
Attribute | Description | Example |
---|---|---|
model |
Claude model used | claude-3-7-sonnet-20250219 , claude-opus-4-20250514 |
service_tier |
API service tier | standard , batch , priority |
context_window |
Context window size | 0-200k , 200k-1M |
workspace_id |
Anthropic workspace identifier (null for default workspace) | wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ |
api_key_id |
API key identifier (null for workbench usage) | apikey_01Rj2N8SVvo6BePZj99NhmiT |
description |
Human-readable cost description | Claude Sonnet 4 Usage - Input Tokens, Cache Write 1 Hour - Batch |
currency |
ISO 4217 currency code | USD |
Limit data collection to specific models, tiers, or workspaces:
receivers:
anthropicusage:
usage:
# Collect only specific models
models: ["claude-3-7-sonnet-20250219", "claude-3-haiku-20240307"]
# Filter by service tiers
service_tiers: ["standard", "priority"]
# Filter by context window sizes
context_window: ["0-200k", "200k-1M"]
# Filter by workspaces
workspace_ids: ["wrkspc_01JwQvzr7rXLA5AGx3HKfFUJ", "wrkspc_013jtUYxRJqPEXaTUxQVmmJa"]
# Customize grouping
group_by: [model, service_tier, context_window, workspace_id]
Send data to multiple destinations:
service:
pipelines:
metrics:
receivers: [anthropicusage]
processors: [batch]
exporters: [otlp, prometheus, debug]
logs:
receivers: [anthropicusage]
processors: [batch]
exporters: [otlp, debug]
No data appearing in Honeycomb:
Missing cost data:
cost.enabled: true
in your configurationCheckpoint persistence not working:
High API usage:
collection_interval
to reduce API call frequency (minimum recommended: 1 minute)anthropic.scraper.up
metric for health statusRate limiting: