Prometheus exporter for Anthropic Claude API usage and cost per key, model, and monthly rollups.
3.9K
Prometheus exporter for Anthropic Claude API spend. Polls the Admin Usage API and Cost API on a configurable interval and exposes metrics on :9402/metrics — broken down by API key, model, token type, geographic region, and date, with dedicated monthly rollup metrics for at-a-glance cost tracking.
A pre-built Grafana dashboard is included in the GitHub repo.
docker run -d \
--name anthropic-exporter \
--restart unless-stopped \
-e ANTHROPIC_ADMIN_KEY=sk-ant-admin01-... \
-p 9402:9402 \
antlac1/claude-api-exporter:latest
Then verify:
curl http://localhost:9402/metrics
services:
anthropic-exporter:
image: antlac1/claude-api-exporter:latest
container_name: anthropic-exporter
restart: unless-stopped
environment:
ANTHROPIC_ADMIN_KEY: sk-ant-admin01-...
ports:
- "9402:9402"
| Metric | Labels | Description |
|---|---|---|
anthropic_usage_tokens | api_key_id, api_key_name, model, token_type, inference_geo, date | Token counts per daily bucket. token_type: input / output / cache_write / cache_read |
anthropic_estimated_cost_usd | api_key_id, api_key_name, model, inference_geo, date | Estimated USD cost from token counts × pricing table |
anthropic_billed_cost_usd | workspace_id, description, date | Actual billed cost from the Cost API (workspace level) |
anthropic_monthly_estimated_cost_usd | api_key_id, api_key_name | Estimated cost for the current calendar month, per API key |
anthropic_monthly_billed_cost_usd | workspace_id | Billed cost for the current calendar month, per workspace |
anthropic_exporter_up | — | 1 if the last poll succeeded, 0 if it failed |
anthropic_exporter_last_success_timestamp_seconds | — | Unix timestamp of the last successful poll |
anthropic_exporter_poll_errors_total | — | Cumulative count of failed poll cycles |
All configuration is via environment variables.
| Variable | Default | Description |
|---|---|---|
ANTHROPIC_ADMIN_KEY | — | Required. Org admin key (sk-ant-admin01-...) — create one in the Claude Console |
EXPORTER_PORT | 9402 | Port the /metrics endpoint listens on |
POLL_INTERVAL_SECONDS | 300 | Seconds between poll cycles. Keep ≥ 60 |
LOOKBACK_DAYS | 2 | Days of history re-fetched each cycle (covers late/revised data) |
COST_IN_CENTS | true | Set to false if your Cost API returns fractional dollars instead of cents |
PRICING_FILE | /app/pricing.json | Path to the pricing table. Mount a custom file to override rates without rebuilding |
LOG_LEVEL | INFO | Set to DEBUG to log unmapped token fields |
Model pricing is fetched automatically from the Anthropic documentation at image build time. If the fetch fails, the image falls back to a bundled pricing.json. You can override rates at any time by mounting your own file:
docker run -d \
-e ANTHROPIC_ADMIN_KEY=sk-ant-admin01-... \
-v ./pricing.json:/app/pricing.json:ro \
-p 9402:9402 \
antlac1/claude-api-exporter:latest
scrape_configs:
- job_name: anthropic
scrape_interval: 300s
static_configs:
- targets: ["anthropic-exporter:9402"]
A pre-built dashboard is available in the GitHub repo at grafana/dashboard.json. Import it via Dashboards → Import → Upload JSON file and select your Prometheus data source.
Dashboard sections:
Content type
Image
Digest
sha256:a6c6e8e7e…
Size
42.7 MB
Last updated
27 days ago
docker pull antlac1/claude-api-exporter