Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#547·speech-to-speech

Support optional mid-session STT, LLM, and TTS model switching through session.update

Author: andimarafiotiCreated Sep 5, 2026Updated Sep 23, 2026
Labelsfor-hf-staff-only

Problem

Allow a client to change the configured STT, LLM, and TTS model routes after a Realtime speech-to-speech session has started, using session.update without reconnecting or losing the retained conversation. The client can change one stage or several stages in the same update. All three stages remain present, and subsequent transcription, inference, and speech requests use the selected compatible routes. A route may identify a logical model and an explicit provider; deployment-side routing decides which compatible worker serves each request.

This should be an optional extension that preserves existing supported OpenAI Realtime client flows. OpenAI's hosted API does not support changing the session model through session.update, and its voice has additional update limits, so documentation must distinguish this behavior from exact OpenAI API conformance: official session.update reference.

Proposed contract

Reuse session.update. The existing session.model field remains an LLM-only shorthand. An optional session.models extension identifies the stage selections, for example:

json
{
  "type": "session.update",
  "session": {
    "type": "realtime",
    "models": {
      "stt": {"model": "asr-alternative", "provider": "example"},
      "llm": "reachy-alternative",
      "tts": {"model": "speech-alternative", "provider": "example"}
    }
  }
}
  • Make switching an explicitly supported, documented server capability. Clients that do not request a switch keep their current behavior; no new mandatory event type or client field is required. Stage choices and provider aliases are specific to the configured service, and this operation is not portable to OpenAI's hosted API.
  • Initially support switching among configured remote STT, LLM, and TTS routes handled by the existing adapters. Allow each stage to change independently or as part of one combined update. Preserve an explicit provider choice; do not silently fall back to a different model/provider.
  • Accept a switch only at a safe turn boundary. Reject it while input speech/transcription, a response, speech synthesis, or a tool continuation is pending or in progress. The client can finish the turn or cancel active generation and wait for cleanup first. Cancellation alone must not make unresolved tool history valid.
  • Validate all requested routes and the current session's requirements before committing the change, including applicable STT/TTS audio formats and voices and LLM tools, images, context limits, and continuation semantics. Rejected or failed switches leave every previous effective selection and session configuration intact.
  • Apply the selections atomically with respect to new STT, LLM, and TTS work. A successful session.updated must report the effective stage models and LLM shorthand; subsequent requests at each changed stage must actually use their new routes. An update that includes other session fields must not leave a partially applied configuration if any selection is rejected.
  • Preserve the connection, session/conversation identity, retained history, and compatible session settings. Serialize the retained context for the destination using existing adapters and history policy. Reject switches that require unsupported history conversion; never silently discard required context or carry unsupported backend-local continuation references to another provider.
  • Clear or replace old stage routing affinity when changing compatible pools. Keep conversation identity stable and propagate it with selected routes on internal STT, LLM, and TTS requests, without requiring public clients to manage worker affinity.
  • Return failures through the existing Realtime error mechanism, correlated to the supplied client event ID. Preserve normal response, audio, tool, and cancellation event ordering.

Ownership and integration

speech-to-speech owns the session update, safe switch boundary, conversation serialization, and propagation of logical stage routes/conversation identity through its STT, LLM, and TTS client adapters. The deployment gateway owns route catalogs, route authorization, provider credentials, compatible worker pools, quotas, scheduling, draining, and autoscaling. Reuse existing configuration and adapters; do not move fleet management into this library.

The deployment revision inspected during design, 3986f453012a131632eee4731995474046846794, records model updates in session configuration, while Chat Completions requests use the handler's model name. Recheck current code when implementing: acknowledging a new session model is not proof that inference switched.

Related work:

  • andimarafioti/s2s-endpoint#114: model/provider resolution and independent deployment pools. This issue is its upstream companion; the gateway work remains a separate PR stacked on endpoint PR #110.
  • andimarafioti/s2s-endpoint#112: affinity and draining must account for explicit model/pool changes without reusing an incompatible binding.
  • andimarafioti/s2s-endpoint#113: continuation contracts and cache verification must distinguish same-pool worker reassignment from an explicit model/provider switch.
  • #519: preserve Responses reasoning items and tool-continuation fidelity; reuse that work where needed.
  • #484: retain the established official-client compatibility coverage for WebSocket and WebRTC.

Acceptance criteria

  • A multi-turn speech-to-speech session changes its STT, LLM, and TTS models after it starts, both one stage at a time and in a combined update, without reconnecting. The next transcription, inference, and speech requests use their respective new routes; LLM inference retains conversation context; session.updated reports all effective selections accurately; normal audio output continues.
  • Explicit provider-specific choices are respected for each stage. Unknown, unauthorized, or incompatible choices fail without changing any effective stage route or other session configuration.
  • Tests cover busy/pending STT, LLM, and TTS work, unresolved tool calls, cancellation cleanup, concurrent update/admission, rejected combined updates, and disconnect/pipeline reuse. A change in one session cannot affect another session or a reused pipeline slot.
  • Tests demonstrate that routing identity remains stable while affinity is isolated by each selected compatible stage pool; no backend-local response reference or stale work leaks across a switch.
  • Existing supported OpenAI client flows remain covered over both WebSocket and WebRTC. Exercise the extension with a pinned official client capable of sending the existing event shape, and document any SDK limitations.
  • Documentation explains enabling/using the extension, safe switching and error behavior, supported stage/history/capability boundaries, and its differences from OpenAI-hosted model and voice update rules.

Non-goals

  • Implementing deployment pools, fleet lifecycle, shared provider quota policy, or a dynamic provider/plugin framework here.
  • Hot-loading arbitrary local model weights, changing the pipeline adapter type in place, or requiring empty, text-only, or transcription-only session modes to accomplish model switching.
  • Migrating an in-flight generation, replaying a partially streamed response, or implementing GPU KV-cache transfer or a distributed response-history store.
  • Guaranteeing that every model/provider supports every existing session or all OpenAI Realtime features.

Source: huggingface/speech-to-speech

View original on GitHubView discussion on GitHub