Types of 429 Errors
QBench has a rate limiting policy in place when utilizing the API. This is to help with server stability and ensure that your requests all come through without any unexpected issues. When a 429 response is returned, your request does not go through and it is safe to retry. QBench returns two types of 429 errors:
- Too many concurrent requests (default 10 concurrent requests)
GET /qbench/api/v1/sample HTTP/1.1
"error": "exceeded concurrent request limit of 10", "qbdf8e": "4b333542"
- Too many requests within the configured rate limit (default 300 requests per minute)
GET /qbench/api/v1/order HTTP/1.1
"error": "ratelimit exceeded 300 per 60 seconds [current count: 301. Retry in 30 seconds]"
Handling The "Exceeded Concurrent Request Limit" Response:
For handling too many concurrent requests, the most basic thing you can do is retry your API call using an exponential back-off algorithm. With a sleep of 1 second, you can attempt to retry the API call and it will eventually go through once your previous requests have completed.
Another recommendation is to write your script in such a way that it keeps track of how many current API requests are active. If the number of active requests exceed the limit, stop and wait until the active requests are finished before making another API call.
Handling The "Rate Limit Exceeded 300 per 60 seconds" Response:
Similar to handling concurrent requests, the most basic thing you can do here is also retry your API call with an exponential back-off algorithm. An alternative method is to use the provided response headers to wait until the rate limit has reset. The X-QBAPI-Throttle-Request-Count header is the number of requests you have made within the rate limiting timeframe. The X-QBAPI-Throttle-TTL header is the number of seconds left until the rate limit resets.
Here is a basic example of how you can implement this in python:
response = requests.get(url)
if response.status_code == 429 and response.headers.get("X-QBAPI-Throttle-TTL"):
seconds = int(response.headers.get("X-QBAPI-Throttle-TTL")
If you have followed these guidelines and are still receiving 429 responses, please contact email@example.com for additional assistance.