Request tags for filtering logs in @sanity/client
Learn how to use request tags to identify and filter API requests in your Sanity project's request logs for debugging and monitoring.
Request tags help you identify and filter API requests in your project's request logs. This is valuable for debugging, monitoring performance, and understanding how your application uses the API.
You can set a tag prefix for every request with the requestTagPrefix client option, and a tag for an individual request with the tag option. When you set both, the client joins them with a dot:
import {createClient} from '@sanity/client'
// Set default tag on client
const client = createClient({
projectId: 'YOUR_PROJECT_ID',
dataset: 'YOUR_DATASET',
apiVersion: '2026-03-01',
requestTagPrefix: 'myapp', // Prefix for all requests
})
// Tag individual queries
const posts = await client.fetch(
'*[_type == "post"]',
{},
{tag: 'homepage-posts'}
)
// Request appears in logs as: myapp.homepage-posts
// Tag getDocument requests
const post = await client.getDocument('post-123', {
tag: 'post-detail'
})
// Tag listeners
const subscription = client.listen(
'*[_type == "post"]',
{},
{tag: 'realtime-posts'}
).subscribe(update => {
// ...
})A tag can contain only letters, digits, underscores, dashes, and dots. The full tag, including the prefix, must be 75 characters or fewer. If the prefix or a request tag breaks these rules, createClient() or the request method (such as fetch() or getDocument()) fails with this error: Tag can only contain alphanumeric characters, underscores, dashes and dots, and be between one and 75 characters long.
Tags appear in the attributes.sanity.tags field of your project's request logs. To download the logs, open your project in Manage and select Usage > Request logs. The export is a compressed newline-delimited JSON file that you can filter by tag with tools such as jq or GROQ CLI to analyze request patterns, find slow queries, and debug issues. For more information, see Request logs.