From 078c3ac8a03902ab37358e8fe87b6f5a3cd60416 Mon Sep 17 00:00:00 2001 From: liuhao1024 Date: Wed, 17 Jun 2026 13:46:44 +0800 Subject: [PATCH] fix(agent): detect modern services.ai.azure.com in _is_azure_openai_url() Modern Azure OpenAI resources (post-2024) use `{resource}.services.ai.azure.com` instead of the legacy `{resource}.openai.azure.com`. The substring check missed these endpoints, causing Azure-specific routing to fail for gpt-5.x models served without the `/v1/` prefix. Extend the detection to also match `ai.azure.com` and update the docstring to document both URL patterns. --- run_agent.py | 12 +++++++----- tests/run_agent/test_run_agent.py | 3 +++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/run_agent.py b/run_agent.py index bca3dd1e718d..abbd5070d55a 100644 --- a/run_agent.py +++ b/run_agent.py @@ -1057,16 +1057,18 @@ def _is_azure_openai_url(self, base_url: str = None) -> bool: Azure OpenAI exposes an OpenAI-compatible endpoint at ``{resource}.openai.azure.com/openai/v1`` that accepts the - standard ``openai`` Python client. Unlike api.openai.com it - does NOT support the Responses API — gpt-5.x models are served - on the regular ``/chat/completions`` path — so routing decisions - must treat Azure separately from direct OpenAI. + standard ``openai`` Python client. Modern Azure OpenAI resources + (post-2024) also use ``{resource}.services.ai.azure.com``. + Unlike api.openai.com Azure does NOT support the Responses API — + gpt-5.x models are served on the regular ``/chat/completions`` + path — so routing decisions must treat Azure separately from + direct OpenAI. """ if base_url is not None: url = str(base_url).lower() else: url = getattr(self, "_base_url_lower", "") or "" - return "openai.azure.com" in url + return "openai.azure.com" in url or "ai.azure.com" in url def _is_github_copilot_url(self, base_url: str = None) -> bool: """Return True when a base URL targets GitHub Copilot's OpenAI-compatible API.""" diff --git a/tests/run_agent/test_run_agent.py b/tests/run_agent/test_run_agent.py index 827bc0ef690a..df686cb1a0bf 100644 --- a/tests/run_agent/test_run_agent.py +++ b/tests/run_agent/test_run_agent.py @@ -5203,6 +5203,9 @@ def test_is_azure_openai_url_detection(self, agent): assert agent._is_azure_openai_url("https://foo.openai.azure.com/openai/v1") is True assert agent._is_azure_openai_url("https://api.openai.com/v1") is False assert agent._is_azure_openai_url("https://openrouter.ai/api/v1") is False + # Modern Azure OpenAI resources use *.services.ai.azure.com + assert agent._is_azure_openai_url("https://my-resource.services.ai.azure.com/") is True + assert agent._is_azure_openai_url("https://my-resource.services.ai.azure.com/openai/v1") is True # Path-embedded azure string should still detect — we're ~substring matching agent.base_url = "https://my-resource.openai.azure.com/openai/v1" assert agent._is_azure_openai_url() is True