Troubleshooting the use of CDN in a Sanity.io project
I can see the issue here! Based on the official API CDN documentation, the warning you're seeing is likely not related to authentication at all. Here's what's actually happening:
Your Images ARE Using the CDN
You correctly noticed that your images are loading from cdn.sanity.io - that's the Asset CDN, which always works through the CDN regardless of your client configuration.
The Build-Time Warning is Expected
When you run next build (or similar build commands), you're generating static content. During static builds, you should NOT use the CDN - you want the freshest data possible to build your pages. The warning is actually helpful here because it's reminding you that build-time queries should hit the live API, not the cached CDN.
The useCDN option controls whether your GROQ/GraphQL data queries use the cached API CDN (apicdn.sanity.io) or the live API (api.sanity.io).
About Authenticated Requests and the CDN
One important clarification: The API CDN documentation explicitly states that authenticated requests ARE cached on the CDN. They're just "segmented for each unique authentication token." So if you have a token in your client config, it will still use the CDN when useCDN: true is set.
Your Configuration is Actually Correct
Your setup looks good:
const options = {
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET_NAME,
apiVersion: "2022-01-18",
useCDN: process.env.NEXT_PUBLIC_SANITY_DATASET_NAME === "production", // ✅ Good
};For production runtime: useCDN: true means browser requests will use the fast, cached CDN
For build time: The warning reminds you that builds should use fresh data
Note on the Option Name
The property name is useCdn (lowercase 'n'), not useCDN. While many JavaScript clients accept both due to case-insensitive handling, the canonical form is useCdn. If you're seeing a warning specifically about the casing, try changing:
useCDN: true // might cause a warningto:
useCdn: true // canonical formWhen You Actually See CDN Usage
The CDN is used for:
- Client-side queries when
useCdn: true - Image assets (always)
- Runtime data fetching in browsers
The CDN is NOT used for:
- Build-time queries (intentionally, to get fresh data)
- Server-side rendering in some frameworks (depends on configuration)
Your setup is working correctly - the images are on the CDN, and your production client will use the API CDN for data queries at runtime. The build warning is just informing you that during the build process itself, you're hitting the live API for the freshest content.
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.