Vidu - Image-to-video - First and last frame API reference

Updated at:

The Vidu first and last frame video generation model creates a smoothly transitioning video based on a first frame image , a last frame image, and a text prompt .

ImportantThis document applies only to the China (Beijing) region. Use an API key from this region.

Activate the service

Go to the Alibaba Cloud Model Studio console, search for Vidu, find the Vidu model card, and click Activate Now. In the pop-up window, confirm the activation and authorization.

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.

HTTP calls

Because first and last frame video generation tasks take a long time (typically 1 to 5 minutes), the API uses asynchronous invocation. The entire process involves two core steps: Create a task -> Poll for the result. The procedure is as follows:

Step 1: Create a task and get the task ID

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

Note

  • After the task is created successfully, use the task_id returned by the API to query the result. task_id is valid for 24 hours. Do not create tasks repeatedly; just poll for the result.

Request parameters

Request headers

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)

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

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

Request body

model string (Required)

Model name. Valid values:

  • vidu/viduq3-pro_start-end2video
  • vidu/viduq3-turbo_start-end2video
  • vidu/viduq2-pro_start-end2video
  • vidu/viduq2-turbo_start-end2video

input object (Required)

Basic input information, including the first frame, last frame image, and prompt.

Properties

prompt string (Required)

The text prompt. It describes the transition process from the first frame to the last frame.

Both Chinese and English are supported. Each Chinese character or letter counts as one character. The maximum length is 5,000 characters. Any excess characters are automatically truncated.

Example: A kitten jumps down from the windowsill, lands lightly on the sofa, and then looks around curiously.

For more information about how to write prompts, see Vidu Video Generation Prompt Guide.

media array (Required)

A list of media resources, including the first and last frame images.

Each element in the array is a media object that contains type and url fields.

Properties

type string (Required)

The media type. The static field is:

  • image: Image URL.

Material limits:

  • There must be exactly 2 images.
  • The first image in the array represents the first frame, and the second image represents the last frame.

url string (Required)

The publicly accessible URL of the image.

Image limits:

  • Format: JPG, PNG, WEBP.
  • Aspect ratio: 1:4 to 4:1.
  • File size: No more than 50 MB.
  • Resolution: The resolutions of the first and last frames must be similar. The ratio of their total pixel values (width × height) must be between 0.8 and 1.25.

parameters object (Required)

Video generation parameters, such as video resolution and duration.

Properties

resolution string (Required)

Importantresolution directly affects the fee. Confirm the model pricing before calling.

The resolution of the generated video. Valid values:

  • 540P
  • 720P: Default value.
  • 1080P

duration integer (Required)

Importantduration directly affects the fee. Billing is per second; the longer the duration, the higher the fee. Confirm the model pricing before calling.

The duration of the generated video, in seconds.

  • vidu/viduq3-pro_start-end2video, vidu/viduq3-turbo_start-end2video: an integer in [1, 16]. Default value is 5.
  • vidu/viduq2-pro_start-end2video, vidu/viduq2-turbo_start-end2video: an integer in [1, 10]. Default value is 5.

audio boolean (Optional)

Supported models: vidu/viduq3-pro_start-end2video, vidu/viduq3-turbo_start-end2video.

Whether to generate a video with audio. When enabled, the model automatically generates matching background music or sound effects based on the video content.

  • false: Default value; outputs a video without audio.
  • true: Outputs a video with audio.

watermark boolean (Optional)

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

  • false: Default value; no watermark added.
  • true: Adds a watermark.

seedinteger(Optional)

Random number seed. The value range is [0, 2147483647].

If not specified, the system automatically generates a random seed. To improve the reproducibility of generated results, it is recommended to use a fixed seed value.

Note: Because model generation is probabilistic, even with the same seed, identical results are not guaranteed for each generation.

First and Last Frame to Video

curl --location 'https://{WorkspaceId}.cn-beijing.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": "vidu/viduq3-turbo_start-end2video",
    "input": {
        "media": [
            {
                "type": "image",
                "url": "https://wanx.alicdn.com/material/20250318/first_frame.png"
            },
            {
                "type": "image",
                "url": "https://wanx.alicdn.com/material/20250318/last_frame.png"
            }
        ],
        "prompt": "一只小猫从窗台向下跳跃,轻盈地落在沙发上,然后好奇地环顾四周。"
    },
    "parameters": {
        "resolution": "540P",
        "duration": 5,
        "watermark": true
    }
}'

Python SDK

import dashscope
import os
from dashscope import DashScopeError

# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
# 获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
client = dashscope.Client(api_key=os.getenv("DASHSCOPE_API_KEY"))

media = [{'type': 'image', 'url': 'https://wanx.alicdn.com/material/20250318/first_frame.png'}, {'type': 'image', 'url': 'https://wanx.alicdn.com/material/20250318/last_frame.png'}]

def sample_async_call():
    # 异步提交视频生成任务
    try:
        job = client.videos.jobs.create(model='vidu/viduq3-turbo_start-end2video',
                                        media=media,
                                        prompt='一只小猫从窗台向下跳跃,轻盈地落在沙发上,然后好奇地环顾四周。',
                                        resolution='540P',
                                        duration=5,
                                        watermark=True)
        print(job)
        print("task_id: %s" % job.task_id)
    except DashScopeError as e:
        print(f"HTTP返回码:{e.status_code}")
        print(f"错误码:{e.code}")
        print(f"错误信息:{e.message}")
        print("请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code")
        return

    # 查询任务状态
    try:
        snapshot = client.videos.jobs.fetch(job.task_id)
        print(snapshot.status)
    except DashScopeError as e:
        print(f"HTTP返回码:{e.status_code}")
        print(f"错误码:{e.code}")
        print(f"错误信息:{e.message}")
        print("请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code")

    # 等待任务完成
    try:
        done = client.videos.jobs.wait(job)
        print(done)
        print(done.video_url)
    except DashScopeError as e:
        print(f"HTTP返回码:{e.status_code}")
        print(f"错误码:{e.code}")
        print(f"错误信息:{e.message}")
        print("请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code")

if __name__ == '__main__':
    sample_async_call()

Response Parameters

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_idstring

Unique request identifier for tracing and troubleshooting.

codestring

Error code. Returned only for failed requests. See Error codes.

messagestring

Detailed error message. Returned only for failed requests. See Error codes.

Successful response

Save the task_id for querying task status and results.

{
    "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 codes.

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

Step 2: Query the result by task ID

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

Note

  • Polling recommendation: Video generation takes several minutes. We recommend that you use a polling mechanism and set a reasonable query interval, such as 15 seconds, to obtain the result.
  • Task status flow: PENDING (In queue) -> RUNNING (Processing) -> SUCCEEDED (Successful) / FAILED (Failed).
  • task_id validity: 24 hours. After this period, you cannot query the result, and the API returns the task status as UNKNOWN.
  • RPS limit: The default records per second (RPS) for the query API is 20. For higher-frequency queries or event notifications, you can configure an asynchronous task callback.
  • More operations: For operations such as batch queries and task cancellation, see Manage asynchronous tasks.

Request parameters

Request headers

Authorization string (Required)

Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx.

URL path parameters

task_id string (Required)

The ID of the task.

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 -X GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"

Response parameters

outputobject

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. format is YYYY-MM-DD HH:mm:ss.SSS.

scheduled_time string

The time when the task was executed. format is YYYY-MM-DD HH:mm:ss.SSS.

end_time string

The time when the task was completed. format is YYYY-MM-DD HH:mm:ss.SSS.

video_urlstring

Video URL. Returned only when task_status is SUCCEEDED.

The video is in MP4 format (H.264 encoding). The video link is valid for 24 hours. We recommend that you download it promptly.

orig_prompt string

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

codestring

Error code. Returned only for failed requests. See Error codes.

messagestring

Detailed error message. Returned only for failed requests. See Error codes.

usage object

Statistics for the output information. This parameter is counted only for successful results.

Properties

duration integer

The total billable video duration in seconds. Example: 5.

output_video_durationinteger

The duration of the output video in seconds. Example: 5.

size string

The resolution of the output video. Example: 828*624.

fps integer

The frame rate of the output video. Example: 24.

SR string

The resolution tier of the output video. Example: 540.

audio boolean

Indicates whether the output video has sound. Example: false.

video_count integer

The number of output videos. This is a static field with a value of 1.

request_idstring

Unique request identifier for tracing and troubleshooting.

Task successful

{
    "request_id": "cf7a3a1d-27b0-4d45-8b89-xxxxxx",
    "output": {
        "task_id": "88125b85-b53d-45f1-ba13-xxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2026-03-27 14:39:15.041",
        "scheduled_time": "2026-03-27 14:39:15.081",
        "end_time": "2026-03-27 14:40:03.428",
        "orig_prompt": "一只小猫从窗台向下跳跃,轻盈地落在沙发上,然后好奇地环顾四周。",
        "video_url": "https://prod-ss-vidu.s3.cn-northwest-1.amazonaws.com.cn/xxx.mp4?xxx"
    },
    "usage": {
        "duration": 5,
        "size": "828*624",
        "output_video_duration": 5,
        "fps": 24,
        "video_count": 1,
        "audio": false,
        "SR": "540"
    }
}

Task failed

If the task fails, task_status is set to FAILED, and an error code and message are 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

task_id can be queried within 24 hours. After that, queries are no longer available and the following error message is returned.

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

Error codes

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

FAQ

Q: Is there a required order for the first and last frames in the media array?

A: Yes, there is. The media array must contain two type=image objects. The first element represents the first frame, and the second element represents the last frame.

Q: Do the first and last frame images need to have the same resolution?

A: No, they do not. However, we recommend that the resolutions are similar. The ratio of the total pixel count (width × height) between the first and last frames must be between 0.8 and 1.25. A large difference in resolution degrades the generation quality.