fix: use resolved credentials in health checks

This commit is contained in:
Apricooooot 2026-08-18 12:50:06 -07:00
parent aa90828811
commit 21c8c337f7
2 changed files with 43 additions and 4 deletions

View file

@ -8385,29 +8385,36 @@ async def ahealth_check(
api_base_from_params: Final = model_params.get("api_base", None)
api_key_from_params: Final = model_params.get("api_key", None)
model, custom_llm_provider, _, _ = get_llm_provider(
model, custom_llm_provider, dynamic_api_key, dynamic_api_base = get_llm_provider(
model=model,
custom_llm_provider=custom_llm_provider_from_params,
api_base=api_base_from_params,
api_key=api_key_from_params,
)
resolved_model_params: Final = dict( # mutable-ok: health-check handlers require mutable request parameters
model_params
)
if dynamic_api_base is not None:
resolved_model_params["api_base"] = dynamic_api_base
if dynamic_api_key is not None:
resolved_model_params["api_key"] = dynamic_api_key
resolved_model_params["cache"] = {"no-cache": True}
if model in litellm.model_cost and mode is None:
mode = litellm.model_cost[model].get("mode")
model_params["cache"] = {"no-cache": True} # don't used cached responses for making health check calls
mode = mode or "chat"
if "*" in model:
return await HealthCheckHelpers.ahealth_check_wildcard_models(
model=model,
custom_llm_provider=custom_llm_provider,
model_params=model_params,
model_params=resolved_model_params,
litellm_logging_obj=litellm_logging_obj,
)
mode_handlers: Final = HealthCheckHelpers.get_mode_handlers(
model=model,
custom_llm_provider=custom_llm_provider,
model_params=model_params,
model_params=resolved_model_params,
prompt=prompt,
input=input,
)

View file

@ -15,6 +15,38 @@ import asyncio
import litellm
@pytest.mark.asyncio
async def test_hosted_vllm_health_check_uses_resolved_provider_credentials(
monkeypatch,
):
monkeypatch.setenv("HOSTED_VLLM_API_BASE", "https://env.example/v1")
monkeypatch.setenv("HOSTED_VLLM_API_KEY", "env-key")
mock_response = litellm.ModelResponse(
choices=[{"message": {"role": "assistant", "content": "ok"}}]
)
with (
patch(
"litellm.litellm_core_utils.health_check_helpers.HealthCheckHelpers."
"_update_model_params_with_health_check_tracking_information",
side_effect=lambda model_params: model_params,
),
patch(
"litellm.acompletion",
new_callable=AsyncMock,
return_value=mock_response,
) as mock_acompletion,
):
response = await litellm.ahealth_check(
model_params={"model": "hosted_vllm/org/model"},
mode="chat",
)
assert "error" not in response
assert mock_acompletion.await_args.kwargs["api_base"] == "https://env.example/v1"
assert mock_acompletion.await_args.kwargs["api_key"] == "env-key"
@pytest.mark.asyncio
async def test_azure_health_check():
response = await litellm.ahealth_check(