Generate realistic, smooth-motion videos from a first-frame image and an optional text prompt using the HappyHorse model.
Usage notes
The model, endpoint URL, and API key must belong to the same region. Cross-region calls fail.
- Select a model: Check which region the model belongs to.
- Select a URL: Select the endpoint URL for the same region. HTTP URLs are supported.
- Configure an API key: Get an API key for the same region, and then configure the API key as an environment variable.
The sample code in this topic applies to the China (Beijing) region.
HTTP calls
Image-to-video tasks take 1–5 minutes, so the API uses asynchronous calls. The workflow consists of two core steps: "create a task → poll for the result", as follows:
Step 1: Create a task
- China (Beijing)
- Singapore
- US (Virginia)
- Germany (Frankfurt)
- Japan (Tokyo)
POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis{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 parametersContent-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)Asynchronous processing configuration parameter. HTTP requests support only asynchronous calls and must be set to enable.Request bodymodelstring (required)The model name.Allowed values:
object (required)Model input, including the text prompt.
Properties prompt string (optional)Describes the video content to generate.Supports any language. Maximum: 5,000 non-Chinese characters or 2,500 Chinese characters. Longer input is truncated.media array (required)The input media list. It specifies the images used for video generation.
media[] element properties type string (required)The type of media. Allowed value:
string (required)The URL of the media.
Input image (type=first_frame) The URL or Base64-encoded data of the first frame image.Image constraints:
object (optional)Video output settings such as resolution and duration.
Properties resolution string (optional)Specifies the resolution tier of the generated video, which controls the video's clarity (total pixels).Based on the selected tier, the model automatically scales the output to a similar total pixel count. The output video's aspect ratio approximately matches that of the input first frame.Allowed values:
integer (optional)The duration of the generated video, in seconds.The value must be an integer in the range [3, 15]. Default: 5.watermark boolean (optional)Whether to add a watermark to the generated video. The watermark appears in the bottom-right corner with the fixed text "Happy Horse".
integer (Optional)The random number seed, in the range [0, 2147483647].If not specified, the system automatically generates a random seed. To improve the reproducibility of the results, we recommend using a fixed seed value.Note that model generation is probabilistic: even with the same seed, identical results are not guaranteed every time. |
|
Response parametersoutputobjectThe task's output.
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: Poll for the result
- China (Beijing)
- Singapore
- US (Virginia)
- Germany (Frankfurt)
- Japan (Tokyo)
GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}- Polling recommendation: Video generation takes several minutes. We recommend using a polling mechanism with a reasonable query interval (such as 15 seconds) to retrieve the result.
- 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.- RPS limit: The default RPS for the query API is 20. For higher-frequency queries or event notifications, we recommend that you configure an asynchronous task callback.
- More operations: For batch queries, task cancellation, and other operations, see Manage asynchronous tasks.
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 {task_id} with the task_id value returned by the previous API call. The task_id is valid for 24 hours. Replace {WorkspaceId} with your actual workspace ID. |
Response parametersoutputobjectThe task's output.
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. Format: YYYY-MM-DD HH:mm:ss.SSS.scheduled_time stringThe time when the task was executed. Format: YYYY-MM-DD HH:mm:ss.SSS.end_time stringThe time when the task was completed. Format: YYYY-MM-DD HH:mm:ss.SSS.video_urlstringThe video URL. Returned only when task_status is SUCCEEDED.The URL is valid for 24 hours. Download the MP4 video (24 fps, H.264 encoded) from this URL.orig_prompt stringThe original input prompt, corresponding to the request parameter prompt.code stringError code. Returned only for failed requests. See Error codes.message stringDetailed error message. Returned only for failed requests. See Error codes.objectUsage statistics. Calculated only for successful tasks.
Properties input_video_duration integerThe duration of the input video, in seconds.output_video_duration integerThe duration of the output video, in seconds.duration integerThe total video duration used for billing.SR integerThe resolution tier of the output video.video_count integerThe number of output videos. This value is always 1.stringUnique request identifier for tracing and troubleshooting. |
Video URLs are valid for only 24 hours and then automatically purged. Save generated videos promptly. |
Error codes
If a call fails and returns an error, see Error codes for troubleshooting.
FAQ
Video aspect ratio
Output aspect ratio matches the first frame. Unlike the HappyHorse text-to-video model, image-to-video does not support the ratio parameter.