llm network_error ai_generated true

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

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

Also available as: JSON · Markdown · 中文
87%Fix Rate
84%Confidence
1Evidence
2024-04-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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

Root Cause

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

中文

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

Official Documentation

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

Workarounds

  1. 90% success Implement a custom retry handler that first checks for Retry-After header; if missing, use a default exponential backoff (e.g., 1s, 2s, 4s) up to a max of 60 seconds.
    Implement a custom retry handler that first checks for Retry-After header; if missing, use a default exponential backoff (e.g., 1s, 2s, 4s) up to a max of 60 seconds.
  2. 85% success Use a third-party retry library like `tenacity` with a custom retry condition that handles missing Retry-After headers gracefully.
    Use a third-party retry library like `tenacity` with a custom retry condition that handles missing Retry-After headers gracefully.

中文步骤

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

Dead Ends

Common approaches that don't work:

  1. 75% fail

    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% fail

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

  3. 90% fail

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