Skip to content

Commit eb224cd

Browse files
[codex] Add rate limit documentation (#252)
* Add rate limit documentation * Fix React return types * chore(warningInfo): add disclaimer in rate limits --------- Co-authored-by: raul@facturapi.io <raul@facturapi.io> Co-authored-by: Raúl García <141654545+raul-facturapi@users.noreply.github.com>
1 parent ae610f4 commit eb224cd

6 files changed

Lines changed: 582 additions & 4 deletions

File tree

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
sidebar_position: 6
3+
---
4+
5+
# Límites de tasa (Rate limits)
6+
7+
Para mantener la API estable para todos, Facturapi aplica límites de tasa y de concurrencia.
8+
9+
Estos límites **pueden cambiar** con el tiempo conforme evoluciona el producto y los patrones de uso.
10+
Por eso recomendamos diseñar tu integración para tolerar `429 Too Many Requests` de forma explícita.
11+
12+
:::warning Aviso
13+
Rate limits entrarán en vigor a partir del 19 de Mayo de 2026.
14+
:::
15+
16+
## Qué puedes esperar
17+
18+
La API aplica políticas distintas según el tipo de operación (por ejemplo):
19+
20+
- Lecturas de detalle.
21+
- Lecturas con búsqueda/listado.
22+
- Creación de recursos.
23+
- Escrituras.
24+
- Operaciones de escritura más costosas.
25+
26+
Los límites se evalúan por identidad autenticada (organización o usuario). Si una solicitud no incluye una identidad autenticada, se aplica el control por IP.
27+
28+
En entorno test y live aplicamos la misma política de límites para mantener una experiencia consistente durante desarrollo y producción.
29+
30+
:::info
31+
En condiciones normales de integración no deberías tener problemas con estos límites.
32+
33+
No publicamos umbrales exactos por endpoint para evitar abuso dirigido y preservar la confiabilidad global.
34+
:::
35+
36+
## Respuesta cuando excediste el límite
37+
38+
Cuando una solicitud excede el límite, la API responde con:
39+
40+
- `429 Too Many Requests`
41+
- header `Retry-After` (segundos sugeridos antes de reintentar)
42+
- código de error `RATE_LIMIT_EXCEEDED`
43+
44+
### Ejemplo de manejo de `429`
45+
46+
```javascript
47+
async function requestWithRetry(call, { maxRetries = 5 } = {}) {
48+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
49+
try {
50+
return await call();
51+
} catch (err) {
52+
const status = err?.response?.status;
53+
if (status !== 429 || attempt === maxRetries) {
54+
throw err;
55+
}
56+
57+
const retryAfter = Number(err?.response?.headers?.['retry-after'] || 1);
58+
const jitterMs = Math.floor(Math.random() * 250);
59+
await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000 + jitterMs));
60+
}
61+
}
62+
}
63+
```
64+
65+
## Recomendaciones de integración
66+
67+
### 1) Usa colas para escrituras
68+
69+
Procesa creación de comprobantes con workers y concurrencia controlada, en lugar de disparar ráfagas masivas desde requests web síncronas.
70+
71+
### 2) Implementa backoff exponencial con jitter
72+
73+
Evita reintentos inmediatos y sincronizados. Respeta siempre `Retry-After`.
74+
75+
### 3) Reutiliza recursos ya creados
76+
77+
Guarda `id` de clientes, productos y otros recursos para no recrearlos en cada operación.
78+
79+
### 4) Maneja `429` como parte normal del flujo
80+
81+
Incluye reintentos con backoff y jitter, y respeta siempre `Retry-After`.
82+
83+
## Buenas prácticas operativas
84+
85+
- Incluye y conserva `X-Facturapi-Log-Id` en tu observabilidad para correlacionar incidentes.
86+
- Define alertas por tasa de `429` y latencia p95/p99.
87+
- Si tu integración requiere límites más altos, contacta a soporte para incrementarlos para tu organización.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
sidebar_position: 6
3+
---
4+
5+
# Rate limits
6+
7+
To keep the API stable for everyone, Facturapi applies request rate and concurrency limits.
8+
9+
These limits **may change** over time as the product and traffic patterns evolve.
10+
Because of this, we recommend building your integration to explicitly handle `429 Too Many Requests`.
11+
12+
:::warning Disclaimer
13+
Rate limits will take effect starting May 19, 2026.
14+
:::
15+
16+
## What to expect
17+
18+
The API applies different policies depending on the operation type (for example):
19+
20+
- Detail reads.
21+
- Search/list reads.
22+
- Resource creation.
23+
- Writes.
24+
- Heavier write operations.
25+
26+
Limits are evaluated by authenticated identity (organization or user). If a request does not include an authenticated identity, IP-based limiting is applied.
27+
28+
We apply the same rate-limit policy in test and live mode for a consistent experience across development and production.
29+
30+
:::info
31+
Under normal integration behavior, you should not run into issues with these limits.
32+
33+
We do not publish exact per-endpoint thresholds to reduce targeted abuse and preserve global reliability.
34+
:::
35+
36+
## Response when you hit the limit
37+
38+
When a request exceeds the limit, the API returns:
39+
40+
- `429 Too Many Requests`
41+
- `Retry-After` header (recommended seconds before retrying)
42+
- `RATE_LIMIT_EXCEEDED` error code
43+
44+
### Example `429` handling
45+
46+
```javascript
47+
async function requestWithRetry(call, { maxRetries = 5 } = {}) {
48+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
49+
try {
50+
return await call();
51+
} catch (err) {
52+
const status = err?.response?.status;
53+
if (status !== 429 || attempt === maxRetries) {
54+
throw err;
55+
}
56+
57+
const retryAfter = Number(err?.response?.headers?.['retry-after'] || 1);
58+
const jitterMs = Math.floor(Math.random() * 250);
59+
await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000 + jitterMs));
60+
}
61+
}
62+
}
63+
```
64+
65+
## Integration recommendations
66+
67+
### 1) Use queues for writes
68+
69+
Process invoice creation with workers and controlled concurrency, instead of sending large synchronous bursts from web requests.
70+
71+
### 2) Implement exponential backoff with jitter
72+
73+
Avoid immediate synchronized retries. Always honor `Retry-After`.
74+
75+
### 3) Reuse previously created resources
76+
77+
Store `id` values for customers, products, and other resources so you do not recreate them on every operation.
78+
79+
### 4) Treat `429` as a normal integration scenario
80+
81+
Include retries with backoff and jitter, and always honor `Retry-After`.
82+
83+
## Operational best practices
84+
85+
- Include and preserve `X-Facturapi-Log-Id` in your observability stack to correlate incidents.
86+
- Add alerts for `429` rate and p95/p99 latency.
87+
- If your integration needs higher limits, contact support to increase them for your organization.

0 commit comments

Comments
 (0)