Skip to content

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]

chore: merge litellm_internal_staging into devin_ai_fix_lit5034_empty_choices

Devin AI4068b4a2f089
diff --cc litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py
index 194cbcc9327,2d7589a8715..aeb990c7bb4
--- a/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py
+++ b/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py
@@@ -329,27 -348,7 +348,27 @@@ class AnthropicStreamWrapper(AdapterCom
merged_chunk["context_management"] = ContextManagementResponse(applied_edits=list(self.applied_edits))
return self._augment_message_delta_usage(merged_chunk)
+ def _handle_choiceless_chunk(self, chunk: Any) -> bool:
+ """Consume an OpenAI-compatible chunk that carries no ``choices``.
+
+ ``choices`` is legitimately empty on metadata-only chunks; the final
+ usage chunk emitted when ``stream_options.include_usage`` is set is the
+ common case (vLLM and other OpenAI-compatible servers do this). Such a
+ chunk carries no content-block information, so the caller must not run
+ the content-block state machine over it.
+
+ Returns True when a merged ``message_delta`` was queued (usage folded
+ into the held stop-reason chunk); False when the chunk should be
+ skipped entirely.
+ """
+ if self.holding_stop_reason_chunk is not None and getattr(chunk, "usage", None) is not None:
+ self.chunk_queue.append(self._merge_usage_into_held_stop_reason_chunk(chunk))
+ self.queued_usage_chunk = True
+ self.holding_stop_reason_chunk = None
+ return True
+ return False
+
- def _ensure_context_management_attached(self, message_delta_chunk: Dict[str, Any]) -> Dict[str, Any]:
+ def _ensure_context_management_attached(self, message_delta_chunk: MessageBlockDelta) -> MessageBlockDelta:
"""Attach ``context_management`` to a ``message_delta`` chunk if
``self.applied_edits`` is non-empty and the chunk does not already
carry it. Returns the (possibly new) chunk dict.