The two redaction tests raised the deprecated InvalidStatusCode, which the websockets 15 asyncio client never raises, and asserted the raw 403 close code that the handshake refusal path replaced with 1008. The refusal path builds its close reason from the status code alone, so there is no secret to redact there, and the handshake refusal tests already cover the error event and the 1008 close. Those refusal tests only passed when run after a sibling test had imported websockets.asyncio.client, since websockets lazy-loads its exceptions submodule. Importing InvalidStatus, Response, and Headers from their own submodules makes them pass in any order. Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com> |
||
|---|---|---|
| .. | ||
| README.md | ||
| test_openai_realtime_handler.py | ||
| test_transcription_sessions.py | ||
OpenAI Realtime Handler Tests
Important Context: additional_headers vs extra_headers
Background
There was confusion about the correct parameter name for passing headers to websockets.connect(). This README documents the resolution for future maintainers.
Timeline of Changes
- Dec 5, 2025 - Changed
extra_headers→additional_headers(commit8db7f1b8e4) - Dec 18, 2025 - Changed
extra_headers→additional_headersagain (PR #17950, commit9f88d61d10) - Jan 15, 2026 - Upgraded
websocketsfrom 13.1.0 → 15.0.1 (commita3cf178e24, Issue #19089)
The Issue & Resolution
The websockets library changed its API between versions:
- websockets < 14.0: Used
extra_headersparameter ✅ - websockets >= 14.0: Uses
additional_headersparameter ✅
LiteLLM uses websockets 15.0.1 (per uv.lock), which requires additional_headers.
Verification
You can verify the correct parameter name:
uv run python -c "import websockets; import inspect; print(inspect.signature(websockets.connect))"
This shows: additional_headers: 'HeadersLike | None' = None for websockets 15.0.1.
Current Implementation (Correct)
# ✅ Correct for websockets 15.0.1+
await websockets.connect(url, additional_headers={
"Authorization": f"Bearer {api_key}",
"OpenAI-Beta": "realtime=v1"
})
Impact
This is NOT just a test fix - this was a critical bug that affected all realtime APIs:
- OpenAI realtime
- Azure realtime
- xAI realtime
- Any pass-through realtime connections
Using extra_headers with websockets 15.0.1 resulted in:
TypeError: connect() got an unexpected keyword argument 'extra_headers'
For Future Maintainers
If you see test failures related to header parameters:
-
Check installed websockets version:
uv run python -c "import websockets; print(websockets.__version__)" -
Check
uv.lockfor the pinned version -
Verify the correct parameter:
- websockets >= 14.0: use
additional_headers - websockets < 14.0: use
extra_headers
- websockets >= 14.0: use
-
Ensure consistency across all files:
litellm/llms/openai/realtime/handler.pylitellm/llms/azure/realtime/handler.pylitellm/llms/custom_httpx/llm_http_handler.pylitellm/realtime_api/main.pylitellm/proxy/pass_through_endpoints/pass_through_endpoints.py
Current Status (Feb 2026):
- ✅ websockets version: 15.0.1
- ✅ Correct parameter:
additional_headers - ✅ All handlers updated and working