Build payments into your product with TPE virtual. Start integrating →
Logo

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.

  1. Read Retry-After. It's the number of seconds to wait.
  2. Wait at least that long, and add a small random delay so that your workers don't all retry at once.
  3. Send the request again. For POST /instances, POST /links and POST /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-Remaining and 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.

On this page