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
Return `signature` on anthropic streaming + migrate to `signature` field instead of `signature_delta` [MINOR bump] (#9021)
Krish Dholakiaec4f665e299b
diff --git a/litellm/litellm_core_utils/prompt_templates/factory.py b/litellm/litellm_core_utils/prompt_templates/factory.pyindex d8ecd14d387..93c5013fc6f 100644--- a/litellm/litellm_core_utils/prompt_templates/factory.py+++ b/litellm/litellm_core_utils/prompt_templates/factory.py@@ -2983,7 +2983,7 @@ class BedrockConverseMessagesProcessor:reasoning_content_blocks: List[BedrockContentBlock] = []for thinking_block in thinking_blocks:reasoning_text = thinking_block.get("thinking")- reasoning_signature = thinking_block.get("signature_delta")+ reasoning_signature = thinking_block.get("signature")text_block = BedrockConverseReasoningTextBlock(text=reasoning_text or "",)diff --git a/litellm/llms/anthropic/chat/handler.py b/litellm/llms/anthropic/chat/handler.pyindex 46c8edae034..04edb407549 100644--- a/litellm/llms/anthropic/chat/handler.py+++ b/litellm/llms/anthropic/chat/handler.py@@ -527,6 +527,7 @@ class ModelResponseIterator:provider_specific_fields = {}content_block = ContentBlockDelta(**chunk) # type: ignorethinking_blocks: List[ChatCompletionThinkingBlock] = []+self.content_blocks.append(content_block)if "text" in content_block["delta"]:text = content_block["delta"]["text"]@@ -544,13 +545,13 @@ class ModelResponseIterator:provider_specific_fields["citation"] = content_block["delta"]["citation"]elif ("thinking" in content_block["delta"]- or "signature_delta" == content_block["delta"]+ or "signature" in content_block["delta"]):thinking_blocks = [ChatCompletionThinkingBlock(type="thinking",- thinking=content_block["delta"].get("thinking"),- signature_delta=content_block["delta"].get("signature"),+ thinking=content_block["delta"].get("thinking") or "",+ signature=content_block["delta"].get("signature"),)]provider_specific_fields["thinking_blocks"] = thinking_blocksdiff --git a/litellm/llms/bedrock/chat/converse_transformation.py b/litellm/llms/bedrock/chat/converse_transformation.pyindex 18ec425e444..0b0d55f23d7 100644--- a/litellm/llms/bedrock/chat/converse_transformation.py+++ b/litellm/llms/bedrock/chat/converse_transformation.py@@ -272,7 +272,7 @@ class AmazonConverseConfig(BaseConfig):optional_params["temperature"] = valueif param == "top_p":optional_params["topP"] = value- if param == "tools":+ if param == "tools" and isinstance(value, list):optional_params = self._add_tools_to_optional_params(optional_params=optional_params, tools=value)@@ -598,7 +598,7 @@ class AmazonConverseConfig(BaseConfig):if _text is not None:_thinking_block["thinking"] = _textif _signature is not None:- _thinking_block["signature_delta"] = _signature+ _thinking_block["signature"] = _signaturethinking_blocks_list.append(_thinking_block)return thinking_blocks_listdiff --git a/litellm/types/llms/openai.py b/litellm/types/llms/openai.pyindex 77e729daf20..6dce7f33566 100644--- a/litellm/types/llms/openai.py+++ b/litellm/types/llms/openai.py@@ -360,7 +360,7 @@ class ChatCompletionCachedContent(TypedDict):class ChatCompletionThinkingBlock(TypedDict, total=False):type: Required[Literal["thinking"]]thinking: str- signature_delta: str+ signature: strcache_control: Optional[Union[dict, ChatCompletionCachedContent]]diff --git a/tests/llm_translation/test_anthropic_completion.py b/tests/llm_translation/test_anthropic_completion.pyindex df318a80367..20b550e3c24 100644--- a/tests/llm_translation/test_anthropic_completion.py+++ b/tests/llm_translation/test_anthropic_completion.py@@ -1188,18 +1188,20 @@ def test_anthropic_thinking_output(model):assert isinstance(resp.choices[0].message.thinking_blocks, list)assert len(resp.choices[0].message.thinking_blocks) > 0+ assert resp.choices[0].message.thinking_blocks[0]["signature"] is not None+@pytest.mark.parametrize("model",["anthropic/claude-3-7-sonnet-20250219",- "bedrock/us.anthropic.claude-3-7-sonnet-20250219-v1:0",+ # "bedrock/us.anthropic.claude-3-7-sonnet-20250219-v1:0",],)def test_anthropic_thinking_output_stream(model):# litellm.set_verbose = Truetry:- litellm._turn_on_debug()+ # litellm._turn_on_debug()resp = litellm.completion(model=model,messages=[{"role": "user", "content": "Tell me a joke."}],@@ -1209,6 +1211,7 @@ def test_anthropic_thinking_output_stream(model):)reasoning_content_exists = False+ signature_block_exists = Falsefor chunk in resp:print(f"chunk 2: {chunk}")if (@@ -1220,8 +1223,11 @@ def test_anthropic_thinking_output_stream(model):and isinstance(chunk.choices[0].delta.reasoning_content, str)):reasoning_content_exists = True- break+ print(chunk.choices[0].delta.thinking_blocks[0])+ if chunk.choices[0].delta.thinking_blocks[0].get("signature"):+ signature_block_exists = Trueassert reasoning_content_exists+ assert signature_block_existsexcept litellm.Timeout:pytest.skip("Model is timing out")diff --git a/tests/local_testing/test_streaming.py b/tests/local_testing/test_streaming.pyindex f438fdc5c04..668ad12a48e 100644--- a/tests/local_testing/test_streaming.py+++ b/tests/local_testing/test_streaming.py@@ -4084,6 +4084,7 @@ def test_reasoning_content_completion(model):)reasoning_content_exists = False+ signature_delta_exists = Falsefor chunk in resp:print(f"chunk 2: {chunk}")if (@@ -4118,3 +4119,4 @@ def test_is_delta_empty():audio=None,))+