diff --git a/litellm/llms/azure_ai/responses/transformation.py b/litellm/llms/azure_ai/responses/transformation.py index 11a1cbdd1b3..c5a30abac31 100644 --- a/litellm/llms/azure_ai/responses/transformation.py +++ b/litellm/llms/azure_ai/responses/transformation.py @@ -114,9 +114,11 @@ class AzureAIResponsesAPIConfig(OpenAIResponsesAPIConfig): query_params["api-version"] = api_version # Build the responses endpoint path. - # Check /projects/ first: project-based endpoints under - # services.ai.azure.com need /openai/v1/responses, which differs - # from the non-project services.ai.azure.com path (/models/responses). + # IMPORTANT: The /projects/ check MUST come before the general + # services.ai.azure.com check (_should_use_api_key_header), because + # project URLs also contain that domain. If we checked + # services.ai.azure.com first, project URLs would incorrectly get + # the /models/responses path instead of /openai/v1/responses. if "/projects/" in api_base: new_url = _add_path_to_api_base( api_base=api_base, ending_path="/openai/v1/responses" diff --git a/tests/test_litellm/llms/azure_ai/responses/test_azure_ai_responses.py b/tests/test_litellm/llms/azure_ai/responses/test_azure_ai_responses.py index 312b35e1815..811837de47e 100644 --- a/tests/test_litellm/llms/azure_ai/responses/test_azure_ai_responses.py +++ b/tests/test_litellm/llms/azure_ai/responses/test_azure_ai_responses.py @@ -125,8 +125,11 @@ class TestAzureAIResponsesURL: ) assert url == "https://custom-proxy.example.com/v1/responses" - def test_missing_api_base_raises(self): + def test_missing_api_base_raises(self, monkeypatch): """ValueError raised when api_base is None and no env var set.""" + # Patch litellm.api_base to None so the test is isolated from + # any global state set by other tests or config. + monkeypatch.setattr(litellm, "api_base", None) config = AzureAIResponsesAPIConfig() with patch.dict(os.environ, {}, clear=False): # Ensure env var is not set