add anthropic RateLimitError to list of defined rate limit errors

This commit is contained in:
Alezander9
2025-03-30 13:59:05 -07:00
parent 23d5bc495e
commit 207fc7fca4

View File

@@ -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