Skip to content

fix(gemini): gemini live bridge fidelity (vad, barge-in, language, response.create, output items) - #47172

Open
tech-carrement wants to merge 10 commits into
BerriAI:mainfrom
tech-carrement:feat-gemini-live-bridge-fixes
Open

tech-carrement wants to merge 10 commits into
BerriAI:mainfrom
tech-carrement:feat-gemini-live-bridge-fixes

Conversation

@tech-carrement

@tech-carrement tech-carrement commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Five fixes to the Gemini Live bridge of /v1/realtime, one commit each, each reviewable on its own. Main was merged in on 21 Nov 2026 (754c2225d7); the original fix 1 (holding client frames until the deferred setup completes) is dropped, because #39864 covers it, see its proof section below. They were opened as separate PRs; this account is capped at five open PRs on the repo, so they are consolidated here (the standalone PRs are closed and point to this one).

  1. buffer every client frame until the deferred Gemini setup completes (was fix(realtime): buffer every client frame until the deferred gemini setup completes #47131): dropped, fix(realtime)!: send the Gemini Live setup at the first content so session.update settings apply #39864 covers it
  2. map live start- and end-of-speech sensitivity (b3ffabe019, was feat(gemini): map live start- and end-of-speech sensitivity #47139)
    • Gemini Live's automaticActivityDetection accepts startOfSpeechSensitivity and endOfSpeechSensitivity, but nothing in the OpenAI-shaped turn_detection mapping filled them
    • A client that streams the microphone continuously had no way to tame an eager end-of-speech detection: sentences were cut into fragments and the user had to repeat
    • turn_detection.start_of_speech_sensitivity and turn_detection.end_of_speech_sensitivity (the Gemini names in snake_case, since OpenAI has no equivalent) are forwarded to automaticActivityDetection
    • Values outside the StartOfSpeechSensitivityEnum / EndOfSpeechSensitivityEnum literals are dropped rather than sent, because Gemini closes the socket on an unknown enum value
  3. surface live barge-in as input_audio_buffer.speech_started (0ad66deb1d, was feat(gemini/realtime): surface barge-in as input_audio_buffer.speech_started #31709)
    • Gemini Live emits serverContent.interrupted when the user talks over the model; the bridge mapped it only to response.done
    • A realtime client acts on input_audio_buffer.speech_started to flush its playback and cancel the response; without it the model's already-buffered audio keeps playing after the interruption
    • The interrupted frame now also emits input_audio_buffer.speech_started (built with the shared speech_event helper, carrying the interrupted item id), once per open response and ahead of the events main now sends to close the interrupted item
  4. forward the output language to live speechConfig.languageCode (1ec6108d56, was never opened: no slot)
    • The GA realtime session field audio.output.language never reached Gemini Live, so speechConfig.languageCode was never set and the model picked the spoken language on its own; on long French sessions it drifted to English after a few turns
    • The only place the language could have gone was the voice mapping, which runs only when a voice is sent and is skipped when an OpenAI stock voice name is dropped
    • audio.output.language is normalized like audio.output.voice and forwarded to speechConfig.languageCode
    • It is set next to the voice, on its own when no voice is sent, and even when an OpenAI stock voice name is dropped with a warning
  5. honor response.create and turn_complete on live conversation items (d7238c6bf0, was feat(gemini): honor response.create and turn_complete on live conversation items #47167)
    • Gemini Live has no response.create: it generates whenever a client turn completes, so the bridge dropped response.create entirely
    • A client could not hand the floor to the model without an item (an opening driven by the system instruction stayed silent), and could not add several conversation items and then ask for one answer: every conversation.item.create completed a turn
    • conversation.item.create honors turn_complete: false, which appends the turn to the conversation without asking for a generation
    • response.create emits a bare clientContent{turnComplete: true}, Google's documented way to hand the floor to the model, unless the previous client frame already asked for a generation (an item that completed the turn, or a tool response): standard OpenAI clients that send the item and then response.create still get exactly one answer
  6. response.done lists the output items of the live turn (d7d64a2f69, was fix(gemini): response.done lists the output items of the live turn #47168)
    • OpenAI's response.done lists the items the response produced (output); the Gemini Live bridge always sent output: []
    • Clients that read the function calls or the message items off response.done, instead of collecting every response.output_item.done, saw an empty turn
    • The bridge remembers the response.output_item.done events it emitted since the previous response.done, across frames, and lists their items in the next response.done
    • The suppressed trailing response.done after a tool call (an existing special case) is untouched: items that follow it are carried to the next real response.done

User Flow

2. map live start- and end-of-speech sensitivity

Before: a developer tunes turn_detection on ws://localhost:4000/v1/realtime?model=gemini-live

  1. They send session.update with silence_duration_ms and end_of_speech_sensitivity: END_SENSITIVITY_LOW
  2. The setup sent to Gemini carries only silenceDurationMs; the sensitivity is silently lost
  3. The model keeps interrupting the user mid-sentence

After: the same session.update

  1. The setup carries startOfSpeechSensitivity / endOfSpeechSensitivity next to silenceDurationMs
  2. Gemini accepts the setup and the session runs with the requested detection

3. surface live barge-in as input_audio_buffer.speech_started

Before: a user talks over the assistant on ws://localhost:4000/v1/realtime?model=gemini-live

  1. Gemini stops generating and the client receives response.done
  2. The client has no barge-in signal, so the seconds of audio it had buffered keep playing

After: the same interruption

  1. The client receives input_audio_buffer.speech_started, flushes its playback and cancels, then the events that close the interrupted item and a single cancelled response.done

4. forward the output language to live speechConfig.languageCode

Before: a developer sets audio.output.language: "fr-FR" in session.update on ws://localhost:4000/v1/realtime?model=gemini-live

  1. The setup sent to Gemini has no languageCode; with an OpenAI voice name it has no speechConfig at all
  2. The model decides the language itself and may switch mid-conversation

After: the same session.update

  1. The setup carries speechConfig.languageCode: "fr-FR", with or without a voice
  2. Gemini accepts the setup and the session runs with the requested language

5. honor response.create and turn_complete on live conversation items

Before: a developer whose opening line lives in the system instruction connects to ws://localhost:4000/v1/realtime?model=gemini-live

  1. After session.updated they send response.create
  2. Nothing happens: the model never speaks until the user does

After: the same response.create

  1. The model opens the conversation as instructed
  2. A standard client that sends a user item and then response.create still gets one answer, not two

6. response.done lists the output items of the live turn

Before: a developer runs a tool-calling turn on ws://localhost:4000/v1/realtime?model=gemini-live

  1. The function call arrives as response.output_item.done, then the spoken answer
  2. Both response.done events carry output: []

After: the same turn

  1. The first response.done lists the function_call item, the second lists the message item

Relevant issues

Complements #39864 (setup sent with the first content frame) and #46702 (error when a session.update is dropped). Supersedes #47131, #47139, #31709, #47167 and #47168.

Pre-Submission checklist

  • I have Added testing in the tests/unit directory, Adding at least 1 test is a hard requirement
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem: six problems of the same bridge, one commit per problem, consolidated because of the open-PR cap; happy to split again on request

Proof of Fix

Every proof below is a live LiteLLM proxy run against vertex_ai/gemini-3.8-live in eu, before at the merge base and after at the fix. Proofs 2, 4, 5 and 6 were taken in October before main was merged; 1 and 3 were re-measured after the merge.

1. dropped: #39864 covers the deferred-setup race

Live LiteLLM proxy on main 754c2225d7 (no change from this branch), vertex_ai/gemini-3.8-live in eu, gemini_live_defer_setup: true. Ten sessions per scenario, the question is "What is the capital of France?":

  • A: session.update, conversation.item.create and response.create sent back to back
  • B: three audio frames first, then the same three frames back to back
scenario A: 10/10 answered
scenario B: 10/10 answered

The branch after the merge gives the same 10/10 and 10/10, so the frame hold is gone from this PR.

2. map live start- and end-of-speech sensitivity

Run on the standalone branch at c794d231c6; cherry-picked here as b3ffabe019 with the same code.

The setup.realtimeInputConfig built by VertexAIRealtimeConfig.transform_realtime_request from the same session.update (server_vad, silence_duration_ms: 700, both sensitivities LOW), run against each tree:

base  @ 46ae68021e setup.realtimeInputConfig = {"automaticActivityDetection": {"disabled": false, "silenceDurationMs": 700}}
pr    @ c794d231c6 setup.realtimeInputConfig = {"automaticActivityDetection": {"disabled": false, "silenceDurationMs": 700, "startOfSpeechSensitivity": "START_SENSITIVITY_LOW", "endOfSpeechSensitivity": "END_SENSITIVITY_LOW"}}

Live LiteLLM proxy at the PR tip c794d231c6, vertex_ai/gemini-3.8-live in eu, real calls, the same session.update then one user text item:

t+580ms session.updated
t+580ms >> user text item sent (turn complete)
t+1096ms response.created id=resp_7ad914dd-6385-41fd-aaca-536bb6f98d55 mod=['audio']
t+1096ms response.output_audio_transcript.delta 'Bonjour, je suis '
t+1747ms response.output_audio_transcript.delta 'DialogPro. Comment'
t+2947ms response.output_audio_transcript.delta ' vous appelez-vous ?'
t+4266ms response.done status=completed out={'audio_tokens': 88, 'reasoning_tokens': 93, 'text_tokens': 13}

Gemini accepted the setup (no 1007) and answered. Unit test: tests/unit/llms/gemini/realtime/test_gemini_realtime_transformation.py::test_gemini_maps_the_two_vad_sensitivities

3. surface live barge-in as input_audio_buffer.speech_started

Run on the standalone branch at a5de355a7d; cherry-picked here as 0ad66deb1d with the same code.

Live LiteLLM proxy, vertex_ai/gemini-3.8-live in eu, real calls. Client: the model is asked to count slowly from one to twenty; 1.5 s into its answer the client streams 6.3 s of real French speech (16 kHz PCM) over it.

Before, merge base 46ae68021e:

t+253ms >> user item (model starts counting)
t+696ms response.created
t+2350ms >> user speaks over the model (real speech, 6336 ms of 16 kHz PCM)
t+8857ms response.done
t+8857ms response.done
speech_started=0 response.created=1 response.done=2

After, PR tip a5de355a7d (a 4.7 s utterance this time):

t+504ms >> user item (model starts counting)
t+925ms response.created
t+1587ms >> user speaks over the model (real speech, 4711 ms of 16 kHz PCM)
t+6477ms input_audio_buffer.speech_started
t+6477ms response.done
t+6477ms response.done
speech_started=1 response.created=1 response.done=2

After the merge of main, same client on both sides: a long story is requested, 2.5 s into the spoken answer the client streams a 3.3 s spoken interruption (24 kHz PCM produced by Gemini TTS) under server VAD.

Before, main 754c2225d7:

  4.2s response.output_audio.done x1
  4.2s response.output_item.done x1
  4.2s response.done x1
interruption sent at 3.7s | speech_started at []

After, branch 70d1f63b67:

  4.1s input_audio_buffer.speech_started x1
  4.1s response.output_audio.done x1
  4.1s response.output_item.done x1
  4.1s response.done x1
interruption sent at 3.5s | speech_started at [4.1]

Unit test: tests/unit/llms/gemini/realtime/test_gemini_realtime_transformation.py::test_gemini_interrupted_emits_speech_started_before_response_done

4. forward the output language to live speechConfig.languageCode

Run on the standalone branch at f27f617aad; cherry-picked here as 1ec6108d56 with the same code.

The speechConfig built by VertexAIRealtimeConfig.transform_realtime_request from the same session.update, run against each tree:

base @ 46ae68021e
{"voice": "Puck", "language": "fr-FR"} -> {"voiceConfig": {"prebuiltVoiceConfig": {"voiceName": "Puck"}}}
{"voice": "marin", "language": "fr-FR"} -> null

pr   @ f27f617aad
{"voice": "Puck", "language": "fr-FR"} -> {"voiceConfig": {"prebuiltVoiceConfig": {"voiceName": "Puck"}}, "languageCode": "fr-FR"}
{"voice": "marin", "language": "fr-FR"} -> {"languageCode": "fr-FR"}

Live LiteLLM proxy at the PR tip, vertex_ai/gemini-3.8-live in eu, real calls, session.update with audio.output.language: "fr-FR", voice Puck, then one user text item: Gemini accepted the setup (no 1007) and answered

t+1219ms session.updated
t+1652ms response.created id=resp_55466668-8013-46b0-bf6d-2af0515f7b10 mod=['audio']
t+1652ms response.output_audio_transcript.delta 'Bonjour, je suis '
t+2387ms response.output_audio_transcript.delta 'DialogPro, votre assistant'
t+7224ms response.done status=completed out={'audio_tokens': 146, 'reasoning_tokens': 35, 'text_tokens': 17}

Unit tests in tests/unit/llms/gemini/realtime/test_gemini_realtime_transformation.py: test_gemini_output_language_reaches_speech_config_language_code, test_gemini_output_language_is_kept_without_a_voice, test_gemini_output_language_is_kept_when_an_openai_voice_is_dropped

5. honor response.create and turn_complete on live conversation items

Run on the standalone branch at f7f6939876; cherry-picked here as d7238c6bf0 with the same code.

Live LiteLLM proxy, vertex_ai/gemini-3.8-live in eu, real calls. Client: instruction "À ton tout premier tour, dis : « Bonjour, je suis DialogPro. Comment vous appelez-vous ? »", then a bare response.create once session.updated arrives.

Before, merge base 46ae68021e:

t+364ms >> response.create sent
counts: {'session.created': 1, 'session.updated': 1}

After, PR tip f7f6939876:

t+589ms >> response.create sent
t+1004ms response.created id=resp_aa6cb67d-1987-4f27-8d43-edee7db1ccff mod=['audio']
t+1004ms response.output_audio_transcript.delta 'Bonjour, je '
t+1668ms response.output_audio_transcript.delta 'suis DialogPro.'
t+2669ms response.output_audio_transcript.delta ' Comment'
t+3904ms response.output_audio_transcript.delta ' vous appelez-vous ?'
t+4435ms response.done status=completed

Standard client (one user item, then response.create) on the PR tip: response.created=1 response.done=1, no second generation. Unit tests in tests/unit/llms/gemini/realtime/test_gemini_realtime_transformation.py: test_gemini_response_create_alone_hands_the_floor_to_the_model, test_gemini_response_create_after_a_completed_item_does_not_generate_twice, test_gemini_history_replay_with_turn_complete_false_generates_once, test_gemini_response_create_after_a_tool_response_does_not_generate_twice, test_gemini_response_create_works_again_once_the_turn_completed

6. response.done lists the output items of the live turn

Run on the standalone branch at 63c03de617; cherry-picked here as d7d64a2f69 with the same code.

Live LiteLLM proxy, vertex_ai/gemini-3.8-live in eu, real calls. Client: a set_username tool, one user text item ("Je m'appelle Laurent, enregistre mon prénom s'il te plaît.") then response.create; on the function call it answers with function_call_output and response.create.

Before, merge base 46ae68021e:

t+538ms >> user item + response.create
t+785ms response.created resp_2f593591
t+785ms output_item.done function_call set_username
t+785ms >> function_call_output + response.create
t+786ms response.done resp_2f593591 output=['function_call'] usage_out=0
t+1295ms response.created resp_3587cc69
t+3949ms output_item.done message
t+3955ms response.done resp_3587cc69 output=[] usage_out=153

After, PR tip 63c03de617:

t+840ms >> user item + response.create
t+1160ms response.created resp_03d19557
t+1160ms output_item.done function_call set_username
t+1160ms >> function_call_output + response.create
t+1160ms response.done resp_03d19557 output=['function_call'] usage_out=0
t+1595ms response.created resp_b1a44f7e
t+4683ms output_item.done message
t+4688ms response.done resp_b1a44f7e output=['message'] usage_out=160

The function-call response.done already listed its item (built in the tool-call path); the spoken answer's response.done now lists its message item instead of []. Unit test: tests/unit/llms/gemini/realtime/test_gemini_realtime_transformation.py::test_gemini_response_done_lists_the_output_items_of_the_turn

Type

🐛 Bug Fix (6) and 🆕 New Feature (2, 3, 4, 5)

Caveats

  • Low: the two fields are a Gemini-specific extension of turn_detection; other providers ignore them
  • Low: with create_response: false on a model that rejects tuning next to disabled: true, the existing early return applies and the sensitivities are not sent
  • Low: the event carries the interrupted item id when one is open, a fresh id otherwise; OpenAI clients only key on the event type. An interruption with no open response emits nothing, and a repeated one emits it once
  • Low: languageCode steers the spoken language, it does not override an instruction written in another language: with an English system prompt the model still answers in English
  • High: this changes what response.create does on Gemini Live, from a no-op to a turn trigger; the guard against double generation covers the item-then-trigger and tool-response-then-trigger sequences, a client that sends two bare response.create in a row will trigger twice, as it would on OpenAI
  • Medium: turn_complete on conversation.item.create is a Gemini-specific extension of the OpenAI event
  • Low: items are remembered per bridge instance, so a session that closes with items pending simply drops them

Final Attestation

  • I attest that this PR is ready for review and merge

…tup completes

With gemini_live_defer_setup, only audio frames were held until the backend
acknowledged the setup. A response.create or conversation.item.create sent
right after the synthetic session.created was forwarded between the setup and
Gemini's setupComplete, answered with the text "Error: Session is not set up
yet" and dropped, so the opening turn was lost. Only the session.update that
triggers the setup may pass; every other client frame now waits.
Gemini Live's automaticActivityDetection accepts startOfSpeechSensitivity and
endOfSpeechSensitivity, but nothing filled them: a client streaming the
microphone continuously saw its sentences cut into fragments by an eager
end-of-speech detection. OpenAI has no equivalent, so the client passes them
under their Gemini names in snake_case; values outside the enums are dropped.
Gemini Live emits serverContent.interrupted when the user talks over the
model; the bridge mapped it only to response.done, which loses the signal a
realtime client acts on to flush its playback and cancel the response.
The interrupted frame now also emits input_audio_buffer.speech_started, built
with the shared speech_event helper, before the response.done.
…geCode

Gemini Live picks the spoken language on its own and drifts mid-conversation
(a French session answering in English after a few turns). The GA session
field audio.output.language now reaches speechConfig.languageCode, next to
the voice, on its own when no voice is sent, and even when an OpenAI stock
voice name is dropped.
…ation items

Gemini Live has no response.create: it generates whenever a client turn
completes. The bridge therefore dropped response.create, so a client could
not replay a saved history and then ask for one answer: every replayed item
produced a spoken answer, and a bare response.create (no item) never gave the
model the floor.

- conversation.item.create honors turn_complete: false, which appends the turn
  to the conversation without asking for a generation
- response.create emits a bare clientContent{turnComplete: true}, Google's
  documented way to hand the floor to the model, unless the previous client
  frame (an item that completed the turn, or a tool response) already asked for
  a generation: standard OpenAI clients that send the item and then
  response.create still get exactly one answer
OpenAI's response.done carries the items the response produced; the Gemini
Live bridge always sent output: []. Clients that read the function calls or
the message items off response.done (instead of collecting every
response.output_item.done) saw an empty turn. The bridge now remembers the
output_item.done events it emitted since the previous response.done, across
frames, and lists them in the next response.done.
@codspeed

codspeed Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 32 untouched benchmarks


Comparing tech-carrement:feat-gemini-live-bridge-fixes (d7d64a2) with main (1552b5b)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (e0514d9) during the generation of this report, so 1552b5b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mateo-berri

Copy link
Copy Markdown
Contributor

#39864 merged and reworks the Gemini Live setup in realtime_streaming.py, so fix 1 likely overlaps. Could you merge main and drop what it covers

BerriAI#39864 holds client content until the first setup and sends it right after the
setup; Gemini Live still drops what reaches it before setupComplete, so that
content now waits with the other pending frames. The barge-in speech_started is
emitted once per open response, ahead of the close events BerriAI#39864 added, and the
manual-activity activityEnd counts as the generation request.
The speech config no longer rebinds its dropped-voice flag, the VAD sensitivity
tables list their literals instead of get_args (Any), and the duplicated logging
import from the merge is gone.
… covers

Since BerriAI#39864 the Gemini Live setup goes out with the first content, and a client
that sends session.update, an item and response.create back to back is answered
20 times out of 20 against Vertex eu (gemini-3.8-live) on main. The explicit
response.create of the transcription-guardrail test now hands the floor to the
model, per the response.create fix of this branch.
@tech-carrement tech-carrement changed the title fix(gemini): gemini live bridge fidelity (deferred setup, vad, barge-in, language, response.create, output items) fix(gemini): gemini live bridge fidelity (vad, barge-in, language, response.create, output items) Nov 21, 2026
@tech-carrement

Copy link
Copy Markdown
Contributor Author

Thanks, merged main (754c2225d7). You were right about fix 1: since #39864 sends the setup with the first content, a client that sends session.update, an item and response.create back to back is answered 10/10 on main against vertex_ai/gemini-3.8-live in eu (another 10/10 with audio frames first), so I dropped it. The barge-in fix now emits input_audio_buffer.speech_started once per open response, ahead of the close events main added for interrupted turns; the before/after on the same recording is in the description. Type-discipline, test-quality and ruff-strict gates pass, and basedpyright on the touched file is at its merge-base count.

@veria-ai

veria-ai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Reviews

@tech-carrement

Copy link
Copy Markdown
Contributor Author

Follow-up on fix 1: audio setups win the race on main (the 20/20 above), but Live Avatar (video) setups don't: the first item gets Error: Session is not set up yet in 5 runs out of 5. Since only #47158 adds video setups, I moved the frame hold there, with that proof.

…idge-fixes

# Conflicts:
#	litellm/llms/gemini/realtime/transformation.py
#	tests/unit/llms/gemini/realtime/test_gemini_realtime_transformation.py

This branch has not been deployed

No deployments
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