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

# 限流

> 限流维度、429 处理与退避策略

为保障稳定，TokenDog 对请求频率施加限流。超限时返回 HTTP `429 Too Many Requests`。

## 维度

限流通常按 **API 密钥**与**模型分组**计量。具体额度与窗口以控制台中你的套餐为准。

## 处理 429

收到 `429` 时应**退避后重试**，采用指数退避 + 随机抖动，避免雪崩：

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

client = OpenAI(base_url="https://tokendog.io/v1", api_key="YOUR_TOKENDOG_API_KEY")

def chat_with_retry(**kwargs):
    for attempt in range(5):
        try:
            return client.chat.completions.create(**kwargs)
        except RateLimitError:
            time.sleep((2 ** attempt) + random.random())
    raise RuntimeError("rate limited after retries")
```

<Tip>批量任务建议自行做并发上限与排队，平滑请求曲线优于事后重试。</Tip>
