Web3 API rate limit with async python

Hi, I’m using the web3 API and I’m making the calls asynchronously with python. I’m using a semaphore of 2 and a delay of 0.5 seconds, so I’m roughly getting ~4 API calls per second. However when I check the headers of the response, the “x-rate-limit-used” fluctuates wildly from 0 to 25 calls per second (the “x-rate-limit-limit” is 25 at all times). I’m wondering why this is the case as I would be expecting x-rate-limit-used to be around ~4 API calls a second as well. I would like to hopefully use a semaphore of 25 and delay of 1 second but that will generate a lot of 429 responses. I’m also new to this so I’m just trying to understand how it works. Thanks.

Endpoints may have different weight values so they count as multiple requests; you can see them here. https://docs.moralis.io/misc/rate-limit#request-weights

This will give you a clearer idea of how many requests are being made per second.

1 Like

Makes sense now, thank you.