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
fix(azure_ai): strip non-OpenAI-spec message fields before request
ayaangazalidb061d6e3118
diff --git a/litellm/llms/azure_ai/chat/transformation.py b/litellm/llms/azure_ai/chat/transformation.pyindex 5540d79f667..683c05cfbaa 100644--- a/litellm/llms/azure_ai/chat/transformation.py+++ b/litellm/llms/azure_ai/chat/transformation.py@@ -11,6 +11,7 @@ from litellm._logging import verbose_loggerfrom litellm.litellm_core_utils.prompt_templates.common_utils import (_audio_or_image_in_message_content,convert_content_list_to_str,+ filter_value_from_dict,)from litellm.llms.azure.common_utils import BaseAzureLLMfrom litellm.llms.base_llm.chat.transformation import LiteLLMLoggingObj@@ -28,6 +29,13 @@ class AzureFoundryErrorStrings(str, enum.Enum):SET_EXTRA_PARAMETERS_TO_PASS_THROUGH = "Set extra-parameters to 'pass-through'"+NON_OPENAI_SPEC_MESSAGE_FIELDS = (+ "thinking_blocks",+ "provider_specific_fields",+ "cache_control",+)++class AzureAIStudioConfig(OpenAIConfig):def get_supported_openai_params(self, model: str) -> list:model_supports_tool_choice = True # azure ai supports this by default@@ -167,10 +175,19 @@ class AzureAIStudioConfig(OpenAIConfig):) -> list:"""- Azure AI Studio doesn't support content as a list. This handles:- 1. Transforms list content to a string.- 2. If message contains an image or audio, send as is (user-intended)+ 1. Strips message fields that are not part of the OpenAI chat-completions+ schema (thinking_blocks, provider_specific_fields, cache_control).+ Azure AI Foundry backends set additionalProperties=false and reject+ these with "Extra inputs are not permitted", which breaks multi-turn+ Anthropic-format clients that echo thinking blocks back as history.+ 2. Transforms list content to a string.+ 3. If message contains an image or audio, send as is (user-intended)"""for message in messages:+ message_dict = cast(dict, message) # cast-ok: TypedDict is a runtime dict stripped in place+ for field in NON_OPENAI_SPEC_MESSAGE_FIELDS:+ filter_value_from_dict(message_dict, field)+# Do nothing if the message contains an image or audioif _audio_or_image_in_message_content(message):continuediff --git a/tests/test_litellm/llms/azure_ai/chat/test_azure_ai_transformation.py b/tests/test_litellm/llms/azure_ai/chat/test_azure_ai_transformation.pyindex 2e75039139c..80c4355b560 100644--- a/tests/test_litellm/llms/azure_ai/chat/test_azure_ai_transformation.py+++ b/tests/test_litellm/llms/azure_ai/chat/test_azure_ai_transformation.py@@ -262,3 +262,75 @@ def test_drop_tool_level_extra_fields_strips_copilot_mcp_server_name():assert "copilot_mcp_server_name" not in toolassert result["tools"][0]["type"] == "function"assert result["tools"][1]["function"]["name"] == "read_file"+++def _find_key_anywhere(obj, key: str) -> bool:+ if isinstance(obj, dict):+ if key in obj:+ return True+ return any(_find_key_anywhere(v, key) for v in obj.values())+ if isinstance(obj, list):+ return any(_find_key_anywhere(item, key) for item in obj)+ return False+++def test_azure_ai_strips_non_openai_spec_message_fields():+ """+ Regression for https://github.com/BerriAI/litellm/issues/33961.++ Azure AI Foundry backends set additionalProperties=false, so any message+ field outside the OpenAI chat-completions schema causes a 400 "Extra inputs+ are not permitted". Anthropic-format clients (e.g. Claude Code) echo prior+ assistant turns back as history carrying thinking_blocks, a nested thought+ signature at tool_calls[].function.provider_specific_fields, and Anthropic+ cache_control annotations. transform_request must strip all of these before+ the request reaches the upstream.+ """+ config = AzureAIStudioConfig()++ messages = [+ {"role": "user", "content": "Read a file."},+ {+ "role": "assistant",+ "content": "I can help.",+ "thinking_blocks": [+ {+ "type": "thinking",+ "thinking": "The user wants me to read a file.",+ "signature": "",+ "cache_control": {"type": "ephemeral"},+ }+ ],+ "provider_specific_fields": {"thought_signature": "sig-top"},+ "tool_calls": [+ {+ "id": "call_1",+ "type": "function",+ "function": {+ "name": "read_file",+ "arguments": "{}",+ "provider_specific_fields": {"thought_signature": "sig-nested"},+ },+ }+ ],+ },+ {"role": "user", "content": "go ahead"},+ ]++ request = config.transform_request(+ model="fw-glm-5.2",+ messages=messages,+ optional_params={},+ litellm_params={},+ headers={},+ )++ transformed_messages = request["messages"]++ assert not _find_key_anywhere(transformed_messages, "thinking_blocks")+ assert not _find_key_anywhere(transformed_messages, "provider_specific_fields")+ assert not _find_key_anywhere(transformed_messages, "cache_control")++ assistant_message = transformed_messages[1]+ assert assistant_message["content"] == "I can help."+ assert assistant_message["tool_calls"][0]["function"]["name"] == "read_file"