diff --git a/litellm/llms/vllm/common_utils.py b/litellm/llms/vllm/common_utils.py index f663ec7870a..106aae29aab 100644 --- a/litellm/llms/vllm/common_utils.py +++ b/litellm/llms/vllm/common_utils.py @@ -63,8 +63,13 @@ class VLLMModelInfo(BaseLLMModelInfo): endpoint: Final = "/v1/models" url: Final = _add_path_to_api_base(api_base, endpoint) - response: Final = litellm.module_level_client.get( - url=url, + response: Final = ( + litellm.module_level_client.get( + url=url, + headers={"x-api-key": api_key}, # mutable-ok: optional authentication header + ) + if api_key is not None + else litellm.module_level_client.get(url=url) ) response.raise_for_status() diff --git a/tests/test_litellm/proxy/auth/test_model_checks.py b/tests/test_litellm/proxy/auth/test_model_checks.py index bea46a3fd23..021d6a7f056 100644 --- a/tests/test_litellm/proxy/auth/test_model_checks.py +++ b/tests/test_litellm/proxy/auth/test_model_checks.py @@ -465,6 +465,34 @@ def test_get_known_models_from_wildcard_hosted_vllm_uses_provider_endpoint(): ] +def test_get_known_models_from_wildcard_hosted_vllm_forwards_api_key(): + import litellm + from litellm.proxy.auth.model_checks import get_known_models_from_wildcard + from litellm.types.router import LiteLLM_Params + + response = MagicMock() + response.json.return_value = {"data": [{"id": "qwen2.5"}]} + original_check_provider_endpoint = litellm.check_provider_endpoint + try: + litellm.check_provider_endpoint = True # test-quality-ok: required to exercise provider endpoint discovery + with patch( # test-quality-ok: required HTTP boundary + "litellm.module_level_client.get", return_value=response + ) as mock_get: + result = get_known_models_from_wildcard( + "hosted_vllm/*", + LiteLLM_Params( + model="hosted_vllm/*", + api_base="http://localhost:8000/v1", + api_key="test-key", + ), + ) + finally: + litellm.check_provider_endpoint = original_check_provider_endpoint # test-quality-ok: restore test global + + assert result == ["hosted_vllm/qwen2.5"] + assert mock_get.call_args.kwargs["headers"] == {"x-api-key": "test-key"} + + def test_get_known_models_from_wildcard_unknown_provider_returns_empty(): from litellm.proxy.auth.model_checks import get_known_models_from_wildcard