🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Excessive API calls and CDN usage in Sanity Studio setup for Next.js app.

10 replies
Last updated: Dec 8, 2023
Hi all! I'm using Sanity studio in a next js app, specifically the setup provided by this repo provided by the sanity team. My actual implementation is linked here . I'm noticing that my total API call usage is exorbitantly high, and i've narrowed the reason down to two possible issues. When I update documents in the studio, i'm faced with thousands of sanity API requests that fire on each keystroke when i'm editing saved documents, and this is running up my limit of API requests very quickly. Is there any way to minimize these requests when editing in the studio, say, only fire an API request when getting preexisting documents or publishing new documents rather than on every update to the UI? The second issue is that even though I've set 'useCDN' to be true on the client, next is still grabbing data from the sanity api rather than the api CDN. As such, my API CDN usage is actually minuscule when compared to my my API usage, a value that is supposedly meant to be much smaller, which is actually very high for me. Has anyone had any experience with this issue before?
Nov 27, 2023, 4:40 PM
Studio requests do not count toward your usage. Are you actively editing in your Studio? If so, the cache is invalidated when you publish changes.
Nov 27, 2023, 5:48 PM
Thanks for your input! yes, I am actively editing in my studio. I'm really trying to debug where the respective API and API CDN calls are coming from: from this link in the docs it makes it seem like API calls usually come from editing content (which would be sanity studio in my case) whereas API CDN calls come from serving content to end users. Is there a way to debug where these requests are coming from from Sanity, to determine where the excessive API calls are occurring?
Nov 27, 2023, 8:19 PM
I can tell you which API calls are occurring most frequently, but I can’t give you referrer data. What’s your project ID?
Nov 27, 2023, 10:12 PM
thank you! my project id is nwlu3bfm
Nov 27, 2023, 10:19 PM
It looks like this is the culprit. Are you able to find where you’re performing that query in your code?
Nov 27, 2023, 10:23 PM
Hmm yeah that's my loadSettings query in my navbar and footer- thats interesting. Is it taking up a disproportionate amount of the API calls? Also, I'm surprised that its going to the API rather than the API CDN, i have useCDN set to true on my client and I would prefer to be fetching that information from the CDN rather than the API.
Nov 27, 2023, 10:51 PM
Did you have any luck solving this
user P
?
Dec 8, 2023, 1:42 AM
I did actually, you can see the changes made in this commit
Dec 8, 2023, 2:24 AM
specifically in the 'sanity/loader/loadQuery.ts' folder
Dec 8, 2023, 2:24 AM
awesome thank you!
Dec 8, 2023, 3:11 AM

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?