The Wan kf2v model generates a smoothly transitioning video from a first frame image, a last frame image, and a text prompt.
References: User guide
Availability
The model, endpoint URL, and API key must be in the same region. Cross-region calls fail.
Select a model: Confirm model availability in your region.
Select a URL: Choose the endpoint URL for your region. Both HTTP URLs and DashScope SDK URLs are supported.
Configure your API key: Select your region, get your API key, and configure it as an environment variable.
Install the SDK: If you plan to call the API using the SDK, install the DashScope SDK.
Sample codes in this topic apply to the Singapore region.
HTTP
Image-to-video tasks take 1 to 5 minutes, so the API uses asynchronous calls: Create a task → Poll for the result.
Step 1: Create a task
Singapore
POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesis
Beijing
POST https://dashscope.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesis
After the task is created, use the returned
task_idto query the result. Thetask_idis valid for 24 hours. Do not create duplicate tasks. Instead, use polling to retrieve the result.For guidance for beginners, see Postman.
Request parameters | Image-to-video from first and last framesGenerate a video based on the first frame, last frame, and a prompt. Use a negative promptUse the negative_prompt parameter to prevent the generated video from containing "people". |
Request headers | |
Content-Type The content type of the request. Must be | |
Authorization Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx. | |
X-DashScope-Async Enables asynchronous processing. HTTP requests support only asynchronous calls. Must be Important If this request header is missing, the error "current user api does not support synchronous calls" is returned. | |
Request body | |
model The model name. Example: wan2.2-kf2v-flash. For more information, see Model list and pricing. | |
input Basic input information, including the prompt. | |
parameters Video processing parameters. |
Response parameters | Successful responseSave the Error responseTask creation failed. See Error messages. |
output The task output information. | |
request_id Unique request identifier for tracing and troubleshooting. | |
code Error code. Returned only for failed requests. See Error messages. | |
message Detailed error message. Returned only for failed requests. See Error messages. |
Step 2: Query task result
Singapore
GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/{task_id}
Beijing
GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}
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_idvalidity: 24 hours. After this period, queries return the task status asUNKNOWN.
Request parameters | Query task resultReplace API keys are different for each region. For more information, see Get an API key. If you use a model in the Beijing region, replace |
Request headers | |
Authorization Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx. | |
Path parameters | |
task_id The ID of the task. |
Response parameters | Task succeededVideo URLs are valid for only 24 hours and then automatically purged. Save generated videos promptly. Task failedWhen a task fails, Task query expiredThe |
output The task output information. | |
usage Usage statistics. Counts only successful results. | |
request_id Unique request identifier for tracing and troubleshooting. |
DashScope SDK
SDK parameter names match the HTTP API. Parameter structures follow language-specific conventions.
Image-to-video tasks take 1 to 5 minutes, so the SDK wraps async call logic and supports both sync and async calls.
The actual time depends on queue length and service performance. Please wait patiently for the result.
Python SDK
Ensure DashScope Python SDK version is at least 1.23.8 before running this code. Older versions may trigger "url error, please check url!" errors. Update via the SDK installation guide.
Set base_http_api_url for your 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'
Sample code
Synchronous call
This example shows a synchronous call with two image input methods: public URL and local file path.
Request example
import os
from http import HTTPStatus
# dashscope sdk >= 1.23.4
from dashscope import VideoSynthesis
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# Get the DashScope API key (Model Studio API key) from the environment variable
api_key = os.getenv("DASHSCOPE_API_KEY")
# ========== Image input method (choose one) ==========
# [Method 1] Use a public image URL
first_frame_url = "https://wanx.alicdn.com/material/20250318/first_frame.png"
last_frame_url = "https://wanx.alicdn.com/material/20250318/last_frame.png"
# [Method 2] Use a local file path (file:// + file path)
# Use an absolute path
# first_frame_url = "file://" + "/path/to/your/first_frame.png" # Linux/macOS
# last_frame_url = "file://" + "C:/path/to/your/last_frame.png" # Windows
# Or use a relative path
# first_frame_url = "file://" + "./first_frame.png" # Use your actual path
# last_frame_url = "file://" + "./last_frame.png" # Use your actual path
def sample_sync_call_kf2v():
print('please wait...')
rsp = VideoSynthesis.call(api_key=api_key,
model="wan2.2-kf2v-flash",
prompt="Realistic style, a small black cat looks up at the sky curiously, the camera gradually rises from eye level, and finally captures its curious gaze from a top-down view.",
first_frame_url=first_frame_url,
last_frame_url=last_frame_url,
resolution="720P",
prompt_extend=True)
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_sync_call_kf2v()Response example
The video_url is valid for 24 hours. Download promptly.
{
"status_code": 200,
"request_id": "a37fafc3-907c-96f3-95a6-5b2a8268a3fd",
"code": null,
"message": "",
"output": {
"task_id": "4dba0092-da13-42b2-afb1-0f7b8a0f4643",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-wlcb-acdr-1.oss-cn-wulanchabu-acdr-1.aliyuncs.com/xxx.mp4?xxxxx",
"submit_time": "2025-05-23 15:50:12.404",
"scheduled_time": "2025-05-23 15:50:12.443",
"end_time": "2025-05-23 15:54:56.502",
"orig_prompt": "Realistic style, a small black cat looks up at the sky curiously, the camera gradually rises from eye level, and finally captures its curious gaze from a top-down view.",
"actual_prompt": "Realistic style, a small black cat looks up at the sky curiously, the camera gradually rises from eye level, and finally captures its curious gaze from a top-down view. The cat's yellow eyes are bright and expressive, its ears are pricked up, and its whiskers are clearly visible. The background is a simple, light-colored wall, which highlights the cat's black fur and focused expression. A close-up shot emphasizes the change in the cat's gaze and posture."
},
"usage": {
"video_count": 1,
"video_duration": 5,
"video_ratio": "standard"
}
}Asynchronous call
An asynchronous call returns a task ID immediately. Poll for the result or wait for completion.
Request example
import os
from http import HTTPStatus
# dashscope sdk >= 1.23.4
from dashscope import VideoSynthesis
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# Get the DashScope API key (Model Studio API key) from the environment variable
api_key = os.getenv("DASHSCOPE_API_KEY")
# ========== Image input method (choose one) ==========
# [Method 1] Use a public image URL
first_frame_url = "https://wanx.alicdn.com/material/20250318/first_frame.png"
last_frame_url = "https://wanx.alicdn.com/material/20250318/last_frame.png"
# [Method 2] Use a local file path (file:// + file path)
# Use an absolute path
# first_frame_url = "file://" + "/path/to/your/first_frame.png" # Linux/macOS
# last_frame_url = "file://" + "C:/path/to/your/last_frame.png" # Windows
# Or use a relative path
# first_frame_url = "file://" + "./first_frame.png" # Use your actual path
# last_frame_url = "file://" + "./last_frame.png" # Use your actual path
def sample_async_call_kf2v():
print('please wait...')
rsp = VideoSynthesis.async_call(api_key=api_key,
model="wan2.2-kf2v-flash",
prompt="Realistic style, a small black cat looks up at the sky curiously, the camera gradually rises from eye level, and finally captures its curious gaze from a top-down view.",
first_frame_url=first_frame_url,
last_frame_url=last_frame_url,
resolution="720P",
prompt_extend=True)
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))
# get the task information include the task status.
status = VideoSynthesis.fetch(task=rsp, api_key=api_key)
if status.status_code == HTTPStatus.OK:
print(status.output.task_status) # check the task status
else:
print('Failed, status_code: %s, code: %s, message: %s' %
(status.status_code, status.code, status.message))
# wait the task complete, will call fetch interval, and check it's in finished status.
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_kf2v()Response example
1. Response for creating a task
{
"status_code": 200,
"request_id": "c86ff7ba-8377-917a-90ed-xxxxxx",
"code": "",
"message": "",
"output": {
"task_id": "721164c6-8619-4a35-a6d9-xxxxxx",
"task_status": "PENDING",
"video_url": ""
},
"usage": null
}2. Response for querying a task result
The video_url is valid for 24 hours. Download promptly.
{
"status_code": 200,
"request_id": "efa545b3-f95c-9e3a-a3b6-xxxxxx",
"code": null,
"message": "",
"output": {
"task_id": "721164c6-8619-4a35-a6d9-xxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.mp4?xxxxx",
"submit_time": "2025-02-12 11:03:30.701",
"scheduled_time": "2025-02-12 11:06:05.378",
"end_time": "2025-02-12 11:12:18.853",
"orig_prompt": "Realistic style, a small black cat looks up at the sky curiously, the camera gradually rises from eye level, and finally captures its curious gaze from a top-down view.",
"actual_prompt": "Realistic style, a small black cat looks up at the sky curiously, the camera gradually rises from eye level, and finally captures its curious gaze from a top-down view. The cat's fur is jet black and shiny, its eyes are large and bright with golden pupils. It looks up with its ears pricked, appearing exceptionally focused. After the camera moves up, the cat turns to look directly at the camera, its eyes full of curiosity and alertness. The background is simple, highlighting the cat's detailed features. A close-up shot with soft, natural light."
},
"usage": {
"video_count": 1,
"video_duration": 5,
"video_ratio": "standard"
}
}Java SDK
Ensure DashScope Java SDK version is at least 2.20.9 before running this code. Older versions may trigger "url error, please check url!" errors. Update via the SDK installation guide.
Sample code
Synchronous call
This example shows a synchronous call with two image input methods: public URL and local file path.
Request example
// Copyright (c) Alibaba, Inc. and its affiliates.
// dashscope sdk >= 2.20.1
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.HashMap;
import java.util.Map;
public class Kf2vSyncIntl {
static {
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// Get DashScope API key (Model Studio API key) from environment variable
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
/**
* Image input method (choose one):
*
* [Method 1] Public URL
*/
static String firstFrameUrl = "https://wanx.alicdn.com/material/20250318/first_frame.png";
static String lastFrameUrl = "https://wanx.alicdn.com/material/20250318/last_frame.png";
/**
* [Method 2] Local file path (file:// + absolute path or file:/// + absolute path)
*/
// static String firstFrameUrl = "file://" + "/your/path/to/first_frame.png"; // Linux/macOS
// static String lastFrameUrl = "file:///" + "C:/path/to/your/img.png"; // Windows
public static void syncCall() {
Map<String, Object> parameters = new HashMap<>();
parameters.put("prompt_extend", true);
parameters.put("resolution", "720P");
VideoSynthesis videoSynthesis = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.2-kf2v-flash")
.prompt("Realistic style, a small black cat looks up at the sky curiously, the camera gradually rises from eye level, and finally captures its curious gaze from a top-down view.")
.firstFrameUrl(firstFrameUrl)
.lastFrameUrl(lastFrameUrl)
.parameters(parameters)
.build();
VideoSynthesisResult result = null;
try {
System.out.println("---sync call, please wait a moment----");
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 promptly.
{
"request_id": "e6bb4517-c073-9c10-b748-dedb8c11bb41",
"output": {
"task_id": "984784fe-83c1-4fc4-88c7-52c2c1fa92a2",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-wlcb-acdr-1.oss-cn-wulanchabu-acdr-1.aliyuncs.com/xxx.mp4?xxxxx"
},
"usage": {
"video_count": 1,
"video_duration": 5,
"video_ratio": "standard"
}
}Asynchronous call
An asynchronous call returns a task ID immediately. Poll for the result or wait for completion.
Request example
// Copyright (c) Alibaba, Inc. and its affiliates.
// dashscope sdk >= 2.20.1
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.HashMap;
import java.util.Map;
public class Kf2vAsync {
static {
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// Get DashScope API key (Model Studio API key) from environment variable
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
/**
* Image input method (choose one)
*
* [Method 1] Public URL
*/
static String firstFrameUrl = "https://wanx.alicdn.com/material/20250318/first_frame.png";
static String lastFrameUrl = "https://wanx.alicdn.com/material/20250318/last_frame.png";
/**
* [Method 2] Local file path (file:// + absolute path or file:/// + absolute path)
*/
// static String firstFrameUrl = "file://" + "/your/path/to/first_frame.png"; // Linux/macOS
// static String lastFrameUrl = "file:///" + "C:/path/to/your/img.png"; // Windows
public static void asyncCall(){
// Set parameters
Map<String, Object> parameters = new HashMap<>();
parameters.put("prompt_extend", true);
parameters.put("resolution", "720P");
VideoSynthesis videoSynthesis = new VideoSynthesis();
VideoSynthesisParam param =
VideoSynthesisParam.builder()
.apiKey(apiKey)
.model("wan2.2-kf2v-flash")
.prompt("Realistic style, a small black cat looks up at the sky curiously, the camera gradually rises from eye level, and finally captures its curious gaze from a top-down view.")
.firstFrameUrl(firstFrameUrl)
.lastFrameUrl(lastFrameUrl)
.parameters(parameters)
.build();
VideoSynthesisResult result = null;
try {
System.out.println("---async call, please wait a moment----");
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 for creating a task
{
"request_id": "5dbf9dc5-4f4c-9605-85ea-xxxxxxxx",
"output": {
"task_id": "7277e20e-aa01-4709-xxxxxxxx",
"task_status": "PENDING"
}
}2. Response for querying a task result
The video_url is valid for 24 hours. Download promptly.
{
"request_id": "1625235c-c13e-93ec-aff7-xxxxxxxx",
"output": {
"task_id": "464a5e46-79a6-46fd-9823-xxxxxxxx",
"task_status": "SUCCEEDED",
"video_url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.mp4?xxxxxx"
},
"usage": {
"video_count": 1,
"video_duration": 5,
"video_ratio": "standard"
}
}Limitations
Data retention:
task_idandvideo_urlare retained for 24 hours. After expiration, they cannot be queried or downloaded.Audio support: Generates silent videos only. Audio output is not supported. To generate audio, use speech synthesis.
Content moderation: Content Moderation reviews all prompts, images, and videos. If content violates policies, the system returns "IPInfringementSuspect" or "DataInspectionFailed" errors. See Error messages for details.
Error codes
If a model call fails, see Error messages for troubleshooting.
FAQ
Q: How do I generate a video with a specific aspect ratio, such as 3:4?
A: Output video aspect ratio is determined by the first frame image (first_frame_url). However, exact ratios (e.g., strict 3:4) are not guaranteed and may vary slightly.
Why does drift occur:
The model uses your input image aspect ratio as a baseline and calculates the closest valid resolution based on the resolution setting's pixel count. Video dimensions must be multiples of 16, so the model fine-tunes the final resolution. Output aspect ratio may not be exactly 3:4 but will be very close.
Example: input 750×1000 (ratio 3:4 = 0.75), resolution = "720P" (target ~920,000 pixels), output 816×1104 (ratio ≈ 0.739, ~900,000 pixels).
Best practices:
Input control: Use a first-frame image with an aspect ratio as close as possible to your target.
Post-processing: If you require exact ratios, crop or add black bars to the generated video using editing tools.
Q: How do I get the domain name whitelist for video storage?
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.