Usage API reference
Reference documentation for the Usage API
The Usage API reports metered usage, such as API requests, documents and function invocations, for a Sanity project, media library or organization. A snapshot gives the usage so far within a day, month or year. History gives usage over a date range, grouped by day, month or year, with optional running totals.
Authentication
- All requests must be authenticated.
Base API server URL
Production environment
https://api.sanity.ioResources
Get resource usage.
Get resource usage snapshot
/v2026-09-01/usage/{resourceType}/{resourceId}/snapshotReturns resource usage snapshot for a specific resource.
Path parameters
Type of the resource that we are querying for. Any other value is rejected with a 400.
Example:organizationID of the resource (project, media library or organization) that we are querying for
Example:or0Bc1hcJ
Query parameters
- metricsstring
Comma-separated list of metrics that we want to get in the response.
Example:apicdnrequests,documents,assets - datestring (date)
Date for which to fetch the snapshot, in ISO format (e.g. 2017-09-14). Defaults to today's date.
- periodstring
Billing period for which to fetch the snapshot, valid values are day, month, year. Defaults to month. Example: date=2017-09-14 with period=month will return usage from 2017-09-01 to 2017-09-14, while the same date with period=year will return usage from 2017-01-01 to 2017-09-14 (defaults to snapshotPeriod=startOfPeriod).
- snapshotPeriodstring
Accepts previousPeriod and startOfPeriod. If snapshotPeriod is set to previousPeriod, then a snapshot period will be used strictly. Example: with date=2017-09-14, period=month and snapshotPeriod=previousPeriod will return usage from 2017-08-15 to 2017-09-14, while the same date with period=year and snapshotPeriod=previousPeriod will return usage from 2016-09-15 to 2017-09-14. Defaults to startOfPeriod
Responses
Resource usage snapshot for the requested period.
- resourceTypestringExample:
organization - resourceIdstringExample:
or0Bc1hcJ - usageobject
Map of metric names to their value for the snapshot period. Values can be fractional.
Example{"apirequests":14,"standard-function-gb-seconds":12.01} - timestampsobject
Map of metric names to the latest timestamp recorded in the period, or null when the metric has no data.
Example{"apirequests":"2025-02-13T00:00:00Z","users":null}
Bad request
Unauthorized
Resource not found
Get resource usage history
/v2026-09-01/usage/{resourceType}/{resourceId}/historyReturns resource usage history for a specific resource.
Path parameters
Type of the resource that we are querying for. Any other value is rejected with a 400.
Example:organizationID of the resource (project, media library or organization) that we are querying for
Example:or0Bc1hcJ
Query parameters
- metricsstring
Comma-separated list of metrics that we want to get in the response.
Example:apicdnrequests,documents,assets - fromstring (date)
Date from which to fetch history, in ISO format (e.g. 2017-09-14). Defaults to 30 days before today. Will not be aligned with period, so make sure it is set to the first day in the period if this is required.
- tostring (date)
Date up to which to fetch history, in ISO format (e.g. 2017-09-14). Defaults to today's date. Will not be aligned with period, so make sure it is set to the last day in the period if this is required.
- periodstring
Period for which to aggregate usage, valid values are
day,month, andyear. Defaults tomonth. The requested range is limited by the period:dayaccepts at most 90 days betweenfromandto,monthat most 24 calendar months, andyearis unlimited. Exceeding the limit is rejected with a 400. - cumulativeboolean
If true, calculate cumulative usage (running total) for counter type metrics instead of the usage within each individual period. Defaults to false.
- cumulative_periodstring
Period after which the cumulative usage will reset to 0. E.g. cumulative usage with
period=dayandcumulative_period=monthwill calculate cumulative total within each. The period is locked to the calendar. Defaults to forever.
Responses
Resource usage history, wrapped in a resource envelope.
- resourceTypestringExample:
organization - resourceIdstringExample:
or0Bc1hcJ - dataarray
Show child attributes
items
- datestring
Start of the aggregation period, formatted according to the requested period (e.g. 2024-11-05 for day, 2024-11 for month, 2024 for year).
Example:2024-11 - metricsobject
Map of metric names to their aggregated value for this period.
Example{"apirequests":563,"agent-actions":563} - cumulativeobject
Map of metric names to their running total for counter metrics. Only present when cumulative=true was requested.
Example{"apirequests":1126,"agent-actions":1126}
Bad request
Unauthorized
Resource not found
Get scoped resource usage snapshot
/v2026-09-01/usage/{resourceType}/{resourceId}/{scope}/snapshotReturns resource usage snapshot grouped by scope (e.g., per-user usage within an organization). User-scoped metrics exist only for organizations: content-agent-queries, content-agent-actions, content-agent-queries-ai-usage, content-agent-actions-ai-usage, ai-usage, embeddings-writes and embeddings-reads. Other metrics and resource types return no scoped data.
Path parameters
Type of the resource that we are querying for. Any other value is rejected with a 400.
Example:organizationID of the resource (project, media library or organization) that we are querying for
Example:or0Bc1hcJScope level for grouping usage metrics. Currently only 'user' is supported.
Example:user
Query parameters
- metricsstring
Comma-separated list of metrics that we want to get in the response.
Example:apicdnrequests,documents,assets - datestring (date)
Date for which to fetch the snapshot, in ISO format (e.g. 2017-09-14). Defaults to today's date.
- periodstring
Billing period for which to fetch the snapshot, valid values are day, month, year. Defaults to month. Example: date=2017-09-14 with period=month will return usage from 2017-09-01 to 2017-09-14, while the same date with period=year will return usage from 2017-01-01 to 2017-09-14 (defaults to snapshotPeriod=startOfPeriod).
- snapshotPeriodstring
Accepts previousPeriod and startOfPeriod. If snapshotPeriod is set to previousPeriod, then a snapshot period will be used strictly. Example: with date=2017-09-14, period=month and snapshotPeriod=previousPeriod will return usage from 2017-08-15 to 2017-09-14, while the same date with period=year and snapshotPeriod=previousPeriod will return usage from 2016-09-15 to 2017-09-14. Defaults to startOfPeriod
Responses
Scoped usage snapshot
- resourceTypestringExample:
organization - resourceIdstringExample:
or0Bc1hcJ - scopestringExample:
user - dataarray
Show child attributes
items
- idstring
Identifier of the scoped entity (e.g., user ID)
Example:user-123 - usageobject
Map of metric names to their values
Example{"content-agent-queries":150,"content-agent-actions":45} - timestampsobject
Map of metric names to their last recorded timestamps
Example{"content-agent-queries":"2024-12-12T13:48:25.727Z","content-agent-actions":"2024-12-12T12:30:00.000Z"}
Bad request
Unauthorized
Resource not found
Get scoped resource usage history
/v2026-09-01/usage/{resourceType}/{resourceId}/{scope}/historyReturns resource usage history grouped by scope (e.g., per-user usage history within an organization). User-scoped metrics exist only for organizations: content-agent-queries, content-agent-actions, content-agent-queries-ai-usage, content-agent-actions-ai-usage, ai-usage, embeddings-writes and embeddings-reads. Other metrics and resource types return no scoped data.
Path parameters
Type of the resource that we are querying for. Any other value is rejected with a 400.
Example:organizationID of the resource (project, media library or organization) that we are querying for
Example:or0Bc1hcJScope level for grouping usage metrics. Currently only 'user' is supported.
Example:user
Query parameters
- metricsstring
Comma-separated list of metrics that we want to get in the response.
Example:apicdnrequests,documents,assets - fromstring (date)
Date from which to fetch history, in ISO format (e.g. 2017-09-14). Defaults to 30 days before today. Will not be aligned with period, so make sure it is set to the first day in the period if this is required.
- tostring (date)
Date up to which to fetch history, in ISO format (e.g. 2017-09-14). Defaults to today's date. Will not be aligned with period, so make sure it is set to the last day in the period if this is required.
- periodstring
Period for which to aggregate usage, valid values are
day,month, andyear. Defaults tomonth. The requested range is limited by the period:dayaccepts at most 90 days betweenfromandto,monthat most 24 calendar months, andyearis unlimited. Exceeding the limit is rejected with a 400.
Responses
Scoped usage history
- resourceTypestringExample:
organization - resourceIdstringExample:
or0Bc1hcJ - scopestringExample:
user - dataarray
Show child attributes
Bad request
Unauthorized
Resource not found