Add automatic retry with backoff for rate limit errors
When running Codex, I encountered a rate limit error that caused the entire application to exit immediately:
[Error]: Rate limit reached for o4-mini in organization org-xxxxxxxxxx on tokens per min (TPM): Limit 200000, Used 164863, Requested 38980. Please try again in 1.152s. Visit https://platform.openai.com/account/rate-limits to learn more.
The error message itself suggests waiting 1.152 seconds before retrying, but instead of implementing this wait-and-retry logic, the application exits completely. This results in wasted resources and a poor user experience, as users must manually restart the process.
Environment:
Node.js: v22.14.0
OS: Ubuntu 24 LTS
Proposed Solution:
Implement automatic retry logic with exponential backoff for rate limit errors. Since the API response already specifies the recommended wait time (1.152s in this case), the application could:
Catch rate limit exceptions:
- Parse the suggested wait time from the error message
- Wait for the specified duration (plus a small buffer)
- Automatically retry the request
- Implement a maximum retry count to prevent infinite loops
This would significantly improve user experience and prevent wasted resources.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗