diff --git a/litellm/proxy/health_check.py b/litellm/proxy/health_check.py index 6b51fea02c9..5b7ad115815 100644 --- a/litellm/proxy/health_check.py +++ b/litellm/proxy/health_check.py @@ -135,10 +135,13 @@ _AUDIO_OUTPUT_PROBE_PROVIDERS: Final[frozenset[str]] = frozenset({"openai", "azu def _health_check_requires_audio_output( - model_info: Mapping[str, object], probe_params: Mapping[str, object], mode: str | None, deployment_model: object + model_info: Mapping[str, object], probe_params: Mapping[str, object], mode: str | None, deployment_model: str | None ) -> bool: if (mode or "chat") != "chat": return False + operator_modalities: Final = probe_params.get("modalities") + if isinstance(operator_modalities, list) and "audio" not in operator_modalities: + return False model: Final = probe_params.get("model") if not isinstance(model, str): return False @@ -152,14 +155,16 @@ def _health_check_requires_audio_output( if provider not in _AUDIO_OUTPUT_PROBE_PROVIDERS: return False base_model: Final = model_info.get("base_model") or probe_params.get("base_model") + checked_model: Final = base_model if isinstance(base_model, str) and model == deployment_model else model + checked_model_prefix: Final = checked_model.partition("/")[0] return litellm.supports_audio_output( - model=base_model if isinstance(base_model, str) and model == deployment_model else model, - custom_llm_provider=provider, + model=checked_model, + custom_llm_provider=checked_model_prefix if checked_model_prefix in _AUDIO_OUTPUT_PROBE_PROVIDERS else provider, ) def _health_check_audio_output_params( - model_info: Mapping[str, object], probe_params: Mapping[str, object], mode: str | None, deployment_model: object + model_info: Mapping[str, object], probe_params: Mapping[str, object], mode: str | None, deployment_model: str | None ) -> Mapping[str, object]: if not _health_check_requires_audio_output(model_info, probe_params, mode, deployment_model): return MappingProxyType({}) @@ -848,9 +853,11 @@ def update_litellm_params_for_health_check( `audio` in the `health_check_voice` (default "alloy"), since those models reject text-only requests. `base_model` (from `model_info`, then `litellm_params`) decides it only while the probe still targets `deployment_model` (default: the incoming `litellm_params` model), so a `health_check_model` or a `model` - in `health_check_params` is judged on its own. Keys already set through `health_check_params` are kept + in `health_check_params` is judged on its own. Keys already set through `health_check_params` are kept, + and `modalities` set there without "audio" turns the audio fields off """ - base_model_owner: Final = deployment_model or _PROBE_PARAMS_ADAPTER.validate_python(litellm_params).get("model") + incoming_model: Final = _PROBE_PARAMS_ADAPTER.validate_python(litellm_params).get("model") + base_model_owner: Final = deployment_model or (incoming_model if isinstance(incoming_model, str) else None) mode: Final = resolve_health_check_mode( model_info, litellm_params, # any-ok: untyped router config dict diff --git a/tests/unit/proxy/health_endpoints/test_health_endpoints.py b/tests/unit/proxy/health_endpoints/test_health_endpoints.py index 1055de06e38..6e2fadfd793 100644 --- a/tests/unit/proxy/health_endpoints/test_health_endpoints.py +++ b/tests/unit/proxy/health_endpoints/test_health_endpoints.py @@ -394,7 +394,7 @@ async def test_test_model_connection_loads_config_from_router(): mock_run_with_timeout = AsyncMock(return_value=mock_health_check_result) # Mock _update_litellm_params_for_health_check - def mock_update_params(model_info, litellm_params, deployment_model=None): + def mock_update_params(model_info, litellm_params, deployment_model: str | None = None): # Just return params with messages added params = litellm_params.copy() params["messages"] = [{"role": "user", "content": "test"}] @@ -545,7 +545,7 @@ async def test_test_model_connection_uses_model_info_id_to_disambiguate_duplicat mock_ahealth_check = AsyncMock(return_value=mock_health_check_result) mock_run_with_timeout = AsyncMock(return_value=mock_health_check_result) - def mock_update_params(model_info, litellm_params, deployment_model=None): + def mock_update_params(model_info, litellm_params, deployment_model: str | None = None): params = litellm_params.copy() params["messages"] = [{"role": "user", "content": "test"}] return params @@ -656,7 +656,7 @@ async def test_test_model_connection_falls_back_to_deployments_zero_without_id() mock_ahealth_check = AsyncMock(return_value=mock_health_check_result) mock_run_with_timeout = AsyncMock(return_value=mock_health_check_result) - def mock_update_params(model_info, litellm_params, deployment_model=None): + def mock_update_params(model_info, litellm_params, deployment_model: str | None = None): params = litellm_params.copy() params["messages"] = [{"role": "user", "content": "test"}] return params diff --git a/tests/unit/proxy/test_health_check_max_tokens.py b/tests/unit/proxy/test_health_check_max_tokens.py index b6ce1893202..e48bf4edc09 100644 --- a/tests/unit/proxy/test_health_check_max_tokens.py +++ b/tests/unit/proxy/test_health_check_max_tokens.py @@ -855,6 +855,7 @@ def test_health_check_params_apply_to_non_chat_modes(): {"base_model": "gpt-4o-mini", "health_check_params": {"model": "openai/gpt-audio-mini"}}, {"model": "openai/my-text-model"}, ), + ({"base_model": "openai/gpt-audio-1.5"}, {"model": "azure/my-audio-deployment"}), ], ) def test_openai_and_azure_audio_chat_probe_asks_for_audio_output( @@ -875,6 +876,8 @@ def test_openai_and_azure_audio_chat_probe_asks_for_audio_output( ({}, {"model": "azure/my-audio-deployment"}), ({}, {"model": "unmapped-model-name"}), ({"mode": "responses"}, {"model": "openai/gpt-audio-mini"}), + ({"mode": "completion"}, {"model": "openai/gpt-audio-mini"}), + ({"base_model": "gemini/lyria-3-clip-preview"}, {"model": "azure/my-audio-deployment"}), ( {"base_model": "azure/gpt-audio-mini", "health_check_model": "azure/gpt-4o-mini"}, {"model": "azure/my-audio-deployment"}, @@ -939,6 +942,15 @@ def test_every_audio_output_chat_model_in_the_cost_map_gets_the_audio_probe(cost assert updated["modalities"] == ["text", "audio"] +def test_text_only_modalities_in_health_check_params_get_no_default_audio(): + updated: Final = update_litellm_params_for_health_check( + {"health_check_params": {"modalities": ["text"]}}, {"model": "openai/gpt-audio-mini"} + ) + + assert updated["modalities"] == ["text"] + assert "audio" not in updated + + def test_audio_chat_probe_uses_health_check_voice(): updated: Final = update_litellm_params_for_health_check( {"health_check_voice": "verse"}, {"model": "openai/gpt-audio-mini"}