Skip to content

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

Closed

Description

@lucasrod

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.

Activity

  1. e-e-e commented on Apr 27, 2025

    @e-e-e

    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.

  2. tibo-openai commented on Apr 29, 2025

    @tibo-openai
    Collaborator

    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: #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.

  3. e-e-e commented on Apr 29, 2025

    @e-e-e

    @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 - #690 (comment)

  4. codex-maintainers commented on Aug 7, 2025

    @codex-maintainers

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions