Generate physically realistic, motion-smooth video from text prompts with the HappyHorse model.
Availability
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: Use the region's endpoint URL. HTTP is supported.
- Configure an API key: Get an API key for the region, and then Export API key as environment variable.
The sample code in this topic applies to the Singapore region.
HTTP request
Text-to-video tasks typically take 1 to 5 minutes. The API uses asynchronous calls with two steps: "Create a task → Poll for results".
Step 1: Create a task and get the task ID
- 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 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)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-t2v.input object (Required)Model input.
Properties prompt string (Required)Text description of the video to generate.Supports any language. Maximum 5,000 non-Chinese characters or 2,500 Chinese characters. Excess is truncated.object (Optional)Video output settings (resolution, aspect ratio, duration).
Properties resolution string (Optional)Output video resolution.Valid values:
string (Optional)Output video aspect ratio.Valid values:
integer (Optional)Output video duration in seconds.
boolean (Optional)Whether to add a watermark. Displays "HappyHorse" in the lower-right corner.
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 parametersoutputobjectTask output information.
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 by task ID
- 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 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 parametersHeadersAuthorizationstring (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 queries for 24 hours, Replace {WorkspaceId} with your actual workspace ID. |
Response parametersoutputobjectTask output information.
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.objectOutput statistics. Only successful tasks are counted.
Properties input_video_duration integerInput video duration in seconds.output_video_duration integerOutput video duration in seconds.duration integerTotal video duration for billing.SR integerOutput video resolution.ratio stringOutput video aspect ratio.video_count integerNumber of output videos. 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. |