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