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

# Rate Limits

> Understanding and handling rate limits in the Shopi Storefront SDK

## Limits

Rate limits are enforced **per API key** with a sliding window of 60 seconds. The limit is set by the shop owner when generating the key from the seller dashboard.

The SDK automatically retries `429` responses — you only need to handle them if all retries are exhausted.

## Checking remaining requests

After every successful request, the SDK populates `shop.rateLimit` with the current window state:

```typescript theme={null}
const shop = new Shopi({ apiKey: process.env.SHOPI_API_KEY! });

await shop.products.list();

console.log(shop.rateLimit);
// {
//   limit: 60,        // max requests per window
//   remaining: 58,    // requests left in current window
//   reset: 1714000060 // unix timestamp when window resets
// }
```

## Displaying rate limit state in UI

```typescript theme={null}
function getRateLimitStatus(shop: Shopi) {
  if (!shop.rateLimit) return null;

  const { remaining, limit, reset } = shop.rateLimit;
  const resetIn = Math.max(0, reset - Math.floor(Date.now() / 1000));

  return {
    remaining,
    limit,
    resetIn, // seconds until window resets
    isLow: remaining < 10,
  };
}
```

## Handling 429 in UI

```typescript theme={null}
import { ShopiError } from '@shopi-lk/storefront-sdk';

try {
  await shop.products.list();
} catch (error) {
  if (error instanceof ShopiError && error.status === 429) {
    // SDK already retried twice — genuinely rate limited
    showToast('Too many requests. Please wait a moment.');
  }
}
```

<Note>
  The SDK retries `429` responses automatically using the `Retry-After` header. Your catch block only runs if all retries are exhausted.
</Note>
