From 2233f764af2cbe215d2a4109b15a3c9d34c70854 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Tue, 24 Mar 2026 07:23:07 -0700 Subject: [PATCH] fix(tools): handle 402 insufficient credits error in vision tool (#2802) Co-authored-by: Dilee --- tools/vision_tools.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/vision_tools.py b/tools/vision_tools.py index 6cc35437..f27fbfa6 100644 --- a/tools/vision_tools.py +++ b/tools/vision_tools.py @@ -375,6 +375,13 @@ async def vision_analyze_tool( # so it can inform the user instead of a cryptic API error. err_str = str(e).lower() if any(hint in err_str for hint in ( + "402", "insufficient", "payment required", "credits", "billing", + )): + analysis = ( + "Insufficient credits or payment required. Please top up your " + f"API provider account and try again. Error: {e}" + ) + elif any(hint in err_str for hint in ( "does not support", "not support image", "invalid_request", "content_policy", "image_url", "multimodal", "unrecognized request argument", "image input",