From 207fc7fca40ce7b645bfb8cfa34db927f6dda1cb Mon Sep 17 00:00:00 2001 From: Alezander9 Date: Sun, 30 Mar 2025 13:59:05 -0700 Subject: [PATCH] add anthropic RateLimitError to list of defined rate limit errors --- browser_use/agent/service.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py index bbc13941d..5be172574 100644 --- a/browser_use/agent/service.py +++ b/browser_use/agent/service.py @@ -563,8 +563,16 @@ class Agent(Generic[Context]): else: from google.api_core.exceptions import ResourceExhausted from openai import RateLimitError + from anthropic import RateLimitError as AnthropicRateLimitError - if isinstance(error, RateLimitError) or isinstance(error, ResourceExhausted): + # Define a tuple of rate limit error types for easier maintenance + RATE_LIMIT_ERRORS = ( + RateLimitError, # OpenAI + ResourceExhausted, # Google + AnthropicRateLimitError, # Anthropic + ) + + if isinstance(error, RATE_LIMIT_ERRORS): logger.warning(f'{prefix}{error_msg}') await asyncio.sleep(self.settings.retry_delay) self.state.consecutive_failures += 1