> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ya.works/llms.txt
> Use this file to discover all available pages before exploring further.

# Rate Limiting

> Entiende los límites de peticiones y cómo manejar respuestas 429

# Rate Limiting

La Business API aplica límites de peticiones por merchant para garantizar un uso justo y la estabilidad de la plataforma.

## Headers de Respuesta

Cada respuesta incluye headers de rate limit que te indican tu cuota actual:

| Header | Descripción |
| - | - |
| `X-RateLimit-Limit` | Máximo de peticiones permitidas en la ventana actual |
| `X-RateLimit-Remaining` | Peticiones restantes en la ventana actual |
| `X-RateLimit-Reset` | Timestamp Unix cuando la ventana se reinicia |

Consulta estos headers en cada respuesta para conocer tu límite y cuántas peticiones te quedan.

## Manejar 429 Too Many Requests

Cuando excedes el límite, la API responde con status `429` y agrega un header `Retry-After`:

```bash theme={null}
HTTP/1.1 429 Too Many Requests
Content-Type: application/json
Retry-After: 1
X-RateLimit-Limit: 1
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1710288000
```

```json theme={null}
{
  "type": "RateLimitExceededError",
  "detail": "Rate limit exceeded"
}
```

## Estrategia de Reintentos

Usa backoff exponencial cuando recibas una respuesta 429:

<CodeGroup>
  ```python Python theme={null}
  import time
  import httpx

  def request_with_retry(url: str, headers: dict, max_retries: int = 3):
      for attempt in range(max_retries):
          response = httpx.get(url, headers=headers)
          if response.status_code != 429:
              return response
          retry_after = int(response.headers.get("Retry-After", 2 ** attempt))
          time.sleep(retry_after)
      return response
  ```

  ```javascript Node.js theme={null}
  async function requestWithRetry(url, headers, maxRetries = 3) {
    for (let attempt = 0; attempt < maxRetries; attempt++) {
      const response = await fetch(url, { headers });
      if (response.status !== 429) return response;
      const retryAfter = parseInt(response.headers.get("Retry-After") || 2 ** attempt);
      await new Promise((r) => setTimeout(r, retryAfter * 1000));
    }
  }
  ```
</CodeGroup>

## Buenas Prácticas

* **Monitorea el header `X-RateLimit-Remaining`** para reducir la velocidad proactivamente antes de alcanzar el límite.
* **Cachea las respuestas** cuando los datos no cambian frecuentemente — especialmente catálogos de productos.
* **Agrupa tu trabajo** — solicita páginas más grandes (hasta `limit=100`) para reducir el número de peticiones.
* **Respeta `Retry-After`** — siempre espera el tiempo indicado antes de reintentar, en lugar de usar un delay fijo.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.