Skip to content

Studio: accept OpenAI video_url content parts on /v1/chat/completions - #10439

Merged
danielhanchen merged 27 commits into
unslothai:mainfrom
Lyxot:feat/studio-media-content-parts
Sep 15, 2026
Merged

danielhanchen merged 27 commits into
unslothai:mainfrom
Lyxot:feat/studio-media-content-parts

Conversation

@Lyxot

@Lyxot Lyxot commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator

/v1/chat/completions rejected an OpenAI-shaped video_url content part. The part is not in _KNOWN_CONTENT_PART_TAGS, so it parsed as UnknownContentPart and _reject_unsupported_content_parts refused it:

400 {"error": {"message": "Message content parts of type 'video_url' are not supported.",
               "type": "invalid_request_error", "param": "messages",
               "code": "unsupported_parameter"}}

The only way to send a clip was Unsloth's own top-level video_base64 field, which is an [x-unsloth] extension that no OpenAI-compatible client emits. Studio's frontend was its only caller. Fixes the GGUF part of #10389.

video_url is not in the official OpenAI spec. It is the de-facto convention that vLLM and the llama.cpp-compatible ecosystem settled on, {"type": "video_url", "video_url": {"url": ...}}, and it is what OpenAI-compatible clients send when they send video at all.

What changed

video_url parts. VideoContentPart joins the ContentPart union, and _translate_video_parts rewrites each part in place as llama.cpp's own input_video just before dispatch. This translation is required rather than cosmetic: llama-server accepts image_url, input_audio and input_video and throws unsupported content[].type for anything else, and the upstream PR adding the alias (ggml-org/llama.cpp#27921) is still open. Frame sampling stays with llama-server. A clip on any non-user message is refused, since llama-server renders the media marker into whichever turn carried it.

Data URIs only. input_video always carries data. A remote http(s) URL is refused with a 400, at the pre-switch validation and again at the dispatch boundary. llama-server, not Studio, would perform the download, and its client sets set_follow_location(true) (common/http.h) and re-resolves the hostname itself, so a public URL that redirects to a private address defeats any check made on this side. Guarding the shape is not soundly possible; refusing it is. #11010 tracks the pinned fetch that would let images and video both accept a remote URL safely, and remote video can return on top of it.

Both spellings behave identically. _request_has_video reads the legacy field and the parts together, so external-provider routing, the non-GGUF path, the pre-switch capability gate, tool passthrough, the size caps and token counting all behave the same whichever spelling the client used.

Non-GGUF. _local_video_clip reads both spellings, so a transformers or MLX model that serves video_base64 serves a video_url part identically.

Routes that cannot serve a clip. Registering video_url makes the tag known, which removes the unknown-part refusal that some routes were relying on. The preview route refuses a clip in its preflight, before the checkpoint load that the refusal would otherwise follow, and /audio/generate refuses one instead of dropping it and speaking the text alone.

URL schemes. handle_media treats the one string it finds the same way whichever key carried it, and honours file:// when llama-server runs with --media-path, so forwarding a clip as opaque payload does not neutralise its scheme. Anything that is not a data URI or bare base64 is refused by name.

Admission accounting. The llama admission estimator prices a video_url clip like the legacy field, matching both the pre- and post-translation spellings so the server-side tool loop's recost does not price the payload as prompt text. Every clip is base64, so the 64 MB cap applies uniformly. Rolling-context trimming treats video_url as unpriced media.

Validation

studio/backend/tests/test_video_chat_completions_behaviour.py drives the real router through TestClient and asserts status codes and the body dispatched to llama-server, rather than asserting that a line is present in routes/inference.py. Every route case is parametrised over both spellings, so the invariant above is tested rather than described. Each fix is mutation-checked: reverting the production line it covers fails that test and only that test.

It covers the URL forms (lower and upper case data URI, no comma, bare base64, http, https, uppercase scheme, file://, ftp://, bare path, malformed authority), several clips in a turn and clips on older turns, each backend cell, each refusing route, message roles, the cap boundary and one over, admission charged once, and the still-unknown part type so the catch-all did not widen.

Cross-platform, Python 3.12 with CPU torch:

runner result
ubuntu-latest (x64 Linux) pass
macos-15 (Apple Silicon) pass
windows-latest (x64 Windows) pass

Full backend suite on Linux, CI shape, this branch against its merge base: the differing files run clean in isolation on both sides, and the same seven flaky tests (checkpoint_compaction, account_tool_confinement, hf_xet_fallback) fail identically on base and head. Zero new failures.

Backend grid, both spellings:

llama.cpp GGUF (+video mmproj)        serves, wire={'data': ...}
llama.cpp GGUF (no video mmproj)      400 needs an mmproj with video support
MLX / transformers (has_video_input)  serves clip
MLX / transformers (no video)         400 only supported on a local GGUF or MLX

UI

No screenshots: this change has no UI-visible effect, and a before/after pair would be two identical images. studio/frontend is untouched, and the frontend only ever sends the legacy video_base64 field as a data URI (chat-adapter.ts), never a video_url part or a remote URL, so none of the new refusals are reachable from the UI. Driving the exact bodies the frontend sends through the real route on main and on this branch produces byte-identical dispatch and identical status codes, and the admission figure behind the context-usage indicator is unchanged (10005 on both).

Risks and tradeoffs

Remote video_url URLs are not supported, by choice, as above. This is stricter than the image path, where a remote image_url is currently forwarded to llama-server on the GGUF path; that is pre-existing on main and tracked in #11010 rather than changed here.

The video_url part is GGUF and MLX only, by way of input_video and _local_video_clip respectively. There is no OS-dependent code in this change, and no GPU-vendor branching.

@Lyxot

Lyxot commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-15T22:13:33.977319Z 4df7549 Manual request
🔒 Security Review ✅ Completed 2026-09-13T18:55:17.511699Z d3ca9bd Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b41dba1179

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread studio/backend/models/inference.py Resolved
Comment thread studio/backend/routes/inference.py Resolved
@Lyxot
Lyxot force-pushed the feat/studio-media-content-parts branch from b41dba1 to cfa1037 Compare September 7, 2026 14:18
@Lyxot

Lyxot commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cfa1037472

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread studio/backend/models/inference.py Resolved
Comment thread studio/backend/routes/inference.py Resolved
@Lyxot
Lyxot force-pushed the feat/studio-media-content-parts branch from cfa1037 to e89700b Compare September 7, 2026 14:47
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: e89700b186

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member

main already carries the input_audio part and its lift in studio/backend/models/inference.py and routes/inference.py, so this now overlaps there and no longer merges cleanly; could you rebase and narrow it to the video_url part plus its admission pricing, leaving the speech-model refusal and monitor-row changes for a separate branch?

@Lyxot
Lyxot force-pushed the feat/studio-media-content-parts branch from e89700b to 4b51c40 Compare September 8, 2026 04:18
@Lyxot Lyxot changed the title Studio: accept OpenAI video_url and input_audio content parts on /v1/chat/completions Studio: accept OpenAI video_url content parts on /v1/chat/completions Sep 8, 2026
@Lyxot

Lyxot commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4b51c405b1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread studio/backend/routes/inference.py Resolved
@Lyxot
Lyxot force-pushed the feat/studio-media-content-parts branch from 4b51c40 to c8c4bd2 Compare September 8, 2026 04:59
@Lyxot
Lyxot requested a review from Imagineer99 as a code owner September 8, 2026 04:59
@Lyxot

Lyxot commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

Done — rebased onto latest main and narrowed as asked. The branch is now a single commit, c8c4bd2.

The input_audio part and its lift are gone; main's implementation covers that, and it differs from mine (the lift lives in the route as _normalise_chat_content_parts rather than as a request-scope validator), so there is nothing left to reconcile. The speech-model video refusal and the monitor-row change are gone too, along with the move of the non-GGUF refusal ahead of the speech and audio-input dispatches — that refusal sits where main has it, now reading both spellings through one predicate. Those are worth a follow-up branch: as it stands a clip sent to a speech model on the non-GGUF path is still swallowed by the early dispatch, exactly as the legacy video_base64 field is today, so the two spellings behave identically and nothing regresses.

What remains is the video_url part, its translation to llama-server's input_video, the existing gates reading both spellings, and admission pricing.

One addition outside that list, which I would rather flag than slip past you. Registering video_url in _KNOWN_CONTENT_PART_TAGS makes the tag known, so it no longer trips the unknown-part refusal that routes which cannot serve video were relying on. On the preview route that meant a clip passed the preflight and was refused only after load_model_for_preview had already evicted the resident model — the exact cost the preflight's own comment says it exists to avoid. There is now a video refusal beside that unsupported-part check, four lines.

The same reasoning applies to /audio/generate, where a clip would now be dropped silently and the text spoken alone. I have left that one out, since it is a speech route and you asked for those to be separate; note that it matches how the legacy video_base64 field behaves there today.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: c8c4bd28f0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: da78528e6e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 4df7549f64

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants