Skip to content

fix(py/plugins/google-genai): keep inline Veo video bytes out of raw - #6784

Closed
hilariie wants to merge 1 commit into
mainfrom
fix/py-google-genai-veo-raw-bytes
Closed

hilariie wants to merge 1 commit into
mainfrom
fix/py-google-genai-veo-raw-bytes

Conversation

@hilariie

Copy link
Copy Markdown
Contributor

Why

Vertex Veo fails in the Dev UI with Error serializing to JSON: invalid utf-8 sequence. Without output_gcs_uri, Vertex returns the video inline as video_bytes. _from_veo_operation dumped the SDK response into raw in Python mode, so the raw bytes stayed as bytes and Operation.model_dump_json() raised. The Gemini API returns a download URI instead, so it was never affected.

Changes

  • raw is now dumped in JSON mode with generated_videos[].video.video_bytes excluded. The video still reaches the caller as a base64 data URL in the media part, which is where callers should read it from; raw no longer carries a second multi-MB copy.
  • Tests for an operation with non-UTF-8 inline bytes: raw has no videoBytes, and the media data URL survives a JSON round trip.

Verification

  • The new tests fail on main with the same error as the Dev UI and pass with the fix.
  • Vertex Veo without output_gcs_uri now renders in the Dev UI.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates the Veo video generation model helper to exclude inline video bytes from the raw payload dump of the GenerateVideosOperation response, as they are already delivered to the caller as a data URL in the media part. It also adds corresponding unit tests to verify that inline video bytes are excluded from the raw output and that they correctly survive a JSON round trip as a data URL. I have no feedback to provide as there are no review comments.

@cabljac cabljac 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.

LGTM with comments

_NON_UTF8_VIDEO = b'\x00\x00\x00\x18ftypmp42\x00\x00\x00\x00\xff\xfe\x80'


def _inline_bytes_op() -> genai_types.GenerateVideosOperation:

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.

The tests only build one video, so a regression on the second one isn't caught:

'__all__' -> 0 in _veo.py     -> suite passes
number_of_videos=2 on Vertex  -> 2nd video's bytes back in raw as multi-MB base64

Might be worth having _inline_bytes_op return two non-UTF-8 videos and checking both entries in raw.

raw_payload = response.model_dump(by_alias=True, exclude_none=True)
# Inline video bytes already reach the caller as a data URL in the media part.
raw_payload = response.model_dump(
mode='json',

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.

Is dropping the bytes from raw deliberate? mode='json' alone seems to fix the crash, so the exclude is a separate choice:

mode='json' only                -> raw keeps videoBytes as URL-safe base64, no crash
mode='json' + exclude           -> raw has no videoBytes (this PR)
Go (googlegenai/veo.go:263)     -> raw keeps videoBytes as base64
JS (vertexai/converters.ts:458) -> raw keeps the bytes, REST shape

Smaller raw here, but it no longer matches Go.

@cabljac cabljac 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.

Holding off on this one for now, let's address any comments, get it up to date and sync with the team on how/when it should go in (so we don't step on toes)

@MichaelDoyle

Copy link
Copy Markdown
Contributor

@huangjeff5 @hilariie heads up — since Python SDK development has moved to https://github.com/genkit-ai/genkit-python (and @hilariie already ported the MCP PRs over there), could we re-open this Veo fix on genkit-ai/genkit-python so we can close it out here?

@hilariie

Copy link
Copy Markdown
Contributor Author

Moved to genkit-ai/genkit-python#161

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants