From e0b42d51dbefbf0d58c2273dd7a53335848ea8bf Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Fri, 4 Apr 2025 21:45:56 +1300 Subject: [PATCH] fix: Do not retry litellm.APIError for insufficient credits. --- aider/exceptions.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/aider/exceptions.py b/aider/exceptions.py index 0170ce5da..a81a058e0 100644 --- a/aider/exceptions.py +++ b/aider/exceptions.py @@ -92,4 +92,16 @@ class LiteLLMExceptions: " limiting your requests." ), ) + + # Check for specific non-retryable APIError cases like insufficient credits + if ex.__class__ is litellm.APIError: + err_str = str(ex).lower() + if "insufficient credits" in err_str and '"code":402' in err_str: + return ExInfo( + "APIError", + False, + "Insufficient credits with the API provider. Please add credits.", + ) + # Fall through to default APIError handling if not the specific credits error + return self.exceptions.get(ex.__class__, ExInfo(None, None, None))