Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion litellm/llms/openai/chat/gpt_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ def chunk_parser(self, chunk: dict) -> ModelResponseStream:
choices = self._map_reasoning_to_reasoning_content(choices)

kwargs = {
"id": chunk["id"],
"id": chunk.get("id"),
"object": "chat.completion.chunk",
"created": chunk.get("created"),
"model": chunk.get("model"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,45 @@ def test_chunk_parser_reasoning_field_not_present(self):
# Verify that reasoning_content is not set (it should be deleted by Delta.__init__)
assert not hasattr(parsed_chunk.choices[0].delta, "reasoning_content")

def test_chunk_parser_without_id_field(self):
"""
Test that chunk_parser works when chunk is missing the 'id' field.

Some OpenAI-compatible providers (e.g., MiniMax) return streaming chunks
without an 'id' field in certain cases. This should not raise KeyError.

Regression test for: KeyError: 'id' when using MiniMax m2.5 model
"""
handler = OpenAIChatCompletionStreamingHandler(
streaming_response=None, sync_stream=True
)

# Simulate a chunk without 'id' field (as returned by MiniMax)
chunk = {
"object": "chat.completion.chunk",
"created": 1769511767,
"model": "minimax/m2.5",
"choices": [
{
"delta": {
"content": "Hello",
"role": "assistant",
},
"finish_reason": None,
"index": 0,
}
],
}

# Parse the chunk - should not raise KeyError
parsed_chunk = handler.chunk_parser(chunk)

# Verify that content is present and id was auto-generated
assert parsed_chunk.choices[0].delta.content == "Hello"
assert parsed_chunk.choices[0].delta.role == "assistant"
# ModelResponseStream auto-generates an id when None is passed
assert parsed_chunk.id is not None


class TestPromptCacheKeyIntegration:
"""Tests for prompt_cache_key support"""
Expand Down
Loading