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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(streaming): return None from count_reasoning_tokens when no reasoning content found (#23076)
Ishaan Jaff517a929ccdfd
diff --git a/litellm/litellm_core_utils/streaming_chunk_builder_utils.py b/litellm/litellm_core_utils/streaming_chunk_builder_utils.pyindex 143d87ebf34..ba35a2c7cad 100644--- a/litellm/litellm_core_utils/streaming_chunk_builder_utils.py+++ b/litellm/litellm_core_utils/streaming_chunk_builder_utils.py@@ -476,13 +476,15 @@ class ChunkProcessor:"prompt_tokens_details": prompt_tokens_details,}- def count_reasoning_tokens(self, response: ModelResponse) -> int:- reasoning_tokens = 0+ def count_reasoning_tokens(self, response: ModelResponse) -> Optional[int]:+ reasoning_tokens: Optional[int] = Nonefor choice in response.choices:if (hasattr(cast(Choices, choice).message, "reasoning_content")and cast(Choices, choice).message.reasoning_content is not None):+ if reasoning_tokens is None:+ reasoning_tokens = 0reasoning_tokens += token_counter(text=cast(Choices, choice).message.reasoning_content,count_response_tokens=True,