feat(alibaba): support wan2.7 text-to-video and reference-to-video models - #16644
Merged
Conversation
Adds the new wan2.7 R2V protocol (input.media) alongside the legacy wan2.6 protocol (input.reference_urls): - wan2.7-r2v / wan2.7-r2v-2026-06-12 model IDs - media / ratio provider options - inputReferences + frameImages auto-mapping to media items, with base64 image refs sent as data URIs - resolution tier + ratio parameters instead of size - alibaba/wan-v2.7-r2v gateway model ID - docs, example, tests Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
joshualipman123
marked this pull request as ready for review
July 2, 2026 17:59
gr2m
approved these changes
Jul 2, 2026
…he resolution string does not parse into two positive integers (e.g. capital `X`, trailing suffix, or non-numeric segment).
This commit fixes the issue reported at packages/alibaba/src/alibaba-video-model.ts:120
## Bug
`deriveRatioFromResolution` (packages/alibaba/src/alibaba-video-model.ts) computes an aspect ratio via a Euclidean GCD loop:
```ts
const [width, height] = resolution.split('x').map(Number);
let a = width;
let b = height;
while (b !== 0) {
[a, b] = [b, a % b];
}
```
If the resolution string doesn't split cleanly on lowercase `'x'` into two numeric parts, `width` and/or `height` become `NaN`/`undefined`. Because `NaN !== 0` is always `true` and `NaN % anything === NaN`, `b` never reaches `0` and the loop spins forever, hanging the request/process.
### Concrete triggers
- `"1920X1080"` (capital `X`) → `split('x')` yields `["1920X1080"]` → `width = NaN`, `height = undefined`.
- `"1920x1080P"` → `height = Number("1080P") = NaN`.
- Any non-numeric segment.
Verified experimentally: `"1920X1080"` triggers an unbounded loop (detected after 1,000,000 iterations without terminating).
### Why runtime values can be invalid
Although `resolution` is typed `${number}x${number}`, TypeScript template-literal types are not enforced at runtime. JS callers or unexpected upstream values can pass arbitrary strings, and this helper is called directly on `options.resolution` with no prior validation in `doGenerate` for wan2.7 t2v/r2v models.
## Fix
Validate that both parsed dimensions are positive integers before entering the GCD loop; otherwise return `undefined` (the same "unsupported" signal already used when the ratio isn't in `supportedRatios`):
```ts
const [width, height] = resolution.split('x').map(Number);
if (
!Number.isInteger(width) ||
!Number.isInteger(height) ||
width <= 0 ||
height <= 0
) {
return undefined;
}
```
Confirmed valid inputs (`1920x1080`, `1280x720`, `960x960`) still return the correct ratios, while malformed inputs now safely return `undefined` instead of hanging.
Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: gr2m <gregor@martynus.net>
shaper
reviewed
Jul 2, 2026
Contributor
|
|
Contributor
|
🚀 Published in:
|
gr2m
added a commit
that referenced
this pull request
Jul 6, 2026
…o-video models (#16660) This is an automated backport of #16644 to the release-v6.0 branch. FYI @joshualipman123 This backport has conflicts that need to be resolved manually. ### `git cherry-pick` output ``` Auto-merging content/providers/01-ai-sdk-providers/32-alibaba.mdx CONFLICT (modify/delete): packages/alibaba/src/alibaba-video-model-options.ts deleted in HEAD and modified in 0c3c7e4 (feat(alibaba): support wan2.7 text-to-video and reference-to-video models (#16644)). Version 0c3c7e4 (feat(alibaba): support wan2.7 text-to-video and reference-to-video models (#16644)) of packages/alibaba/src/alibaba-video-model-options.ts left in tree. Auto-merging packages/alibaba/src/alibaba-video-model.test.ts Auto-merging packages/alibaba/src/alibaba-video-model.ts CONFLICT (content): Merge conflict in packages/alibaba/src/alibaba-video-model.ts error: could not apply 0c3c7e4... feat(alibaba): support wan2.7 text-to-video and reference-to-video models (#16644) hint: After resolving the conflicts, mark them with hint: "git add/rm <pathspec>", then run hint: "git cherry-pick --continue". hint: You can instead skip this commit with "git cherry-pick --skip". hint: To abort and get back to the state before "git cherry-pick", hint: run "git cherry-pick --abort". hint: Disable this message with "git config set advice.mergeConflict false" ``` --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Alibaba wan2.7 video model family (
wan2.7-t2v,wan2.7-r2v, plus-2026-06-12dated snapshots) are served on the same endpoint as wan2.6 but use a changed request protocol.Summary
@ai-sdk/alibaba:isWan27Modelpredicate gates the protocol split inAlibabaVideoModel.wan2.7-t2v,wan2.7-t2v-2026-06-12,wan2.7-r2v,wan2.7-r2v-2026-06-12.@ai-sdk/gateway: addedalibaba/wan-v2.7-t2vandalibaba/wan-v2.7-r2vvideo model IDs.wan2.7-t2v,wan2.7-r2v, andwan2.7-r2v-reference-voice(voice references via themediaprovider option) underexamples/ai-functions/src/generate-video/alibaba/.Manual Verification
reference_voice, resolution/ratio enums and defaults, duration ranges, base64-for-images/URL-only-for-videos constraints, removedshot_type/audioparameters, prompt reference conventions).Checklist
pnpm changesetin the project root)Future Work
feat/video-reference-inputslands (addsmediaTypeto URL references), prefer the explicitmediaTypeover the current.mp4/.movextension sniffing when classifying URL references inresolveMedia.release-v6.0