How to retrieve project usage data via API?
No, there's no API endpoint that returns a project's usage totals (API requests, bandwidth and so on). The documented way to see usage is the Usage tab in sanity.io/manage. To get usage data into your own tooling (Grafana, BigQuery and similar), use request logs: raw per-request data you can add up yourself.
What the Projects API covers
The Projects API has endpoints for projects, CORS origins, datasets (including copy), tokens, users, features, permissions and tags. None of them return usage or quota figures.
The Activity Log API (GET https://api.sanity.io/v2021-02-01/activity) doesn't fill this gap either. It returns management events such as invites, role changes and plan changes. It has no usage metrics, and it can't retrieve content activity.
Viewing usage in the dashboard
- Project usage: sanity.io/manage → your project → Usage tab. Quotas are measured per calendar month. A longer date range is a rollup of those months (Understanding quotas).
- Organization usage: select the organization instead of a project → Usage. AI Credits are under AI and Sanity Functions under Compute.
- API request and bandwidth quotas reset at 00:00 UTC on the first day of each month.
Getting usage data out: request logs
Request logs record each API request with fields such as domain, endpoint, dataset, request tags, status, duration and response size. You can add these up into your own usage metrics.
Self-serve export (all self-serve plans):
- Project settings → Usage → download up to 1 GB of logs from the last 7 days, up to the day before you download.
- You can start a new export every 24 hours. It's a manual download, not an API.
- The file is gzipped NDJSON. If the logs are larger than 1 GB, the file is cut off and covers less than 7 days.
For example, to sum bandwidth (in MB) per asset URL on the CDN:
gunzip --stdout request-logs.ndjson.gz \
| jq -r 'select(.attributes.sanity.domain == "cdn")
| select(any(.attributes.sanity.tags[]?; startswith("sanity.studio")) | not)
| "\(.body.responseSize)\t\(.body.url)"' \
| awk -F'\t' '{bytes[$2] += $1} END {for (url in bytes) printf "%.1f\t%s\n", bytes[url]/1000/1000, url}' \
| sort -rn | head -10Continuous delivery to Google Cloud Storage (paid feature on some Enterprise plans; contact sales):
- A project admin adds a GCS bucket in the project's management settings, and logs start arriving within a couple of minutes.
- Logs arrive as compressed NDJSON batches, each with 10,000 lines or 5 minutes of data, Hive-partitioned by
project_id,kindanddt. - You can then query them from BigQuery as an external table, or connect them to a dashboard. Delivery is at-least-once, so remove duplicates if you need exact counts.
Add request tags to your client requests so you can break usage down by app or feature.
Other options
- If you need detailed usage figures that neither the Usage tab nor request logs cover, contact Sanity support with your project ID.
- On the Free plan you get email alerts at 80% and 100% of a quota (Understanding quotas).
Check the docs above for changes, since a usage endpoint isn't documented today.
Show original thread2 replies
Was this answer helpful?
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.