fix: generalize RateLimitError handling to support Anthropic models#3958
fix: generalize RateLimitError handling to support Anthropic models#3958r266-tech wants to merge 1 commit intocamel-ai:masterfrom
Conversation
The retry logic in _get_model_response and _aget_model_response only caught openai.RateLimitError, causing Anthropic rate limit errors to propagate as unhandled exceptions. This fix adds anthropic.RateLimitError to the caught exception tuple via a try/except import that gracefully falls back when anthropic is not installed. Fixes camel-ai#3882
There was a problem hiding this comment.
Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit in Settings → Usage.
Once credits are available, reopen this pull request to trigger a review.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can use TruffleHog to scan for secrets in your code with verification capabilities.Add a TruffleHog config file (e.g. trufflehog-config.yml, trufflehog.yml) to your project to customize detectors and scanning behavior. The tool runs only when a config file is present. |
| try: | ||
| from anthropic import RateLimitError as AnthropicRateLimitError | ||
|
|
||
| _RATE_LIMIT_ERRORS: tuple = (RateLimitError, AnthropicRateLimitError) | ||
| except ImportError: | ||
| _RATE_LIMIT_ERRORS: tuple = (RateLimitError,) # type: ignore[misc] |
There was a problem hiding this comment.
i think we also need to think about cases that not using OpenAI or Anthropic clients
Problem
The retry logic in and only catches , causing Anthropic (and potentially other provider) rate limit errors to propagate as unhandled exceptions.
Fixes #3882
Solution
Changes
Testing
The fix is backward-compatible: when anthropic is not installed, it falls back to catching only as before.