API rate limit error followed by ECONNREFUSED - IP blocked?

18 replies
Last updated: Sep 3, 2021
I got a single error while querying the API
API rate limit exceeded
. Since then, I’m getting
ECONNREFUSED 34.102.211.197:443
.
The project usage seems well within its limits, and I’m not getting the error if I change to another network connection.

Could it be that my IP has been blocked? Is there anyone here who can help me to figure this out?
AI Update

I understand how frustrating this situation is! Based on your symptoms, it does appear that your IP address may have been temporarily blocked after triggering the rate limit. The fact that switching to another network connection resolves the issue is a strong indicator of an IP-level block.

The IP address 34.102.211.197:443 is one of Sanity's API servers, so the ECONNREFUSED error suggests your requests from that specific IP are being rejected at the connection level.

Why this happens: When Sanity's API detects rate limit violations, it can temporarily block the offending IP address as a protective measure. Even though your project usage is within limits, the rate limiting is often applied per IP address per time window, not just overall project usage.

Immediate solutions:

  1. Wait it out: These blocks are typically temporary (often 15-60 minutes). If you can afford to wait, the block should lift automatically.

  2. Use a different network: As you've discovered, switching networks (different IP) works. This could be switching between WiFi and mobile hotspot, or working from a different location temporarily.

  3. Contact support: For immediate assistance, reach out to Sanity support. They can check if your IP is blocked and potentially remove the block manually. Be sure to include:

Preventing future occurrences:

  • Use the API CDN (apicdn.sanity.io) which has unlimited rate for cached content - this is particularly helpful since cached responses won't count against rate limits
  • Implement request throttling in your code
  • Use proper caching strategies to reduce API calls
  • Consider batching requests where possible
  • Configure your Sanity client with useCdn: true to take advantage of the CDN

If you're in active development and hitting rate limits, you might want to review your query patterns to see if you're making unnecessary requests (like queries in tight loops or on every keystroke). The good news is that this is typically a temporary issue that resolves itself, but support can definitely help if you need immediate access!

Show original thread
18 replies
It seems to be working again. I’m still curious to find out what it could have been, for next time.
can you please check that your API is getting called in a loop i faced same issue check in console.
Thanks User. There is quite a bit of outgoing requests, but no infinite loops, if that’s what you mean?
It worked for a while, but now I get the same error again. Hmm…
Now I’m getting
getaddrinfo ENOTFOUND [project_id_masked].<http://api.sanity.io|api.sanity.io>
And now it’s working again… Strange
can you send me the console pic.
Hey User! What's the context that you're getting this error in?
Hi
user M
. I’m getting these errors in local development while building – using a custom static site generator. There are about 600 queries, but I’m caching them to disk, so they are requested only once in a while whenever I manually empty the cache. Of course, then all of them will be requested in one burst.
Hi
user M
. I’m getting this in local development while building using a custom static site generator. There are about 600 queries, but I’m caching them to disk, so they are requested only once in a while whenever I manually empty the cache. Of course, then all of them will be requested in one burst.
Hi
user M
. I’m getting these errors in local development when building a website using a custom Node.js static site generator. It uses
@sanity/client
.
There are about 600 queries, but I’m caching the results to disk, so they are requested only once in a while whenever I manually empty the cache. But of course, then all of them will be requested in one burst.
I’m usually not using the CDN in development, relying on the local on-disk cache I put between.
I’m usually not using the CDN in development.
Ah, got it. I think you're hitting this rate limit for concurrent queries, which is why you're only occasionally getting the error.
That must be it
user M
. Thank you very much!
Does the
@sanity/client
have the option or possibility to rate limit itself?
Is there any way to limit concurrency in the
@sanity/client
?
There isn't a method built into the client, but there's an example of handling concurrency in this bit of the docs . You could probably adapt it to suit your needs here!

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.

Was this answer helpful?