From 84e8b9a7bf12ff415a8f66ab98e758f76cddf50e Mon Sep 17 00:00:00 2001 From: Haiyi Date: Tue, 25 Nov 2025 12:40:00 +1100 Subject: [PATCH] fix: handle None or empty contents in Gemini token counter (#17020) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds null/empty check before processing contents in GoogleAIStudioTokenCounter to prevent errors when contents is None or empty. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude --- litellm/llms/gemini/count_tokens/handler.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/litellm/llms/gemini/count_tokens/handler.py b/litellm/llms/gemini/count_tokens/handler.py index 4d6c7fd886..fdb77452d4 100644 --- a/litellm/llms/gemini/count_tokens/handler.py +++ b/litellm/llms/gemini/count_tokens/handler.py @@ -30,6 +30,10 @@ class GoogleAIStudioTokenCounter: from google.genai.types import FunctionResponse + # Handle None or empty contents + if not contents: + return contents + cleaned_contents = copy.deepcopy(contents) for content in cleaned_contents: