litellm/tests/test_litellm/llms/openai/realtime
yuneng-jiang 6a0d03914c
test: drop the cwd-relative sys.path.insert calls from the test suite (#37802)
* test: drop the cwd-relative sys.path.insert calls from the test suite

TQ003 stands at 1,077 across 1,058 files, and 1,015 of them are the same shape:
sys.path.insert(0, os.path.abspath("../..")) and its deeper siblings. The
argument resolves against the working directory rather than the file, so from
the repo root, where every job runs pytest, it inserts the directory two levels
above the checkout. It has never pointed at litellm. The package is installed
into the environment anyway, which is what actually makes the import work, and
what the rule's message has said all along.

Removing them leaves 1,634 imports of sys and os with no remaining reference,
and those go too, except where another test module imports the name back out of
the file. The rest of TQ003 is 62 call sites that resolve against __file__ or a
variable, which are a different question and are left alone.

Collection is identical either way: 45,871 tests and the same 51 pre-existing
collection errors before and after, and ruff reports no new undefined name.

* test: drop the duplicate imports the sys.path sweep exposed to F811

* test(pre-call-utils): restore the os import the new bedrock tests need
2026-08-22 09:25:58 -07:00
..
README.md build: migrate packaging, CI, and Docker from Poetry to uv (#25007) 2026-04-09 11:46:23 -07:00
test_openai_realtime_handler.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
test_transcription_sessions.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00

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

  1. Dec 5, 2025 - Changed extra_headersadditional_headers (commit 8db7f1b8e4)
  2. Dec 18, 2025 - Changed extra_headersadditional_headers again (PR #17950, commit 9f88d61d10)
  3. Jan 15, 2026 - Upgraded websockets from 13.1.0 → 15.0.1 (commit a3cf178e24, Issue #19089)

The Issue & Resolution

The websockets library changed its API between versions:

  • websockets < 14.0: Used extra_headers parameter
  • websockets >= 14.0: Uses additional_headers parameter

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:

  1. Check installed websockets version:

    uv run python -c "import websockets; print(websockets.__version__)"
    
  2. Check uv.lock for the pinned version

  3. Verify the correct parameter:

    • websockets >= 14.0: use additional_headers
    • websockets < 14.0: use extra_headers
  4. Ensure consistency across all files:

    • litellm/llms/openai/realtime/handler.py
    • litellm/llms/azure/realtime/handler.py
    • litellm/llms/custom_httpx/llm_http_handler.py
    • litellm/realtime_api/main.py
    • litellm/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