Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix: handle None or empty contents in Gemini token counter (#17020)

Haiyi84e8b9a7bf12
diff --git a/litellm/llms/gemini/count_tokens/handler.py b/litellm/llms/gemini/count_tokens/handler.py
index 4d6c7fd8864..fdb77452d4c 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: