mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
fix(vllm): forward api key for model discovery
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
624f4281aa
commit
9edc1018fb
2 changed files with 35 additions and 2 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue