fix(responses): preserve websocket api key

This commit is contained in:
puffer 2026-07-23 10:22:27 +08:00
parent f1f0a0bacd
commit 3a56358fd5
2 changed files with 27 additions and 0 deletions

View file

@ -2031,6 +2031,7 @@ async def _aresponses_websocket(
resolved_api_base = dynamic_api_base or litellm_params.api_base or litellm.api_base or None
resolved_api_key = (
dynamic_api_key
or api_key
or litellm_params.api_key
or litellm.api_key
or litellm.openai_key

View file

@ -102,6 +102,32 @@ class TestResponsesAPIWebSocketSupport:
def test_openai_model_in_websocket_url_default(self):
assert OpenAIResponsesAPIConfig().model_in_websocket_url() is True
@pytest.mark.asyncio
async def test_openai_websocket_forwards_explicit_api_key(self, monkeypatch):
from unittest.mock import AsyncMock
import litellm
from litellm.responses import main as responses_main
websocket_handler = AsyncMock()
monkeypatch.setattr(litellm, "api_key", None)
monkeypatch.setattr(litellm, "openai_key", None)
monkeypatch.delenv("OPENAI_API_KEY", raising=False)
monkeypatch.setattr(
responses_main.base_llm_http_handler,
"async_responses_websocket",
websocket_handler,
)
await responses_main._aresponses_websocket.__wrapped__(
model="gpt-4o",
websocket=MagicMock(),
api_key="explicit-api-key",
litellm_logging_obj=MagicMock(),
)
assert websocket_handler.await_args.kwargs["api_key"] == "explicit-api-key"
def test_xai_uses_managed_websocket(self):
"""XAI should use managed websocket handler"""
config = XAIResponsesAPIConfig()