From 7358c0bf7c02b53e6bc2598052d0c18864ae9435 Mon Sep 17 00:00:00 2001 From: Christian Sidak Date: Sun, 12 Apr 2026 18:21:48 -0700 Subject: [PATCH] fix: patch litellm.api_base in test and add branch-order guard comment Addresses review feedback: - Reset litellm.api_base to None in get_api_base tests for isolation - Add comment clarifying why /projects/ branch must precede services.ai.azure.com Co-Authored-By: Claude Opus 4.6 (1M context) --- litellm/llms/azure_ai/responses/transformation.py | 8 +++++--- .../llms/azure_ai/responses/test_azure_ai_responses.py | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) 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