Fundamentals
Rate limits
Each key can make 600 requests in 60 seconds.
Limits apply to each API key separately. The current limit is 600 requests in 60 seconds per key.
When you go over it, the request fails with 429 and the error code rate_limited. The response carries a Retry-After header with the number of seconds to wait.
http
HTTP/1.1 429 Too Many Requests
Retry-After: 12
Content-Type: application/json
{"error":{"code":"rate_limited","message":"Too many requests.","field":null,"request_id":"req_01JEX4R7Q2K8M3"}}If Valeron cannot check the limit, it refuses the request with 503 rate_limit_unavailable rather than letting it through. Retry after a short delay.
#Back off and retry
JavaScript
async function valeron(path, options = {}, attempt = 0) {
const response = await fetch(`https://api.valeron.io${path}`, {
...options,
headers: { Authorization: `Bearer ${process.env.VALERON_API_KEY}`, ...options.headers },
});
if ((response.status === 429 || response.status === 503) && attempt < 5) {
const wait = Number(response.headers.get("Retry-After")) || 2 ** attempt;
await new Promise((resolve) => setTimeout(resolve, wait * 1000));
return valeron(path, options, attempt + 1);
}
return response;
}Python
import os
import time
import requests
def valeron(method, path, attempt=0, **kwargs):
response = requests.request(
method,
f"https://api.valeron.io{path}",
headers={"Authorization": f"Bearer {os.environ['VALERON_API_KEY']}"},
**kwargs,
)
if response.status_code in (429, 503) and attempt < 5:
time.sleep(int(response.headers.get("Retry-After", 2 ** attempt)))
return valeron(method, path, attempt + 1, **kwargs)
return response#Staying under the limit
- Ask for the most you can per request:
limit=200on lists. - Sync with
updated_sinceso you fetch only what changed. See Pagination and syncing. - Use webhooks instead of polling.
