The HappyHorse reference-to-video model lets you provide multiple reference images and a text prompt to generate a video that combines subjects from the images into a scene based on the prompt.
Usage notes
To ensure successful API calls, you must use a model, endpoint URL, and API key that all belong to the same region. Cross-region calls will fail.
- Select a model: Confirm the region where your model is located.
- Select a URL: Choose the corresponding endpoint URL. Both HTTP and DashScope SDK URLs are supported.
- Configure an API key: Select a region, get an API key, and then configure the API key as an environment variable.
The sample code in this topic applies to the Singapore region.
HTTP calls
Because reference-to-video tasks are time-consuming (typically 1–5 minutes), the API uses an asynchronous call. The workflow consists of two core steps: "Create a task -> Poll for the result".
Step 1: Create a task
- Singapore
- US (Virginia)
- China (Beijing)
- Germany (Frankfurt)
- China (Hong Kong)
- Japan (Tokyo)
POST https://{WorkspaceId}.ap-southeast-1.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 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 model name. For available models, see the Model Studio console.Example: happyhorse-1.1-r2v.input object (Required)The model input, which includes the reference images and text prompt.
Properties prompt string (Required)A description of the desired elements and visual style for the generated video.Input in any language is supported. The length is limited to 5,000 non-Chinese characters or 2,500 Chinese characters. Content exceeding this limit is automatically truncated.Image referencing: In the prompt, use "[Image 1]" and "[Image 2]" to refer to the corresponding reference image in the media array. The order must be consistent with the order in the media array. When using a reference, specify the object in the image, such as "the woman in a red qipao in [Image 1]".media array (Required)A list of reference images.Each element in the array is a media object that contains type and url fields.
Element properties type string (Required)The type of media asset. Set this to:
string (Required)The URL or Base64-encoded data of a reference image.Image requirements:
object (Optional)Parameters for video generation, such as video resolution, aspect ratio, and duration.
Properties resolution string (Optional)The resolution tier of the generated video.Valid values:
string (Optional)The aspect ratio of the generated video.Valid values:
integer (Optional)The duration of the generated video, in seconds.Value range: An integer from 3 to 15.Default value: 5.watermark boolean (Optional)Specifies whether to add a watermark to the generated video. The watermark is placed in the bottom-right corner with the fixed text "Happy Horse".
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. |
|
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: Get the task result
- Singapore
- US (Virginia)
- China (Beijing)
- Germany (Frankfurt)
- China (Hong Kong)
- Japan (Tokyo)
GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id}- Polling recommendation: Video generation can take several minutes. We recommend that you implement a polling mechanism with a reasonable query interval (for example, 15 seconds) to retrieve the result.
- Task status flow: PENDING (Queued) → RUNNING (Processing) → SUCCEEDED (Succeeded) or FAILED (Failed).
- Task ID validity: The task ID is valid for 24 hours. After this period, you can no longer query the result, and the API returns a task status of
UNKNOWN.
Request parametersRequest headersAuthorizationstring (Required)Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx.URL 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 queries for 24 hours, Replace {WorkspaceId} with your actual workspace ID. |
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.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 for the task. You are only billed for successful tasks.
Properties duration integerThe billable duration of the generated video, in seconds.input_video_duration integerThe total duration of the input video, in seconds. This is always 0 for reference-to-video tasks.output_video_duration integerThe total duration of the output video, in seconds.ratio stringThe aspect ratio of the generated video.SR integerThe resolution tier of the generated video.video_count integerThe number of generated videos. This 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. |