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]

Merge branch 'litellm_internal_staging' into litellm_staging_03_22_2026

Sameer Kankute57eae8d01c2c
diff --cc tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py
index 1a203174e60,e6e96868f33..83b91360324
--- a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py
+++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py
@@@ -2127,156 -2162,16 +2163,170 @@@ class TestTranslateAnthropicOutputForma
assert sorted(schema["required"]) == ["age", "email", "name"]
def test_invalid_output_format_returns_none(self):
+ assert self.adapter.translate_anthropic_output_format_to_openai("invalid") is None
+ assert self.adapter.translate_anthropic_output_format_to_openai({"type": "text"}) is None
+ assert self.adapter.translate_anthropic_output_format_to_openai({"type": "json_schema"}) is None
+ assert (
+ self.adapter.translate_anthropic_output_format_to_openai("invalid") is None
+ )
+ assert (
+ self.adapter.translate_anthropic_output_format_to_openai({"type": "text"})
+ is None
+ )
+ assert (
+ self.adapter.translate_anthropic_output_format_to_openai(
+ {"type": "json_schema"}
+ )
+ is None
+ )
+
+
+class TestAnthropicStreamWrapperToolArgs:
+ """
+ Regression test for https://github.com/BerriAI/litellm/issues/24134
+
+ When Gemini sends tool call args in the same streaming chunk as a content
+ block transition, the Anthropic adapter was discarding the processed_chunk
+ containing input_json_delta. This verifies the args are preserved.
+ """
+
+ def _build_chunks(self):
+ """Build mock OpenAI-format chunks simulating Gemini tool call response."""
+ # Chunk 1: text content
+ text_chunk = ModelResponseStream(
+ id="chatcmpl-123",
+ created=1700000000,
+ model="gemini-2.0-flash",
+ object="chat.completion.chunk",
+ choices=[
+ StreamingChoices(
+ index=0,
+ delta=Delta(content="Let me check", role="assistant"),
+ finish_reason=None,
+ )
+ ],
+ )
+
+ # Chunk 2: tool call (triggers new content block + carries args)
+ tool_chunk = ModelResponseStream(
+ id="chatcmpl-123",
+ created=1700000000,
+ model="gemini-2.0-flash",
+ object="chat.completion.chunk",
+ choices=[
+ StreamingChoices(
+ index=0,
+ delta=Delta(
+ tool_calls=[
+ ChatCompletionDeltaToolCall(
+ id="call_123",
+ type="function",
+ function=Function(
+ name="get_weather",
+ arguments='{"city": "Tokyo"}',
+ ),
+ index=0,
+ )
+ ]
+ ),
+ finish_reason=None,
+ )
+ ],
+ )
+
+ # Chunk 3: finish
+ finish_chunk = ModelResponseStream(
+ id="chatcmpl-123",
+ created=1700000000,
+ model="gemini-2.0-flash",
+ object="chat.completion.chunk",
+ choices=[
+ StreamingChoices(
+ index=0,
+ delta=Delta(),
+ finish_reason="stop",
+ )
+ ],
+ usage=Usage(prompt_tokens=10, completion_tokens=5, total_tokens=15),
+ )
+
+ return [text_chunk, tool_chunk, finish_chunk]
+
+ def _make_stream_wrapper(self, chunks):
+ from litellm.llms.anthropic.experimental_pass_through.adapters.streaming_iterator import (
+ AnthropicStreamWrapper,
+ )
+
+ class SimpleIterator:
+ def __init__(self, items):
+ self._items = iter(items)
+
+ def __iter__(self):
+ return self
+
+ def __next__(self):
+ return next(self._items)
+
+ def __aiter__(self):
+ return self
+
+ async def __anext__(self):
+ try:
+ return next(self._items)
+ except StopIteration:
+ raise StopAsyncIteration
+
+ return AnthropicStreamWrapper(
+ completion_stream=SimpleIterator(chunks),
+ model="gemini/gemini-2.0-flash",
+ )
+
+ def _find_tool_deltas(self, events):
+ return [
+ e for e in events
+ if isinstance(e, dict)
+ and e.get("type") == "content_block_delta"
+ and isinstance(e.get("delta"), dict)
+ and e["delta"].get("type") == "input_json_delta"
+ ]
+
+ def test_sync_tool_args_not_dropped(self):
+ import json
+
+ chunks = self._build_chunks()
+ wrapper = self._make_stream_wrapper(chunks)
+
+ events = list(wrapper)
+ tool_deltas = self._find_tool_deltas(events)
+
+ assert len(tool_deltas) > 0, (
+ f"No input_json_delta events found (issue #24134). "
+ f"Event types: {[e.get('type') for e in events if isinstance(e, dict)]}"
+ )
+
+ combined = "".join(d["delta"]["partial_json"] for d in tool_deltas)
+ parsed = json.loads(combined)
+ assert parsed == {"city": "Tokyo"}
+
+ @pytest.mark.asyncio
+ async def test_async_tool_args_not_dropped(self):
+ import json
+
+ chunks = self._build_chunks()
+ wrapper = self._make_stream_wrapper(chunks)
+
+ events = []
+ async for event in wrapper:
+ events.append(event)
+
+ tool_deltas = self._find_tool_deltas(events)
+
+ assert len(tool_deltas) > 0, (
+ f"No input_json_delta events found (issue #24134). "
+ f"Event types: {[e.get('type') for e in events if isinstance(e, dict)]}"
+ )
+
+ combined = "".join(d["delta"]["partial_json"] for d in tool_deltas)
+ parsed = json.loads(combined)
+ assert parsed == {"city": "Tokyo"}
++