Skip to content

Graceful backoff on rate limits #137

Closed

Description

@RamXX

It's normal to hit rate limits, but the current behavior of codex is to basically crash and abort everything in flight:

[Error]: Rate limit reached for gpt-4.1 in organization org-abcxyz on tokens per min (TPM): Limit 450000, 
Used 368526, Requested 91276. Please try again in 1.306s.

A better behavior would be to take that output, and retry 1.4 seconds later with exponential backoff. Furthermore, given the limits are well-known, an even better behavior would be to display tokens left (or %) and have the CLI be aware enough to influence the AI behavior. For example, at 95% write a plan for a next session, etc.

Activity

  1. tibo-openai commented on Apr 16, 2025

    @tibo-openai
    Collaborator

    Latest version should back-off for 15s and retry. Please upgrade and let me know if you still see this issue.

  2. DanielHou315 commented on Apr 16, 2025

    @DanielHou315

    Built from source with latest pull and still observing rate limit crashes:

    [Error]: Rate limit reached for o4-mini in organization org-abcxyz on tokens per min (TPM): Limit 200000, Used 168699, Requested 41255. Please try again in 2.986s.
    

    There is no sign of 15s backoff in the output.

  3. tibo-openai commented on Apr 17, 2025

    @tibo-openai
    Collaborator

    Could you check from source again, after #153. Thx!

  4. RamXX commented on Apr 17, 2025

    @RamXX
    Author

    I haven't seen the error again since the last time I updated about an hour ago, but I'm not pushing it that hard at the moment... others may chime in. Thanks for the prompt response! (no pun intended 😉 )

  5. kilsbo commented on Apr 17, 2025

    @kilsbo

    I just tested this on the latest main (post-#153) by installing from source:

    git clone https://github.com/openai/codex.git
    cd codex/codex-cli
    npm install
    npm run build
    npm link
    

    I’m still seeing immediate CLI exit on token rate limits with no retry behavior. Example:

    [Error]: Rate limit reached for gpt-4.1 on tokens per min (TPM): Limit 30000, Used 24695, Requested 5446. Please try again in 282ms.
        at iterator (cli.js)
        at async run (cli.js)
    

    So either the retry logic isn’t wired up yet, or it’s not catching this case. Happy to help debug further if needed.

    Cheers

  6. lextoon commented on Apr 17, 2025

    @lextoon

    I still get hit by rate limits as well, crashes and does not know where to resume, so I have to run all instructions again...

    [Error]: Rate limit reached for o4-mini in organization org-BRZky604OkacepMUlEb9lq1i on tokens per min (TPM): Limit 200000, Used 148977, Requested 55092. Please try again in 1.22s. Visit https://platform.openai.com/account/rate-limits to learn more.
    at e.a [as iterator] (file:///Users/XXX/local/codex/codex-cli/dist/cli.js:375:1514)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async E0.run (file:///Users/XXX/local/codex/codex-cli/dist/cli.js:392:2925) {
    status: undefined,
    headers: undefined,
    request_id: undefined,
    error: {
    type: 'tokens',
    code: 'rate_limit_exceeded',
    message: 'Rate limit reached for o4-mini in organization org-BRZky604OkacepMUlEb9lq1i on tokens per min (TPM): Limit 200000, Used 148977, Requested 55092. Please try again in 1.22s. Visit https://platform.openai.com/account/rate-limits to learn more.',
    param: null
    },
    code: 'rate_limit_exceeded',
    param: null,
    type: 'tokens'
    }

    Node.js v22.14.0

    codex --version
    0.1.2504161510

  7. vabole commented on Apr 17, 2025

    @vabole

    Getting the same error
    Codex version: 0.1.2504161551

    [Error]: Rate limit reached for gpt-4.1 in organization org-5MFShhFqaGV0OkehheyElBcz on tokens per min (TPM): Limit 30000, Used 26407, Requested 15377. Please try again in 23.568s. Visit https://platform.openai.com/account/rate-limits to learn more.
        at e.a [as iterator] (file:///opt/homebrew/lib/node_modules/@openai/codex/dist/cli.js:445:1514)
        at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
        at async R0.run (file:///opt/homebrew/lib/node_modules/@openai/codex/dist/cli.js:462:2639) {
      status: undefined,
      headers: undefined,
      request_id: undefined,
      error: {
        type: 'tokens',
        code: 'rate_limit_exceeded',
        message: 'Rate limit reached for gpt-4.1 in organization org-5MFShhFqaGV0OkehheyElBcz on tokens per min (TPM): Limit 30000, Used 26407, Requested 15377. Please try again in 23.568s. Visit https://platform.openai.com/account/rate-limits to learn more.',
        param: null
      },
      code: 'rate_limit_exceeded',
      param: null,
      type: 'tokens'
    }
    
    Node.js v23.11.0
  8. pierresisson commented on Apr 17, 2025

    @pierresisson

    same here!

  9. WASasquatch commented on Apr 20, 2025

    @WASasquatch

    This is unacceptable behavior of this system. It should have inherently been built with cooldown.

    Now I have no option but to wait 7 days (after my first purchase) to get the access I need (if that's even enough). It's such an annoyance and hindrance to my workflow I decided on, and thought I could use, that I want to call, dispute all charges to OpenAI with my bank as a scamming service, and close out and move to services with same features, but bypass all rate limits and token limits with unlimited packages with their own API keys to OpenAI.

    I had been using o4 for days no on Windsurf without any rate limit issues, and it's cheaper by leaps and bounds. Insane.

  10. Yamilquery commented on Apr 21, 2025

    @Yamilquery

    Ok. It seems that I then need to stop using Codex until OpenAI fixes this.

  11. mishgoni commented on Apr 28, 2025

    @mishgoni

    I reached the daily limit of 200 requests (yes, I just signed up) on 4.1-mini. And this was like my second promt. It worked for 15 minutes and then crashed. 🤦‍♂️ Totally useless tool as it can only waste my money and do nothing.

  12. tibo-openai commented on Apr 29, 2025

    @tibo-openai
    Collaborator

    This was fixed a while ago, please ensure that you are running the latest version here: https://github.com/openai/codex/blob/main/CHANGELOG.md#012504251709

    You should see

    $ codex --version
    0.1.2504251709
    
  13. levkk commented on May 24, 2025

    @levkk

    Just got that error again.

    % codex --version
    0.1.2505172129
    
     [Error]: Rate limit reached for gpt-4.1 in organization <ord ID> on tokens per min (TPM): Limit 30000, Used 1271, Requested 29281. Please try again in 1.104s. Visit https://platform.openai.com/account/rate-limits to learn more.
        at e.a [as iterator] (file:///opt/homebrew/lib/node_modules/@openai/codex/dist/cli.js:582:1514)
        at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
        at async ky.run (file:///opt/homebrew/lib/node_modules/@openai/codex/dist/cli.js:599:2785) {
      status: undefined,
      headers: undefined,
      request_id: undefined,
      error: {
        type: 'tokens',
        code: 'rate_limit_exceeded',
        message: 'Rate limit reached for gpt-4.1 in organization <org ID> on tokens per min (TPM): Limit 30000, Used 1271, Requested 29281. Please try again in 1.104s. Visit https://platform.openai.com/account/rate-limits to learn more.',
        param: null
      },
      code: 'rate_limit_exceeded',
      param: null,
      type: 'tokens'
    }
    
  14. cjangrist commented on Aug 10, 2025

    @cjangrist

    Signed up 200/month to try gpt5 . 30k tokens per minute ? .... that means the context window isn't 400k like advertised.... it's 30k....

    Thank God for claude

    Codex as of yesterday still completely crashes and burns when hitting 30k limit, requiring complelty starting new chat.

  15. shenanigans12 commented on Aug 15, 2025

    @shenanigans12

    @tibo-openai

    🖐 stream disconnected before completion: Rate limit reached for gpt-5 in organization org-xxxx on tokens per min (TPM): Limit 30000, Used 23332, Requested 15275. Please try again in 17.214s. Visit https://platform.openai.com/account/rate-limits to learn more.

    codex-cli 0.21.0

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