Unlock seamless workflows and faster delivery with our latest releases – get the details

AVIF

Images that have the query parameter auto set to format (see documentation) and are requested from a browser that supports the AVIF format will usually get an AVIF returned. There are a few exceptions/quirks:

  • The first few requests for an AVIF may get the "second best option" (WebP if supported, otherwise PNG/JPG depending on the source image). Subsequent requests will eventually get an AVIF back. This is done to ensure a speedy response, since encoding AVIFs is a slow process.
  • Image requests made prior to the rollout of the AVIF support may already be cached in our CDN and will not return an AVIF response until they expire/fall out of the cache.

In other words: if you are not seeing AVIF images being returned, don't worry — they should eventually return AVIF. You can use curl to verify the behavior:

# Replace the URL with an actual URL from your project.
# Remember to include `?auto=format`!
curl -sS -I \
  -H 'accept: image/avif,image/webp,image/*' \
  'https://cdn.sanity.io/images/:projectId/:dataset/:filename?auto=format' \
  | grep 'content-type:'

On the first request, you will likely see image/webp returned. After waiting 30 seconds, run the same command again, and you should see image/avif. If you don't, wait a little longer and retry. If you still do not see AVIF, ensure that the accept header includes image/avif (before other formats) and that the query parameters includes auto=format.

Reporting issues

If you encounter any issues, send an email to avif@sanity.io with comprehensive details on the issue.

Was this article helpful?