Handling third party API limits

How to handle external API limits? E.g. setting an API call in queue or something when the limit has been reached until e.g. 300 requests per minute are refreshed again. Rather this than keeping to send requests and getting API limit reached HTTP responses
1 Reply
Kev
Kev2y ago
Depending on how the API you're hitting works, you may be rate limited based on an API key, or an IP address, or some other metric. Either the API documentation or a header like X-RATE-LIMIT on the response you get back should indicate how many requests you can make and when you can retry (you might find this number in an X-RETRY-AFTER type of header. - If it's by API key, you can't practically do much beside back off the requests and retry once you have a new window to send more request. You can look into topics like exponential back off. - If it's by IP address, you might be able to do some clever networking and send requests from different IP addresses once you've hit the limit with one client you're using. Another point to consider is when do you need to hit the endpoint? Is freshness of the data you're getting back paramount? If not, can you *cache *the response for some time and re-use it? If all else fails, perhaps you can negotiate with the provider for a more forgiving rate limit . For instance, at my work, we hit the Riot Games API and we have a custom agreement for our servers that provides a higher rate limit for our requests. Hope this helps!
Want results from more Discord servers?
Add your server