Back to catalog / Agent workflows
Report team usage, model mix, and costs
Aggregate token usage and USD costs by period and workspace through the Admin API into an auditable CSV.
Goal
Goal: Aggregate token usage and USD costs by period and workspace through the Admin API into an auditable CSV.
Steps
- Read the Admin API key from a secret manager; build UTC
starting_at/ending_atand choose a supported granularity. [usage] - Call Messages Usage and Cost endpoints with workspace/model filters and paginate through every
next_page. [usage] - Aggregate input/output/cache tokens and USD amounts, export CSV, and label timezone, granularity, currency, and retrieval time. [usage]
How to verify
Compare sample API buckets with the CSV; verify no pages are missing and stay within endpoint granularity limits.
Troubleshooting
If date buckets are missing, check UTC boundaries; usage and cost endpoints differ, so do not treat absent values as zero.
Permissions
Prerequisites
- Python 3.11+, Anthropic Admin API key, and an admin role authorized to read organization usage/cost.
Permissions
- Use the admin key only for reporting; keep it in a secret manager and restrict reports to authorized finance/platform teams.
Limitations
Usage supports multiple granularities; Cost is daily with a bounded window, and Priority Tier costs may be absent.
Pinned upstream source
- Repository
- anthropics/anthropic-cookbook
- File path
- observability/usage_cost_api.ipynb
- Pinned commit
9c1e493ddd2b82df399d2a61b9c806c539e18be6- Source checked
- 2026-10-14 · Reviewed against the pinned upstream source
Repository metrics
These values describe the upstream repository, not popularity or likes for an individual skill or playbook.
- Stars
- Not collected
- Forks
- Not collected
- Observed at
- Not collected
No metrics snapshot is available yet.
License: MIT
Main topic
Turn ecommerce campaign materials into a reviewable weekly brief