Loading...
Loading...
Use when generating videos from images with DashScope Wan 2.7 image-to-video model (wan2.7-i2v). Use when implementing first-frame video generation, first+last frame interpolation, video continuation, or audio-driven video synthesis via the video-synthesis async API.
npx skill4agent add cinience/alicloud-skills aliyun-wan-i2vmkdir -p output/aliyun-wan-i2v
python -m py_compile skills/ai/video/aliyun-wan-i2v/scripts/generate_i2v.py && echo "py_compile_ok" > output/aliyun-wan-i2v/validate.txtoutput/aliyun-wan-i2v/validate.txtoutput/aliyun-wan-i2v/python3 -m venv .venv
. .venv/bin/activate
python -m pip install dashscopeDASHSCOPE_API_KEYdashscope_api_key~/.alibabacloud/credentialswan2.7-i2v| Capability | Description | Required media types |
|---|---|---|
| First-frame video | Generate video from a single image | |
| First+last frame | Interpolate video between two images | |
| Video continuation | Extend an existing video clip | |
| Audio-driven | Drive video with audio (lip-sync, rhythm) | |
POST https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesisAuthorization: Bearer $DASHSCOPE_API_KEYContent-Type: application/jsonX-DashScope-Async: enabledashscope.aliyuncs.comdashscope-intl.aliyuncs.compromptnegative_promptmediatypeurltypefirst_framelast_framedriving_audiofirst_clipurlresolution720P1080P1080Pdurationprompt_extendwatermarkseeddurationoutput.task_idoutput.task_statusrequest_idoutput.video_urloutput.orig_promptoutput.actual_promptusage.video_countusage.video_durationimport os
import json
import time
import requests
API_KEY = os.getenv("DASHSCOPE_API_KEY")
BASE_URL = "https://dashscope.aliyuncs.com/api/v1"
def create_i2v_task(req: dict) -> str:
"""Create an image-to-video task and return task_id."""
payload = {
"model": "wan2.7-i2v",
"input": {
"prompt": req.get("prompt", ""),
"media": req["media"],
},
"parameters": {
"resolution": req.get("resolution", "1080P"),
"duration": req.get("duration", 5),
"prompt_extend": req.get("prompt_extend", True),
"watermark": req.get("watermark", False),
},
}
if req.get("negative_prompt"):
payload["input"]["negative_prompt"] = req["negative_prompt"]
if req.get("seed") is not None:
payload["parameters"]["seed"] = req["seed"]
resp = requests.post(
f"{BASE_URL}/services/aigc/video-generation/video-synthesis",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"X-DashScope-Async": "enable",
},
json=payload,
)
resp.raise_for_status()
data = resp.json()
return data["output"]["task_id"]
def poll_task(task_id: str, interval: int = 15) -> dict:
"""Poll until task completes. Returns final response."""
while True:
resp = requests.get(
f"{BASE_URL}/tasks/{task_id}",
headers={"Authorization": f"Bearer {API_KEY}"},
)
resp.raise_for_status()
data = resp.json()
status = data["output"]["task_status"]
if status in ("SUCCEEDED", "FAILED", "CANCELED"):
return data
time.sleep(interval)# First-frame only
media = [{"type": "first_frame", "url": "https://example.com/image.jpg"}]
# First + last frame interpolation
media = [
{"type": "first_frame", "url": "https://example.com/start.jpg"},
{"type": "last_frame", "url": "https://example.com/end.jpg"},
]
# Audio-driven from first frame
media = [
{"type": "first_frame", "url": "https://example.com/face.jpg"},
{"type": "driving_audio", "url": "https://example.com/speech.mp3"},
]
# Video continuation
media = [{"type": "first_clip", "url": "https://example.com/clip.mp4"}]| Error | Likely cause | Action |
|---|---|---|
| 401/403 | Missing or invalid | Check env var or credentials file |
400 | Unsupported resolution, bad duration, missing media | Validate parameters |
| "does not support synchronous calls" | Missing | Add required header |
| 429 | Rate limit or quota | Retry with backoff |
output/aliyun-wan-i2v/videos/OUTPUT_DIRwan2.7-i2vfirst_framealiyun-wan-videoeditreferences/api_reference.mdreferences/sources.md