Skip to content

Wan 2.7 - image-to-video API

The Wan 2.7 image-to-video model supports multimodal input (text, images, audio, and video) and performs three tasks: first-frame-to-video, first-and-last-frame-to-video, and video continuation.

References : User guide Note

The new image-to-video API (wan2.7 model) supports all three tasks. The earlier image-to-video from first frame API (wan2.6 and earlier) supports only first-frame-to-video.

Availability

The model, endpoint URL, and API key must belong to the same region. Cross-region calls fail.

  • Select a model: Verify that the model is available in your target region.

  • Select a URL: Choose the endpoint URL that matches your model's region. Both HTTP and DashScope SDK URLs are supported.

  • Configure an API key : Get an API key for the region, and then configure the API key as an environment variable.

  • Install the SDK : To make API calls with the SDK, install the DashScope SDK.

Note

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

HTTP

Important

This API uses the new image-to-video protocol and supports only the wan2.7 model.

Image-to-video tasks typically take 1 to 5 minutes, so the API uses asynchronous invocation. The workflow has two steps: create a task, then poll for the result.

Step 1: Create a task and get the task ID

Singapore

POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis

Beijing

POST https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesisNote

  • After the task is created, use the returned task_id to query the result. The task_id is valid for 24 hours. Do not create duplicate tasks. Instead, use polling to retrieve the result.

  • For guidance for beginners, see Postman.

Request parameters

## Video generation from the first frame

Generate a video based on a first frame image and audio.

curl
curl --location 'https://dashscope-intl.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-i2v-2026-04-25",
 "input": {
 "prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life on a concrete wall. He sings an English rap song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The light comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of the rap, with no other dialogue or noise.",
 "media": \[
 {
 "type": "first_frame",
 "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png"
 },
 {
 "type": "driving_audio",
 "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3"

}
 \]
 },
 "parameters": {
 "resolution": "720P",
 "duration": 10,
 "prompt_extend": true,
 "watermark": true
 }
 }'

## Video generation from the first and last frames

Pass a first frame and a last frame to generate a video.

curl
curl --location 'https://dashscope-intl.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-i2v-2026-04-25",
 "input": {
 "prompt": "Realistic style, a small black cat looks up at the sky curiously. The camera angle gradually rises from eye level, finally capturing its curious gaze from a top-down view.",
 "media": \[
 {
 "type": "first_frame",
 "url": "https://wanx.alicdn.com/material/20250318/first_frame.png"
 },
 {
 "type": "last_frame",
 "url": "https://wanx.alicdn.com/material/20250318/last_frame.png"
 }
 \]
 },
 "parameters": {
 "resolution": "720P",
 "duration": 10,
 "prompt_extend": false,
 "watermark": true
 }
 }'

## Video continuation

Generate subsequent content based on an initial video clip.

curl
curl --location 'https://dashscope-intl.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-i2v-2026-04-25",
 "input": {
 "prompt": "A girl takes a selfie in the mirror, then leaves with her backpack.",
 "media": \[
 {
 "type": "first_clip",
 "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260129/hfugmr/wan-r2v-role1.mp4"
 }
 \]
 },
 "parameters": {
 "resolution": "720P",
 "duration": 10,
 "prompt_extend": true,
 "watermark": true
 }
 }'

Content-Type *string* (Required) The content type of the request. Must be application/json.

Authorization *string* (Required) Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx.

X-DashScope-Async *string* (Required) Enables asynchronous processing. HTTP requests support only asynchronous calls. Must be enable.

**

**Important ** If this request header is missing, the error "current user api does not support synchronous calls" is returned.

Request body

model *string* (Required) The model name. For a list of models and their pricing, see Model pricing. Example: wan2.7-i2v-2026-04-25.

input *object* (Required) Basic input information, including the prompt. Properties

prompt *string* (Optional) Text prompt that describes the elements and visual characteristics for the generated video. Chinese and English are supported. Up to 5,000 characters. Each Chinese character or letter counts as one character. Text that exceeds the limit is automatically truncated. The length limit varies by model version: Example: A kitten runs on the grass. For more information about how to use prompts, see Text-to-video/image-to-video prompt guide.

negative_prompt *string* (Optional) Describes content to exclude from the video. Chinese and English are supported. Maximum 500 characters. Text that exceeds the limit is automatically truncated. Example: low resolution, error, worst quality, low quality, deformed, extra fingers, bad proportions.

media *array* (Required) Reference materials (images, audio, and video) for video generation. Each element is a media object with type and url fields. Asset combinations Only the following asset combinations are valid. Invalid combinations return an error.

  • Video generation from the first frame: <li> First frame: first_frame
  • First frame + audio: first_frame+driving_audio </li>
  • Video generation from the first and last frames: <li> First frame + last frame: first_frame+last_frame
  • First frame + last frame + audio: first_frame+last_frame+driving_audio </li>
  • Video continuation: <li> First video clip continuation: first_clip
  • First video clip + last frame continuation: first_clip+last_frame </li>

Properties

type *string* (Required) The media asset type. Valid values:

  • first_frame
  • last_frame
  • driving_audio
  • first_clip Limit: Each type can appear at most once in the media array. For example, you cannot pass two first_frame assets.

url *string* (Required) The URL of the media asset (image, audio, or video). Pass an image (type=first_frame or last_frame) URL or Base64-encoded data for the first or last frame image. Image limits:

  • Format: JPEG, JPG, PNG (alpha channel not supported), BMP, WEBP.

  • Resolution: The width and height must be in the range of [240, 8000] pixels.

  • Aspect ratio: 1:8 to 8:1.

  • File size: up to 20 MB. Supported input formats:

  • Public URL: <li> The HTTP or HTTPS protocol is supported.

  • Example: https://xxx/xxx.png. </li>

  • A Base64-encoded image string: <li> Data format: data:{MIME_type};base64,{base64_data}.

  • Example: data:image/png;base64,GDU7MtCZzEbTbmRZ...... (The example is truncated for demonstration purposes). Base64-encoded data format Format: data:{MIME_type};base64,{base64_data} . <li> {base64_data}: The Base64-encoded string of the image file.

  • {MIME_type}: The Multipurpose Internet Mail Extensions (MIME) type of the image, which must correspond to the file format.

</li> </li>

Pass audio (type=driving_audio) URL of the audio file.

  • With audio: The model uses it as a driving source for lip-sync and action timing.

  • Without audio: The model automatically generates matching background music or sound effects. Audio limits:

  • Format: wav, mp3.

  • Duration: 2 s to 30 s.

  • File size: up to 15 MB.

  • Truncation: If the audio duration exceeds the duration value (for example, 5 s), the audio is automatically truncated to the first 5 seconds, and the rest is discarded. If the audio duration is shorter than the video duration, the portion of the video that exceeds the audio duration will be silent. For example, if the audio is 3 s long and the video is 5 s long, the first 3 seconds of the output video will have sound, and the last 2 seconds will be silent. Supported input formats:

  • Public URL: <li> The HTTP and HTTPS protocols are supported.

  • Example: https://xxx/xxx.mp3. </li>

Pass a video (type=first_clip) URL of the video file. The model generates a continuation based on the video content. The duration parameter controls the maximum total duration of the output. ** For example, if duration=15 and the input video is 3 s long, the model generates a 12-s continuation. The final output video is 15 s long and is billed for 15 s. Video limits:

  • Format: mp4, mov.

  • Duration: 2 s to 10 s.

  • Resolution: The width and height must be in the range of [240, 4096] pixels.

  • Aspect ratio: 1:8 to 8:1.

  • File size: up to 100 MB. Supported input formats:

  • Public URL: <li> The HTTP and HTTPS protocols are supported.

  • Example: https://xxx/xxx.mp4. </li>

<b>parameters** *object* (Optional) Video processing parameters: resolution, duration, prompt rewriting, and watermarks. Properties

resolution *string* (Optional)

**

**Important ** Resolution directly affects cost. Before calling, check the Model pricing.

Resolution tier for the generated video. Controls the total pixel count. The model automatically scales the video to a total pixel count close to the selected tier. The output aspect ratio follows the input material (first frame or first video clip). For details, see FAQ. Valid values are 720P and 1080P. Default: 1080P.

duration *integer* (Optional)

**

**Important ** Duration directly affects cost. Billing is per second. Before calling, check the Model pricing.

Duration of the generated video in seconds. Valid range depends on the model: Valid values: an integer from 2 to 15. Default: 5.

**prompt_extend ***boolean* (Optional) Whether to enable prompt rewriting. When enabled, a model rewrites the input prompt to improve results for short prompts, but increases processing time.

  • true (default)
  • false

watermark *boolean* (Optional) Whether to add an "AI Generated" watermark in the lower-right corner of the video.

  • false (default)
  • true

seed *integer* (Optional) The random number seed must be an integer in the range \[0, 2147483647\]. If not specified, a random seed is generated. A fixed seed improves reproducibility. Because model generation is probabilistic, the same seed does not guarantee identical results.

Response parameters

Successful response

Save the task_id to query the task status and result.

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

Error response

Task creation failed. See Error messages.

json
{
 "code": "InvalidApiKey",
 "message": "No API-key provided.",
 "request_id": "7438d53d-6eb8-4596-8835-xxxxxx"
}
     **output** `*object*`  Task output information.

Properties

task_id *string* The task ID. Valid for queries for 24 hours.

task_status *string* The status of the task. Enumeration values

  • PENDING
  • RUNNING
  • SUCCEEDED
  • FAILED
  • CANCELED
  • UNKNOWN: The task does not exist or its status is unknown.

request_id *string* Unique request identifier for tracing and troubleshooting.

code *string* Error code. Returned only for failed requests. See Error messages.

message *string* Detailed error message. Returned only for failed requests. See Error messages.

Step 2: Query the result by task ID

Singapore

GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/{task_id}

Beijing

GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}Note

  • Polling recommendation: Video generation takes several minutes. Use a polling mechanism with a reasonable interval, such as 15 seconds.

  • Task state transition: PENDING → RUNNING → SUCCEEDED or FAILED.

  • Result link : After a task succeeds, a video URL valid for 24 hours is returned. Download and save the video to permanent storage, such as OSS.

  • task_id****validity : 24 hours . After this period, queries return the task status as UNKNOWN.

Request parameters

## Query task result

Replace {task_id} with the task_id value returned by the previous API call. The task_id is valid for queries for 24 hours.

curl
curl -X GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/{task_id} \\
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
Headers

Authorization *string* (Required) Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx.

Path parameters

task_id *string* (Required) The ID of the task.

Response parameters

## Task successful

Video URLs are valid for only 24 hours and then automatically purged. Save generated videos promptly.

json
{
 "request_id": "2ca1c497-f9e0-449d-9a3f-xxxxxx",
 "output": {
 "task_id": "af6efbc0-4bef-4194-8246-xxxxxx",
 "task_status": "SUCCEEDED",
 "submit_time": "2025-09-25 11:07:28.590",
 "scheduled_time": "2025-09-25 11:07:35.349",
 "end_time": "2025-09-25 11:17:11.650",
 "orig_prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life on a concrete wall. He sings an English rap song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The light comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise.",
 "video_url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.mp4?Expires=xxx"
 },
 "usage": {
 "duration": 15,
 "input_video_duration": 0,
 "output_video_duration": 15,
 "video_count": 1,
 "SR": 720
 }
}

## Task failed

When a task fails, task_status is FAILED with an error code and message. See Error messages.

json
{
 "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 is valid for 24 hours. After this period, queries return the following error.

json
{
 "request_id": "a4de7c32-7057-9f82-8581-xxxxxx",
 "output": {
 "task_id": "502a00b1-19d9-4839-a82f-xxxxxx",
 "task_status": "UNKNOWN"
 }
}
     **output **`*object*`* * Task output information.

Properties

task_id *string* The task ID. Valid for queries for 24 hours.

task_status *string* The status of the task. Enumeration values

  • PENDING
  • RUNNING
  • SUCCEEDED
  • FAILED
  • CANCELED
  • UNKNOWN: The task does not exist or its status is unknown.

State transitions during polling:

  • PENDING → RUNNING → SUCCEEDED or FAILED.
  • The initial query status is usually PENDING or RUNNING.
  • When the status changes to SUCCEEDED, the response contains the generated video URL.
  • If the status is FAILED, check the error message and retry the task.

submit_time *string* The time when the task was submitted. The time is in UTC+8 and the format is YYYY-MM-DD HH:mm:ss.SSS.

scheduled_time *string* The time when the task was executed. The time is in UTC+8 and the format is YYYY-MM-DD HH:mm:ss.SSS.

end_time *string* The time when the task was completed. The time is in UTC+8 and the format is YYYY-MM-DD HH:mm:ss.SSS.

video_url *string* URL of the generated video. Returned only when task_status is SUCCEEDED. Valid for 24 hours. The video is in MP4 format with H.264 encoding.

orig_prompt *string* The original input prompt, corresponding to the request parameter prompt.

code *string* Error code. Returned only for failed requests. See Error messages.

message *string* Detailed error message. Returned only for failed requests. See Error messages.

usage *object* Usage statistics. Calculated only for successful tasks. Properties

input_video_duration&nbsp;*integer* Duration of the input video, in seconds.

output_video_duration&nbsp;*integer* Duration of the output video, in seconds.

duration&nbsp;*integer* Total video duration used for billing.

SR *integer* Output video resolution. Example: 720.

video_count *integer* Number of output videos. Fixed at 1.

request_id *string* Unique request identifier for tracing and troubleshooting.

DashScope SDK

The SDK parameter names match those in the HTTP API. The parameter structure is encapsulated based on language conventions.

Image-to-video tasks typically take 1 to 5 minutes. The SDK encapsulates the HTTP asynchronous invocation process and supports both synchronous and asynchronous calls.

Actual processing time depends on the task queue and service load. Wait for the result.

Python SDK

Important

Make sure the DashScope Python SDK version is not lower than 1.25.16 before running the following code.

If the version is too old, errors such as "url error, please check url!" may occur. For more information, see Install the SDK to update it.

Set dashscope.base_http_api_url based on the model's region:

Singapore

dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

Beijing

dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'

Synchronous call

Request example
HELPCODEESCAPE-python

from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os

# This is the URL for the Singapore region. The URL varies by region. For more information, see https://www.alibabacloud.com/help/en/model-studio/image-to-video-general-api-reference
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

# If you have not configured the environment variable, replace the following line with: api_key="sk-xxx"
# API keys vary by region. For more information, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")

media = [
    {
        "type": "first_frame",
        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png"
    },
    {
        "type": "driving_audio",
        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3"
    }
]

def sample_sync_call():
    print('----Synchronous call, please wait a moment----')
    rsp = VideoSynthesis.call(
        api_key=api_key,
        model="wan2.7-i2v-2026-04-25",
        media=media,
        resolution="720P",
        duration=10,
        watermark=True,
        prompt="An urban fantasy art scene featuring a dynamic graffiti character. A boy made of spray paint comes to life on a concrete wall. He sings an English rap song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night, lit by a single street lamp. This creates a cinematic atmosphere with high energy and amazing detail. The video's audio consists entirely of the rap, with no other dialogue or noise.",
    )
    if rsp.status_code == HTTPStatus.OK:
        print(rsp.output.video_url)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (rsp.status_code, rsp.code, rsp.message))

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

The video_url is valid for 24 hours. Download the video promptly.

HELPCODEESCAPE-json
{
    "status_code": 200,
    "request_id": "ac5faf37-ddfa-9720-a0c5-xxxxxx",
    "code": null,
    "message": "",
    "output": {
        "task_id": "b97c6d86-ad73-4bb7-80ff-xxxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
        "submit_time": "2026-04-13 10:45:47.597",
        "scheduled_time": "2026-04-13 10:45:56.342",
        "end_time": "2026-04-13 10:47:26.273",
        "orig_prompt": "An urban fantasy art scene. A dynamic graffiti character. A boy made of spray paint comes to life on a concrete wall. He performs a fast-paced English rap song while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The light comes from a single street lamp, creating a cinematic atmosphere with high energy and incredible detail. The audio consists solely of the rap, with no other dialogue or background noise."
    },
    "usage": {
        "video_count": 1,
        "video_duration": 0,
        "video_ratio": "",
        "duration": 10,
        "input_video_duration": 0,
        "output_video_duration": 10,
        "SR": 720
    }
}

Asynchronous call

Request example
HELPCODEESCAPE-python
# -*- coding: utf-8 -*-
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os

# This is the URL for the Singapore region. The URL varies by region. To obtain the URL for your region, see https://www.alibabacloud.com/help/en/model-studio/image-to-video-general-api-reference
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

# If the environment variable is not set, replace the following line with: api_key="sk-xxx"
# API keys vary by region. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key = os.getenv("DASHSCOPE_API_KEY")

media = [
    {
        "type": "first_frame",
        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png"
    },
    {
        "type": "driving_audio",
        "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3"
    }
]

def sample_async_call():
    # Submit an asynchronous task. Information about the task is returned immediately.
    rsp = VideoSynthesis.async_call(
        api_key=api_key,
        model="wan2.7-i2v-2026-04-25",
        media=media,
        resolution="720P",
        duration=10,
        watermark=True,
        prompt="A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life on a concrete wall. He sings an English rap song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The light comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of the rap, with no other dialogue or noise.",
    )
    print(rsp)
    if rsp.status_code == HTTPStatus.OK:
        print("task_id: %s" % rsp.output.task_id)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (rsp.status_code, rsp.code, rsp.message))

    # Query the task status.
    status = VideoSynthesis.fetch(task=rsp, api_key=api_key)
    if status.status_code == HTTPStatus.OK:
        print(status.output.task_status)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (status.status_code, status.code, status.message))

    # Wait for the task to complete.
    rsp = VideoSynthesis.wait(task=rsp, api_key=api_key)
    print(rsp)
    if rsp.status_code == HTTPStatus.OK:
        print(rsp.output.video_url)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (rsp.status_code, rsp.code, rsp.message))

if __name__ == '__main__':
    sample_async_call()
Response example
  1. Response example for creating a task

    HELPCODEESCAPE-json
    {
        "status_code": 200,
        "request_id": "6dc3bf6c-be18-9268-9c27-xxxxxx",
        "code": "",
        "message": "",
        "output": {
            "task_id": "686391d9-7ecf-4290-a8e9-xxxxxx",
            "task_status": "PENDING",
            "video_url": ""
        },
        "usage": null
    }
  2. Response example for querying a task result

    The video_url is valid for 24 hours. Download the video promptly.

    HELPCODEESCAPE-json
    {
        "status_code": 200,
        "request_id": "ac5faf37-ddfa-9720-a0c5-xxxxxx",
        "code": null,
        "message": "",
        "output": {
            "task_id": "b97c6d86-ad73-4bb7-80ff-xxxxxx",
            "task_status": "SUCCEEDED",
            "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
            "submit_time": "2026-04-13 10:45:47.597",
            "scheduled_time": "2026-04-13 10:45:56.342",
            "end_time": "2026-04-13 10:47:26.273",
            "orig_prompt": "An urban fantasy art scene. A dynamic graffiti character. A boy made of spray paint comes to life on a concrete wall. He performs a fast-paced English rap song while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The light comes from a single street lamp, creating a cinematic atmosphere with high energy and incredible detail. The audio consists solely of the rap, with no other dialogue or background noise."
        },
        "usage": {
            "video_count": 1,
            "video_duration": 0,
            "video_ratio": "",
            "duration": 10,
            "input_video_duration": 0,
            "output_video_duration": 10,
            "SR": 720
        }
    }

Java SDK

Important

Ensure that the DashScope Java SDK version is not lower than 2.22.14 before running the following code.

If the version is too old, errors such as "url error, please check url!" may occur. For more information, see Install the SDK to update it.

Set Constants.baseHttpApiUrl based on the model's region:

Singapore

Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1"

Beijing

Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1"

Synchronous call

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

Request example
HELPCODEESCAPE-java
// 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.Constants;
import com.alibaba.dashscope.utils.JsonUtils;

import java.util.ArrayList;
import java.util.List;

public class Image2Video {

    static {
        // This is the URL for the Singapore region. If you use a model in the Beijing region, replace the URL with: https://dashscope.aliyuncs.com/api/v1
        Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
    }

    // If the environment variable is not configured, replace the following line with: apiKey="sk-xxx"
    // API keys are region-specific. To obtain an API key, visit: https://www.alibabacloud.com/help/en/model-studio/get-api-key
    static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    public static void syncCall() {
        VideoSynthesis videoSynthesis = new VideoSynthesis();
        final String prompt = "A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life on a concrete wall. He sings an English rap song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The light comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise.";
        List&lt;VideoSynthesisParam.Media&gt; media = new ArrayList&lt;VideoSynthesisParam.Media&gt;(){​{
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png")
                    .type("first_frame")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3")
                    .type("driving_audio")
                    .build());
        }​};
        VideoSynthesisParam param =
                VideoSynthesisParam.builder()
                        .apiKey(apiKey)
                        .model("wan2.7-i2v-2026-04-25")
                        .prompt(prompt)
                        .media(media)
                        .watermark(true)
                        .duration(10)
                        .resolution("720P")
                        .build();
        VideoSynthesisResult result = null;
        try {
            System.out.println("---Sync call, please wait...----");
            result = videoSynthesis.call(param);
        } catch (ApiException | NoApiKeyException e){
            throw new RuntimeException(e.getMessage());
        } catch (InputRequiredException e) {
            throw new RuntimeException(e);
        }
        System.out.println(JsonUtils.toJson(result));
    }

    public static void main(String[] args) {
        syncCall();
    }
}
Response example

The video_url is valid for 24 hours. Download the video promptly.

HELPCODEESCAPE-json
{
    "request_id": "78178b55-8399-9823-8173-xxxxxx",
    "output": {
        "task_id": "be457e1b-8a79-47ed-aeff-xxxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
        "orig_prompt": "An urban fantasy art scene featuring a dynamic graffiti art character. A boy made of spray paint comes to life on a concrete wall. He rapidly sings an English rap song while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. A single street lamp provides the light, creating a high-energy cinematic atmosphere with incredible detail. The audio consists entirely of his rap, with no other dialogue or background noise.",
        "submit_time": "2026-04-13 10:57:36.795",
        "scheduled_time": "2026-04-13 10:57:46.280",
        "end_time": "2026-04-13 10:59:16.338"
    },
    "usage": {
        "video_count": 1,
        "duration": 10.0,
        "input_video_duration": 0.0,
        "output_video_duration": 10.0,
        "SR": "720"
    },
    "status_code": 200,
    "code": "",
    "message": ""
}

Asynchronous call

Request example
HELPCODEESCAPE-java
// 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.Constants;
import com.alibaba.dashscope.utils.JsonUtils;

import java.util.ArrayList;
import java.util.List;

public class Image2Video {

    static {
        // This is the URL for the Singapore region. If you use a model in the Beijing region, replace the URL with: https://dashscope.aliyuncs.com/api/v1
        Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
    }

    // If the environment variable is not configured, replace the following line with: apiKey = "sk-xxx"
    // API keys are region-specific. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
    static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    public static void asyncCall() {
        VideoSynthesis videoSynthesis = new VideoSynthesis();
        final String prompt = "A scene of urban fantasy art. A dynamic graffiti art character. A boy made of spray paint comes to life on a concrete wall. He sings an English rap song at high speed while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. The light comes from a single street lamp, creating a cinematic atmosphere full of high energy and amazing detail. The audio of the video consists entirely of his rap, with no other dialogue or noise.";
        List&lt;VideoSynthesisParam.Media&gt; media = new ArrayList&lt;VideoSynthesisParam.Media&gt;(){​{
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/wpimhv/rap.png")
                    .type("first_frame")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/ozwpvi/rap.mp3")
                    .type("driving_audio")
                    .build());
        }​};
        VideoSynthesisParam param =
                VideoSynthesisParam.builder()
                        .apiKey(apiKey)
                        .model("wan2.7-i2v-2026-04-25")
                        .prompt(prompt)
                        .media(media)
                        .watermark(true)
                        .duration(10)
                        .resolution("720P")
                        .build();
        VideoSynthesisResult result = null;
        try {
            System.out.println("--- Starting the asynchronous call. Please wait... ---");
            result = videoSynthesis.asyncCall(param);
        } catch (ApiException | NoApiKeyException e){
            throw new RuntimeException(e.getMessage());
        } catch (InputRequiredException e) {
            throw new RuntimeException(e);
        }
        System.out.println(JsonUtils.toJson(result));

        String taskId = result.getOutput().getTaskId();
        System.out.println("taskId=" + taskId);

        try {
            result = videoSynthesis.wait(taskId, apiKey);
        } catch (ApiException | NoApiKeyException e){
            throw new RuntimeException(e.getMessage());
        }
        System.out.println(JsonUtils.toJson(result));
        System.out.println(JsonUtils.toJson(result.getOutput()));
    }

    public static void main(String[] args) {
        asyncCall();
    }
}
Response example
  1. Response example for creating a task

    HELPCODEESCAPE-json
    {
        "request_id": "5dbf9dc5-4f4c-9605-85ea-xxxxxxxx",
        "output": {
            "task_id": "7277e20e-aa01-4709-xxxxxxxx",
            "task_status": "PENDING"
        }
    }
  2. Response example for querying a task result

    The video_url is valid for 24 hours. Download the video promptly.

    HELPCODEESCAPE-json
    {
        "request_id": "78178b55-8399-9823-8173-xxxxxx",
        "output": {
            "task_id": "be457e1b-8a79-47ed-aeff-xxxxxx",
            "task_status": "SUCCEEDED",
            "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
            "orig_prompt": "An urban fantasy art scene featuring a dynamic graffiti art character. A boy made of spray paint comes to life on a concrete wall. He rapidly sings an English rap song while striking a classic, energetic rapper pose. The scene is set under an urban railway bridge at night. A single street lamp provides the light, creating a high-energy cinematic atmosphere with incredible detail. The audio consists entirely of his rap, with no other dialogue or background noise.",
            "submit_time": "2026-04-13 10:57:36.795",
            "scheduled_time": "2026-04-13 10:57:46.280",
            "end_time": "2026-04-13 10:59:16.338"
        },
        "usage": {
            "video_count": 1,
            "duration": 10.0,
            "input_video_duration": 0.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 messages to resolve the issue.

FAQ

Q: How do I generate a video with a specific aspect ratio, such as 3:4?

A: The output aspect ratio is determined by the input material (first frame image or first video clip) but is not guaranteed to match exactly. A slight drift may occur.

The following example explains the logic using a first frame image as input:

  • Why does drift occur?

    • Execution logic: The system uses the input image's aspect ratio as a baseline, combined with the target total pixels for the resolution tier. Because video encoding requires width and height to be multiples of 16, the system adjusts the output to the closest valid resolution.

    • Calculation example: A 750 x 1000 pixel input image (3:4 ratio = 0.75) with "720P" resolution (~920,000 total pixels) produces an 816 x 1104 pixel output (ratio ~0.739, ~900,000 total pixels).

  • Recommendations:

    • Input control: Use a first frame or video clip that matches your target aspect ratio.

    • Post-processing: For strict aspect ratio requirements, crop the video or add black bars after generation.

Q: How do I get the whitelist of domain names for video storage access?

A: Videos generated by models are stored in OSS. The API returns a temporary public URL. To configure a firewall whitelist for this download URL, note the following: The underlying storage may change dynamically. This topic does not provide a fixed OSS domain name whitelist to prevent access issues caused by outdated information. If you have security control requirements, contact your account manager to obtain the latest OSS domain name list.

Mirror of Alibaba Cloud Model Studio docs for reference and RAG. Not affiliated with Alibaba Cloud.