fix(responses): preserve websocket api key

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

View file

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

View file

@ -111,6 +111,32 @@ class TestResponsesAPIWebSocketSupport:
FireworksAIResponsesAPIConfig().supports_native_websocket() is False
), "Fireworks AI should use managed websocket handler"
@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()