Agent Wealth HubFree public resources
中文 EN العربية

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

  1. Read the Admin API key from a secret manager; build UTC starting_at/ending_at and choose a supported granularity. [usage]
  2. Call Messages Usage and Cost endpoints with workspace/model filters and paginate through every next_page. [usage]
  3. 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

Permissions

Limitations

Usage supports multiple granularities; Cost is daily with a bounded window, and Priority Tier costs may be absent.

Pinned upstream source

https://github.com/anthropics/anthropic-cookbook/blob/9c1e493ddd2b82df399d2a61b9c806c539e18be6/observability/usage_cost_api.ipynb

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

Related resources