Rate limits
Per-key request limits, X-RateLimit headers, 429 responses with Retry-After, plan quotas (X-Quota) and how to retry with backoff.
There are two kinds of limits: the rate limit (how many calls you can make per unit of time) and plan quotas (how many resources you can create, for example invoices per year).
Rate limit
Each API key has a per-minute request limit: by default 3,000 requests per minute, more than enough for a normal integration. It may be adjusted to protect the service, so don't hard-code it: read it from the headers.
Every response to an API key request includes:
| Header | Description |
|---|---|
X-RateLimit-Limit | Requests allowed in the current window. |
X-RateLimit-Remaining | Requests left in the window. |
X-RateLimit-Reset | When the window resets (seconds since epoch, UTC). |
HTTP/1.1 200 OK
X-RateLimit-Limit: 3000
X-RateLimit-Remaining: 2987
X-RateLimit-Reset: 1793527260
X-Request-Id: req_01JBQ8A1B3C5D7E9F1G3H5J7K9If you exceed it, the API answers 429 Too Many Requests with a Retry-After header (seconds) and the same value in the body:
{
"detail": "Has superado el límite de peticiones. Vuelve a intentarlo en 12 segundos.",
"code": "rate_limited",
"retry_after": 12,
"request_id": "req_01JBQ8B2C4D6E8F0G2H4J6K8M0"
}The limit applies per key: two integrations with different keys don't share the same allowance.
Plan quotas
Some resources have a plan maximum (invoices per year, customers, document scans, storage…). Requests that consume quota include:
| Header | Description |
|---|---|
X-Quota-Feature | Resource consuming quota (e.g. invoices_per_year). |
X-Quota-Limit | Plan maximum for the period. |
X-Quota-Used | Used in the period. |
X-Quota-Remaining | Available. |
X-Quota-Period | Quota period (e.g. the current year). |
X-Quota-Hard-Limit | true if creation is blocked when the maximum is reached. |
When a hard quota runs out, the API answers 402 with "code": "quota_exceeded". Retrying makes no sense: upgrade the plan or wait for the next period. If a resource belongs to a module the organization doesn't have, the response is 403 module_not_available.
Retrying with backoff
- On
429, wait exactlyRetry-Afterseconds. - On
500,502,503or504, or a network error, wait with exponential backoff with jitter: 0.5 s, 1 s, 2 s, 4 s… (capped at about 30 s) times a random factor. - Cap the number of attempts (4–6) and log the
X-Request-Idof every failure. - On
POSTandPATCHreuse the sameIdempotency-Keyon every attempt.
import { setTimeout as sleep } from "node:timers/promises";
export async function billoraFetch(url, init = {}, maxAttempts = 5) {
for (let attempt = 1; ; attempt++) {
let res;
try {
res = await fetch(url, { ...init, signal: AbortSignal.timeout(30_000) });
} catch (err) {
if (attempt >= maxAttempts) throw err;
await sleep(jitter(attempt));
continue;
}
if (res.status !== 429 && res.status < 500) return res;
if (attempt >= maxAttempts) return res;
const retryAfter = Number(res.headers.get("Retry-After"));
await sleep(res.status === 429 && retryAfter ? retryAfter * 1000 : jitter(attempt));
}
}
const jitter = (attempt) => Math.min(30_000, 500 * 2 ** (attempt - 1)) * (0.5 + Math.random() / 2);import random, time
import requests
def billora_request(session, method, url, max_attempts=5, **kwargs):
for attempt in range(1, max_attempts + 1):
try:
res = session.request(method, url, timeout=30, **kwargs)
except requests.RequestException:
if attempt >= max_attempts:
raise
time.sleep(jitter(attempt))
continue
if res.status_code != 429 and res.status_code < 500:
return res
if attempt >= max_attempts:
return res
retry_after = res.headers.get("Retry-After")
time.sleep(int(retry_after) if res.status_code == 429 and retry_after else jitter(attempt))
def jitter(attempt):
return min(30, 0.5 * 2 ** (attempt - 1)) * random.uniform(0.5, 1)function billoraRequest(string $method, string $url, array $headers, ?string $body = null, int $maxAttempts = 5): array {
for ($attempt = 1; ; $attempt++) {
$responseHeaders = [];
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $body,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HEADERFUNCTION => function ($ch, $line) use (&$responseHeaders) {
$parts = explode(":", $line, 2);
if (count($parts) === 2) $responseHeaders[strtolower(trim($parts[0]))] = trim($parts[1]);
return strlen($line);
},
]);
$raw = curl_exec($ch);
$status = $raw === false ? 0 : curl_getinfo($ch, CURLINFO_HTTP_CODE);
$retryable = $status === 0 || $status === 429 || $status >= 500;
if (!$retryable || $attempt >= $maxAttempts) {
return [$status, $responseHeaders, $raw];
}
$wait = ($status === 429 && isset($responseHeaders["retry-after"]))
? (int) $responseHeaders["retry-after"]
: min(30, 0.5 * 2 ** ($attempt - 1)) * (0.5 + mt_rand() / mt_getrandmax() / 2);
usleep((int) ($wait * 1_000_000));
}
}Best practices
- Request large pages (
page_size=200) when syncing instead of many small pages. - Use incremental sync with
updated_afterand webhooks instead of polling everything. - For bulk jobs, limit concurrency (for example 4–8 parallel requests) and watch
X-RateLimit-Remaining. - Cache data that hardly changes: series, taxes, categories, payment methods.
