From 02d55be89121513e4dd687cdcae4e387b10b8fc4 Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Balusu Date: Thu, 2 Apr 2026 08:50:59 -0700 Subject: [PATCH] fix: use direct attribute access for enforce_openai_completion_token_invariant Replace getattr() with direct attribute access so CodeQL can trace the usage of the module-level variable. --- litellm/litellm_core_utils/streaming_chunk_builder_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litellm/litellm_core_utils/streaming_chunk_builder_utils.py b/litellm/litellm_core_utils/streaming_chunk_builder_utils.py index ab904c0e16d..5bd3f5a6b4a 100644 --- a/litellm/litellm_core_utils/streaming_chunk_builder_utils.py +++ b/litellm/litellm_core_utils/streaming_chunk_builder_utils.py @@ -728,7 +728,7 @@ class ChunkProcessor: # Gate behind litellm.enforce_openai_completion_token_invariant so # operators who rely on raw backend values can opt out. if ( - getattr(litellm, "enforce_openai_completion_token_invariant", True) + litellm.enforce_openai_completion_token_invariant and returned_usage.completion_tokens_details is not None and returned_usage.completion_tokens_details.reasoning_tokens is not None and returned_usage.completion_tokens_details.reasoning_tokens