From bd5740a3675dcf9e8e5b524f36a010cf5fd74a36 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Mon, 13 Apr 2026 16:42:15 -0700 Subject: [PATCH] fix(streaming): skip role-only first chunk when logprobs.content is empty When logprobs are requested, OpenAI's first streaming chunk has role='assistant' and logprobs=ChoiceLogprobs(content=[]). The Azure streaming fix (PR #25638) made is_chunk_non_empty() treat any first chunk with a non-None role as non-empty, which caused this role-only chunk to be emitted. Callers checking 'logprobs in chunk.choices[0]' then crashed on logprobs.content[0] (IndexError: list index out of range). Guard the role condition: don't emit the first chunk as non-empty when logprobs is present but has no content entries. Azure's use case (no logprobs, empty choices[]) is unaffected. --- litellm/litellm_core_utils/streaming_handler.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/litellm/litellm_core_utils/streaming_handler.py b/litellm/litellm_core_utils/streaming_handler.py index 1ae79f74087..ca5f6a2f6db 100644 --- a/litellm/litellm_core_utils/streaming_handler.py +++ b/litellm/litellm_core_utils/streaming_handler.py @@ -839,6 +839,10 @@ class CustomStreamWrapper: not self.sent_first_chunk and hasattr(model_response.choices[0].delta, "role") and model_response.choices[0].delta.role is not None + and not ( + model_response.choices[0].logprobs is not None + and not model_response.choices[0].logprobs.content + ) ) ): return True