Skip to content

fix(openai): support http:// baseURL by mapping to ws:// (not wss://) on WebSocket URLs#1540

Merged
toubatbrian merged 2 commits into
livekit:mainfrom
enriqueespaillat-gyde:enrique/ws-url-http-scheme-support
May 18, 2026
Merged

fix(openai): support http:// baseURL by mapping to ws:// (not wss://) on WebSocket URLs#1540
toubatbrian merged 2 commits into
livekit:mainfrom
enriqueespaillat-gyde:enrique/ws-url-http-scheme-support

Conversation

@enriqueespaillat-gyde
Copy link
Copy Markdown
Contributor

@enriqueespaillat-gyde enriqueespaillat-gyde commented May 18, 2026

Summary

The OpenAI plugin's three WebSocket URL builders (Responses-API LLM, realtime STT, conversational Realtime) all derive their upgrade URL from baseURL but assumed the scheme was always HTTPS — either by force-mapping http:// and https:// to wss:// via regex, or by only handling https:wss: and leaving http: unchanged. With a plain-HTTP baseURL, this produced either an invalid WebSocket URL or a spurious TLS handshake against a non-TLS listener.

The scheme of baseURL is now respected: http:// maps to ws:// and https:// maps to wss://. OpenAI's native endpoint is HTTPS, so this is a no-op for direct connections; the change unbreaks OpenAI-compatible proxy / gateway setups (which might be in-cluster, no TLS), which are an explicit design goal of baseURL parameter support.

Files

  • plugins/openai/src/ws/llm.tsbuildResponsesWsUrl: regex /^https?/, 'wss'/^http(s?):/, 'ws$1:'
  • plugins/openai/src/stt.tsbuildRealtimeSttUrl: add else if (url.protocol === 'http:') url.protocol = 'ws:'
  • plugins/openai/src/realtime/realtime_model.tsprocessBaseURL: same http:ws: branch; exported for unit testing

Prior art

#1467 added gateway routing via ?model= to these same builders. This PR addresses a separate assumption (baseURL is always HTTPS) inherited from before #1467 — same proxy use case, complementary fix.

Test plan

  • pnpm install
  • pnpm build:agents && pnpm --filter "@livekit/agents-plugin-openai..." build — succeeds
  • pnpm test -- --run plugins/openai — 35 passed, 7 skipped (require OPENAI_API_KEY)
  • pnpm --filter @livekit/agents-plugin-openai lint — only pre-existing warnings; no new findings
  • pnpm format:check — clean
  • Unit tests added for http:// baseURLs in all three builders, plus regression guards for https:// / wss:// / ws:// passthrough

🤖 Generated with Claude Code

…cket URLs

The Responses-API LLM (`ws/llm.ts`), realtime STT (`stt.ts`), and
conversational Realtime endpoint (`realtime/realtime_model.ts`) all
build their upgrade URL from `baseURL`, but force-mapped (or only
half-mapped) the scheme to `wss://`. With a plain-HTTP baseURL (e.g.
an in-cluster LiteLLM proxy at `http://litellm:4000`), this produced
a `wss://litellm:4000/...` URL, attempted a TLS handshake against a
non-TLS listener, and failed with `tls_get_more_records:packet length
too long`. The fix maps `http://` -> `ws://` and `https://` -> `wss://`.
OpenAI's native endpoint is always HTTPS, so this is a no-op for
direct connections.

- `ws/llm.ts`: regex `/^https?/, 'wss'` -> `/^http(s?):/, 'ws$1:'`
- `stt.ts`: add `else if (url.protocol === 'http:') url.protocol = 'ws:'`
- `realtime/realtime_model.ts`: same as stt.ts; export `processBaseURL`
  for unit testing
- add unit tests covering `http://` baseURLs for all three builders
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 18, 2026

🦋 Changeset detected

Latest commit: 369e90e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 31 packages
Name Type
@livekit/agents-plugin-openai Patch
@livekit/agents-plugin-anam Patch
@livekit/agents-plugin-cartesia Patch
@livekit/agents-plugin-cerebras Patch
@livekit/agents-plugin-deepgram Patch
@livekit/agents-plugin-elevenlabs Patch
@livekit/agents-plugin-fishaudio Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-hume Patch
@livekit/agents-plugin-inworld Patch
@livekit/agents-plugin-neuphonic Patch
@livekit/agents-plugin-resemble Patch
@livekit/agents-plugin-rime Patch
@livekit/agents-plugin-sarvam Patch
@livekit/agents-plugin-xai Patch
@livekit/agents Patch
@livekit/agents-plugin-assemblyai Patch
@livekit/agents-plugin-baseten Patch
@livekit/agents-plugin-bey Patch
@livekit/agents-plugin-hedra Patch
@livekit/agents-plugin-lemonslice Patch
@livekit/agents-plugin-liveavatar Patch
@livekit/agents-plugin-livekit Patch
@livekit/agents-plugin-minimax Patch
@livekit/agents-plugin-mistral Patch
@livekit/agents-plugin-mistralai Patch
@livekit/agents-plugin-phonic Patch
@livekit/agents-plugin-runway Patch
@livekit/agents-plugin-silero Patch
@livekit/agents-plugin-trugen Patch
@livekit/agents-plugins-test Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

The fix simply respects the scheme of baseURL; the LiteLLM in-cluster
example was a specific motivating case, not the contract. Generalize
the doc comments and test fixtures accordingly.
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@enriqueespaillat-gyde
Copy link
Copy Markdown
Contributor Author

r? @toubatbrian sorry for the ping but in case this can go out with the prior - realized our team had to put a separate patch in place to support our internal litellm instance (http vs. https -> ws vs. wss)

@toubatbrian toubatbrian merged commit fc3cb83 into livekit:main May 18, 2026
6 checks passed
@github-actions github-actions Bot mentioned this pull request May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants