Skip to content

feat(inference, google): run GPT-Live as inference.DuplexModel, wrap Gemini 3.x reply instructions, update the realtime model list - #7673

Merged
russellmartin-livekit merged 16 commits into
mainfrom
russ/gemini-live-reply-instructions
Oct 15, 2026
Merged

russellmartin-livekit merged 16 commits into
mainfrom
russ/gemini-live-reply-instructions

Conversation

@russellmartin-livekit

@russellmartin-livekit russellmartin-livekit commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Combines eight changes, previously #7673, #7346 and #7678, plus GPT-Live under LiveKit Inference as inference.DuplexModel (change 5), single-final-transcript turn handling on hosted xAI (change 6), two realtime session fixes (change 7), and the direct OpenAI Realtime plugin owning its label (change 8). Changes 3 through 6 all edit the realtime model lists, llm_from_model_string and the inference docs, so they stay in one PR rather than landing in a forced order.

Note

Reviewing the GPT-Live move. Most of the line count is the GPT-Live client moving from the OpenAI plugin into livekit-agents, which inference.DuplexModel subclasses. GitHub shows it as an add plus a delete because the plugin files stay as re-export shims, but only 50 of its ~1,300 lines change (3 in the types file). To see just those:

diff <(git show origin/main:livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/gpt_live_model.py) livekit-agents/livekit/agents/llm/_realtime/gpt_live.py

Important

Ordering: cut the release containing this after these have deployed:

  • livekit/cloud-config#20197. Replaces xai/grok-voice-think-fast-2.0 with xai/grok-voice-3.0 in the gateway and catalog, and aliases the old id to 3.0.
  • livekit/agent-gateway#1572 (merged). Until it deploys, the gateway ignores provider on realtime, contrary to the new docstring and knowledge-base text.

livekit/cloud-config#19900 no longer blocks the release. The retired openai/gpt-realtime-2 and -1.5 ids still resolve to inference.RealtimeModel (with a deprecation warning), so they keep working before and after it aliases them to 2.1.

1. fix(google): send Gemini 3.x reply instructions as a wrapped user turn

Problem

On Gemini 3.1 and 3.8 Live, generate_reply(instructions=R) sends R as a trailing model-role turn. #7289 dropped the "." user placeholder on these models, and nothing else was changed. Gemini then treats R as its own unfinished turn and continues it, instead of answering it.

I ran this directly against gemini-3.8-live (Gemini API, no gateway), seeding one user/model exchange and then calling generate_reply. Over 15 runs, only 4 were clean:

  • in 8, the model spoke its reasoning aloud, e.g. "The developer wants me to provide the following information…", "Draft: Welcome to the Marlowe…", or R itself;
  • in 2, it ignored the instruction;
  • in 1, it stayed silent.

Fix

When the model takes no placeholder, send R as a user turn wrapped in _DEFAULT_INLINE_INSTRUCTIONS_TEMPLATE. That is the shape convert_mid_conversation_instructions already gives generate_reply instructions on the Gemini LLM path. Placeholder models (2.5) keep model + ".".

The wrapping matters. I followed each reply with "repeat back every message I've said to you":

  • a plain user turn was quoted back as the caller's own words 5/5 times;
  • the wrapped turn was quoted 0/15 on 3.8, and replied and followed the instruction 15/15.

On 2.5 the current shape is the better one: model + "." was clean 5/5, while the wrapped user turn was quoted back 3/5. So this change is gated on the existing placeholder check.

Vertex AI

I repeated the comparison on Vertex AI (gemini-3.8-live, us-central1), with 10 runs per shape:

  • the wrapped user turn was clean 10/10;
  • a plain user turn was quoted back as the caller's words 8/10 times;
  • a model turn did much better than on the Gemini API: 9/10 clean, though once it recited the system prompt and some JSON.

Vertex documents mid-session system instruction updates (a role="system" turn). That doesn't steer a single reply:

  • a system turn with turnComplete: true produced no reply (3/3);
  • a system update followed by an empty turnComplete produced no reply either (5/5), and in 2 of those runs the instruction came out in the answer to the next, unrelated question.

On the Gemini API, both role="system" and an unset role close the session with 1007. Neither API has a per-reply mechanism, so this keeps to the documented user/model roles.

The Inference gateway had the same issue for google/gemini-3.8-live; it is fixed in livekit/agent-gateway#1545, in production since v0.93.60.

2. docs: correct stale OpenAI Realtime Inference availability claims

After the OpenAI Realtime inference client moved into agents core (inference.RealtimeModel, #7318), two docs still said OpenAI Realtime is unavailable through LiveKit Inference and needs the provider plugin:

  • examples/homepage/knowledge_base/products/livekit-inference.md is loaded at runtime by the homepage agent, so it was steering users away from Inference for realtime. It now lists the realtime models.
  • examples/voice_agents/README.md contradicted examples/README.md.

Both now list xAI Grok Voice as available through inference.RealtimeModel too. The first commit is from the Doc Drift bot.

3. fix(inference): retire gpt-realtime-1.5 and -2 from the realtime model list

Removes openai/gpt-realtime-1.5 and openai/gpt-realtime-2 from OpenAIRealtimeModels. With livekit/cloud-config#19900, LiveKit Inference serves only gpt-realtime-2.1 and -2.1-mini; openai/gpt-realtime and -mini resolve to those two, and the retired ids alias to 2.1.

The retired ids move to DEPRECATED_REALTIME_MODELS, which is_realtime_model() still recognizes. llm="openai/gpt-realtime-2" keeps building inference.RealtimeModel rather than the text LLM, and logs openai/gpt-realtime-2 is deprecated, use openai/gpt-realtime-2.1 instead.

The direct OpenAI and Azure plugins are unchanged, since they run on the customer's own key.

4. fix(inference): replace Grok Voice Think Fast 2.0 with Grok Voice 3.0; document realtime provider; deprecate realtime inference_class

  • Replaces xai/grok-voice-think-fast-2.0 with xai/grok-voice-3.0 in XAIRealtimeModels and grok-voice-think-fast-2.0 with grok-voice-3.0 in the xAI plugin's GrokRealtimeModels, matching livekit/cloud-config#20197. xai/grok-voice-think-fast-2.0 stays a deprecated id, as in change 3, pointing to xai/grok-voice-3.0.
  • The knowledge base now lists only what Inference serves after #19900 and #20197 (2.1, 2.1 mini, and Grok Voice 3.0). Before, it still listed GPT Realtime 2 and 1.5, which change 3 retires.
  • Documents provider on inference.RealtimeModel: it pins the hosting engine, and the session is refused if no host in the region matches. This is the behavior livekit/agent-gateway#1572 adds, matching inference.LLM.
  • Deprecates inference_class on inference.RealtimeModel. The gateway ignores the priority header on realtime: sessions have no priority tier and are bounded by the concurrent-session quota, not paced. It is no longer sent, and passing it logs that it has no effect and will be removed in v2.0. It shipped in 1.8.3, so it stays accepted until then.

5. feat(inference): run OpenAI GPT-Live through LiveKit Inference as inference.DuplexModel

GPT-Live previously needed openai.realtime.GPTLiveModel and the customer's own OpenAI key. It now runs on LiveKit credentials:

session = AgentSession(llm="openai/gpt-live-1")
# or
session = AgentSession(
    llm=inference.DuplexModel(
        model="openai/gpt-live-1",
        voice="marin",
        extra_kwargs={"responses_options": {"model": "gpt-4.1-mini"}},
    )
)
  • Client moved into core. The GPT-Live client and types move from the OpenAI plugin to livekit.agents.llm._realtime.gpt_live. The plugin modules re-export them explicitly.
    • openai.realtime.GPTLiveModel is a thin subclass of the core class, so it keeps its own metrics label without core naming the plugin.
    • It forwards the plugin's hosted tools (OpenAITool) through a _provider_tool_config hook, so core doesn't reference the plugin. It doesn't duck-type on to_dict, because the Anthropic, xAI, Mistral and Google tools have that method too.
  • inference.DuplexModel is shaped like the other inference classes: named by kind, model: DuplexModels | str required, shared settings (voice, provider) as arguments, and GPT-Live's delegation and responses_options in extra_kwargs, typed per model with @overload as OpenAIDuplexOptions. Unknown extra_kwargs keys raise. It is separate from inference.RealtimeModel because GPT-Live speaks a different protocol.
    • It connects to {inference url}/live/sessions?model=openai/gpt-live-1 and signs a fresh LiveKit token for each connection.
    • provider behaves as on inference.RealtimeModel. There is no inference_class.
    • It matches what the gateway accepts:
      • Hosted tools raise RealtimeError, since the gateway refuses non-function tools.
      • extra_kwargs["responses_options"]["service_tier"] must be unset or "default".
      • The gateway's client-error codes are fatal: invalid_model, unsupported_server_tool, unsupported_service_tier, invalid_delegated_model and unsupported_delegated_model.
  • Model strings. openai/gpt-live-1 is in its own DuplexModels alias with is_duplex_model(), not in RealtimeModels.
    • llm="openai/gpt-live-1" resolves to inference.DuplexModel, and AgentSession and Agent wrap it in the duplex adapter as they do for the direct model.
    • inference.RealtimeModel rejects duplex ids and points to inference.DuplexModel.
    • google/gemini-3.8-live, google/gemini-3.8-live-extended-thinking and google/gemini-live join RealtimeModels, so llm="google/gemini-3.8-live" resolves to inference.RealtimeModel. The gateway's Gemini adapter has the matching fixes in livekit/agent-gateway#1545 (reply instructions) and add changeset: google-genai version update #1559 (session updates and manual turns).
  • Exports. inference exports RealtimeModels and DuplexModels, one alias per kind; the new per-provider lists stay internal.
  • Production verification fixes:
    • GPTLiveVoices replaces "aster" (which OpenAI rejects with forbidden / "Voice session access denied.") with "cedar", and "forbidden" is treated as a fatal error code so a refused voice doesn't retry 3 times.
    • DuplexSession._report_connection_acquired and RealtimeSession._report_connection_acquired set label= on connection-timing RealtimeModelMetrics.
    • RealtimeSession.update_options only attaches audio.input or audio.output when that side changed, preventing an empty audio.input: {} on a voice update from clearing input_audio_transcription on xAI.
    • Late output deltas arriving after interrupt() suppress ChanClosed.
    • Hosted xAI sessions hold input_audio_transcription.completed until the agent speaks (6c93c3c23), emitting one final user transcript per turn.
  • Docs: the examples READMEs, the GPT-Live example README ("LiveKit Inference" section) and the homepage knowledge base use inference.DuplexModel(model="openai/gpt-live-1").

Production already serves gpt-live-1 (it is in the catalog, with an EU route since livekit/cloud-config#20355), so this change doesn't change the release ordering above.

6. fix(inference): emit one final user transcript per turn on hosted xAI

The gateway forwards xAI's conversation.item.input_audio_transcription.completed events unchanged (livekit/agent-gateway#1579). Unlike OpenAI, xAI sends .completed multiple times for one user item (status: "in_progress" partials, and a fresh full-item transcript on each commit across pauses within a turn). inference.RealtimeSession subclasses the base OpenAI session directly rather than the xAI plugin, so hosted xai/… sessions treated every .completed as final and added duplicate user items.

When model starts with xai/, inference.RealtimeSession now applies the same turn-state handling as livekit.plugins.xai.realtime.RealtimeSession (#6729):

  • holds committed .completed events in _pending_transcription, emits is_final=False as they arrive, and flushes a single final transcript when the agent starts speaking or generating text, the next user turn starts, the session reconnects, or aclose() runs;
  • preserves the held user item during update_chat_ctx diffs, appends unanchored conversation.item.added items to the tail, and discards responses xAI abandoned before speaking.

Hosted openai/… sessions are unchanged.

7. fix(realtime): retry a refused first handshake as a fresh connection; flush turn audio

Both found while validating review findings on the JS port (livekit/agents-js#2532), and both affect direct and hosted OpenAI-protocol sessions:

  • Refused first handshake. _main_task set reconnecting after every attempt, so when the first handshake failed (e.g. a 503), the retry ran the reconnection replay. That rejected any generate_reply() requested during startup with "pending response discarded due to session reconnection", and emitted session_reconnected for a session that never connected. reconnecting is now set once a connection opens. The startup events are still queued, so the fresh connection sends them.
  • Turn audio. AudioByteStream sends 100 ms frames and holds the remainder. commit_audio committed without it, so up to 90 ms of a client-committed turn's tail went out at the start of the next turn, and clear_audio left the stale remainder in place. commit_audio now sends the partial frame before committing, and clear_audio discards it.

8. refactor(openai): plugin RealtimeModel owns its label; explicit re-exports

This gives the OpenAI Realtime client that #7318 moved into core the same cleanup change 5 gives GPT-Live:

  • llm/_realtime/openai.py no longer hardcodes livekit.plugins.openai.realtime.realtime_model.RealtimeModel as its label. openai.realtime.RealtimeModel is now a thin subclass, so the label comes from the class and is unchanged for users.
  • with_azure builds cls(...) and returns Self, so openai.realtime.RealtimeModel.with_azure(...) still returns the plugin class.
  • The plugin's realtime_model.py and utils.py re-export by name instead of import * plus __getattr__. Every public name either module defines is still importable, as are the three private helpers xAI and the tests import (_DiscardedGeneration, _MessageGeneration, _is_fatal_error). Names that were only reachable through the wildcard, such as realtime_model.logger, are not.

Note

inference.RealtimeModel (and its openai.realtime.InferenceRealtimeModel alias) is no longer a subclass of openai.realtime.RealtimeModel, so isinstance(inference_model, openai.realtime.RealtimeModel) is now False. Both still subclass the core OpenAI Realtime class and share RealtimeSession. Nothing in the repo relied on the old relation, and GitHub code search found no external uses.

Tests

  • test_reply_instructions_turns_follow_the_model covers 3.8, 3.1 and 2.5; the 3.x cases fail without the fix.
  • test_gpt_live_model.py adds a "LiveKit Inference" section.
    • Against a loopback gateway, it checks the path, the model query, a re-signed bearer token on reconnect, the provider header, that no tier header is sent, and the session.start model, voice and Responses options passed through extra_kwargs.
    • It also covers the defaults, unknown extra_kwargs, hosted-tool refusal, the default-tier-only rule, fatal gateway codes, other providers' tools being ignored, and the plugin and inference classes each getting their own label.
  • test_inference_model_string.py covers the GPT-Live string, its duplex wrapping in AgentSession, and the retired realtime ids. test_openai_inference_realtime_model.py covers the duplex-id guard and the deprecation warnings for retired ids and inference_class.
  • test_openai_realtime_model.py covers change 7: a server that refuses the first handshake with a 503 still answers a generate_reply() made during startup without a reconnection, a commit carries the turn's partial frame, and a clear drops it. All three fail without the fix.
  • test_direct_model_preserves_public_label_and_model_types covers change 8: the plugin label, with_azure returning the plugin class, the shared RealtimeSession, and inference.RealtimeModel not subclassing the plugin class.
  • uv run pytest tests/test_gpt_live_model.py tests/test_inference_model_string.py tests/test_realtime/test_openai_inference_realtime_model.py tests/test_realtime/test_openai_realtime_model.py tests/test_realtime/test_xai_realtime_model.py tests/test_plugin_google_realtime.py tests/test_openai_realtime_chat_ctx.py tests/test_plugin_openai_realtime_reasoning.py tests/test_realtime_*.py tests/test_config.py: 482 passed.
  • Verified live against production (wss://agent-gateway.livekit.cloud/v1) across openai/gpt-live-1 (all Responses delegation options, function tool round-trip with LLMMetrics, client delegation, max_session_duration reconnect, mute/unmute, context appends, and all voices), 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. The GPT-Live run predates the DuplexModel rename, which doesn't change the wire protocol. Gemini (generate_reply instructions, manual turns, update_instructions, tools and tool_choice="none", interrupt, text-only) was re-verified on 14 October against gateway v0.94.00.
  • ruff format --check, ruff check and mypy: clean.

@russellmartin-livekit russellmartin-livekit self-assigned this Oct 8, 2026
@russellmartin-livekit
russellmartin-livekit marked this pull request as ready for review October 8, 2026 18:20
@russellmartin-livekit
russellmartin-livekit requested a review from a team as a code owner October 8, 2026 18:20

@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: No Issues Found

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

Devin Review

@russellmartin-livekit russellmartin-livekit changed the title fix(google): send Gemini 3.x reply instructions as a wrapped user turn fix(google, inference): wrap Gemini 3.x reply instructions, drop gpt-realtime-1.5 and -2, fix realtime docs Oct 12, 2026
devin-ai-integration[bot]

This comment was marked as resolved.

@russellmartin-livekit russellmartin-livekit changed the title fix(google, inference): wrap Gemini 3.x reply instructions, drop gpt-realtime-1.5 and -2, fix realtime docs fix(google, inference): wrap Gemini 3.x reply instructions, update the realtime model list, fix realtime docs Oct 13, 2026
@russellmartin-livekit
russellmartin-livekit force-pushed the russ/gemini-live-reply-instructions branch from 3f3ed2b to 91e75e1 Compare October 14, 2026 00:46
base_url: str | None = None,
api_key: str | None = None,
api_secret: str | None = None,
inference_class: InferenceClass | None = None,

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.

should we remove this parameter if it has no effect yet?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed, along with the header it fed.

class ErrorEvent(BaseModel):
type: Literal["error"] = "error"
error: ErrorBody = ErrorBody()
def __getattr__(name: str) -> Any:

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.

should we do explicit re exports instead of getattr

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in gpt_live_types.py and gpt_live_model.py.

@theomonnom theomonnom left a comment

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.

GPT-Live shouldn't get its own class in inference. It's a duplex model, so it should be exposed as inference.DuplexModel, the same way the other models in this module are named by what they are: inference.LLM, inference.STT, inference.TTS, inference.RealtimeModel. Left notes on each place that needs to change.

"TurnDetectorVersions",
"RealtimeModel",
"RealtimeSession",
"GPTLiveModel",

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.

Right now this exports GPTLiveModel and GPTLiveSession from livekit.agents.inference, so users end up writing inference.GPTLiveModel(). Nothing else in this module is named after a specific model. These should be DuplexModel and DuplexSession, used as inference.DuplexModel(model="openai/gpt-live-1").

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 00662e2: inference.DuplexModel / DuplexSession, taking model: DuplexModels | str.


return getattr(avatar, name)
if name in ("RealtimeModel", "RealtimeSession"):
if name in ("RealtimeModel", "RealtimeSession", "GPTLiveModel", "GPTLiveSession"):

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.

Same here: the lazy import currently hands out GPTLiveModel / GPTLiveSession. It should hand out DuplexModel / DuplexSession next to RealtimeModel / RealtimeSession (and the TYPE_CHECKING import on L26 too).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 00662e2: inference.DuplexModel / DuplexSession, taking model: DuplexModels | str.

@@ -1,6 +1,9 @@
from .gpt_live import GPTLiveModel, GPTLiveSession

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.

This re-exports the class under the GPT-Live name. It should come out of here as DuplexModel / DuplexSession.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 00662e2: inference.DuplexModel / DuplexSession, taking model: DuplexModels | str.

inference_class: InferenceClass | None


class GPTLiveModel(_GPTLiveModel):

@theomonnom theomonnom Oct 14, 2026 •

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.

The class itself is fine, it just has the wrong name for this module. Rename it to DuplexModel (and GPTLiveSession to DuplexSession), taking model: DuplexModels | str. The GPT-Live name is fine in the OpenAI plugin, just not here. For the GPT-Live-only arguments, see the comment on L69-71.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 00662e2: inference.DuplexModel / DuplexSession, taking model: DuplexModels | str.


RealtimeModels = OpenAIRealtimeModels | XAIRealtimeModels
RealtimeModels = (
OpenAIRealtimeModels | OpenAIGPTLiveModels | GoogleRealtimeModels | XAIRealtimeModels

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.

Right now openai/gpt-live-1 is part of RealtimeModels, so is_realtime_model() returns True for it, and llm_from_model_string only picks the right class because the GPT-Live check happens first. It's a duplex model, not a realtime one. It should go in its own DuplexModels alias, with an is_duplex_model() next to is_realtime_model().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. openai/gpt-live-1 moved out of RealtimeModels into its own DuplexModels, with is_duplex_model(). llm_from_model_string checks duplex, then realtime, then LLM.

:class:`livekit.agents.inference.RealtimeModel`, every other string to
:class:`livekit.agents.inference.LLM`.
"""
if is_gpt_live_model(model):

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.

With the rename this should return inference.DuplexModel for duplex model strings (and the docstring above should say so).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 00662e2: inference.DuplexModel / DuplexSession, taking model: DuplexModels | str. llm_from_model_string returns inference.DuplexModel for duplex strings, and the docstring says so.

Comment thread examples/README.md Outdated
```

**Note:** OpenAI Realtime models are available through `inference.RealtimeModel`; use provider plugin classes for direct credentials. See the [Real-time Models](#-real-time-models) examples in `voice_agents/`.
**Note:** OpenAI Realtime and xAI Grok Voice models are available through `inference.RealtimeModel`, and OpenAI GPT-Live through `inference.GPTLiveModel`; use provider plugin classes for direct credentials or for other real-time models such as Amazon Nova Sonic. See the [Real-time Models](#-real-time-models) examples in `voice_agents/`.

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.

This currently tells users to use inference.GPTLiveModel. Should be inference.DuplexModel(model="openai/gpt-live-1").

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to inference.DuplexModel(model="openai/gpt-live-1").

Comment thread examples/voice_agents/README.md Outdated
```

**Note:** Real-time voice-to-voice models (Amazon Nova Sonic, xAI Grok, etc.) are not supported by LiveKit Inference and must use the provider plugin directly.
**Note:** OpenAI Realtime and xAI Grok Voice models are available through `inference.RealtimeModel`, and OpenAI GPT-Live through `inference.GPTLiveModel`; use provider plugin classes for direct credentials or for other real-time models such as Amazon Nova Sonic. See the [Real-time Models](#real-time-models) examples below.

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.

Same as the top-level README: inference.DuplexModel instead of inference.GPTLiveModel.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to inference.DuplexModel(model="openai/gpt-live-1").


## LiveKit Inference

Both examples connect to OpenAI with `OPENAI_API_KEY`. To run GPT-Live through LiveKit Inference with your LiveKit credentials instead, pass `llm="openai/gpt-live-1"` or `inference.GPTLiveModel()`; it takes the same `voice`, `delegation`, and `responses_options`. Inference runs delegated work on the default service tier only, needs `responses_options["model"]` to be an OpenAI LLM it serves (`gpt-5.6-luna` by default), and does not run hosted tools such as `WebSearch()`.

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.

inference.GPTLiveModel() here should become inference.DuplexModel(model="openai/gpt-live-1").

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to inference.DuplexModel(model="openai/gpt-live-1").

Cartesia offers sonic-3 with over 40 languages, sonic-2 and sonic-turbo with 15 languages each, and the original sonic model. Deepgram offers aura-2 for English and Spanish. Inworld offers inworld-tts-1.5-max and inworld-tts-1.5-mini for 13 languages, and inworld-tts-1-max and inworld-tts-1 for 12 languages. Rime offers coda for 8 languages and mistv2 for 4 languages.

SUPPORTED REALTIME MODELS:
Realtime speech-to-speech models are available in Python through inference.RealtimeModel, passed as the llm argument of an AgentSession. OpenAI offers GPT Realtime 2.1 and GPT Realtime 2.1 mini, with openai/gpt-realtime and openai/gpt-realtime-mini as aliases; in regions that offer both, the provider argument pins an OpenAI model to Azure or to OpenAI directly. xAI offers Grok Voice 3.0. OpenAI's full-duplex GPT-Live 1 is available through inference.GPTLiveModel, or as llm="openai/gpt-live-1"; its delegated work runs on a backend OpenAI model that LiveKit Inference serves. Other realtime models, such as Amazon Nova Sonic, use provider plugins.

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.

This says GPT-Live 1 is available through inference.GPTLiveModel. Should say inference.DuplexModel.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to inference.DuplexModel(model="openai/gpt-live-1").

@theomonnom theomonnom left a comment

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.

A few more things on the public side. This PR is titled as a Gemini fix, but it also adds a new class to inference, changes which model names are recognized, and moves about 1,300 lines of GPT-Live code from the OpenAI plugin into livekit-agents. That last part would be a lot easier to review as its own PR.

Comment on lines -8 to -9
"openai/gpt-realtime-1.5",
"openai/gpt-realtime-2",

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.

These names get removed from the list, and is_realtime_model() only recognizes what's on it. So anyone who has llm="openai/gpt-realtime-2" today now gets inference.LLM, a text model, with no error at all. Same for xai/grok-voice-think-fast-2.0 below. If these models are gone, the old names should either fail with a clear message or point to the new ones.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 00662e2. openai/gpt-realtime-2, openai/gpt-realtime-1.5 and xai/grok-voice-think-fast-2.0 still route to inference.RealtimeModel and log <old> is deprecated, use <new> instead. I didn't make them fail: the gateway still serves them, and cloud-config #19900 and #20197 alias them to 2.1 and 3.0. An error would break sessions that work today.


OpenAIGPTLiveModels = Literal["openai/gpt-live-1"]

GoogleRealtimeModels = Literal[

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.

With this, llm="google/gemini-live" now builds inference.RealtimeModel, which speaks the OpenAI realtime protocol and only has special handling for xAI. Does the gateway actually translate this for Gemini end to end? The reply-instructions fix in this PR is in the Google plugin, so it doesn't apply on this path. If this isn't tested against the real service, I'd leave Gemini off this list for now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, end to end. On this path Gemini goes through the gateway's own Gemini Live adapter, not the Google plugin. The adapter got its own fixes: reply instructions in agent-gateway#1545, session updates and manual turns in agent-gateway#1559, both live in v0.94.00. I ran the Gemini 3.8 Live models through inference.RealtimeModel against production today from Python and JS. These all passed: generate_reply(instructions=...) without leaking the prompt, manual turns, update_instructions, tools and tool_choice="none", interrupt, and text-only output. So I'd keep Gemini on the list.

if "/" not in model:
raise ValueError("model must be provider-prefixed, for example 'openai/gpt-realtime'")
if is_gpt_live_model(model):
raise ValueError(f"{model} speaks the GPT-Live protocol; use inference.GPTLiveModel")

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.

Right now is_realtime_model("openai/gpt-live-1") returns True, but passing that same name here raises. Once GPT-Live has its own DuplexModels list (see the other comment), this check goes away on its own.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

is_realtime_model() no longer matches it, but I kept the check. Without it, inference.RealtimeModel(model="openai/gpt-live-1") would open an OpenAI Realtime session against a duplex model and fail with an unclear gateway error. Now it raises openai/gpt-live-1 is a duplex model; use inference.DuplexModel.

provider (str, optional): Host that must serve the model, e.g. ``"azure"`` or
``"openai"`` for OpenAI models. The session is refused if no host in the
region matches.
inference_class (InferenceClass, optional): Has no effect on realtime sessions.

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.

The docs here say inference_class does nothing for this class. If it has no effect, it shouldn't be an argument. Users will set it and expect something to happen.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

inference.RealtimeModel shipped this argument in 1.8.3, so removing it would break existing calls with a TypeError. I deprecated it instead: it's no longer sent, and passing it logs that it has no effect and will be removed in v2.0. It's gone entirely from DuplexModel, and from JS, where this class never shipped.

model: Provider-prefixed GPT-Live model, ``openai/gpt-live-1`` by default.
provider: Host that must serve the model, e.g. ``"openai"``. The session is
refused if no host in the region matches.
inference_class: Has no effect on GPT-Live sessions.

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.

Same as on RealtimeModel: this argument is documented as having no effect but it's still accepted, and it's also passed down into the request headers on L144. Either it does something or it should go.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed, along with the header it fed.

)
if type(self) is GPTLiveModel:
# Preserve the pre-move metrics label for direct OpenAI sessions.
self._label = "livekit.plugins.openai.realtime.gpt_live_model.GPTLiveModel"

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.

This file now lives in livekit-agents, but it hardcodes the OpenAI plugin's class path as its label. Code in livekit-agents shouldn't have to know about a plugin. The plugin can set its own label on its side.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Core no longer names the plugin. The label comes from the class, and the plugin ships a thin GPTLiveModel subclass that gets its own label. The subclass also overrides a new _provider_tool_config hook, which removes core's other plugin reference (the sys.modules lookup for OpenAITool).


## Voices

Both examples use `voice="marin"`. `GPTLiveVoices` also offers `aster`, `beacon`, `cinder`, `stone`, and `vesper`. Other supported names and custom voice objects still pass through to the API.

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.

Small one: this lists aster, but GPTLiveVoices doesn't have it. It has cedar and marin instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. The list is now beacon, cedar, cinder, stone, vesper, plus the default marin. The JS example README had the same bug and is fixed too.

@theomonnom theomonnom left a comment

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.

Last pass, on keeping what inference exports consistent. Every model class here should look the same from the outside: named by kind (LLM, STT, TTS, RealtimeModel, DuplexModel), one XModels alias each, and constructor arguments that follow the same pattern.

Comment on lines +72 to +73
"OpenAIGPTLiveModels",
"GoogleRealtimeModels",

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.

Right now inference exports one list of names per kind (STTModels, TTSModels, LLMModels, VADModels), and keeps the per-provider lists like DeepgramModels or CartesiaModels inside their modules. This adds two more per-provider lists to the exports, OpenAIGPTLiveModels and GoogleRealtimeModels. These should stay internal, and the exports should be RealtimeModels and DuplexModels, same as the other kinds.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done: OpenAIGPTLiveModels and GoogleRealtimeModels are no longer exported, so the exports are RealtimeModels and DuplexModels. I left OpenAIRealtimeModels and XAIRealtimeModels because main already exports them, and dropping them would break imports.

"""OpenAI GPT-Live full-duplex voice model, served through LiveKit Inference."""

def __init__(
self,

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.

This one has a default model, but none of the others do: inference.LLM, inference.STT, inference.TTS and inference.RealtimeModel all make you pass model. It should be required here too, typed as DuplexModels | str like LLM takes LLMModels | str.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. model: DuplexModels | str, required.

Comment on lines +69 to +71
inference_class: InferenceClass | None = None,
voice: GPTLiveVoices | str | dict[str, Any] = DEFAULT_VOICE,
delegation: types.DelegationTarget = "responses",

@theomonnom theomonnom Oct 14, 2026 •

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.

Right now delegation and responses_options are their own arguments, but they only make sense for GPT-Live. inference.LLM, inference.STT and inference.TTS keep only the shared settings as arguments (voice, language, ...) and put anything model-specific in extra_kwargs. STT and TTS also use @overload so each model family gets its own typed options dict (CartesiaOptions, DeepgramOptions, ...). This should do the same: keep voice as NotGivenOr[str] = NOT_GIVEN like on RealtimeModel, and move delegation and responses_options into extra_kwargs, typed as something like OpenAIDuplexOptions.

Right now these arguments also use types inference doesn't export (GPTLiveVoices, DelegationTarget, ResponsesDelegationOptions all come from the private llm._realtime modules). With an options dict that lives in inference, that problem goes away too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. voice is NotGivenOr[str] = NOT_GIVEN, and delegation / responses_options moved into extra_kwargs. They're typed with @overload as OpenAIDuplexOptions and OpenAIResponsesOptions, both defined in inference, so nothing private leaks. Unknown keys raise, and a non-default service_tier is still refused.

@russellmartin-livekit russellmartin-livekit changed the title fix(google, inference): wrap Gemini 3.x reply instructions, update the realtime model list, fix realtime docs feat(inference, google): run GPT-Live as inference.DuplexModel, wrap Gemini 3.x reply instructions, update the realtime model list Oct 14, 2026
russellmartin-livekit and others added 14 commits October 14, 2026 15:57
Move the GPT-Live client into livekit-agents core (llm/_realtime/gpt_live.py);
livekit.plugins.openai.realtime.GPTLiveModel re-exports it and keeps its metrics label.

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.
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.
- DuplexModels / is_duplex_model split GPT-Live out of RealtimeModels
- DuplexModel takes a required model, voice as a string, and GPT-Live's
  delegation / responses_options through extra_kwargs (OpenAIDuplexOptions)
- drop the no-op inference_class from DuplexModel; deprecate it on RealtimeModel
- keep retired realtime ids (gpt-realtime-2, -1.5, grok-voice-think-fast-2.0)
  routed to RealtimeModel with a warning naming the replacement
- stop exporting the per-provider GoogleRealtimeModels / OpenAIGPTLiveModels
- the OpenAI plugin subclasses GPTLiveModel for its own label and hosted tools,
  with explicit re-exports instead of module __getattr__
- docs: inference.DuplexModel, cedar instead of aster
- a failed first handshake retried as a reconnection, which discarded
  replies requested during startup; it now retries as a fresh connection
- commit_audio sends the buffered partial frame; clear_audio drops it
…ports

Core no longer hardcodes the OpenAI plugin's class path. The plugin ships a thin RealtimeModel subclass, so its label comes from the class, and with_azure builds cls(...) and returns Self. realtime_model.py and utils.py re-export by name instead of import * plus __getattr__.
@russellmartin-livekit
russellmartin-livekit force-pushed the russ/gemini-live-reply-instructions branch from 4aa2420 to 9b7a144 Compare October 14, 2026 21:58
Azure retired the preview realtime API (realtime_beta_access_required), and api_version is deprecated.

@theomonnom theomonnom left a comment

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.

Looks good, thanks. The inference API is consistent now: DuplexModel next to RealtimeModel, model-specific options in extra_kwargs, and nothing private in the signatures.

@russellmartin-livekit
russellmartin-livekit merged commit b1b8dbb into main Oct 15, 2026
25 checks passed
@russellmartin-livekit
russellmartin-livekit deleted the russ/gemini-live-reply-instructions branch October 15, 2026 01:47
jipeng6036-del added a commit to jipeng6036-del/agents that referenced this pull request Oct 15, 2026
main (livekit#7673) moved the GPT-Live session into
livekit-agents/livekit/agents/llm/_realtime/gpt_live.py, so the
credit_balance_exhausted fatal code now goes into that file's
_FATAL_ERROR_CODES instead of the plugin's gpt_live_model.py.
Li-john1021 added a commit to Li-john1021/agents that referenced this pull request Oct 15, 2026
Rebase onto main was blocked (OAuth token lacks workflow scope for
.github/workflows from livekit#7673/livekit#7779). Resolve the conflict in-place:
keep main's generate_reply wrapping for Gemini 3.x and
test_reply_instructions_turns_follow_the_model from livekit#7673; retain
only the Vertex role="system" update_instructions fix and
test_update_instructions_role_for_api.
Li-john1021 added a commit to Li-john1021/agents that referenced this pull request Oct 15, 2026
Bring the branch tip in line with upstream main (except
.github/workflows, which the OAuth token cannot update) so
GitHub can merge without the livekit#7673 conflict. Keeps the Vertex
role="system" update_instructions fix and
test_update_instructions_role_for_api; preserves main's
generate_reply wrapping and test_reply_instructions_turns_follow_the_model.
Li-john1021 added a commit to Li-john1021/agents that referenced this pull request Oct 15, 2026
Match tests/test_plugin_google_realtime.py to main (keeps
test_reply_instructions_turns_follow_the_model). Leave the Vertex
role="system" change in update_instructions. Follow-up commit will
re-add test_update_instructions_role_for_api after Update branch.
Li-john1021 added a commit to Li-john1021/agents that referenced this pull request Oct 15, 2026
Cover Vertex role="system" vs Gemini role="model" for mid-session
update_instructions (livekit#7785). Placed above the livekit#7673 reply-instructions
test so the branch stays mergeable without a workflow-scoped rebase.
Li-john1021 added a commit to Li-john1021/agents that referenced this pull request Oct 15, 2026
Keep main's generate_reply wrapping and
test_reply_instructions_turns_follow_the_model from livekit#7673. Only the
Vertex role="system" update_instructions change and
test_update_instructions_role_for_api remain on top.
chasef07 added a commit to Kyle-shechtman/agents that referenced this pull request Oct 22, 2026
main (livekit#7673) moved the GPT-Live engine from the OpenAI plugin into
livekit.agents.llm._realtime, leaving the plugin modules as re-export
shims. The tracing changes are ported onto the moved engine and types,
and _gpt_live_telemetry moves alongside them, so the hosted inference
DuplexModel and the plugin share the same backend and protocol spans.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

3 participants