From 11addf2de0622f092ec4b8a4e1f8f7aac6edeb16 Mon Sep 17 00:00:00 2001 From: soroush5 Date: Fri, 4 Sep 2026 19:56:26 +0330 Subject: [PATCH] fix(budget): avoid remote image fetch in projected cost --- litellm/budget_manager.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/litellm/budget_manager.py b/litellm/budget_manager.py index 49060117670..742f648d224 100644 --- a/litellm/budget_manager.py +++ b/litellm/budget_manager.py @@ -100,7 +100,10 @@ class BudgetManager: return self.user_dict[user] def projected_cost(self, model: str, messages: list, user: str): - prompt_tokens: Final = litellm.token_counter(model=model, messages=messages) + # Fixed image estimate: a budget check must never fetch remote + # image URLs (unbounded/chunked bodies exhaust memory, and a check + # should not do network I/O at all). + prompt_tokens: Final = litellm.token_counter(model=model, messages=messages, use_default_image_token_count=True) prompt_cost, _ = litellm.cost_per_token(model=model, prompt_tokens=prompt_tokens, completion_tokens=0) current_cost: Final = self.user_dict[user].get("current_cost", 0) projected_cost: Final = prompt_cost + current_cost