CDN Cache Purge API Reference
API reference for purging cached dataset query results and individual images or files.
Purge cached dataset query results or one dataset image or file from Sanity's CDN.
Self-service cache purging must be enabled for the project. Authenticate with a user or robot token that has permission to update project datasets. The Administrator and Developer roles include this permission.
See Purge CDN caches for usage, completion guarantees, and rate limits.
Base API server URL
Sanity API
https://api.sanity.ioEndpoints
Purge one dataset image or file
/v1/projects/{project_id}/datasets/{dataset_name}/assets/{asset_id}/purgesPurges all cached representations of one dataset image or file. Send a POST with an empty body.
Path parameters
The project that owns the dataset.
The dataset the asset belongs to.
The asset document's
_idor an asset reference's_ref. Useimage-<sha1>-<width>x<height>-<format>orfile-<sha1>-<extension>.
Responses
The request was durably accepted. The purge runs in the background.
- purgeIdstring
An opaque identifier for the accepted purge. Include it when contacting support.
- acceptedAtstring (date-time)
A UTC timestamp in RFC 3339 format.
invalid_request: the request body, asset ID, project ID, or dataset name is invalid.
Error identifier. Each response description lists its possible codes.
A description of the error, in English.
application/json{
"code": "invalid_request",
"message": "asset ID \"file-abc\" is not a dataset image or file ID; expected image-<40 hex characters>-<width>x<height>-<format> or file-<40 hex characters>-<extension>"
}unauthenticated: the credentials are missing, invalid, or expired.
invalid_principal_type: a user or robot token is required.insufficient_permissions: the caller lacks permission to purge this dataset.feature_not_included_in_plan: self-service cache purging is unavailable for the project.
not_found: no endpoint matches the requested URL.
method_not_allowed: use POST for this endpoint.
The project's request limit has been reached. Wait for Retry-After seconds before retrying.
- Example:
API rate limit exceeded
application/json{
"message": "API rate limit exceeded"
}service_unavailable: the request could not be completed. Retry with backoff.
Purge cached query responses for one dataset
/v1/projects/{project_id}/datasets/{dataset_name}/purgesPurges cached GROQ and GraphQL query results for one dataset. Send a POST with an empty body.
Path parameters
The project that owns the dataset.
The dataset whose cached query results will be purged.
Responses
The request was durably accepted. The purge runs in the background.
- purgeIdstring
An opaque identifier shared by requests joining the same pending purge batch. Include it when contacting support.
- acceptedAtstring (date-time)
A UTC timestamp in RFC 3339 format.
invalid_request: the project ID or dataset name is invalid.
unauthenticated: the credentials are missing, invalid, or expired.
invalid_principal_type: a user or robot token is required.insufficient_permissions: the caller lacks permission to purge this dataset.feature_not_included_in_plan: self-service cache purging is unavailable for the project.
not_found: no endpoint matches the requested URL.
method_not_allowed: use POST for this endpoint.
The project's request limit has been reached. Wait for Retry-After seconds before retrying.
- Example:
API rate limit exceeded
application/json{
"message": "API rate limit exceeded"
}service_unavailable: acceptance could not be confirmed. A purge may still execute after a timeout or 503. Allow up to 30 seconds for confirmation and retry with backoff.