How to exclude query attribute from Sanity HTTP API response?
Yes! You can exclude the query attribute from the HTTP API response by using the returnQuery parameter.
According to the Sanity HTTP Query API documentation, there's a query parameter called returnQuery that defaults to true. You can set it to false to omit the query from the response payload.
How to use it:
For GET requests:
https://{projectId}.api.sanity.io/v{apiVersion}/data/query/{dataset}?query=*[_type == 'movie']&returnQuery=falseFor POST requests:
{
"query": "*[_type == 'movie']",
"returnQuery": false
}Wait, actually looking at the documentation more carefully, I see that returnQuery is listed as a query parameter for the GET endpoint, but for POST requests you'd still pass it as a query parameter in the URL, not in the request body:
POST https://{projectId}.api.sanity.io/v{apiVersion}/data/query/{dataset}?returnQuery=falseWith request body:
{
"query": "*[_type == 'movie']"
}Why this helps with Next.js caching:
By setting returnQuery=false, your response payload will be smaller and more consistent. The response will only include:
ms(processing time)result(your actual query results)syncTags(for cache invalidation)
This makes the response more cacheable because the payload is smaller and doesn't include the potentially large query string that was echoing back to you. This is especially helpful when you're using Next.js's caching mechanisms or the Sanity CDN endpoint (apicdn.sanity.io), as smaller, more predictable responses cache better.
Show original thread2 replies
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.