Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(realtime): send openai and xai health check keys as bearer tokens

mateo-berri87b630429d86
diff --git a/litellm/realtime_api/main.py b/litellm/realtime_api/main.py
index f94ba4c4a02..d67e4555a29 100644
--- a/litellm/realtime_api/main.py
+++ b/litellm/realtime_api/main.py
@@ -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(
diff --git a/tests/test_litellm/realtime_api/test_main.py b/tests/test_litellm/realtime_api/test_main.py
index dcd4c01730d..643e65af47c 100644
--- a/tests/test_litellm/realtime_api/test_main.py
+++ b/tests/test_litellm/realtime_api/test_main.py
@@ -276,6 +276,40 @@ async def test_azure_health_check_resolves_stored_credentials(monkeypatch):
assert "api-version=2025-04-01-preview" in connect.url
+ ("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