Skip to content
Anagen
PT EN
Request assessment

Guide 8/12

Rate limits

Each integration has a per-minute quota chosen by the clinic (120 by default).

  • Every response carries X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset (epoch seconds).
  • Over the limit: 429 limite_excedido with Retry-After (seconds).
  • The token endpoint has its own per-IP limit (20 per minute).
  • Prefer webhooks to polling; ask for 100 records per page; cache what rarely changes (schemas, options).
async function chamar(url, opcoes, tentativa = 0) {
  const r = await fetch(url, opcoes);
  if (r.status === 429 && tentativa < 5) {
    const espera = Number(r.headers.get('Retry-After') || 2 ** tentativa);
    await new Promise((ok) => setTimeout(ok, espera * 1000));
    return chamar(url, opcoes, tentativa + 1);
  }
  return r;
}