llm network_error ai_generated true

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

Error 429: Rate limit exceeded — Retry-After header missing or malformed

ID: llm/rate-limit-with-retry-after-header-misread

其他格式: JSON · Markdown 中文 · English
87%修复率
84%置信度
1证据数
2024-04-05首次发现

版本兼容性

版本状态引入弃用备注
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

根因分析

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

English

The API returns a 429 error with a missing or non-standard Retry-After header, causing automatic retry logic to fail or use incorrect wait times.

generic

官方文档

https://platform.openai.com/docs/guides/rate-limits/error-mitigation

解决方案

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

无效尝试

常见但无效的做法:

  1. 75% 失败

    Hardcoding a fixed retry delay (e.g., 10 seconds) may be too short or too long, leading to repeated 429s or unnecessary waiting.

  2. 80% 失败

    Ignoring the Retry-After header and using exponential backoff from scratch can cause multiple rapid retries that all fail.

  3. 90% 失败

    Switching to a different HTTP library (e.g., from requests to httpx) doesn't fix missing headers from the server.