mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-20 00:11:50 +00:00
fix(realtime): send openai and xai health check keys as bearer tokens
This commit is contained in:
parent
5969fbb052
commit
87b630429d
2 changed files with 44 additions and 7 deletions
|
|
@ -55,6 +55,7 @@ xai_realtime: Final = XAIRealtime()
|
|||
vertex_llm_base: Final = VertexBase()
|
||||
base_llm_http_handler = BaseLLMHTTPHandler()
|
||||
_EMPTY_MODEL_PARAMS: Final[Mapping[str, Any]] = MappingProxyType({})
|
||||
_EMPTY_AUTH_HEADERS: Final[Mapping[str, str]] = MappingProxyType({})
|
||||
|
||||
|
||||
def _model_params_with_stored_credentials(model_params: Mapping[str, Any]) -> Mapping[str, Any]:
|
||||
|
|
@ -602,13 +603,15 @@ def _azure_realtime_health_protocol(
|
|||
|
||||
def _realtime_health_check_auth_headers(
|
||||
custom_llm_provider: str, api_key: str | None, model_params: Mapping[str, Any]
|
||||
) -> Mapping[str, str | None]:
|
||||
if custom_llm_provider != "azure":
|
||||
return MappingProxyType({"api-key": api_key})
|
||||
return azure_realtime.get_auth_headers(
|
||||
api_key=api_key,
|
||||
azure_ad_token=(None if api_key else get_azure_ad_token(GenericLiteLLMParams(**model_params))),
|
||||
)
|
||||
) -> Mapping[str, str]:
|
||||
if custom_llm_provider == "azure":
|
||||
return azure_realtime.get_auth_headers(
|
||||
api_key=api_key,
|
||||
azure_ad_token=(None if api_key else get_azure_ad_token(GenericLiteLLMParams(**model_params))),
|
||||
)
|
||||
if api_key is None:
|
||||
return _EMPTY_AUTH_HEADERS
|
||||
return MappingProxyType({"Authorization": f"Bearer {api_key}"})
|
||||
|
||||
|
||||
async def _realtime_health_check(
|
||||
|
|
|
|||
|
|
@ -276,6 +276,40 @@ async def test_azure_health_check_resolves_stored_credentials(monkeypatch):
|
|||
assert "api-version=2025-04-01-preview" in connect.url
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
("custom_llm_provider", "model", "expected_url"),
|
||||
[
|
||||
("xai", "grok-voice-latest", "wss://api.x.ai/v1/realtime?model=grok-voice-latest"),
|
||||
("openai", "gpt-realtime", "wss://api.openai.com/v1/realtime?model=gpt-realtime"),
|
||||
],
|
||||
)
|
||||
async def test_bearer_health_check_sends_stored_credential_as_bearer_token(
|
||||
monkeypatch, custom_llm_provider: str, model: str, expected_url: str
|
||||
):
|
||||
monkeypatch.setattr(
|
||||
litellm,
|
||||
"credential_list",
|
||||
[
|
||||
CredentialItem(
|
||||
credential_name="voice-key",
|
||||
credential_values={"api_key": "sk-from-credential"},
|
||||
credential_info={},
|
||||
)
|
||||
],
|
||||
)
|
||||
connect = _CapturingConnect()
|
||||
with patch("websockets.connect", connect):
|
||||
assert await realtime_main._realtime_health_check(
|
||||
model=model,
|
||||
custom_llm_provider=custom_llm_provider,
|
||||
api_key=None,
|
||||
model_params={"model": f"{custom_llm_provider}/{model}", "litellm_credential_name": "voice-key"},
|
||||
)
|
||||
assert connect.kwargs["additional_headers"] == {"Authorization": "Bearer sk-from-credential"}
|
||||
assert connect.url == expected_url
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_azure_health_check_probes_ga_transcription_url_for_transcription_model(local_model_cost_map):
|
||||
"""Regression for LIT-6240: transcription-only models (mode audio_transcription
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue