All Products
Search
Document Center

Alibaba Cloud Model Studio:Wan2.7 reference-to-video API reference

Last Updated:Nov 24, 2026

The Wan reference-to-video model supports multimodal input (images, videos, and audio) and generates videos that maintain consistent character appearance and voice, making it suitable for single-character performance or multi-character interaction scenarios.

Related documents: User Guide

Scope

To ensure successful calls, make sure that the model, Endpoint URL, and API Key all belong to the same region. Cross-region calls will fail.

NoteThe sample code in this topic applies to the Singapore region.

ImportantAlibaba Cloud Model Studio provides dedicated workspace domains for the China (Beijing) and Singapore regions, which deliver superior performance and higher stability for inference requests. We recommend that you migrate to the new domains:

  • China (Beijing) region: migrate from https://dashscope.aliyuncs.com to https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com
  • Singapore region: migrate from https://dashscope-intl.aliyuncs.com to https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com

Among them, {WorkspaceId} is your workspace ID, which you can view on the Workspace Details page in the Alibaba Cloud Model Studio console. The existing domains remain available.

HTTP call

ImportantThis API uses the new protocol and supports the wan2.7 models.

Since video generation tasks take a long time (usually 1 to 5 minutes), the API uses asynchronous calls. The entire process involves two core steps: "create a task -> poll for the result", as follows:

Step 1: Create a task to obtain the task ID

Singapore

POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis

Beijing

POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis

When you call the API, replace {WorkspaceId} with your actual workspace ID.

Note

  • After the task is created successfully, use the task_id returned by the API to query the result. The task_id is valid for 24 hours. Do not create the task repeatedly; just poll for the result.
  • For a quick start guide, see Postman.

Request parameters

Request headers

Content-Typestring(required)

Request content type. This parameter must be set to application/json.

Authorizationstring(required)

Request authentication. The API uses the Alibaba Cloud Model Studio API Key for authentication. Example value: Bearer sk-xxxx.

X-DashScope-Asyncstring(required)

Asynchronous processing configuration parameter. HTTP requests support asynchronous mode only and must be set to enable.

ImportantIf this request header is missing, an error is reported: "current user api does not support synchronous calls".

Request Body

model string (Required)

The model name. For the model list and prices, see Model Price.

Example values: wan2.7-r2v, wan2.7-r2v-2026-06-12.

input object (Required)

Basic input information, such as the prompt.

Properties

prompt string (Required)

The text prompt. It describes the elements and visual characteristics you want in the generated video.

Supports Chinese and English. Each Chinese character, letter, and punctuation mark counts as one character, and the excess is automatically truncated.

  • wan2.7-r2v, wan2.7-r2v-2026-06-12: up to 5,000 characters.

Reference notation: For Chinese prompts, refer to images with labels like "Image 1, Image 2" and to videos with labels like "Video 1, Video 2". For English prompts, write labels like "Image 1" and "Video 1". Leave a space between the letters and the number, and capitalize the first letter. The order follows the media array order. Images and videos are counted separately, so labels such as Image 1 and Video 1 can coexist. If there is exactly one image or one video as the reference, you can simply write "reference image" or "reference video".

Scene description: Suppose reference Image 1 is a cat and Image 2 is a room. To describe the cat playing in the room, two styles are supported: one directly uses the labels (for example, "Image 1 plays in Image 2"); the other adds the subject and scene for clarification (for example, "the cat in Image 1 plays in the room in Image 2").

When a reference image is a multi-grid (storyboard) image, describe the content in a multi-shot form in the prompt. You do not need to describe every grid; providing the key shots is enough — the model automatically recognizes the grid logic and intelligently completes the shot content. For better results, it is recommended to input only one multi-grid image at a time.

For prompt tips, see the T2V/I2V Prompt Guide.

negative_prompt string (Optional)

The negative prompt, used to describe content that you do not want to appear in the video, which constrains the video output.

Supports Chinese and English, up to 500 characters in length; the excess is automatically truncated.

Example values: low resolution, fault, worst quality, low quality, deformed, extra fingers, bad proportions, etc.

media array (Required)

The media assets array, which includes images, videos, and audio. Images/videos are supported as visual references; images support multi-view. Common references include characters, props, and scenes.

  • Each element in the array is a media object containing the type and url fields.

  • The order in which characters are referenced in prompt follows the array order. Images and videos are counted separately, so Image 1 and Video 1 can coexist.

    • The 1st reference_video in the array corresponds to Video 1, the 2nd to Video 2, and so on.
    • The 1st reference_image in the array corresponds to Image 1, the 2nd to Image 2, and so on.

Properties

type string (Required)

The media asset type. Valid values:

  • reference_image: Reference image. Provides reference for the main character (person/animal/object) and the scene.

  • reference_video: Reference video. Provides reference for the main character (person/animal/object) and the voice. Passing empty-scene videos is not recommended.

  • first_frame: First frame image. The video is generated based on the first frame, which usually contains the main character (person/animal/object). It can be passed together with reference images for joint control. Common usages are as follows:

    • The subject to reference already appears in the first frame: in this case, you can combine it with a subject reference to strengthen consistency, or use it for voice reference.
    • The subject to reference does not appear in the first frame: in this case, you can use subject references to define the features of new subjects appearing during the video.

Asset limits:

  • First frame image: at most 1 image can be passed.
  • At least one reference image or reference video must be passed, and reference images + reference videos ≤ 5.
  • When a reference asset is a main character, it must contain a single character only.

url string (required)

Media asset URL. Each value can point to an image or a video.

Input a reference image (type=reference_image)

The reference image URL or Base64-encoded data. The reference image can be a subject (person/animal/object) or a background. When a subject is included, include only one character.

Image limits:

  • Format: JPEG, JPG, PNG (transparent channels are not supported), BMP, WEBP.
  • Resolution: width and height range from [240, 8000] pixels.
  • Aspect ratio: 1:8 to 8:1.
  • File size: no more than 20 MB.

Supported input formats:

  1. Public URL:

  2. Base64-encoded image string:

    • Data format: data:{MIME_type};base64,{base64_data}.
    • Example value: data:image/png;base64,GDU7MtCZzEbTbmRZ...... (the encoded string is too long; only a fragment is shown).
    • For more information, see Input images.

Input a reference video (type=reference_video)

The reference video URL. The video content is recommended to contain a subject (person/animal/object); background or empty-scene videos are not recommended. When a subject is included, include only one character. If the video has sound, the voice can also be used as a reference.

Video limits:

  • Format: mp4, mov.
  • Duration: 1 to 30 s.
  • Resolution: width and height range from [240,4096] pixels.
  • Aspect ratio: 1:8 to 8:1.
  • File size: no more than 100 MB.

Supported input formats:

  1. Public URL:

reference_voice string (optional)

The audio URL. It is used to specify the voice of the main character in the reference asset (image/video). Use it together with reference_image or reference_video. This audio serves only as a voice reference and is independent of the spoken content. For better matching, keep the language of the reference audio consistent with that of the prompt.

Audio activation logic:

  • Default behavior: if reference_video itself contains audio but reference_voice is not specified, the original video audio is used by default.
  • Priority: if both reference_video (with audio) and reference_voice are passed in, the voice of reference_voice takes precedence and overrides the original video audio.

Audio limits:

  • Format: wav, mp3.
  • Duration: 1 to 10 s.
  • File size: no more than 15 MB.

Supported input formats:

  1. Public URL:

parameters object (optional)

Video processing parameters, such as setting the video resolution.

Properties

resolution string (optional)

Importantresolution directly affects costs. Confirm in the Model Studio console before making a call.

The resolution tier of the generated video, used to control video clarity (total pixels).

  • wan2.7-r2v, wan2.7-r2v-2026-06-12: valid values: 720P, 1080P. The default value is 1080P.

ratio string (optional)

The aspect ratio of the generated video.

Effective logic:

  • If no first frame image is provided: the video is generated according to the specified ratio parameter.
  • If a first frame image is provided: the ratio parameter is automatically ignored, and a video with an aspect ratio close to that of the first frame image is generated.

Valid values:

  • 16:9 (default)
  • 9:16
  • 1:1
  • 4:3
  • 3:4

The output video resolutions (width and height in pixels) corresponding to different aspect ratios are shown in the table below.

duration integer (optional)

Importantduration directly affects the fee. Confirm the model price before calling.

The duration of the generated video, in seconds.

  • wan2.7-r2v, wan2.7-r2v-2026-06-12: the default value is 5.

    • When the reference assets contain videos: the value is an integer within [2, 10].
    • When the reference assets do not contain videos: the value is an integer within [2, 15].

prompt_extend boolean (optional)

Whether to enable intelligent prompt rewriting. When enabled, a large language model is used to intelligently rewrite the input prompt. This significantly improves the generation results for short prompts, but increases processing time.

  • true (default): enable intelligent rewriting.
  • false: disable intelligent rewriting.

watermark boolean (optional)

Whether to add a watermark. The watermark is located in the lower-right corner of the video, with fixed text “AI-generated”.

  • false (default): do not add a watermark.
  • true: add a watermark.

seedinteger (optional)

The random number seed, ranging from [0, 2147483647].

If not specified, the system automatically generates a random seed. To improve the reproducibility of generation results, we recommend fixing the seed value.

Note that due to the probabilistic nature of model generation, even with the same seed, the generation results are not guaranteed to be exactly identical each time.

Multi-subject reference (image + video + voice)

Provide multiple reference assets (images + videos) and specify a voice to generate a video.

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
        -H 'X-DashScope-Async: enable' \
        -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
        -H 'Content-Type: application/json' \
        -d '{
        "model": "wan2.7-r2v-2026-06-12",
        "input": {
            "prompt": "视频1抱着图3,在图4的椅子上弹奏一支舒缓的乡村民谣,并说道:“今天的阳光真好。”图1手中拿着图2,路过视频1,把手中的图2放到视频1旁边的桌子上,并说道:“真好听,能不能再唱一遍”。 ",
            "media": [
                {
                    "type": "reference_image",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/sjuytr/wan-r2v-object-girl.jpg",
                    "reference_voice": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/gbqewz/wan-r2v-girl-voice.mp3"
                },
                {
                    "type": "reference_video",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qigswt/wan-r2v-role2.mp4",
                    "reference_voice": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/isllrq/wan-r2v-boy-voice.mp3"
                },
                {
                    "type": "reference_image",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/rtjeqf/wan-r2v-object3.png"
                },
                {
                    "type": "reference_image",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qpzxps/wan-r2v-object4.png"
                },
                {
                    "type": "reference_image",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/wfjikw/wan-r2v-backgroud5.png"
                }
            ]
        },
        "parameters": {
            "resolution": "720P",
            "ratio": "16:9",
            "duration": 10,
            "prompt_extend": false,
            "watermark": true
        }
    }'

Single-image reference (multi-grid image)

Provide a nine-grid reference image to control the story direction, camera composition, and character settings to generate a video.

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
        -H 'X-DashScope-Async: enable' \
        -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
        -H 'Content-Type: application/json' \
        -d '{
        "model": "wan2.7-r2v-2026-06-12",
        "input": {
            "prompt": "参考图片,3D卡通冒险电影风,角色Q版但材质细腻,动作流畅,色彩鲜明,保持角色与森林场景一致,不要加入文字。氛围: 冒险、轻快、神秘、童趣。角色: 小男孩探险家:圆帽、背包、短斗篷。小伙伴:会飞的小机器人,圆形身体,蓝色发光眼。场景: 奇幻森林,巨大树根、蘑菇、藤蔓、藏宝洞口、阳光光束。分镜脚本: 1. 全景:奇幻森林里高大树木与光束交错,环境神秘明亮。 2. 中景:小男孩拨开藤蔓向前探路。 3. 中景:小机器人飞在他身边,用蓝光扫描前方。 4. 特写:一张旧藏宝图在男孩手里展开。 5. 近景:他露出兴奋表情,眼睛亮起来。 6. 动作镜头:两人跳过树根和小溪,继续深入森林。 7. 中景:藤蔓后方露出一个被苔藓覆盖的宝箱。 8. 特写:宝箱边缘闪出金色光芒。 9. 收束镜头:男孩和小机器人站在宝箱前惊喜对望,冒险感拉满。",
            "media": [
                {
                    "type": "reference_image",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260403/wgjaxy/banana_storyboard_00000020.png"
                }
            ]
        },
        "parameters": {
            "resolution": "720P",
            "duration": 10,
            "prompt_extend": false,
            "watermark": true
        }
    }'

Response parameters

output object

The task output information.

Properties

task_id string

The task ID. Query validity: 24 hours.

task_status string

The task status.

Enumerated values

  • PENDING: The task is queuing
  • RUNNING: The task is being processed
  • SUCCEEDED: The task was executed successfully
  • FAILED: The task failed
  • CANCELED: The task has been canceled
  • UNKNOWN: The task does not exist or its status is unknown

request_idstring

The unique request identifier. It can be used to trace request details and troubleshoot issues.

codestring

The error code returned when the request fails. This parameter is not returned when the request succeeds. For details, see Error codes.

messagestring

The detailed error information returned when the request fails. This parameter is not returned when the request succeeds. For details, see Error codes.

Success response

Save the task_id, which is used to query the task status and results.

{
    "output": {
        "task_status": "PENDING",
        "task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
    },
    "request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}

Error response

Failed to create the task. See Error codes for troubleshooting.

{
    "code": "InvalidApiKey",
    "message": "No API-key provided.",
    "request_id": "7438d53d-6eb8-4596-8835-xxxxxx"
}

Step 2: Query results by task ID

Singapore

GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id}

Beijing

GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}

When you call the API, replace {WorkspaceId} with your actual workspace ID.

Note

  • Polling recommendation: Video generation takes several minutes. We recommend using a polling mechanism and setting a reasonable query interval (such as 15 seconds) to obtain results.
  • Task status transitions: PENDING (queuing) → RUNNING (processing) → SUCCEEDED (success) / FAILED (failed).
  • Result link: A video link is returned after the task succeeds, with a validity period of 24 hours. We recommend downloading the video immediately after obtaining the link and transferring it to permanent storage (such as Alibaba Cloud OSS).
  • task_id validity period: 24 hours. After it expires, results can no longer be queried, and the API returns the task status UNKNOWN.

Request parameters

Request headers (Headers)

Authorizationstring(required)

Request authentication. The API uses the Alibaba Cloud Model Studio API Key for authentication. Example value: Bearer sk-xxxx.

URL path parameters (Path parameters)

task_id string(Required)

The task ID.

Query task results

Replace {task_id} entirely with the task_id value returned by the previous API call. The task_id is valid for queries for 24 hours. Also replace {WorkspaceId} with your actual workspace ID.

curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"

Response parameters

outputobject

The task output information.

Properties

task_id string(Required)

The task ID.

task_status string

The task status.

Enumerated values

  • PENDING: The task is queuing
  • RUNNING: The task is being processed
  • SUCCEEDED: The task was executed successfully
  • FAILED: The task failed
  • CANCELED: The task has been canceled
  • UNKNOWN: The task does not exist or its status is unknown

submit_time string

The task submission time. The time zone is UTC+8, in the format YYYY-MM-DD HH:mm:ss.SSS.

scheduled_time string

The task execution time. The time zone is UTC+8, in the format YYYY-MM-DD HH:mm:ss.SSS.

end_time string

The task completion time. The time zone is UTC+8, in the format YYYY-MM-DD HH:mm:ss.SSS.

video_urlstring

The video URL. Returned only when task_status is SUCCEEDED.

The link is valid for 24 hours, and you can download the video via this URL. The video format is MP4 (H.264 encoding).

orig_prompt string

The original input prompt, corresponding to the request parameter prompt.

codestring

The error code returned when the request fails. This parameter is not returned when the request succeeds. For details, see Error codes.

messagestring

The detailed error information returned when the request fails. This parameter is not returned when the request succeeds. For details, see Error codes.

usage object

Output information statistics. Only successful results are counted.

Properties

input_video_duration integer

The duration of the input video, in seconds.

output_video_duration integer

The duration of the output video, in seconds.

duration integer

The total video duration. Billing is calculated based on the duration.

Formula: duration = input_video_duration + output_video_duration.

SR integer

The resolution tier of the generated video. Example value: 720.

ratio string

The aspect ratio of the generated video. Example value: 16:9.

video_count integer

The number of generated videos. Fixed at 1.

request_idstring

The unique request identifier. It can be used to trace request details and troubleshoot issues.

Task executed successfully

The video URL is retained for only 24 hours and will be automatically deleted after it expires. Save the generated video in a timely manner.

{
    "request_id": "52cade0d-905e-9b7d-a01e-xxxxxx",
    "output": {
        "task_id": "18814247-f944-4102-aa4a-xxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2026-04-02 22:53:19.537",
        "scheduled_time": "2026-04-02 22:53:30.427",
        "end_time": "2026-04-02 23:00:39.287",
        "orig_prompt": "视频2抱着图片3在咖啡厅里弹奏一支舒缓的美式乡村民谣,视频1笑着看着视频2,并缓缓向他走去",
        "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?xxxx"
    },
    "usage": {
        "duration": 15,
        "input_video_duration": 5,
        "output_video_duration": 10,
        "video_count": 1,
        "SR": 720,
        "ratio": "16:9"
    }
}

Task execution failed

If the task fails, task_status will be set to FAILED, with an error code and message provided. See Error codes for troubleshooting.

{
    "request_id": "e5d70b02-ebd3-98ce-9fe8-759d7d7b107d",
    "output": {
        "task_id": "86ecf553-d340-4e21-af6e-a0c6a421c010",
        "task_status": "FAILED",
        "code": "InvalidParameter",
        "message": "The size is not match xxxxxx"
    }
}

Task query expired

The task_id can be queried within 24 hours. After that, the query will no longer be available and the following error message will be returned.

{
    "request_id": "a4de7c32-7057-9f82-8581-xxxxxx",
    "output": {
        "task_id": "502a00b1-19d9-4839-a82f-xxxxxx",
        "task_status": "UNKNOWN"
    }
}

Calling the DashScope SDK

The SDK parameter naming is basically the same as that of the HTTP API, and the parameter structure is encapsulated based on language-specific features.

A reference-to-video task usually takes 1–5 minutes. The SDK encapsulates the HTTP asynchronous call process and supports both synchronous and asynchronous call methods.

The actual time required depends on the number of queued tasks and the service running status.

Calling the Python SDK

ImportantBefore running the following code, make sure the DashScope Python SDK version is ≥2.0.1.

A version that is too old may trigger errors such as "url error, please check url!". See Install the SDK to update it.

Set region based on the region where the model is located (pass it in when constructing the Client; the region value varies by region):

Singapore

region="ap-southeast-1"

Beijing

region="cn-beijing"

When you call the API, replace {WorkspaceId} with your actual workspace ID.

Synchronous call

A synchronous call blocks until video generation is complete and directly returns the result.

Request example
import dashscope
import os
from dashscope import DashScopeError

# The following is the configuration for the Singapore (ap-southeast-1) region. Replace {WorkspaceId} with your actual workspace ID when calling. The region value varies by region.
client = dashscope.Client(
    # If you have not configured the environment variable, replace the following line with your Model Studio API key: api_key="sk-xxx"
    # The API keys differ by region. To get an API key, see https://www.alibabacloud.com/help/model-studio/get-api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    workspace="{WorkspaceId}",
    region="ap-southeast-1",
)

def sample_sync_call_r2v():
    # Synchronous call that returns the result directly.
    # generate is a one-step call (submits the task and waits for completion) that returns a completed Job.
    print('please wait...')
    try:
        job = client.videos.generate(
            model='wan2.7-r2v-2026-06-12',
            prompt='视频1抱着图3,在图4的椅子上弹奏一支舒缓的乡村民谣,并说道:“今天的阳光真好。”图1手中拿着图2,路过视频1,把手中的图2放到视频1旁边的桌子上,并说道:“真好听,能不能再唱一遍”。 ',
            media=[
                {
                    "type": "reference_image",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/sjuytr/wan-r2v-object-girl.jpg",
                    "reference_voice": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/gbqewz/wan-r2v-girl-voice.mp3"
                },
                {
                    "type": "reference_video",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qigswt/wan-r2v-role2.mp4",
                    "reference_voice": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/isllrq/wan-r2v-boy-voice.mp3"
                },
                {
                    "type": "reference_image",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/rtjeqf/wan-r2v-object3.png"
                },
                {
                    "type": "reference_image",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qpzxps/wan-r2v-object4.png"
                },
                {
                    "type": "reference_image",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/wfjikw/wan-r2v-backgroud5.png"
                }
            ],
            resolution='720P',
            ratio='16:9',
            duration=10,
            prompt_extend=False,
            watermark=True)
        print(job)
        print(job.video_url)
    except DashScopeError as e:
        print(f"HTTP status code: {e.status_code}")
        print(f"Error code: {e.code}")
        print(f"Error message: {e.message}")
        print("See the documentation: https://www.alibabacloud.com/help/model-studio/developer-reference/error-code")

if __name__ == '__main__':
    sample_sync_call_r2v()
Response example

The video_url is valid for 24 hours. Download the video in a timely manner.

{
    "request_id": "b040d446-f9b6-977f-b9ad-xxxxxx",
    "task_id": "5dab3291-393e-424d-929b-xxxxxx",
    "status": "SUCCEEDED",
    "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
    "task_metrics": {
        "TOTAL": 1,
        "SUCCEEDED": 1,
        "FAILED": 0
    },
    "usage": {
        "video_count": 1,
        "duration": 15,
        "input_video_duration": 5,
        "output_video_duration": 10,
        "SR": 720,
        "ratio": "16:9"
    }
}

Asynchronous call

An asynchronous call immediately returns a task ID. You can use fetch to query the task status or call wait to wait for completion (with automatic internal polling).

Request example
import dashscope
import os
from dashscope import DashScopeError

# The following is the configuration for the Singapore (ap-southeast-1) region. Replace {WorkspaceId} with your actual workspace ID when calling. The region value varies by region.
client = dashscope.Client(
    # If you have not configured the environment variable, replace the following line with your Model Studio API key: api_key="sk-xxx"
    # The API keys differ by region. To get an API key, see https://www.alibabacloud.com/help/model-studio/get-api-key
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    workspace="{WorkspaceId}",
    region="ap-southeast-1",
)

def sample_async_call_r2v():
    # Make an asynchronous call, which returns a task_id.
    try:
        job = client.videos.jobs.create(
            model='wan2.7-r2v-2026-06-12',
            prompt='视频1抱着图3,在图4的椅子上弹奏一支舒缓的乡村民谣,并说道:“今天的阳光真好。”图1手中拿着图2,路过视频1,把手中的图2放到视频1旁边的桌子上,并说道:“真好听,能不能再唱一遍”。 ',
            media=[
                {
                    "type": "reference_image",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/sjuytr/wan-r2v-object-girl.jpg",
                    "reference_voice": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/gbqewz/wan-r2v-girl-voice.mp3"
                },
                {
                    "type": "reference_video",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qigswt/wan-r2v-role2.mp4",
                    "reference_voice": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/isllrq/wan-r2v-boy-voice.mp3"
                },
                {
                    "type": "reference_image",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/rtjeqf/wan-r2v-object3.png"
                },
                {
                    "type": "reference_image",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qpzxps/wan-r2v-object4.png"
                },
                {
                    "type": "reference_image",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/wfjikw/wan-r2v-backgroud5.png"
                }
            ],
            resolution='720P',
            ratio='16:9',
            duration=10,
            prompt_extend=False,
            watermark=True)
        print(job)
        print("task_id: %s" % job.task_id)
    except DashScopeError as e:
        print(f"HTTP status code: {e.status_code}")
        print(f"Error code: {e.code}")
        print(f"Error message: {e.message}")
        print("See the documentation: https://www.alibabacloud.com/help/model-studio/developer-reference/error-code")
        return

    # Get the asynchronous task information.
    try:
        snapshot = client.videos.jobs.fetch(job.task_id)
        print(snapshot.status)
    except DashScopeError as e:
        print(f"HTTP status code: {e.status_code}")
        print(f"Error code: {e.code}")
        print(f"Error message: {e.message}")
        print("See the documentation: https://www.alibabacloud.com/help/model-studio/developer-reference/error-code")

    # Wait for the asynchronous task to complete.
    # (2.0 jobs.wait uses exponential backoff polling, with a default total budget of 24 hours.)
    try:
        done = client.videos.jobs.wait(job)
        print(done)
        print(done.video_url)
    except DashScopeError as e:
        print(f"HTTP status code: {e.status_code}")
        print(f"Error code: {e.code}")
        print(f"Error message: {e.message}")
        print("See the documentation: https://www.alibabacloud.com/help/model-studio/developer-reference/error-code")

if __name__ == '__main__':
    sample_async_call_r2v()
Response example
  1. Response example of creating a task
{
    "request_id": "6dc3bf6c-be18-9268-9c27-xxxxxx",
    "task_id": "686391d9-7ecf-4290-a8e9-xxxxxx",
    "status": "PENDING"
}
  1. Response example of querying the task result

The video_url is valid for 24 hours. Download the video in a timely manner.

{
    "request_id": "b040d446-f9b6-977f-b9ad-xxxxxx",
    "task_id": "5dab3291-393e-424d-929b-xxxxxx",
    "status": "SUCCEEDED",
    "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
    "task_metrics": {
        "TOTAL": 1,
        "SUCCEEDED": 1,
        "FAILED": 0
    },
    "usage": {
        "video_count": 1,
        "duration": 15,
        "input_video_duration": 5,
        "output_video_duration": 10,
        "SR": 720,
        "ratio": "16:9"
    }
}

Calling the Java SDK

ImportantBefore running the following code, make sure the DashScope Java SDK version is ≥2.22.14.

A version that is too old may trigger errors such as "url error, please check url!". See Install the SDK to update it.

Set baseHttpApiUrl based on the region where the model is located:

Singapore

Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";

Beijing

Constants.baseHttpApiUrl = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";

When you call the API, replace {WorkspaceId} with your actual workspace ID.

Synchronous call

A synchronous call blocks until video generation is complete and directly returns the result.

Request example
// Copyright (c) Alibaba, Inc. and its affiliates.

import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Ref2Video {

    static {
        // The following URL is for the Singapore region. When calling, replace {WorkspaceId} with your actual workspace ID. URLs vary by region.
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }

    // If you have not configured the environment variable, replace the following line with your Model Studio API key: apiKey="sk-xxx"
    // API keys differ by region. Get an API key: https://www.alibabacloud.com/help/model-studio/get-api-key
    public static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    public static void ref2video() throws ApiException, NoApiKeyException, InputRequiredException {
        VideoSynthesis vs = new VideoSynthesis();
        List<VideoSynthesisParam.Media> media = new ArrayList<VideoSynthesisParam.Media>(){{
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/sjuytr/wan-r2v-object-girl.jpg")
                    .type("reference_image")
                    .referenceVoice("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/gbqewz/wan-r2v-girl-voice.mp3")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qigswt/wan-r2v-role2.mp4")
                    .type("reference_video")
                    .referenceVoice("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/isllrq/wan-r2v-boy-voice.mp3")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/rtjeqf/wan-r2v-object3.png")
                    .type("reference_image")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qpzxps/wan-r2v-object4.png")
                    .type("reference_image")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/wfjikw/wan-r2v-backgroud5.png")
                    .type("reference_image")
                    .build());
        }};
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("resolution", "720P");
        parameters.put("ratio", "16:9");
        parameters.put("prompt_extend", false);
        parameters.put("watermark", true);

        VideoSynthesisParam param =
                VideoSynthesisParam.builder()
                        .apiKey(apiKey)
                        .model("wan2.7-r2v-2026-06-12")
                        .prompt("视频1抱着图3,在图4的椅子上弹奏一支舒缓的乡村民谣,并说道:“今天的阳光真好。”图1手中拿着图2,路过视频1,把手中的图2放到视频1旁边的桌子上,并说道:“真好听,能不能再唱一遍”。 ")
                        .media(media)
                        .duration(10)
                        .parameters(parameters)
                        .build();
        System.out.println("please wait...");
        VideoSynthesisResult result = vs.call(param);
        System.out.println(JsonUtils.toJson(result));
    }

    public static void main(String[] args) {
        try {
            ref2video();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}
Response example

The video_url is valid for 24 hours. Download the video in a timely manner.

{
    "request_id": "f6365287-336f-9f2b-ab59-xxxxxx",
    "output": {
        "task_id": "cb7f1da5-a987-41de-b0a4-xxxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxxx",
        "orig_prompt": "视频1抱着图3,在图4的椅子上弹奏一支舒缓的乡村民谣,并说道:“今天的阳光真好。”图1手中拿着图2,路过视频1,把手中的图2放到视频1旁边的桌子上,并说道:“真好听,能不能再唱一遍”。 ",
        "submit_time": "2026-04-17 17:15:11.536",
        "scheduled_time": "2026-04-17 17:15:20.316",
        "end_time": "2026-04-17 17:29:44.277"
    },
    "usage": {
        "video_count": 1,
        "duration": 15.0,
        "input_video_duration": 5.0,
        "output_video_duration": 10.0,
        "SR": "720"
    },
    "status_code": 200,
    "code": "",
    "message": ""
}

Asynchronous call

An asynchronous call immediately returns a task ID. You can use fetch to query the task status or call wait to wait for completion (with automatic internal polling).

Request example
// Copyright (c) Alibaba, Inc. and its affiliates.

import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisListResult;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.task.AsyncTaskListParam;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Ref2VideoAsync {

    static {
        // The following URL is for the Singapore region. When calling, replace {WorkspaceId} with your actual workspace ID. URLs vary by region.
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }

    // If you have not configured the environment variable, replace the following line with your Model Studio API key: apiKey="sk-xxx"
    // API keys differ by region. Get an API key: https://www.alibabacloud.com/help/model-studio/get-api-key
    public static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    public static void asyncRef2video() throws ApiException, NoApiKeyException, InputRequiredException, InterruptedException {
        VideoSynthesis vs = new VideoSynthesis();
        List<VideoSynthesisParam.Media> media = new ArrayList<VideoSynthesisParam.Media>(){{
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/sjuytr/wan-r2v-object-girl.jpg")
                    .type("reference_image")
                    .referenceVoice("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/gbqewz/wan-r2v-girl-voice.mp3")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qigswt/wan-r2v-role2.mp4")
                    .type("reference_video")
                    .referenceVoice("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260408/isllrq/wan-r2v-boy-voice.mp3")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/rtjeqf/wan-r2v-object3.png")
                    .type("reference_image")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/qpzxps/wan-r2v-object4.png")
                    .type("reference_image")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/wfjikw/wan-r2v-backgroud5.png")
                    .type("reference_image")
                    .build());
        }};
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("resolution", "720P");
        parameters.put("ratio", "16:9");
        parameters.put("prompt_extend", false);
        parameters.put("watermark", true);

        VideoSynthesisParam param =
                VideoSynthesisParam.builder()
                        .apiKey(apiKey)
                        .model("wan2.7-r2v-2026-06-12")
                        .prompt("视频1抱着图3,在图4的椅子上弹奏一支舒缓的乡村民谣,并说道:“今天的阳光真好。”图1手中拿着图2,路过视频1,把手中的图2放到视频1旁边的桌子上,并说道:“真好听,能不能再唱一遍”。 ")
                        .media(media)
                        .duration(10)
                        .parameters(parameters)
                        .build();
        // Submit an asynchronous task
        VideoSynthesisResult result = vs.asyncCall(param);
        System.out.println("task_id: " + result.getOutput().getTaskId());
        System.out.println(JsonUtils.toJson(result));

        // Wait for the task to complete
        result = vs.wait(result, null);
        System.out.println(JsonUtils.toJson(result));
    }

    public static void main(String[] args) {
        try {
            asyncRef2video();
        } catch (ApiException | NoApiKeyException | InputRequiredException | InterruptedException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}
Response example
  1. Response example of creating a task
{
    "request_id": "5dbf9dc5-4f4c-9605-85ea-xxxxxxxx",
    "output": {
        "task_id": "7277e20e-aa01-4709-xxxxxxxx",
        "task_status": "PENDING"
    }
}
  1. Response example of querying the task result

The video_url is valid for 24 hours. Download the video in a timely manner.

{
    "request_id": "f6365287-336f-9f2b-ab59-xxxxxx",
    "output": {
        "task_id": "cb7f1da5-a987-41de-b0a4-xxxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxxx",
        "orig_prompt": "视频1抱着图3,在图4的椅子上弹奏一支舒缓的乡村民谣,并说道:“今天的阳光真好。”图1手中拿着图2,路过视频1,把手中的图2放到视频1旁边的桌子上,并说道:“真好听,能不能再唱一遍”。 ",
        "submit_time": "2026-04-17 17:15:11.536",
        "scheduled_time": "2026-04-17 17:15:20.316",
        "end_time": "2026-04-17 17:29:44.277"
    },
    "usage": {
        "video_count": 1,
        "duration": 15.0,
        "input_video_duration": 5.0,
        "output_video_duration": 10.0,
        "SR": "720"
    },
    "status_code": 200,
    "code": "",
    "message": ""
}

Error codes

If a model call fails and returns an error message, see Error codes to resolve the issue.

FAQ

What code changes are required when upgrading from wan2.6 to wan2.7?

The main differences are as follows:

  1. Different reference notation in prompts

    wan2.7 no longer uses identifiers such as character1 and character2. Instead, references are made by type: images are referenced as "Image 1", "Image 2", and videos as "Video 1", "Video 2". For details about prompts, see prompt parameter.

  2. Different multi-shot control method
    • wan2.7: The shot_type parameter is not supported. Multi-shot effects are achieved by describing the storyboard in the prompt.
    • wan2.6: Multi-shot videos are generated by setting shot_type to multi.
  3. Different request parameter structure
    • How reference assets are passed in: wan2.7 uses media (an array of objects, each containing type and url), replacing wan2.6's reference_urls (an array of strings).
    • Resolution parameter: wan2.7 uses resolution (for example, 720P), replacing wan2.6's size (for example, 1280*720).
    • audio parameter: wan2.7 generates videos with audio by default, so no setting is required. wan2.6 requires explicitly setting audio to true or false.

How do I add a voiceover for a subject (voice reference)?

Only wan2.7 supports this. Pass an audio URL via reference_voice in media to specify a reference voice for a reference image or reference video.

{
    "media": [
        {
            "type": "reference_image",
            "url": "<参考图像URL>",
            "reference_voice": "<音频URL>"
        },
        {
            "type": "reference_video",
            "url": "<参考视频URL>",
            "reference_voice": "<音频URL>"
        }
    ]
}