diff --git a/CHANGELOG.md b/CHANGELOG.md index a8f4271..471f3df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - Improve prompts for better open model support. +- Better handle 429 errors on openrouter. ## [0.12.1] - 2025-01-08 - Fix bug where directories are added as related files. diff --git a/ra_aid/agent_utils.py b/ra_aid/agent_utils.py index 564f7aa..5a692fa 100644 --- a/ra_aid/agent_utils.py +++ b/ra_aid/agent_utils.py @@ -552,7 +552,9 @@ def run_agent_with_retry(agent, prompt: str, config: dict) -> Optional[str]: return "Agent run completed successfully" except (KeyboardInterrupt, AgentInterrupt): raise - except (InternalServerError, APITimeoutError, RateLimitError, APIError) as e: + except (InternalServerError, APITimeoutError, RateLimitError, APIError, ValueError) as e: + if isinstance(e, ValueError) and 'code 429' not in str(e): + raise # Re-raise ValueError if it's not a Lambda 429 if attempt == max_retries - 1: logger.error("Max retries reached, failing: %s", str(e)) raise RuntimeError(f"Max retries ({max_retries}) exceeded. Last error: {e}")