fix(realtime): probe Azure's GA realtime upstream in health checks when no protocol is pinned

This commit is contained in:
mateo-berri 2026-09-11 18:14:21 -07:00
parent 4a3950cf67
commit 105dc77109
2 changed files with 31 additions and 13 deletions

View file

@ -586,9 +586,7 @@ def _azure_realtime_health_protocol(
configured: Final = configured_raw if isinstance(configured_raw, str) else None
if configured is not None:
return configured, query_params
if query_params is not None:
return "GA", query_params
return "beta", None
return "GA", query_params
def _realtime_health_check_auth_headers(
@ -621,8 +619,8 @@ async def _realtime_health_check(
api_key: str - api key
custom_llm_provider: str - custom llm provider
realtime_protocol: Optional[str] - protocol version ("GA"/"v1" for GA path, "beta" for beta path);
None resolves it for Azure from model_params/env, with transcription-only models probing GA
plus intent=transcription the way real calls do
None resolves it for Azure from model_params/env and otherwise probes GA, the upstream a client
without the OpenAI-Beta header is bridged to, with transcription-only models adding intent=transcription
Returns:
bool - True if connection is successful, False otherwise

View file

@ -266,7 +266,8 @@ def test_transcription_only_detection_rejects_speech_model(local_model_cost_map)
@pytest.mark.asyncio
async def test_azure_health_check_keeps_beta_path_for_speech_model():
async def test_azure_health_check_probes_the_ga_upstream_for_an_unconfigured_speech_model(monkeypatch):
monkeypatch.delenv("LITELLM_AZURE_REALTIME_PROTOCOL", raising=False)
connect = _CapturingConnect()
with patch("websockets.connect", connect):
assert await realtime_main._realtime_health_check(
@ -276,14 +277,18 @@ async def test_azure_health_check_keeps_beta_path_for_speech_model():
api_base="https://my-endpoint.openai.azure.com",
api_version="2024-10-01-preview",
)
assert connect.url == (
"wss://my-endpoint.openai.azure.com/openai/realtime"
"?api-version=2024-10-01-preview&deployment=gpt-4o-realtime-preview"
)
assert connect.url == "wss://my-endpoint.openai.azure.com/openai/v1/realtime?model=gpt-4o-realtime-preview"
_AZURE_BETA_HEALTH_URL: Final = (
"wss://my-endpoint.openai.azure.com/openai/realtime"
"?api-version=2024-10-01-preview&deployment=gpt-4o-realtime-preview"
)
@pytest.mark.asyncio
async def test_azure_health_check_honors_deployment_realtime_protocol():
async def test_azure_health_check_honors_deployment_realtime_protocol(monkeypatch):
monkeypatch.delenv("LITELLM_AZURE_REALTIME_PROTOCOL", raising=False)
connect = _CapturingConnect()
with patch("websockets.connect", connect):
assert await realtime_main._realtime_health_check(
@ -292,9 +297,24 @@ async def test_azure_health_check_honors_deployment_realtime_protocol():
api_key="fake-key",
api_base="https://my-endpoint.openai.azure.com",
api_version="2024-10-01-preview",
model_params={"realtime_protocol": "GA"},
model_params={"realtime_protocol": "beta"},
)
assert connect.url == "wss://my-endpoint.openai.azure.com/openai/v1/realtime?model=gpt-4o-realtime-preview"
assert connect.url == _AZURE_BETA_HEALTH_URL
@pytest.mark.asyncio
async def test_azure_health_check_honors_env_realtime_protocol(monkeypatch):
monkeypatch.setenv("LITELLM_AZURE_REALTIME_PROTOCOL", "beta")
connect = _CapturingConnect()
with patch("websockets.connect", connect):
assert await realtime_main._realtime_health_check(
model="gpt-4o-realtime-preview",
custom_llm_provider="azure",
api_key="fake-key",
api_base="https://my-endpoint.openai.azure.com",
api_version="2024-10-01-preview",
)
assert connect.url == _AZURE_BETA_HEALTH_URL
class _ConnectThatStopsAfterCapturingTheUrl: