Skip to content

Move OpenAI Realtime inference client into agents core - #2532

Merged
tinalenguyen merged 11 commits into
mainfrom
chop-defrayed-flock
Oct 15, 2026
Merged

tinalenguyen merged 11 commits into
mainfrom
chop-defrayed-flock

Conversation

@rosetta-livekit-bot

@rosetta-livekit-bot rosetta-livekit-bot Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • move the OpenAI-compatible Realtime protocol engine and types from the OpenAI plugin into agents core
  • add inference.RealtimeModel with LiveKit Inference authentication, routing, hosted xAI defaults, and gateway error handling
  • preserve direct OpenAI and xAI plugin compatibility through re-exports and shared turn-detection infrastructure
  • run OpenAI GPT-Live through LiveKit Inference: the GPT-Live client also moves into core, and inference.DuplexModel plus llm: 'openai/gpt-live-1' use it (see below)

Port of livekit/agents#7318.

Alignment with livekit/agents#7673

Rebased onto main, and brought in line with livekit/agents#7673:

  • Gemini 3.x reply instructions (@livekit/agents-plugin-google): models without the placeholder-turn behavior (3.1, 3.8) now get generateReply instructions as a user turn wrapped in <instructions>…</instructions>; 2.5 keeps the model turn plus "." user turn. Extracted as replyTurns() with unit tests.
  • Grok Voice 3.0 (@livekit/agents-plugin-xai, inference.RealtimeModel): replaced grok-voice-think-fast-2.0 with grok-voice-3.0 and grok-voice-latest in GrokRealtimeModels, and set XAIRealtimeModels to 'xai/grok-voice' | 'xai/grok-voice-latest' | 'xai/grok-voice-3.0'.
  • Hosted xAI turn-state parity (inference.RealtimeSession): the gateway forwards xAI's conversation.item.input_audio_transcription.completed events unchanged (https://github.com/livekit/agent-gateway/pull/1579), and xAI sends multiple .completed events per user item (status: 'in_progress' partials plus revised commits across pauses). When model starts with xai/, inference.RealtimeSession now holds committed transcripts in pendingTranscription and flushes one final transcript per turn when the agent answers, the next turn starts, or the session resets/closes, alongside xAI's held-turn chat-context preservation, tail anchoring for unanchored conversation.item.added events, and abandoned-response cleanup (matching @livekit/agents-plugin-xai).
  • Docs: inference.RealtimeModel documents provider (pins the host, e.g. azure or openai; the session is refused if no host in the region matches). It takes no inferenceClass, since the gateway ignores the priority header on realtime. README clarifies hosted vs direct-provider usage.
  • Retired ids: openai/gpt-realtime-2, openai/gpt-realtime-1.5 and xai/grok-voice-think-fast-2.0 still resolve to inference.RealtimeModel and log a warning naming the replacement (2.1 and Grok Voice 3.0), matching feat(inference, google): run GPT-Live as inference.DuplexModel, wrap Gemini 3.x reply instructions, update the realtime model list agents#7673.
  • Model lists: the hosted realtime and duplex lists from feat(inference, google): run GPT-Live as inference.DuplexModel, wrap Gemini 3.x reply instructions, update the realtime model list agents#7673's _realtime_models.py live in agents/src/inference/realtime.ts and agents/src/inference/duplex.ts.

GPT-Live through LiveKit Inference

Ports change 5 of livekit/agents#7673:

const session = new voice.AgentSession({ llm: 'openai/gpt-live-1' });
// or
const session = new voice.AgentSession({
  llm: new inference.DuplexModel({
    model: 'openai/gpt-live-1',
    voice: 'marin',
    modelOptions: { responsesOptions: { model: 'gpt-4.1-mini' } },
  }),
});
  • Client moved into core. gpt_live_model.ts and gpt_live_types.ts move to agents/src/llm/openai_realtime/ (git mv). The plugin re-exports the types and GPTLiveSession. The plugin's GPTLiveModel is now a thin subclass of the core class that forwards OpenAITool hosted tools through a _providerToolConfig() hook, so core doesn't import the plugin.
  • inference.DuplexModel (agents/src/inference/duplex.ts) is shaped like the other inference classes: model is required, shared settings (voice, provider) are options, and GPT-Live's delegation and responsesOptions go in modelOptions, typed per model as OpenAIDuplexOptions. Unknown modelOptions keys throw.
    • It connects to {inference url}/live/sessions?model=openai/gpt-live-1 and signs a fresh LiveKit token for each connection.
    • It accepts provider. There is no inferenceClass.
    • Hosted tools throw RealtimeError.
    • responsesOptions.serviceTier must be unset or 'default'.
    • The gateway's client-error codes are fatal.
  • Model strings. openai/gpt-live-1 is in its own DuplexModels type with isDuplexModel(), not in RealtimeModels. inference.llmFromModelString() resolves duplex strings to inference.DuplexModel, realtime strings to inference.RealtimeModel, and every other string to inference.LLM. AgentSession and Agent use it and wrap duplex models in DuplexRealtimeAdapter. inference.RealtimeModel rejects duplex ids and points to inference.DuplexModel.
  • Production verification fixes:
    • GPTLiveVoices replaces 'aster' (rejected by OpenAI with forbidden) with 'cedar', and 'forbidden' is treated as a fatal error code.
    • RealtimeSession.handleConversationItemCreated falls back to appending at the tail when previous_item_id is not in remoteChatCtx for all providers (such as Gemini sending 'root' or server-side items after setup replay), matching Python.
    • Hosted xAI sessions hold input_audio_transcription.completed until the agent speaks (93e3fd42), emitting one final user transcript per turn.
  • Changeset: one changeset, patch for @livekit/agents, @livekit/agents-plugin-openai, @livekit/agents-plugin-google and @livekit/agents-plugin-xai. API reports regenerated.

Validation for this part:

  • agents/src/inference/duplex.test.ts and agents/src/inference/realtime.test.ts, including modelOptions passthrough, unknown-option rejection, the duplex-id guard and the retired-id warnings (493 tests across agents/src/inference, agents/src/llm/openai_realtime and plugins/openai/src/realtime).
  • Verified live against production (wss://agent-gateway.livekit.cloud/v1) across openai/gpt-live-1, openai/gpt-realtime-2.1, google/gemini-3.8-live, google/gemini-3.8-live-extended-thinking, and xai/grok-voice-think-fast-2.0.

Provider pinning and fallback reporting depend on https://github.com/livekit/agent-gateway/pull/1572 and https://github.com/livekit/cloud-config/pull/20197 being deployed.

Realtime session fixes

Validated from review findings on the engine moved from plugins/openai. These bugs predate this PR, and each has a test that fails without the fix:

Not changed: custom base URLs keep their path as given, matching Python (a full endpoint like /proxy/v1/realtime already works, and appending /realtime to arbitrary paths would break it). api-version in an Azure base URL is still replaced by the apiVersion option, which both SDKs deprecated with a removal date of April 30, 2026.

Validation

  • pnpm build
  • npx --yes --package=node@24 -- node node_modules/vitest/vitest.mjs run agents --silent (2788 passed, 5 skipped)
  • env -u OPENAI_API_KEY pnpm test plugins/openai --silent (156 passed, 7 skipped)
  • pnpm test plugins/xai --silent (26 passed, 1 skipped)
  • pnpm typecheck
  • pnpm format:check
  • pnpm throws:check
  • API checks passed for @livekit/agents, @livekit/agents-plugin-openai, and @livekit/agents-plugin-xai
  • changed-file ESLint passed with warnings only

Full repository lint remains blocked by the pre-existing @typescript-eslint/no-misused-promises error at plugins/openai/src/ws/llm.ts:127. A cue-cli hosted realtime run was attempted with a temporary uncommitted agent, but room creation failed before dispatch with 401 Unauthorized - invalid API key; the temporary harness was removed.

Source diff coverage

Authoritative livekit/agents#7318 file-by-file coverage
Source file Classification Target coverage
.github/workflows/test-realtime.yml Adapted .github/workflows/test.yml: added OpenAI plugin triggers, OpenAI/xAI realtime suites, and hosted realtime inference coverage.
AGENTS.md Adapted CLAUDE.md: documented realtime as core inference infrastructure; target has no AGENTS.md.
examples/README.md Adapted README.md: documented hosted inference.RealtimeModel and direct-provider plugin usage; target has no examples README.
livekit-agents/livekit/agents/inference/__init__.py Ported agents/src/inference/index.ts: exports RealtimeModel, RealtimeSession, realtime namespace, and InferenceClass.
livekit-agents/livekit/agents/inference/_utils.py Adapted agents/src/inference/utils.ts: centralized InferenceClass, credential resolution, priority metadata, and hosted WebSocket header precedence.
livekit-agents/livekit/agents/inference/llm.py Adapted agents/src/inference/llm.ts: consumes centralized inference credentials and InferenceClass.
livekit-agents/livekit/agents/inference/realtime/__init__.py Adapted agents/src/inference/realtime.ts: target inference modules use a flat file namespace.
livekit-agents/livekit/agents/inference/realtime/openai.py Ported agents/src/inference/realtime.ts: hosted model/session, LiveKit auth refresh, provider routing, model omission, xAI defaults, nullable session duration, and fatal gateway errors.
livekit-agents/livekit/agents/llm/_realtime/__init__.py Adapted Core engine is available through package subpaths declared in agents/package.json, matching the target module/export model.
livekit-agents/livekit/agents/llm/_realtime/openai.py Ported agents/src/llm/openai_realtime/realtime_model.ts: moved the existing target protocol engine into core and added hosted extension points.
livekit-agents/livekit/agents/llm/_realtime/openai_types.py Ported agents/src/llm/openai_realtime/api_proto.ts: moved protocol types into core and added RealtimeModels.
livekit-agents/livekit/agents/llm/_realtime/openai_utils.py Adapted Conversion and URL helpers remain co-located in agents/src/llm/openai_realtime/realtime_model.ts, following the existing target architecture.
livekit-agents/pyproject.toml Not applicable @livekit/agents already directly depends on compatible openai, ws, and mutex versions.
livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/models.py Adapted plugins/openai/src/models.ts: re-exports the core RealtimeModels type.
livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/__init__.py Ported plugins/openai/src/realtime/index.ts: preserves direct realtime and GPT Live exports and adds hosted compatibility aliases.
livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/inference_realtime_model.py Adapted InferenceRealtimeModel and InferenceRealtimeSession aliases now resolve to canonical core inference classes.
livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/realtime_model.py Ported plugins/openai/src/realtime/realtime_model.ts: thin compatibility re-export of the core engine.
livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/utils.py Adapted Existing JS helper exports are preserved through the realtime model compatibility wrapper; JS did not have a separate utility module.
livekit-plugins/livekit-plugins-openai/pyproject.toml Adapted plugins/openai/package.json: removed the now-redundant mutex dependency; retained openai and ws because STT, GPT Live, Responses, and other plugin code still use them.
tests/test_inference_utils.py Adapted agents/src/inference/utils.test.ts: covers centralized credentials and inference-priority metadata.
tests/test_realtime/test_openai_inference_realtime_model.py Ported agents/src/inference/realtime.test.ts: covers exports, credentials, URL/wire format, auth refresh, routing headers, model omission, fatal/recoverable errors, API shape, and xAI defaults.
tests/test_realtime/test_openai_realtime_model.py Adapted Existing target engine suite moved to agents/src/llm/openai_realtime/realtime_model.test.ts; plugin compatibility assertions remain in plugins/openai/src/realtime/realtime_model.test.ts.
uv.lock Adapted pnpm-lock.yaml: removed the OpenAI plugin mutex edge.

Additional target infrastructure required for parity is included in agents/src/llm/realtime.ts and agents/src/voice/agent_activity.ts: realtime models can advertise disableable server turn detection, and the voice pipeline resolves and passes the session-specific setting for client-side turn handling.


Ported from livekit/agents#7318

Original PR description

Summary

  • move the OpenAI Realtime protocol engine into a private core module
  • add the hosted RealtimeModel under livekit.agents.inference
  • retain the direct-provider API and legacy hosted imports through compatibility wrappers
  • keep GPT-Live owned by livekit-plugins-openai until LiveKit Inference supports it
  • update dependency bounds, documentation, and realtime CI paths

Compatibility

  • preserve the existing direct OpenAI RealtimeModel metrics label
  • restore realtime.utils and realtime.gpt_live_types package attributes
  • realtime engine logs now use the livekit.agents logger because the implementation lives in core

Validation

  • 126 targeted unit tests passed
  • Ruff lint and format checks passed for affected files
  • mypy passed for livekit.agents and livekit.plugins.openai

@rosetta-livekit-bot
rosetta-livekit-bot Bot requested a review from a team as a code owner September 18, 2026 09:36
@changeset-bot

changeset-bot Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 457b84d

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

This PR includes changesets to release 41 packages
Name Type
@livekit/agents Patch
@livekit/agents-plugin-openai Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-xai Patch
@livekit/agents-plugin-anam Patch
@livekit/agents-plugin-anthropic Patch
@livekit/agents-plugin-assemblyai Patch
@livekit/agents-plugin-azure Patch
@livekit/agents-plugin-baseten Patch
@livekit/agents-plugin-bey Patch
@livekit/agents-plugin-cartesia Patch
@livekit/agents-plugin-cerebras Patch
@livekit/agents-plugin-deepgram Patch
@livekit/agents-plugin-did Patch
@livekit/agents-plugin-elevenlabs Patch
@livekit/agents-plugin-fishaudio Patch
@livekit/agents-plugin-hume Patch
@livekit/agents-plugin-inworld Patch
@livekit/agents-plugin-krisp Patch
@livekit/agents-plugin-lemonslice Patch
@livekit/agents-plugin-liveavatar Patch
@livekit/agents-plugin-livekit Patch
@livekit/agents-plugin-meta Patch
@livekit/agents-plugin-minimax Patch
@livekit/agents-plugin-mistral Patch
@livekit/agents-plugin-mistralai Patch
@livekit/agents-plugin-neuphonic Patch
@livekit/agents-plugin-perplexity Patch
@livekit/agents-plugin-phonic Patch
@livekit/agents-plugin-protoface Patch
@livekit/agents-plugin-resemble Patch
@livekit/agents-plugin-rime Patch
@livekit/agents-plugin-runway Patch
@livekit/agents-plugin-sarvam Patch
@livekit/agents-plugin-silero Patch
@livekit/agents-plugin-soniox Patch
@livekit/agents-plugin-speechify Patch
@livekit/agents-plugin-synthesia Patch
@livekit/agents-plugin-tavus Patch
@livekit/agents-plugins-test Patch
@livekit/agents-plugin-trugen 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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

Devin Review found 4 potential issues.

2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment on lines +641 to +643
this.realtimeSession = this.llm.session({
turnDetectionDisabled: !this.rtTurnDetectionEnabled,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Reused sessions retain stale turn detection

During same-model handoffs, rtTurnDetectionEnabled can change while the old realtime session is reused. The stale server setting can produce duplicate replies or no reply.

Learn more

A realtime session stores its effective turn-detection setting when it is created. The new activity resolves that setting independently from its agent and session configuration. However, _detachReusableResources reuses a session based on model identity, context, instructions, and tools only. The reused session can therefore disagree with the new activity's rtTurnDetectionEnabled. If the session still uses server detection while the activity uses client detection, both sides can generate a reply. In the reverse direction, the activity waits for a server-generated reply that the reused session has disabled.

Example: Agent A uses realtime_llm, then hands off to Agent B using vad with the same model instance. Agent B treats server detection as disabled, but the reused session still has it enabled. The client commits and generates while the server also generates from VAD.

Recommended fix: Include the resolved turn-detection mode in realtime-session reuse eligibility. Close and recreate the session when this.rtTurnDetectionEnabled !== newActivity.rtTurnDetectionEnabled, or add a reliable mid-session update that changes the provider setting before reuse.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in 0b36cc3: a realtime session is only reused when both activities resolve the same turn-detection setting (agent_activity.ts:1138).

Comment on lines +892 to +899
async commitAudio(): Promise<void> {
if (this.pushedDurationMs > 100) {
// OpenAI requires at least 100ms of audio
this.sendEvent({
type: 'input_audio_buffer.commit',
} as api_proto.InputAudioBufferCommitEvent);
this.pushedDurationMs = 0;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Turn boundaries leak buffered audio

When a client-managed turn ends between chunks, commitAudio leaves trailing audio in bstream. That audio is omitted, then prefixed to the next turn.

Learn more

bstream emits only complete 100 ms frames and retains any remainder. pushedDurationMs counts emitted frames, not retained audio. At a client-managed turn boundary, commitAudio commits the provider buffer without flushing or discarding that remainder. The remainder stays in bstream after pushedDurationMs resets, so later input completes a frame containing audio from two user turns. clearAudio has the same stale local remainder because it only clears the provider buffer and duration counter.

Example: A 250 ms turn emits 200 ms and retains 50 ms locally. commitAudio commits only 200 ms. The next user's first 50 ms combines with the retained 50 ms and is sent as that next turn's first chunk.

Recommended fix: Flush bstream at commit boundaries and send the remainder when the resulting provider buffer meets the minimum duration. Reset or replace bstream after every commit and clear. For sub-minimum turns, discard the local and remote buffers together rather than carrying bytes into another turn.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Valid: up to 90 ms of a client-committed turn's tail went out with the next turn. Fixed in 528a0ab: commitAudio sends the partial frame before committing, and clearAudio drops it. Python had the same bug, fixed in livekit/agents#7673.

Comment on lines +1218 to +1220
while (!this.#closed && !signal.aborted) {
this.#logger.debug('Creating WebSocket connection to OpenAI Realtime API');
wsConn = await this.createWsConn();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Initial connection failures bypass retries

When the first createWsConn fails, #mainTask exits before its retry handler. Transient handshake failures ignore maxRetry, and queued replies time out.

Learn more

The retry catch begins only after a WebSocket has been created. Hosted inference uses connectWs, which rejects with retryable APIConnectionError, APIStatusError, or APITimeoutError during the handshake. Because createWsConn() is awaited outside the inner try, those errors terminate the background task immediately. connOptions.maxRetry is never consulted, and pending generateReply() calls remain queued until their separate ten-second timeout.

Example: The gateway returns a transient 503 on the first handshake with maxRetry: 3. The session performs one attempt instead of four. A reply requested during startup fails later with generateReply timed out.

Recommended fix: Move connection creation inside the retry boundary and apply the same retryability and backoff logic to handshake failures. Ensure a failed attempt closes any partially created socket and settles pending work when retries are exhausted.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Valid, and worse on the direct path: the handshake had no 'error' listener, so a refused handshake threw out of the process. Fixed in 528a0ab: handshake failures map to retryable API errors and run inside the retry boundary. A failed first handshake retries as a fresh connection rather than a reconnection replay.

Comment on lines +2153 to +2155
private *resampleAudio(frame: AudioFrame): Generator<AudioFrame> {
yield frame;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Non-24kHz input audio is mislabeled

For non-24kHz input, resampleAudio forwards bytes unchanged. bstream labels them as 24kHz mono, distorting realtime speech.

Learn more

The realtime wire format is fixed at 24 kHz mono, and bstream is constructed for that format. Room input defaults to 24 kHz mono, but RoomInputOptions.audioSampleRate, audioNumChannels, and external audio streams can supply other formats. resampleAudio currently returns every frame unchanged, so the payload contains source-rate samples while the session advertises 24 kHz mono. The declared inputResampler is never initialized or closed.

Example: With room input configured for 48 kHz mono, one second supplies 48,000 samples. The provider interprets them as two seconds of 24 kHz audio, slowing speech and breaking turn timing.

Recommended fix: Track the current input sample rate and channel count. Create an AudioResampler targeting 24 kHz mono whenever either differs, recreate it if the source format changes, and close it during session teardown.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Valid when input isn't the 24 kHz mono default (e.g. audioSampleRate: 48000 or stereo). Fixed in 528a0ab: input is downmixed and resampled to 24 kHz mono, as the GPT-Live client already does.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 2 new potential issues.

2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment on lines +404 to +405
} else if (!url.pathname || ['', '/v1', '/openai', '/openai/v1'].includes(pathStripped)) {
url.pathname = pathStripped + '/realtime';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Custom API roots miss Realtime endpoint

For a custom API root such as /proxy/v1, processBaseURL connects to that root without appending /realtime. Prefixed OpenAI gateways reject the WebSocket handshake, preventing the agent from starting a Realtime session.

Learn more

A base URL can name an API root rather than the final WebSocket endpoint. The model passes its configured base URL directly to processBaseURL, which must turn an API root into a Realtime endpoint. The new path check recognizes only a few root names, so any prefixed API root stays unchanged and the connection goes to the wrong route. At the same time, fully qualified custom WebSocket paths must remain intact.

Example: Given baseURL: 'https://gateway.example.com/proxy/v1', the resulting URL is wss://gateway.example.com/proxy/v1?model=gpt-realtime. An API-root gateway expects /proxy/v1/realtime instead.

Recommended fix: Distinguish explicitly supplied complete WebSocket endpoints from API roots, or provide a documented option for that distinction. Append the Realtime segment for arbitrary API roots while retaining support for custom complete paths and query parameters.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Leaving this as is. A custom path is kept as given on purpose, same as Python's process_base_url. A full endpoint like https://gateway.example.com/proxy/v1/realtime already works, and appending /realtime to arbitrary paths would break it.

Comment on lines +408 to +410
if (isAzure) {
// remove from endpoint URL if present
url.searchParams.delete('api-version');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Azure preview URL loses its version

When an Azure preview baseURL supplies api-version without a separate apiVersion option, processBaseURL removes the version. The preview endpoint then rejects the WebSocket request.

Learn more

An Azure preview endpoint can include api-version in the configured base URL. The Azure branch deletes that query parameter unconditionally, but only restores it when the separate apiVersion option is truthy. Therefore a caller who provides the version solely in the URL loses it before the WebSocket connects.

Example: With baseURL: 'https://resource.openai.azure.com/openai/realtime?api-version=2025-04-01-preview', azureDeployment: 'voice', and no apiVersion, the generated URL omits api-version, unlike the configured endpoint.

Recommended fix: Preserve an existing URL version when no replacement apiVersion was supplied. If a version in the URL selects preview behavior, use it consistently for the preview path and query construction.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Leaving this as is. It only affects the legacy Azure preview path, and apiVersion / OPENAI_API_VERSION is deprecated in both SDKs with a removal date of April 30, 2026. Pass apiVersion if you still need it.

Comment thread .changeset/core-openai-realtime.md Outdated
@@ -0,0 +1,6 @@
---
'@livekit/agents': minor
'@livekit/agents-plugin-openai': minor

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could we collapse to one changeset and set them all as patch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Done: one changeset, all four packages at patch.

@russellmartin-livekit

Copy link
Copy Markdown
Contributor

Mirrored the API review from livekit/agents#7673: inference.DuplexModel / DuplexSession in inference/duplex.ts, with model required and delegation / responsesOptions under typed modelOptions. DuplexModels / isDuplexModel are split from RealtimeModels. Retired realtime IDs still route to RealtimeModel with a warning. inferenceClass is removed from the realtime and duplex paths. The four changesets are now one patch changeset.

528a0ab also fixes the valid Devin findings in realtime_model.ts: a refused or failed handshake now retries instead of crashing or ending the session, input that isn't 24 kHz mono is resampled and downmixed, and a committed turn's trailing audio no longer carries into the next turn.

rosetta-livekit-bot Bot and others added 11 commits October 14, 2026 15:57
…t choice

Match Python: the eager default TurnDetector no longer counts as client-side
turn taking, 'vad' needs a VAD, a realtime session is reused on handoff only
when both activities resolve server turn detection the same way, and a runtime
turnDetection change that would flip it warns.
Move the GPT-Live client into agents core (llm/openai_realtime/gpt_live_model.ts).
openai.realtime.GPTLiveModel becomes a thin subclass that converts the plugin's
hosted tools, so direct-OpenAI behavior is unchanged.

Add inference.GPTLiveModel, which connects to the gateway's /live/sessions?model=
with a LiveKit token signed per connection, and resolve llm: 'openai/gpt-live-1'
to it in Agent and AgentSession. It refuses what the gateway cannot meter before
connecting: hosted tools and a non-default delegation service tier. Gateway
refusals of session.start are fatal.
- DuplexModel/DuplexSession in inference/duplex.ts; model required,
  delegation and responsesOptions move into typed modelOptions
- DuplexModels split out of RealtimeModels; isDuplexModel
- retired realtime ids stay routed to RealtimeModel and warn
- drop inferenceClass from the realtime and duplex paths (no effect)
- one patch changeset
- createWsConn maps handshake failures to retryable APIErrors and handles
  the ws 'error' event, which was unhandled and threw out of the process
- the handshake runs inside the retry boundary; a failed first handshake
  retries as a fresh connection instead of a reconnection replay
- resample and downmix input to 24 kHz mono, as the GPT-Live client does
- commitAudio sends the buffered partial frame; clearAudio drops it
@tinalenguyen
tinalenguyen merged commit c433a25 into main Oct 15, 2026
8 checks passed
@tinalenguyen
tinalenguyen deleted the chop-defrayed-flock branch October 15, 2026 05:17
detail-app Bot added a commit that referenced this pull request Oct 15, 2026
Removes the write-only textModeRecoveryRetries field (declaration, two
= 0 writes, and the stale TODO comment) from the OpenAI Realtime
session, plus the matching field on the test-internal
RealtimeSessionInternals type and its initialization.

The inputResampler field was originally also targeted for removal but
is now actively used after the move into agents core (#2532 added
real usage in pushAudio/close), so it is kept.

Rebased onto main: the implementation moved from
plugins/openai/src/realtime/realtime_model.ts to
agents/src/llm/openai_realtime/realtime_model.ts in #2532.
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