Feature request: automatic back-off + prompt/token optimiser to avoid rate-limit exits
Summary
The CLI currently stops immediately when hitting TPM limits.
Adding an auto-back-off / retry mechanism and an optional token-usage report would:
- Prevent unexpected exits (see related bug report).
- Help users trim prompts before submission.
Current version / environment
- Codex CLI rev: v0.1.2504161551
- Model: o4-mini
- Platform: Darwin 24.4.0 arm64 arm
Proposed behaviour
-
Retry logic
- Config flags:
--max-retries,--base-delay-ms,--max-delay-ms. - Respect
x-ratelimit-resetor fallback to the numeric seconds in the error message.
- Config flags:
-
Token usage insight
- After each request, optionally print:
Prompt: 18 452 tok Completion: 53 432 tok Total: 71 884 tok - Provide tips (“Consider removing large binary blobs or minified JS”).
- After each request, optionally print:
-
Docs update
- Add a “Reducing token usage” section with concrete examples (e.g., strip comments, use
<<file:README.md#L1-L200>>inclusions).
- Add a “Reducing token usage” section with concrete examples (e.g., strip comments, use
Additional information
Similar SDKs (Python / JS official clients) already expose openai.error.RateLimitError handling examples.
Having parity in the CLI would improve UX and reduce load on the API.
An implementation of exponential backoff was released in 0.1.2504221401, however even with this newer version I am experiencing frequent crashes due to rate limits.
Please update to latest version, see https://github.com/openai/codex/blob/main/CHANGELOG.md#012504251709. The version mentioned above is very outdated. The retry logic explain is implemented and I would like to not introduce extra complexity in the form of configurable flags. This should just work well out of the box.
Regarding 2), there is a pending implementation of a /cost command here: https://github.com/openai/codex/pull/322. I am pinging the author to see if they still want to push this forward.
Regarding 3), it's a great idea and in general I'm very supportive of changes that both reduce token usage directly or better inform users on how to configure things better here.
@tibo-openai - I am still experiencing these backoff errors on the later version that includes the "fix" - I left a comment here with the specific error I am experiencing - https://github.com/openai/codex/issues/690#issuecomment-2837467256
Thank you for the detailed feature request! We're primarily focused on the native/Rust implementation of Codex CLI. Please try the latest version, and if this is still an issue, we'd be happy to consider a contribution to the codex-rs/ implementation. Your feedback is invaluable in improving the CLI experience.