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
chore: merge litellm_internal_staging into fix/anthropic-responses-refusal-translation
ryan-crabbe-berri5aedd2dcd88e
diff --cc litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.pyindex 66fcad474d5,32b8cbe6343..adf77dc3dd5--- a/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py+++ b/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py@@@ -997,33 -993,8 +997,33 @@@ class AnthropicStreamWrapper(AdapterComdef _increment_content_block_index(self):self.current_content_block_index += 1+ def _with_refusal_stop_details(+ self,+ processed_chunk: ContentBlockDelta | MessageBlockDelta,+ ) -> ContentBlockDelta | MessageBlockDelta:+ if processed_chunk.get("type") != "message_delta" or not self._refusal_text_parts:+ return processed_chunk+ delta: Final = cast(Mapping[str, object], processed_chunk["delta"]) # cast-ok: keys checked before use+ if delta.get("stop_reason") == "max_tokens":+ return processed_chunk+ return cast( # cast-ok: rebuilt dict matches the message_delta TypedDict shape for this branch+ ContentBlockDelta | MessageBlockDelta,+ { # mutable-ok: fresh translation payload; never mutated after construction+ **processed_chunk,+ "delta": { # mutable-ok: fresh message_delta payload; never mutated after construction+ **delta,+ "stop_reason": "refusal",+ "stop_details": { # mutable-ok: fresh stop_details payload; never mutated after construction+ "type": "refusal",+ "category": None,+ "explanation": "".join(self._refusal_text_parts),+ },+ },+ },+ )+@staticmethod- def _delta_has_content(processed_chunk: dict[str, Any]) -> bool:+ def _delta_has_content(processed_chunk: Mapping[str, object]) -> bool:"""Return True if a translated chunk carries a non-empty``content_block_delta`` payload.diff --cc litellm/llms/anthropic/experimental_pass_through/responses_adapters/streaming_iterator.pyindex 8e5ce77e48f,b0aba386753..06ffcd26d40--- a/litellm/llms/anthropic/experimental_pass_through/responses_adapters/streaming_iterator.py+++ b/litellm/llms/anthropic/experimental_pass_through/responses_adapters/streaming_iterator.py@@@ -49,11 -48,9 +49,11 @@@ class AnthropicResponsesStreamWrapperself._pending_tool_ids: dict[str, str] = {} # item_id -> call_id / name accumulatorself._sent_message_start = Falseself._sent_message_stop = False- self._chunk_queue: deque = deque()+ self._chunk_queue: deque[dict[str, object]] = deque()+ self._refusal_text_parts: list[str] = [] # mutable-ok: accumulates streamed refusal delta text across chunks+ self._sync_responses_iterator: Any = None- def _make_message_start(self) -> dict[str, Any]:+ def _make_message_start(self) -> dict[str, object]:return {"type": "message_start","message": {