Skip to content

feat(alibaba): support wan2.7 text-to-video and reference-to-video models - #16644

Merged
joshualipman123 merged 4 commits into
mainfrom
feat/alibaba-wan2.7-r2v
Jul 3, 2026
Merged

feat(alibaba): support wan2.7 text-to-video and reference-to-video models#16644
joshualipman123 merged 4 commits into
mainfrom
feat/alibaba-wan2.7-r2v

Conversation

@joshualipman123

Copy link
Copy Markdown
Contributor

Background

Alibaba wan2.7 video model family (wan2.7-t2v, wan2.7-r2v, plus -2026-06-12 dated snapshots) are served on the same endpoint as wan2.6 but use a changed request protocol.

Summary

  • @ai-sdk/alibaba: isWan27Model predicate gates the protocol split in AlibabaVideoModel.
  • Model IDs: added wan2.7-t2v, wan2.7-t2v-2026-06-12, wan2.7-r2v, wan2.7-r2v-2026-06-12.
  • @ai-sdk/gateway: added alibaba/wan-v2.7-t2v and alibaba/wan-v2.7-r2v video model IDs.
  • Examples: wan2.7-t2v, wan2.7-r2v, and wan2.7-r2v-reference-voice (voice references via the media provider option) under examples/ai-functions/src/generate-video/alibaba/.

Manual Verification

  • Verified the request mapping field-by-field against Alibaba's official wan2.7 API references (media item shape and reference_voice, resolution/ratio enums and defaults, duration ranges, base64-for-images/URL-only-for-videos constraints, removed shot_type/audio parameters, prompt reference conventions).
  • Ran the new examples

Checklist

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Future Work

  • wan2.7 i2v support
  • Once feat/video-reference-inputs lands (adds mediaType to URL references), prefer the explicit mediaType over the current .mp4/.mov extension sniffing when classifying URL references in resolveMedia.
  • Backport to release-v6.0

joshualipman123 and others added 2 commits July 2, 2026 00:06
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>
Comment thread packages/alibaba/src/alibaba-video-model.ts
…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>
@gr2m gr2m added the backport Admins only: add this label to a pull request in order to backport it to the prior version label Jul 2, 2026
Comment thread content/providers/01-ai-sdk-providers/32-alibaba.mdx
Comment thread content/providers/01-ai-sdk-providers/32-alibaba.mdx
Comment thread packages/alibaba/src/alibaba-video-model-options.ts
Comment thread packages/alibaba/src/alibaba-video-model-options.ts
Comment thread packages/alibaba/src/alibaba-video-model.ts Outdated
@joshualipman123
joshualipman123 requested a review from shaper July 2, 2026 18:33
@joshualipman123
joshualipman123 merged commit 0c3c7e4 into main Jul 3, 2026
49 checks passed
@joshualipman123
joshualipman123 deleted the feat/alibaba-wan2.7-r2v branch July 3, 2026 00:53
github-actions Bot added a commit that referenced this pull request Jul 3, 2026
@github-actions github-actions Bot removed the backport Admins only: add this label to a pull request in order to backport it to the prior version label Jul 3, 2026
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

⚠️ Backport to release-v6.0 created but has conflicts: #16660

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

🚀 Published in:

Package Version
ai 7.0.15 github npm
@ai-sdk/alibaba 2.0.7 github npm
@ai-sdk/amazon-bedrock 5.0.11 github npm
@ai-sdk/angular 3.0.15 github npm
@ai-sdk/anthropic 4.0.8 github npm
@ai-sdk/gateway 4.0.12 github npm
@ai-sdk/google-vertex 5.0.11 github npm
@ai-sdk/harness 1.0.18 github npm
@ai-sdk/harness-claude-code 1.0.18 github npm
@ai-sdk/harness-codex 1.0.19 github npm
@ai-sdk/harness-deepagents 1.0.17 github npm
@ai-sdk/harness-opencode 1.0.18 github npm
@ai-sdk/harness-pi 1.0.18 github npm
@ai-sdk/langchain 3.0.15 github npm
@ai-sdk/llamaindex 3.0.15 github npm
@ai-sdk/otel 1.0.15 github npm
@ai-sdk/policy-opa 1.0.15 github npm
@ai-sdk/react 4.0.16 github npm
@ai-sdk/rsc 3.0.15 github npm
@ai-sdk/sandbox-just-bash 1.0.18 github npm
@ai-sdk/sandbox-vercel 1.0.18 github npm
@ai-sdk/svelte 5.0.15 github npm
@ai-sdk/tui 1.0.15 github npm
@ai-sdk/vue 4.0.15 github npm
@ai-sdk/workflow 1.0.15 github npm
@ai-sdk/workflow-harness 1.0.18 github npm

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

4 participants