diff --git a/litellm/llms/azure/responses/transformation.py b/litellm/llms/azure/responses/transformation.py index 2a1c2a8555f..44ce368fd49 100644 --- a/litellm/llms/azure/responses/transformation.py +++ b/litellm/llms/azure/responses/transformation.py @@ -132,35 +132,6 @@ class AzureOpenAIResponsesAPIConfig(OpenAIResponsesAPIConfig): new_tools.append(tool) response_api_optional_request_params["tools"] = new_tools - # Azure Responses API expects context_management as an object with "strategies" key, - # and strategy items use "token_threshold" (not OpenAI's "compact_threshold"). - # Inferred from Azure error messages; OpenAI uses array + compact_threshold. - # Ref: https://learn.microsoft.com/azure/ai-foundry/openai/reference - if "context_management" in response_api_optional_request_params: - cm = response_api_optional_request_params["context_management"] - - def _normalize_strategy(item: Any) -> Dict[str, Any]: - if isinstance(item, dict): - strategy = dict(item) - if "compact_threshold" in strategy: - strategy["token_threshold"] = strategy.pop( - "compact_threshold" - ) - return strategy - return item # type: ignore - - if isinstance(cm, list): - strategies = [_normalize_strategy(item) for item in cm] - response_api_optional_request_params["context_management"] = { - "strategies": strategies - } - elif isinstance(cm, dict) and "strategies" in cm: - strategies = [_normalize_strategy(s) for s in cm["strategies"]] - response_api_optional_request_params["context_management"] = { - **cm, - "strategies": strategies, - } - return super().transform_responses_api_request( model=stripped_model_name, input=input, diff --git a/tests/test_litellm/llms/azure/response/test_azure_transformation.py b/tests/test_litellm/llms/azure/response/test_azure_transformation.py index 905b31a7c62..f54724b859f 100644 --- a/tests/test_litellm/llms/azure/response/test_azure_transformation.py +++ b/tests/test_litellm/llms/azure/response/test_azure_transformation.py @@ -492,50 +492,3 @@ class TestAzureResponsesAPIConfig: ) assert "tools" not in response_api_params - - def test_azure_responses_api_context_management_array_to_object(self): - """Test that context_management array is converted to object format for Azure. - - Azure Responses API expects context_management as an object with 'strategies' key, - but litellm/OpenAI uses array format [{"type": "compaction", "compact_threshold": N}]. - """ - from litellm.types.router import GenericLiteLLMParams - - context_management = [ - {"type": "compaction", "compact_threshold": 200000} - ] - response_api_params = {"context_management": context_management} - litellm_params = GenericLiteLLMParams() - - result = self.config.transform_responses_api_request( - model=self.model, - input="test input", - response_api_optional_request_params=response_api_params, - litellm_params=litellm_params, - headers={}, - ) - - assert "context_management" in result - assert result["context_management"] == { - "strategies": [{"type": "compaction", "token_threshold": 200000}] - } - - def test_azure_responses_api_context_management_already_object(self): - """Test that context_management in object format has compact_threshold mapped to token_threshold.""" - from litellm.types.router import GenericLiteLLMParams - - context_management = {"strategies": [{"type": "compaction", "compact_threshold": 200000}]} - response_api_params = {"context_management": context_management} - litellm_params = GenericLiteLLMParams() - - result = self.config.transform_responses_api_request( - model=self.model, - input="test input", - response_api_optional_request_params=response_api_params, - litellm_params=litellm_params, - headers={}, - ) - - assert result["context_management"] == { - "strategies": [{"type": "compaction", "token_threshold": 200000}] - }