fix(openai): include ?model= on Responses-API and realtime STT WebSocket URLs#1467
Open
enriqueespaillat-gyde wants to merge 1 commit into
Open
Conversation
…ket URLs OpenAI-compatible gateways (LiteLLM, Cloudflare AI Gateway, Helicone, Portkey, etc.) can only see the URL at the WebSocket upgrade — they cannot read the subsequent `session.update` / `response.create` frame to determine which backend to dial. The conversational endpoint in `realtime/realtime_model.ts` already includes the model in the upgrade URL; this aligns the Responses-API LLM and realtime STT paths with the same convention. OpenAI's native endpoints accept and ignore the parameter, so this is a no-op for direct connections. - `ws/llm.ts`: extract `buildResponsesWsUrl()` and append `?model=` - `stt.ts`: extract `buildRealtimeSttUrl()` and append `?model=` - add unit tests for both URL builders
53ddc8e to
7842d89
Compare
🦋 Changeset detectedLatest commit: 7842d89 The changes in this PR will be included in the next version bump. This PR includes changesets to release 31 packages
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two of the OpenAI plugin's three WebSocket endpoints open the connection without a
?model=query parameter:plugins/openai/src/ws/llm.ts) — openswss://.../responseswith no model in the URL.plugins/openai/src/stt.ts) — openswss://.../realtime?intent=transcriptionwith no model in the URL.The third endpoint — the conversational realtime API in
plugins/openai/src/realtime/realtime_model.ts— already includes the model:This PR extends the same convention to the other two endpoints.
Why
OpenAI-compatible proxies route WebSocket connections at the HTTP upgrade — they don't (and generally can't) wait for and parse the first WS frame to discover which model the client wants. LiteLLM is the most concrete example: its realtime routing docs require
?model=on the upgrade URL (e.g.,ws://0.0.0.0:4000/v1/realtime?model=openai-gpt-4o-realtime-audio) and reject the connection without it. Other OpenAI-compatible gateways (Cloudflare AI Gateway, Helicone, Portkey) have the same shape of constraint when they expose realtime endpoints.OpenAI's own native endpoints accept and ignore the parameter — which is what makes the existing
realtime_model.tsbehavior safe today, and what makes this change a no-op for users hittingapi.openai.comdirectly.Changes
ws/llm.ts: extractbuildResponsesWsUrl(baseURL, model), set?model=on the URL.stt.ts: extractbuildRealtimeSttUrl(baseURL, model), set?model=on the URL./v1-suffix handling.Both helpers are
@internalin JSDoc; they're exported only so the URL construction can be unit-tested without instantiating the full LLM/STT class. Happy to keep them module-private (matchingprocessBaseURLinrealtime_model.ts) if preferred — let me know.Test plan
pnpm test plugins/openai/src/ws/url.test.ts plugins/openai/src/stt.test.ts— 12 passed, 1 skipped (the pre-existing integration test that requiresOPENAI_API_KEY)pnpm --filter @livekit/agents-plugin-openai build— cleanpnpm --filter @livekit/agents-plugin-openai lint— no new warningspnpm format:write— no changes outside touched files