Joint session with Vercel: How to build intelligent storefronts (May 15th)

How is "total documents" calculated in Sanity usage metrics?

2 repliesLast updated: Nov 29, 2025

Hey hey!
Can I ask how “total documents” is calculated in Sanity usage?
I’m asking because I’m trying to replicate that number using a GROQ query, to keep track of our documents.

I end up with either too many, or too few, depending on how I’m counting.
For example, do total documents count across datasets?
AI Update

Great question! The "total documents" number in Sanity usage is calculated with some specific rules that might explain why your GROQ query results differ.

What's Counted in Total Documents

According to the Plans and Payments documentation, the Documents quota is defined as:

"total number of stored documents (including drafts) across all datasets at the end of the month"

Important exclusions:

Replicating the Count with GROQ

Based on the community discussion, here's how to replicate the usage count:

count(*[_type in $types])

Where $types is an array of the document types you've defined in your schema (excluding system documents and assets).

If you're getting too many documents, you're likely including:

If you're getting too few, you might be:

Dataset Considerations

Yes, documents count across ALL datasets in your project. The quota is per-project, not per-dataset. So if you have multiple datasets (like production, staging, development), all their documents add up to your total count.

Practical GROQ Query

To get an accurate count excluding system documents and assets:

count(*[!(_id in path("_.**")) && !(_type match "sanity.*")])

This excludes:

Remember that this count includes drafts, which is consistent with how Sanity calculates your usage quota.

Show original thread
2 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.

Related contributions