> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-rn-guide-message-privately.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Rate Limits

> Understand CometChat JavaScript SDK and REST API rate limits, response headers, 429 errors, and retry handling.

### CometChat REST API Rate Limits

<Note>
  Rate limits are cumulative within each tier. For example, if you make 5,000
  login requests and 5,000 create user requests in one minute, you've hit the
  10,000 core operations limit.
</Note>

## Response Headers

CometChat includes rate limit information in response headers:

| Header                   | Description                               |
| ------------------------ | ----------------------------------------- |
| `X-Rate-Limit`           | Your current rate limit                   |
| `X-Rate-Limit-Remaining` | Requests remaining in current window      |
| `Retry-After`            | Seconds to wait before retrying (on 429)  |
| `X-Rate-Limit-Reset`     | Unix timestamp when limit resets (on 429) |

## Handling Rate Limits

When you exceed the rate limit, CometChat returns HTTP `429 Too Many Requests`. Implement exponential backoff to handle this gracefully:

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={null}
    async function callWithRetry<T>(
      apiCall: () => Promise<T>,
      maxRetries: number = 3
    ): Promise<T> {
      for (let attempt = 0; attempt < maxRetries; attempt++) {
        try {
          return await apiCall();
        } catch (error: any) {
          if (error.code === "TOO_MANY_REQUEST" && attempt < maxRetries - 1) {
            const waitTime = Math.pow(2, attempt) * 1000;
            console.log(`Rate limited. Retrying in ${waitTime / 1000}s...`);
            await new Promise((resolve) => setTimeout(resolve, waitTime));
          } else {
            throw error;
          }
        }
      }
      throw new Error("Max retries exceeded");
    }

    // Usage
    const users: CometChat.User[] = await callWithRetry(() =>
    new CometChat.UsersRequestBuilder().setLimit(30).build().fetchNext()
    );

    ```
  </Tab>

  <Tab title="JavaScript">
    ```javascript theme={null}
    async function callWithRetry(apiCall, maxRetries = 3) {
      for (let attempt = 0; attempt < maxRetries; attempt++) {
        try {
          return await apiCall();
        } catch (error) {
          if (error.code === "TOO_MANY_REQUEST" && attempt < maxRetries - 1) {
            const waitTime = Math.pow(2, attempt) * 1000; // 1s, 2s, 4s
            console.log(`Rate limited. Retrying in ${waitTime / 1000}s...`);
            await new Promise((resolve) => setTimeout(resolve, waitTime));
          } else {
            throw error;
          }
        }
      }
    }

    // Usage
    const users = await callWithRetry(() =>
      new CometChat.UsersRequestBuilder().setLimit(30).build().fetchNext()
    );
    ```
  </Tab>
</Tabs>

## Tips for Staying Within Limits

* **Batch operations** — Space out bulk operations over time instead of firing all at once
* **Monitor headers** — Check `X-Rate-Limit-Remaining` to proactively slow down before hitting limits
* **Avoid frequent login/logout** — Core operations share a lower limit; minimize login cycles
* **Use pagination** — Fetch data in reasonable page sizes (30-50 items) rather than requesting everything at once

<Note>
  Rate limits can be adjusted based on your use case and plan. Contact CometChat
  support if you need higher limits.
</Note>

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Error Codes" icon="triangle-exclamation" href="/sdk/javascript/error-codes">
    Complete SDK error code reference
  </Card>

  <Card title="Best Practices" icon="star" href="/sdk/javascript/best-practices">
    Recommended patterns including rate limit handling
  </Card>

  <Card title="Troubleshooting" icon="wrench" href="/sdk/javascript/troubleshooting">
    Common issues and solutions
  </Card>

  <Card title="Key Concepts" icon="book" href="/sdk/javascript/key-concepts">
    Learn the core concepts behind CometChat
  </Card>
</CardGroup>
