The Wan2.2 first-and-last-frame video generation model generates a video with smooth transitions based on the first frame image, last frame image, and text prompt.
Related documents: User Guide
To ensure successful calls, make sure the model, Endpoint URL, and API Key belong to the same region. Cross-region calls will fail.
Since image-to-video tasks take a long time to complete (usually 1 to 5 minutes), the API uses asynchronous calls. The entire process consists of two core steps, "Create Task -> Poll for Result", as follows:
The SDK parameter naming is basically the same as that of the HTTP API, and the parameter structure is encapsulated according to language characteristics.
Since I2V tasks take a long time (usually 1-5 minutes), the SDK encapsulates the HTTP asynchronous call workflow at the underlying layer, supporting both synchronous and asynchronous call methods.
Set
If a model call fails and returns an error message, see Error codes for troubleshooting.
A: The aspect ratio of the output video is determined by the input first frame image (first_frame_url), but the exact ratio cannot be guaranteed (for example, strictly 3:4); there will be some deviation.
A: Videos generated by the model are stored in Alibaba Cloud OSS, and the API returns a temporary public URL. If you need to configure a firewall whitelist for the download URL, note that: because the underlying storage changes dynamically based on business conditions, this documentation does not provide a fixed OSS domain whitelist to prevent expired information from affecting access. If you have security control requirements, contact your account manager to obtain the latest OSS domain list.
Scope
To ensure successful calls, make sure the model, Endpoint URL, and API Key belong to the same region. Cross-region calls will fail.
- Select Model: Confirm the region of the model.
- Select URL: Select the Endpoint URL of the corresponding region. Both HTTP URLs and DashScope SDK URLs are supported.
- Configure API Key: Select a region and obtain and configure an API Key, then configure the API Key in environment variables.
- Install SDK: To make calls through an SDK, install the DashScope SDK.
The sample code in this document applies to the Singapore region.
HTTP Calls
Since image-to-video tasks take a long time to complete (usually 1 to 5 minutes), the API uses asynchronous calls. The entire process consists of two core steps, "Create Task -> Poll for Result", as follows:
Step 1: Create a task to obtain the task ID
- Singapore
- Beijing
POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesisWhen making calls, replace {WorkspaceId} with your actual workspace ID.- After the task is created, use the
task_idreturned by the API to query the result. The task_id is valid for 24 hours. Do not create the same task repeatedly; just poll for the result. - For a beginner's guide, see Postman.
Request ParametersRequest HeadersContent-Typestring(Required)Request Content Type. This parameter must be set to application/json.Authorizationstring(Required)Request authentication. The API uses an 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.Request Bodymodelstring (Required)Model name. Example value: wan2.2-kf2v-flash.For details, see the Bailian console.input object (Required)Basic input information, such as prompts.
Property prompt string (Optional)Text prompt. Supports Chinese and English, with a length of no more than 800 characters, where each Chinese character/letter counts as one character; any excess is automatically truncated.If the subject and scene differ significantly between the first and last frames, it is recommended to describe the change process, such as camera movement (the camera moves to the left) or subject motion (a person runs forward).Example value: A black kitten looks up at the sky curiously, the camera gradually rises from eye level, and finally shoots from above to capture its curious gaze.For tips on using prompts, see the T2V/I2V Prompt Guide.negative_prompt string (Optional)Negative prompt, used to describe content you do not want to see in the video, which can constrain the video visuals.Supports Chinese and English, with a length of no more than 500 characters; any excess is automatically truncated.Example value: low resolution, fault, worst quality, low quality, incomplete, extra fingers, bad proportions, etc.first_frame_url string (Required)First Frame Image URL. The aspect ratio of the output video is consistent with that of the first frame image.The URL must be a publicly accessible address, supporting the HTTP or HTTPS protocol.Image limits:
string (Required)Last frame image URL.The URL must be a publicly accessible address, supporting the HTTP or HTTPS protocol.Image limits:
object (Optional)Video processing parameters.
Property resolution string (Optional)The resolution tier of the generated video. It only adjusts the video clarity (total pixels) and does not change the video aspect ratio. The video aspect ratio will be consistent with that of the first frame image first_frame_url.The default value and available enumeration values of this parameter depend on the model parameter. The rules are as follows:
integer (optional)Video generation duration, in seconds. The current parameter value is fixed at 5 and cannot be modified. The model always generates videos with a duration of 5 seconds.prompt_extendbool (optional)Whether to enable intelligent prompt rewriting. When enabled, a large model is used to intelligently rewrite the input prompt. It significantly improves generation results for shorter prompts, but increases processing time.
bool (optional)Whether to add a watermark. The watermark is located in the lower-right corner of the image with the text "AI-generated".
integer(optional)Random number seed. Value range: [0, 2147483647].If not specified, the system automatically generates a random seed. To improve the reproducibility of generation results, you are advised to use a fixed seed value.Note that due to the probabilistic nature of model generation, even with the same seed, identical generation results cannot be guaranteed. |
Generates a video based on the first frame, last frame, and prompt. |
Response parametersoutputobjectTask output information.
Property task_id stringTask ID. Query validity: 24 hours.task_status stringStatus.
Enumerated values
stringUnique request identifier. It can be used for tracing request details and troubleshooting.codestringError code returned when the request fails. This parameter is not returned when the request succeeds. For more information, see Error codes.messagestringDetailed error information returned when the request fails. This parameter is not returned when the request succeeds. For more information, see Error codes. |
Please save the task_id, which is used to query the task status and results. |
Step 2: Query the result by task ID
- Singapore
- Beijing
GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id}When making calls, replace {WorkspaceId} with your actual workspace ID.- Polling recommendations: Video generation takes several minutes. We recommend using a polling mechanism with a reasonable query interval (such as 15 seconds) to obtain the results.
- Task status transitions: PENDING (Queuing) → RUNNING (Processing) → SUCCEEDED (Success) / FAILED (Failed).
- Result link: The video URL is returned after the task succeeds, valid for 24 hours. We recommend downloading it immediately after obtaining the URL and transferring it to permanent storage (such as Alibaba Cloud OSS).
- task_id validity: 24 hours. Once it expires, the result can no longer be queried, and the API will return the task status as
UNKNOWN.
Request parametersRequest headersAuthorizationstring(Required)Request authentication. The API uses an Alibaba Cloud Model Studio API Key for authentication. Example value: Bearer sk-xxxx.URL path parameterstask_idstring (required)Task ID. |
Replace 86ecf553-d340-4e21-xxxxxxxxx with the actual task_id.API Keys differ across regions. See Obtain and configure an API Key. If you use models in the China (Beijing) region, replace base_url with https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/86ecf553-d340-4e21-xxxxxxxxx, where {WorkspaceId} must be replaced with the actual workspace ID. |
Response parametersoutputobjectTask output information.
Property task_id stringTask ID. Query validity: 24 hours.task_status stringStatus.
Enumerated values
stringTask submission time. The time zone is UTC+8, in the format YYYY-MM-DD HH:mm:ss.SSS.scheduled_time stringTask execution time. The time zone is UTC+8, in the format YYYY-MM-DD HH:mm:ss.SSS.end_time stringTask completion time. The time zone is UTC+8, in the format YYYY-MM-DD HH:mm:ss.SSS.video_urlstringVideo 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 stringThe original input prompt, corresponding to the request parameter prompt.actual_prompt stringWhen prompt smart rewriting is enabled, the actual optimized prompt used is returned. If this feature is not enabled, this field is not returned.codestringError code returned when the request fails. This parameter is not returned when the request succeeds. For more information, see Error codes.messagestringDetailed error information returned when the request fails. This parameter is not returned when the request succeeds. For more information, see Error codes.objectOutput statistics. Only successful results are counted.
Property video_duration integerThe duration of the generated video, in seconds. The enumerated value is 5. Billing formula: Fee = Video seconds × unit price.video_count integerThe number of generated videos. Fixed at 1.video_ratio stringCurrently, this value is returned only for the 2.1 model. The aspect ratio of the generated video, fixed at standard.SR integerCurrently, this value is returned only for the 2.2 model. The resolution tier of the generated video, with enumerated values 480, 720, and 1080.stringUnique request identifier. It can be used for tracing request details and troubleshooting. |
The video URL is retained for only 24 hours and will be automatically cleared after that. Save the generated video in a timely manner. |
Calling the DashScope SDK
The SDK parameter naming is basically the same as that of the HTTP API, and the parameter structure is encapsulated according to language characteristics.
Since I2V tasks take a long time (usually 1-5 minutes), the SDK encapsulates the HTTP asynchronous call workflow at the underlying layer, supporting both synchronous and asynchronous call methods.
The actual time required depends on the number of queued tasks and service execution. Please wait patiently when retrieving the results.
Calling the Python SDK
Set region according to the region where the model is located (pass it in when constructing the Client; the region values differ across regions):
- Singapore
- Beijing
region="ap-southeast-1"When making calls, replace {WorkspaceId} with your actual workspace ID.Sample Code
- Synchronous Call
- Asynchronous Call
This example demonstrates the synchronous call method, including two image input methods: public URL and local file path.
Request example
Response example
video_url is valid for 24 hours. Download the video in a timely manner.
Calling the Java SDK
Sample Code
- Synchronous Call
- Asynchronous Call
This example demonstrates the synchronous call method, including two image input methods: public URL and local file path.
Request example
Sample Response
video_url is valid for 24 hours. Download the video in a timely manner.
Limits
- Data validity: The task
task_idand the videovideo_urlare retained for only 24 hours. After expiration, they can no longer be queried or downloaded. - Audio support: Currently, only silent videos can be generated, and audio output is not supported. If needed, you can generate audio via speech synthesis.
- Content moderation: The input prompt and images, as well as the output video, are all subject to content safety moderation. Content that violates the rules will return the "IPInfringementSuspect" or "DataInspectionFailed" error. For details, see Error codes.
Error codes
If a model call fails and returns an error message, see Error codes for troubleshooting.
FAQ
Q: How do I generate a video with a specific aspect ratio (such as 3:4)?
A: The aspect ratio of the output video is determined by the input first frame image (first_frame_url), but the exact ratio cannot be guaranteed (for example, strictly 3:4); there will be some deviation.
-
Why is there a deviation?
The model uses the ratio of the input image as the baseline and, combined with the total pixels of the set resolution tier (resolution), automatically calculates the closest valid resolution. Because the width and height of the video must be multiples of 16, the model fine-tunes the final resolution. Therefore, the output ratio cannot be strictly equal to 3:4, but it will be very close.
- For example: with an input image of 750×1000 (aspect ratio 3:4 = 0.75) and resolution set to "720P" (target total pixels of approximately 920,000), the actual output is 816×1104 (aspect ratio ≈ 0.739, approximately 900,000 total pixels).
-
Best practices:
- Input control: Use an image with the same ratio as the target whenever possible as the first frame input.
- Post-processing: If you have strict ratio requirements, we recommend using an editing tool to perform simple cropping or black-bar padding after the video is generated.