codex icon indicating copy to clipboard operation
codex copied to clipboard

Feature request: automatic back-off + prompt/token optimiser to avoid rate-limit exits

Open lucasrod opened this issue 1 year ago • 4 comments

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

  1. Retry logic

    • Config flags: --max-retries, --base-delay-ms, --max-delay-ms.
    • Respect x-ratelimit-reset or fallback to the numeric seconds in the error message.
  2. 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”).
  3. Docs update

    • Add a “Reducing token usage” section with concrete examples (e.g., strip comments, use <<file:README.md#L1-L200>> inclusions).

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.

lucasrod avatar Apr 27 '25 00:04 lucasrod

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.

e-e-e avatar Apr 27 '25 13:04 e-e-e

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 avatar Apr 29 '25 04:04 tibo-openai

@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

e-e-e avatar Apr 29 '25 05:04 e-e-e

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.

codex-maintainers avatar Aug 07 '25 17:08 codex-maintainers