Skip to content

feat(gemini): live avatar support for gemini-3.8-live (avatar config, video deltas, video tokens) - #47158

Closed
tech-carrement wants to merge 5 commits into
BerriAI:mainfrom
tech-carrement:feat-gemini-live-avatar
Closed

tech-carrement wants to merge 5 commits into
BerriAI:mainfrom
tech-carrement:feat-gemini-live-avatar

Conversation

@tech-carrement

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

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Gemini 3.8 Live can render a lip-synced avatar (avatarConfig + responseModalities: ["VIDEO"]), and the model then streams fragmented MP4 (H.264 + AAC-LC) blobs as video/mp4 inlineData parts, continuously and outside any turn
  • The realtime bridge had no way to request it, and every inlineData part was treated as audio: the MP4 blobs would land in response.output_audio.delta, and a video-only frame would open a phantom OpenAI response
  • Video output tokens (candidatesTokensDetails modality VIDEO) were dropped from response.done usage
  • Since main filters response modalities down to TEXT and AUDIO (when validating session.update and when building the setup), a video request is refused or silently downgraded to audio
  • Since fix(realtime)!: send the Gemini Live setup at the first content so session.update settings apply #39864 the setup goes out with the first content and the content follows right away; a video setup is slow enough that Gemini answers the first item with the text Error: Session is not set up yet and drops it, every time

How it solves it:

  • session.update avatar (prebuilt avatar name) maps to setup.avatarConfig.avatarName, and avatar_video_bitrate_bps to avatarConfig.videoBitrateBps (Google's default stream is about 8 Mbit/s); output_modalities: ["video"] already mapped to VIDEO
  • video/* inlineData parts become response.output_video.delta events (a new OpenAIRealtimeOutputVideoDelta TypedDict in the realtime event union: delta = base64 fMP4 chunk, mime_type, current response_id / item_id or null) instead of polluting the audio delta
  • A video-only model turn is a side channel: it opens no response and leaves the delta state alone; the spoken turn is opened by its output transcript and closed by generationComplete like any audio item (the audio is muxed in the MP4, no audio part ever arrives)
  • Video output tokens survive into response.done usage.output_token_details.video_tokens
  • VIDEO is a producible modality when the session asks for an avatar (avatarConfig in the setup), and wins over AUDIO when both are requested since the video stream carries the audio; without an avatar it is still refused or dropped as before
  • With gemini_live_defer_setup, every client frame except the session.update that triggers the setup, held content included, waits for setupComplete. This is the frame hold first proposed in fix(realtime): buffer every client frame until the deferred gemini setup completes #47131 and then in fix(gemini): gemini live bridge fidelity (vad, barge-in, language, response.create, output items) #47172; it was dropped from fix(gemini): gemini live bridge fidelity (vad, barge-in, language, response.create, output items) #47172 because audio setups win the race on main (20/20), but avatar setups lose it (proof below), so it lives here with the feature that needs it

User Flow

Before: a developer asks for the avatar on ws://localhost:4000/v1/realtime?model=gemini-live

  1. They send session.update with output_modalities: ["video"]
  2. Gemini closes the socket: 1007: Avatar config is required for avatar mode. and there is no field to pass it

After: the same developer adds avatar: "Ben" to the session

  1. Video chunks arrive as response.output_video.delta from the first seconds, a few per 100 ms
  2. The spoken answer arrives as transcript deltas inside a normal response, and response.done reports the video tokens

Relevant issues

Closes #43166

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: avatar sessions, including the two things main needs to let them through (the VIDEO modality and the setup race)

Proof of Fix

After merging main (21 Nov 2026, main at 754c2225d7)

Live LiteLLM proxy, vertex_ai/gemini-3.8-live in eu, gemini_live_defer_setup: true, real calls. Same client as below: session.update with output_modalities: ["video"], avatar: "Ben", avatar_video_bitrate_bps: 1500000, voice Puck, then one user text item once session.updated arrives. Five sessions per tree.

main 754c2225d7 (no avatar support): the avatar is ignored and the answer comes back as audio only

t+1934ms response.created mod=['audio']
t+7323ms response.done status=completed out={'text_tokens': 18, 'audio_tokens': 142, 'reasoning_tokens': 47}
video deltas=0 bytes=0

this branch without the frame hold (925beddb4c): 0/5, the first item loses the race to the video setup

run 1..5: KO  TEXT delta 'Error: Session is not set up yet. Please send a setup message first or wait for its completion.'
          (video keeps flowing, about 1000 deltas in 25 s, no transcript, no response.done)

this branch (217366b5b0): 4/5

run 1: OK  video deltas=298 bytes=1411668 transcript='Je suis DialogPro, votre assistant personnel conçu pour r…'
run 2: OK  video deltas=218 bytes=1075368 transcript='Je suis DialogPro, votre assistant virtuel.'
run 3: OK  video deltas=218 bytes=1075564 transcript='Je suis DialogPro, votre assistant virtuel.'
run 4: OK  video deltas=250 bytes=1200831 transcript='Je suis DialogPro, votre assistant virtuel prêt à vous ai…'
run 5: KO  upstream websocket closed with code 1011: Internal error encountered

The 1011 is on Google's side: the same client against a build of this feature on a 1.107 base fails the same way in 1 run out of 10, see Caveats.

New unit tests: test_gemini_video_output_is_accepted_only_with_an_avatar, test_gemini_avatar_session_keeps_video_when_audio_is_requested_too (tests/unit/llms/gemini/realtime/test_gemini_realtime_transformation.py) and test_deferred_setup_holds_every_client_frame_until_backend_setup_complete (tests/unit/litellm_core_utils/test_realtime_streaming.py); they fail without the matching change.

Original proof (October, before main was merged)

Live LiteLLM proxy, vertex_ai/gemini-3.8-live in eu (api_base: https://aiplatform.eu.rep.googleapis.com), real calls. Client: session.update with output_modalities: ["video"], avatar: "Ben", avatar_video_bitrate_bps: 1500000, voice Puck, then one user text item once session.updated arrives.

Before, merge base 46ae68021e:

t+192ms session.created
t+1361ms error {"type": "error", "error": {"type": "server_error", "message": "upstream websocket closed with code 1007: Avatar config is required for avatar mode.; [Session ID: 823fb2da-69f0-4788-95cc-dbc2bd58ede0]

After, at 04f8c5c1a6 (the code commit; d7817d673e on top only adds the coverage-matrix note):

t+430ms session.created
t+572ms session.updated
t+572ms >> user text item sent (turn complete)
t+3354ms video delta bytes=1221 resp=None
t+3443ms video delta bytes=20982 resp=None
t+4375ms response.created id=resp_a3e54bea-053f-4679-8068-394b33647887 mod=['video']
t+4375ms response.output_audio_transcript.delta 'Bonjour, je suis '
t+5174ms response.output_audio_transcript.delta 'DialogPro. Comment'
t+6175ms response.output_audio_transcript.delta ' vous appelez-vous'
t+8628ms response.output_audio.done
t+8628ms response.output_item.done
t+8634ms response.done status=completed out={'audio_tokens': 93, 'reasoning_tokens': 168, 'text_tokens': 13, 'video_tokens': 26832}

The concatenated deltas of a session are a valid fragmented MP4 (ffprobe: h264 704x1280 24 fps + aac 24 kHz mono). Unit tests in tests/unit/llms/gemini/realtime/test_gemini_realtime_transformation.py: test_gemini_avatar_session_update_emits_video_modality_and_avatar_config, test_gemini_avatar_video_bitrate_is_mapped, test_gemini_video_inline_data_becomes_output_video_delta, test_gemini_video_only_frame_emits_no_audio_delta, test_gemini_video_only_frame_never_opens_a_response, test_gemini_transcript_opened_response_is_closed_by_generation_complete, test_gemini_video_output_tokens_survive_response_done

Type

🆕 New Feature

Caveats

  • Medium: response.output_video.delta is not an OpenAI realtime event; it is the natural sibling of response.output_audio.delta, and clients that do not know it ignore it. Happy to rename if there is a preferred vocabulary
  • Medium: avatar and avatar_video_bitrate_bps are new session fields with no OpenAI counterpart; custom avatars (customized_avatar, allowlist-only at Google) are not covered
  • Low: the avatar stream flows continuously, idle animation included (about 1.7 Mbit/s at the 1.5 Mbit/s cap)
  • Low: holding every client frame until setupComplete delays the first content of every deferred Gemini Live session by the setup time (about 100 ms for audio), not only avatar sessions
  • Low: Gemini Live closes about one avatar session in ten with 1011 Internal error encountered, at the same rate on a 1.107-based build of this feature: not caused by this change

Final Attestation

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

@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-avatar (d7817d6) with main (bbd446b)

Open in CodSpeed

… video deltas, video tokens)

Gemini 3.8 Live can render a lip-synced avatar: the setup takes avatarConfig
and responseModalities ["VIDEO"], and the model streams fragmented MP4 (H.264
+ AAC) blobs as video/mp4 inlineData parts, continuously and outside any turn.

- session.update `avatar` -> setup.avatarConfig.avatarName and
  `avatar_video_bitrate_bps` -> avatarConfig.videoBitrateBps (the default
  stream is about 8 Mbit/s); output_modalities ["video"] already maps to VIDEO
- video/* inlineData parts become response.output_video.delta events instead of
  being appended to the audio delta; a video-only model turn is a side channel
  that opens no response, the spoken turn is opened by its output transcript
  and closed by generationComplete like any audio item
- video output tokens survive into response.done usage
  (output_token_details.video_tokens)

Refs BerriAI#43166
@tech-carrement
tech-carrement force-pushed the feat-gemini-live-avatar branch from c08f254 to 04f8c5c Compare October 17, 2026 19:46
@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!

Main now filters response modalities down to TEXT and AUDIO, both when it
validates session.update and when it builds the setup, which dropped or refused
the VIDEO modality an avatar session answers in. VIDEO is producible when the
session asks for an avatar (avatarConfig in the setup), and wins over AUDIO when
both are requested since the video stream carries the audio.
Main opens a transcript-first item as audio itself, so the avatar path no longer
needs its own fallback, and the input transcription check goes back to main's
shape.
…etes

Since BerriAI#39864 the setup goes out with the first content and the content follows
right away. An audio setup completes fast enough, but a Live Avatar (video)
setup does not: Gemini answers the first item with the text "Error: Session is
not set up yet" and drops it. Every client frame except the session.update that
triggers the setup, held content included, now waits for setupComplete.
@tech-carrement

Copy link
Copy Markdown
Contributor Author

Merged main (754c2225d7). Two things main now needs for avatar sessions are in this PR: VIDEO is producible when the session asks for an avatar (main's new modality filter refused or dropped it), and with a deferred setup client frames wait for setupComplete, since a video setup loses the race #39864 leaves open (0/5 without, 4/5 with against Vertex eu, the fifth a Google-side 1011 that a 1.107-based build shows at the same rate). Live proof in the description.

@veria-ai

veria-ai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Reviews

@github-actions

Copy link
Copy Markdown
Contributor

#43166 was fixed by #53270 on main, so this pull request is closed. Reopen it if something was missed.

@github-actions github-actions Bot closed this Nov 21, 2026
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.

[Feature]: Support Gemini Live Avatar (avatar_config / customized_avatar) in realtime Gemini/Vertex integration

1 participant