Handle rate limits
Slow down when the API answers 429, and avoid reaching the limit.
When you exceed a limit, the API answers 429 with a Retry-After header.
- Read
Retry-After. It's the number of seconds to wait. - Wait at least that long, and add a small random delay so that your workers don't all retry at once.
- Send the request again. For
POST /instances,POST /linksandPOST /plans, use the same idempotency key.
import random, time, requests
def call(method, url, **kwargs):
while True:
response = requests.request(method, url, **kwargs)
if response.status_code != 429:
return response
time.sleep(int(response.headers["Retry-After"]) + random.random())Avoid reaching the limit
- Reuse an access token until it expires.
- Read
X-RateLimit-Remainingand slow down before it reaches zero. - Use webhooks instead of polling for status changes.
- Remember that all the integrations on an account share one account limit.
For the numbers, see Rate limits.