Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions litellm/llms/openai/realtime/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ async def async_realtime(

try:
ssl_context = get_shared_realtime_ssl_context()
# Log a masked request preview consistent with other endpoints.
logging_obj.pre_call(
input=None,
api_key=api_key,
additional_args={
"api_base": url,
"headers": {
"Authorization": f"Bearer {api_key}",
"OpenAI-Beta": "realtime=v1",
},
"complete_input_dict": {"query_params": query_params},
},
)
async with websockets.connect( # type: ignore
url,
additional_headers={
Expand Down
4 changes: 4 additions & 0 deletions litellm/realtime_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ async def _arealtime(
api_key=api_key,
)

# Ensure query params use the normalized provider model (no proxy aliases).
if query_params is not None:
query_params = {**query_params, "model": model}

litellm_logging_obj.update_environment_variables(
model=model,
user=user,
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ aioboto3==13.4.0 # for async sagemaker calls
tenacity==8.5.0 # for retrying requests, when litellm.num_retries set
pydantic>=2.11,<3 # proxy + openai req. + mcp
jsonschema>=4.23.0,<5.0.0 # validating json schema - aligned with openapi-core + mcp
websockets==13.1.0 # for realtime API
websockets==15.0.1 # for realtime API
soundfile==0.12.1 # for audio file processing
openapi-core==0.21.0 # for OpenAPI compliance tests

Expand Down
41 changes: 41 additions & 0 deletions tests/llm_translation/test_openai_realtime.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import sys
from unittest.mock import AsyncMock, MagicMock

import pytest

sys.path.insert(
Expand Down Expand Up @@ -315,3 +317,42 @@ def test_realtime_query_params_construction():
assert query_params2["model"] == model
assert "intent" in query_params2
assert query_params2["intent"] == intent


@pytest.mark.asyncio
async def test_realtime_query_params_use_normalized_model_name(monkeypatch):
"""
Ensure query params overwrite model with normalized provider model name.
"""
from litellm.realtime_api import main as realtime_main

mock_async_realtime = AsyncMock()
monkeypatch.setattr(
realtime_main,
"openai_realtime",
MagicMock(async_realtime=mock_async_realtime),
)

def fake_get_llm_provider(model, api_base=None, api_key=None):
return ("gpt-4o-realtime-preview-2024-10-01", "openai", None, None)

monkeypatch.setattr(realtime_main, "get_llm_provider", fake_get_llm_provider)

query_params: RealtimeQueryParams = {
"model": "openai/gpt-4o-realtime-preview-2024-10-01",
"intent": "chat",
}

await realtime_main._arealtime(
model="openai/gpt-4o-realtime-preview-2024-10-01",
websocket=MagicMock(),
api_key="sk-test",
query_params=query_params,
litellm_logging_obj=MagicMock(),
)

called_kwargs = mock_async_realtime.call_args.kwargs
assert (
called_kwargs["query_params"]["model"] == "gpt-4o-realtime-preview-2024-10-01"
)
assert called_kwargs["query_params"]["intent"] == "chat"
Loading