Client API CDN configuration
Sanity provides a CDN-distributed, cached API that is faster and cheaper to use if you are exposing the API to end users. If you are building static sites, use the live API to ensure you always get the freshest version.
A full explanation of the differences between these APIs is outlined in the API CDN documentation.
The Sanity JavaScript client can be configured to use either the API CDN or the live API by setting the useCdn option to true or false, respectively, when configuring the client:
import {createClient} from '@sanity/client'
const client = createClient({
projectId: '<your-project-id>',
dataset: '<your-dataset>',
apiVersion: '2026-03-01',
useCdn: true,
})Protip
In most cases, we recommend setting your apiVersion to today's date. This ensures you get the most recent bug fixes and improvements, and if it works today it will continue to work tomorrow.
The client automatically falls back to using the live API in the following scenarios:
- When a mutation is performed (create/edit/delete).
- When listeners are used (subscribing to changes).
Setting useCdn: false on a client that renders published content for every visitor sends each of those queries to the live API, which counts toward your API request quota. To find out what is driving your API requests, see Diagnose an API request spike.
Was this page helpful?
Feedback submitted, thanks for helping us improve the docs. Have you tried these alternatives?