Help articles

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 sanityClient from '@sanity/client'

const client = sanityClient({
  projectId: 'your-project-id',
  dataset: 'your-dataset',
  apiVersion: '2022-08-12',
  useCdn: true
})

Protip

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).

Gotcha

Was this page helpful?