From af81c160190916950ccfec50a1f7079b1eb9e17e Mon Sep 17 00:00:00 2001 From: Mingyang Wu <129849514+aprylewu@users.noreply.github.com> Date: Fri, 11 Sep 2026 17:57:18 +0800 Subject: [PATCH] refactor(token-counter): avoid redundant empty-text guards --- litellm/litellm_core_utils/token_counter.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/litellm/litellm_core_utils/token_counter.py b/litellm/litellm_core_utils/token_counter.py index ca15769ebec..fab54b3109c 100644 --- a/litellm/litellm_core_utils/token_counter.py +++ b/litellm/litellm_core_utils/token_counter.py @@ -892,13 +892,9 @@ def _count_content_list( elif c["type"] == "thinking": # Claude extended thinking content block # Count the thinking text and skip signature (opaque signature blob) - thinking_text = str(c.get("thinking", "")) - if thinking_text: - num_tokens += count_function(thinking_text) + num_tokens += count_function(str(c.get("thinking", ""))) elif c["type"] == "reasoning": - num_tokens += sum( - count_function(text) for summary in c.get("summary", ()) if (text := summary.get("text")) - ) + num_tokens += sum(count_function(summary.get("text", "")) for summary in c.get("summary", ())) elif c["type"] == "tool_reference": # Anthropic tool-search reference block: a lightweight pointer to # a deferred tool, e.g. {"type": "tool_reference", "tool_name": ...}.