The Wan 2.2 model generates a smoothly transitioning video from a first frame , a last frame, and a text prompt .
Related documents: User guide
To ensure successful API calls, your model, endpoint URL, and API key must be in the same region. Cross-region calls will fail.
Because image-to-video tasks are long-running operations that typically take 1 to 5 minutes, the API uses an asynchronous call. The process involves two core steps: create a task, then poll for the result.
The SDK's parameter names are largely consistent with the HTTP API, and the parameter structure follows the conventions of each programming language.
Because image-to-video tasks are long-running (typically 1–5 minutes), the SDK handles the asynchronous HTTP calls internally, supporting both synchronous and asynchronous call methods.
Set the
If a model call fails, see Error codes for troubleshooting.
A: The output video's aspect ratio depends on the first frame image (first_frame_url). However, an exact ratio (such as a strict 3:4) cannot be guaranteed, and may deviate slightly.
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.
Usage notes
To ensure successful API calls, your model, endpoint URL, and API key must be in the same region. Cross-region calls will fail.
- Select a model: Confirm the region where the model is available.
- Select a URL: Choose the endpoint URL that corresponds to your region. Both HTTP URLs and DashScope SDK URLs are supported.
- Configure your API key: Select a region, get your API key, and then set it as an environment variable.
- Install the SDK: To make API calls using the SDK, install the DashScope SDK.
The code examples in this topic apply to Singapore.
HTTP call
Because image-to-video tasks are long-running operations that typically take 1 to 5 minutes, the API uses an asynchronous call. The process involves two core steps: create a task, then poll for the result.
Step 1: Create a task
- Singapore
- China (Beijing)
POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesisReplace {WorkspaceId} with your actual workspace ID.- 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 Call APIs with Postman or cURL.
Request parametersRequest headersContent-Typestring (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.Request bodymodelstring (Required)The name of the model. Example: wan2.2-kf2v-flash.For details, see the Model Studio console.input object (Required)Contains the primary input for the task, such as the prompt.
Properties prompt string (Optional)The text prompt. Supports both Chinese and English. The maximum length is 800 characters. Both Chinese characters and letters count as a single character. Text exceeding this limit is truncated.If there are significant changes in the subject or scene between the first and last frames, we recommend describing the transition process, such as camera movement (e.g., "camera moves to the left") or subject movement (e.g., "a person runs forward").Example: "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."For tips on writing effective prompts, see the Prompt guide for text-to-video and image-to-video.negative_prompt string (Optional)A negative prompt that describes content to exclude from the video, which helps constrain the output.Supports both Chinese and English. The maximum length is 500 characters. Text exceeding this limit is truncated.Example: "low resolution, error, worst quality, low quality, deformed, extra fingers, bad proportions".first_frame_url string (Required)The URL of the first frame image. The aspect ratio of the output video will match that of the first frame image.The URL must be a publicly accessible address that supports the HTTP or HTTPS protocol.Image requirements:
string (Required)The URL of the last frame image.The URL must be a publicly accessible address that supports the HTTP or HTTPS protocol.Image requirements:
object (Optional)Video processing parameters.
Properties resolution string (Optional)The resolution of the generated video. This parameter adjusts the definition (total pixels) without changing its aspect ratio.The default value and available values for this parameter depend on the model parameter, as described below:
integer (Optional)This value is fixed at 5.prompt_extendbool (Optional)Specifies whether to enable prompt rewriting. When enabled, a large language model (LLM) intelligently rewrites the input prompt. This can significantly improve results for short prompts but increases latency.
bool (Optional)Specifies whether to add a watermark with the text "AI-generated" to the bottom-right corner of the video.
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. |
Generates a video based on a first frame, a last frame, and a prompt. |
Response parametersoutputobjectThe output information for the task.
Properties task_id stringThe task ID. Valid for queries for 24 hours.task_status stringThe status of the task.
Enumeration values
stringUnique request identifier for tracing and troubleshooting.code stringError code. Returned only for failed requests. See Error codes.message stringDetailed error message. Returned only for failed requests. See Error codes. |
Save the task_id to query the task status and result. |
Step 2: Query the result
- Singapore
- China (Beijing)
GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id}Replace {WorkspaceId} with your actual workspace 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 parametersRequest headersAuthorizationstring (Required)Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx.Path parameterstask_idstring (Required)The ID of the task. |
Replace 86ecf553-d340-4e21-xxxxxxxxx with your actual task_id.API keys are different for each region. For more information, see Obtain an API key. If you use a model in the China (Beijing) region, replace |
Response parametersoutputobjectThe output information for the task.
Properties task_id stringThe task ID. Valid for queries for 24 hours.task_status stringThe status of the task.
Enumeration values
stringThe 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 stringThe 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 stringThe 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 stringURL 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 stringThe original input prompt, corresponding to the request parameter prompt.actual_prompt stringThe optimized prompt used when prompt rewriting is enabled. Not returned when disabled.code stringError code. Returned only for failed requests. See Error codes.message stringDetailed error message. Returned only for failed requests. See Error codes.objectTask usage statistics. Only successful tasks are billed.
Properties video_duration integerThe duration of the generated video in seconds, which is always 5. Billing formula: Cost = Video seconds × Unit price.video_count integerThe number of videos generated. This value is fixed at 1.video_ratio stringThis value is currently returned only by the 2.1 model. The aspect ratio of the generated video, which is fixed at standard.SR integerThis value is currently returned only by the 2.2 model. The resolution tier of the generated video. Possible values are 480, 720, and 1080.stringUnique request identifier for tracing and troubleshooting. |
Video URLs are valid for only 24 hours and then automatically purged. Save generated videos promptly. |
DashScope SDK calls
The SDK's parameter names are largely consistent with the HTTP API, and the parameter structure follows the conventions of each programming language.
Because image-to-video tasks are long-running (typically 1–5 minutes), the SDK handles the asynchronous HTTP calls internally, supporting both synchronous and asynchronous call methods.
The actual processing time depends on the number of tasks in the queue and service performance. Please be patient.
Python SDK calls
Set the base_http_api_url based on the model's region:
- Singapore
- Beijing
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'Replace {WorkspaceId} with your actual workspace ID.Sample code
- Synchronous call
- Asynchronous call
This example demonstrates a synchronous call with two image input methods: a public URL and a local file path.
Request example
Response example
The video_url is valid for 24 hours. Please download the video within this period.
Java SDK calls
Sample code
- Synchronous call
- Asynchronous call
This example demonstrates a synchronous call with two image input methods: public URL and local file path.
Request example
Response example
The video_url is valid for 24 hours. Please download the video within this period.
Limitations
- Data retention: The task
task_idand videovideo_urlare retained for 24 hours, after which they cannot be queried or downloaded. - Audio support: The service generates silent videos only. To generate audio, use speech synthesis.
- Content Moderation: Content Moderation reviews all input prompts, images, and output videos. If any content violates the usage policies, the service returns an "IPInfringementSuspect" or "DataInspectionFailed" error. For details, see Error codes.
Error codes
If a model call fails, see Error codes for troubleshooting.
FAQ
Q: How to generate a specific aspect ratio?
A: The output video's aspect ratio depends on the first frame image (first_frame_url). However, an exact ratio (such as a strict 3:4) cannot be guaranteed, and may deviate slightly.
-
Why does the aspect ratio deviate?
The model uses the input image's aspect ratio as a baseline and calculates the closest valid resolution based on the total pixels of the selected
resolutionsetting. Because the video's width and height must be multiples of 16, the model makes minor adjustments to the final resolution.- For example, if you provide a 750×1000 input image (an aspect ratio of 3:4 or 0.75) and set
resolutionto "720P" (targeting approximately 920,000 pixels), the actual output might be 816×1104 (an aspect ratio of approximately 0.739, with about 900,000 pixels).
- For example, if you provide a 750×1000 input image (an aspect ratio of 3:4 or 0.75) and set
-
Recommendations:
- Input Image: For best results, use a first frame image that matches your target aspect ratio.
- Post-processing: If a strict aspect ratio is required, use a video editing tool to crop the generated video or add black bars.