🎤 Builder Talk: The Story Behind Lady Gaga’s Digital Experience – Register now

Understanding the impact of using Sanity's `imageUrlBuilder` on API quotas and bandwidth.

10 replies
Last updated: Jul 6, 2022
Quick question: does Sanity's
imageUrlBuilder
count towards the API quotas?
Jul 5, 2022, 9:43 PM
We're iterating over some arrays at the moment, and if so, has the potential to fry our quotas pretty quickly given our estimated traffic.
Jul 5, 2022, 9:44 PM
.
Jul 5, 2022, 9:44 PM
as far as i understand, the
imageUrlBuilder
is just a utility that makes URL strings for you. it doesn't make API calls during that process. But then when you fetch the image, that counts towards your API usage.
Jul 5, 2022, 10:47 PM
Got it - and am I safe to assume the images would then apply to the bandwidth cap versus the API CDN cap? Or would it be both?
Jul 5, 2022, 11:11 PM
good question. i don't know actually. maybe someone else knows 🙂
Jul 5, 2022, 11:13 PM
I also don't know for sure but from experience and reading the logs and comparing them with my server logs, I believe that the API CDN cap is for the requests themselves -- the textual returned data, part of which is to identify and return the information about the images.
The bandwidth seems to be a mixture of both -- all the data passing through, in terms of what the queries burp out, and almost certainly any image transformations. I don't believe the actual egress of file data is "cached" in any way in that regard, because, well, being held in memory doesn't make it any less made of bytes and that's what has to get pushed to the end user.

So as you can clearly see.....I
also don't know but used more words to say it 😛
Jul 6, 2022, 5:52 AM
user E
you'd be using both an API request and bandwidth when displaying an image, I believe: 1 call to get the asset and bandwidth in the amount of whatever size that asset you're serving is.
Jul 6, 2022, 5:00 PM
Thanks for the insight
user M
! On that note, I'm wondering if there's a more efficient way to do what we're doing. Ex: we have a landing/gallery page that lists out many cards (with thumbnail images) that link to the respective detail pages. A single query grabs the refs to all the images, but we're looping over that dataset in a Vue template and calling the URL builder for each image, which could potentially lead to dozens of API calls on that page alone.
Is there a better way to handle that?
Jul 6, 2022, 5:21 PM
Good question! You can expand the asset ref in your original query to get the image url, then add whatever params you need using string concatenation on your frontend. That means getting all of those urls is a single call, not 1 call x however many images you're building a url for. The downside is that you're not getting the benefits that the builder affords you (I.e. respecting crop & hotspot automatically).
If you want to continue using the builder, though, you can mitigate the impact of these calls by using the CDN (which affords you about 5x the number of calls).
Jul 6, 2022, 5:32 PM
Awesome, will have a deeper look.
Jul 6, 2022, 5:34 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
Hey all - what’s the quickest way to batch delete all documents of a certain type? It looks like the `sanity` cli tool allows...Jan 29, 2021
Rendering nested block contentJan 18, 2021
In the tutorial, there is samples of what the API returns as JSON. Is there a way to view these ?Jan 11, 2021
Warning: Data for Page Exceeds the Threshold of 128 kBAug 17, 2022
Custom Document Views - Is it Even Possible to Use the Structure Builder?Apr 21, 2022
How to get the number of nested/children components in a GROQ query.Jan 19, 2024
Issue with fetching data from an array of references and non-references in a groq query.Dec 14, 2023
GraphQL query resolving references on a _raw field in GatsbyMay 17, 2022
GROQ query for getting references from arrays in another array in Sanity.ioApr 9, 2020
How to populate a list of values in a Sanity schema using a separate fileSep 6, 2021

Related contributions

Turbo Start Sanity
- Template

The battle-tested Sanity template that powers Roboto Studio's websites

Go to Turbo Start Sanity

Schema UI - Next.js Sanity Starter
- Template

A Next.js starter template with Next.js 15, Tailwind CSS, shadcn/ui, and Sanity CMS with Live Editing. Get production-ready React components with matching Sanity schemas and queries. Build dynamic pages faster while keeping full control over customization.

Serge Ovcharenko
Go to Schema UI - Next.js Sanity Starter

The Swaddle
- Made with Sanity

A new brand identity to represent a more mature company, to signify The Swaddle’s evolution from publisher to production house, combined with an easier to navigate platform that can surface multiple content types - drawing readers through The Swaddle’s content offering.

Nightjar
Go to The Swaddle