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

# 速率限制

> API 速率限制和配额

## 概览

KillB 实施速率限制以确保公平使用和系统稳定性。

## 速率限制

| 环境 | 每秒请求数 | 突发  |
| -- | ----- | --- |
| 沙盒 | 100   | 200 |
| 生产 | 50    | 100 |

## 标头

响应包含速率限制标头：

```
X-RateLimit-Limit: 50
X-RateLimit-Remaining: 45
X-RateLimit-Reset: 1704657600
```

## 处理速率限制

```javascript theme={null}
const makeRequestWithRetry = async (url, options) => {
  const response = await fetch(url, options);
  
  if (response.status === 429) {
    const resetTime = response.headers.get('X-RateLimit-Reset');
    const waitTime = (resetTime * 1000) - Date.now();
    
    await new Promise(resolve => setTimeout(resolve, waitTime));
    return makeRequestWithRetry(url, options);
  }
  
  return response;
};
```

## 最佳实践

<AccordionGroup>
  <Accordion title="实现退避" icon="clock">
    在速率限制时等待，不要频繁重试
  </Accordion>

  <Accordion title="缓存响应" icon="database">
    缓存用户数据并减少 API 调用
  </Accordion>

  <Accordion title="使用 Webhooks" icon="bell">
    使用 webhooks 避免轮询
  </Accordion>

  <Accordion title="批量操作" icon="layer-group">
    将相关操作分组在一起
  </Accordion>
</AccordionGroup>

## 下一步

<Card title="最佳实践" icon="star" href="/zh/resources/best-practices">
  生产集成技巧
</Card>
