# 错误429：超过速率限制 — Retry-After标头缺失或格式错误

- **ID:** `llm/rate-limit-with-retry-after-header-misread`
- **领域:** llm
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 87%

## 根因

API返回429错误，但缺少Retry-After标头或标头不符合标准，导致自动重试逻辑失败或使用错误的等待时间。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| openai==1.16.0 | active | — | — |
| anthropic==0.30.0 | active | — | — |
| requests==2.31.0 | active | — | — |
| httpx==0.27.0 | active | — | — |
| gpt-4-turbo-2024-04-09 | active | — | — |
| claude-3-opus-20240229 | active | — | — |

## 解决方案

1. ```
   实现一个自定义重试处理器，首先检查Retry-After标头；如果缺失，使用默认的指数退避（例如，1秒、2秒、4秒），最多60秒。
   ```
2. ```
   使用第三方重试库如`tenacity`，配合自定义重试条件，优雅地处理缺失的Retry-After标头。
   ```

## 无效尝试

- **** — Hardcoding a fixed retry delay (e.g., 10 seconds) may be too short or too long, leading to repeated 429s or unnecessary waiting. (75% 失败率)
- **** — Ignoring the Retry-After header and using exponential backoff from scratch can cause multiple rapid retries that all fail. (80% 失败率)
- **** — Switching to a different HTTP library (e.g., from requests to httpx) doesn't fix missing headers from the server. (90% 失败率)
