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 you should 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 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.
Note that the client will automatically fall 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).