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

# 速率限制

> 了解 API 速率限制及如何优化请求

## 默认限制

SeeOneAPI 根据用户分组设定不同的速率限制：

| 限制类型             | 说明                |
| ---------------- | ----------------- |
| RPM（每分钟请求数）      | 控制每分钟的 API 调用次数   |
| TPM（每分钟 Token 数） | 控制每分钟处理的 Token 总量 |

<Info>
  具体限制值取决于你的用户分组，可在控制台查看当前限制。
</Info>

## 响应头

每个 API 响应都会包含速率限制相关的 Header：

```
x-ratelimit-limit-requests: 60
x-ratelimit-remaining-requests: 59
x-ratelimit-reset-requests: 1s
```

## 遇到限速时

当达到速率限制时，API 会返回 `429 Too Many Requests` 错误。建议的处理方式：

```python theme={null}
import time
from openai import OpenAI, RateLimitError

client = OpenAI(
    api_key="sk-你的API密钥",
    base_url="https://api.seeoneapi.com/v1"
)

def call_with_retry(messages, max_retries=3):
    for attempt in range(max_retries):
        try:
            return client.chat.completions.create(
                model="claude-sonnet-4-5-20250929",
                messages=messages
            )
        except RateLimitError:
            wait_time = 2 ** attempt  # 指数退避
            print(f"速率限制，等待 {wait_time} 秒...")
            time.sleep(wait_time)
    raise Exception("多次重试后仍然失败")
```

## 优化建议

* **使用指数退避**：遇到 429 错误时逐步增加等待时间
* **批量处理**：将多个小请求合并为较少的大请求
* **缓存响应**：对相同输入缓存结果，避免重复请求
* **使用流式输出**：流式响应可以更早开始处理，提高整体吞吐量
