Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add token rate limiter to prevent Anthropic/OpenAI rate limit errors #443

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

im0xMagnus
Copy link

Rate Limiter for Anthropic API Requests

Problem

OpenManus users are experiencing rate limit errors (HTTP 429) when using Anthropic's Claude 3.7 API, which has a limit of 20,000 input tokens per minute. The current retry mechanism doesn't effectively handle these rate limits.

Solution

This PR adds:

  1. A token rate limiter that tracks API usage and proactively waits when approaching limits
  2. A more intelligent retry strategy specifically for rate limit errors
  3. Proper Anthropic API integration with message format conversion
  4. Token estimation to predict usage before sending requests

Benefits

  • Prevents API rate limit errors by managing token usage proactively
  • Provides informative log messages when approaching limits
  • Makes OpenManus more resilient during heavy usage
  • Improves user experience by reducing errors

Testing

Tested with Anthropic APIs under heavy load scenarios.

@hyperchi
Copy link

hyperchi commented Mar 11, 2025

this is what i was trying to solve too! TY so much.

BTW, can you also add readme and associated config exmaple changes for ppl to read

@im0xMagnus
Copy link
Author

this is what i was trying to solve too! TY so much.

BTW, can you also add readme and associated config exmaple changes for ppl to read

Will work on that next for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants