Hailuo Videos Generation API Integration Guide

This article introduces the Hailuo Videos Generation API integration, which can generate official Hailuo videos by accepting custom parameters.

Application Process

To use the Hailuo Videos Generation API, first go to the Ace Data Cloud Console to obtain your API Token for later use.

If you have not logged in or registered, you will be automatically redirected to the login page to register and log in. Once completed, you will be automatically returned to the current page.

A general application's API Key can be used for services enabled for the account; a dedicated application's Key can be used within that application's service scope. Please check the Key's permissions, validity period, and limits, and confirm that the application balance is sufficient to pay for this request. Available trial credits are subject to what is displayed in your account. If the balance is insufficient, click the "Recharge" button.

📘 Full documentation: Hailuo Videos Generation API →

Basic Usage

First, let's look at the basic usage: enter the prompt prompt, generation action action, first-frame reference image first_image_url, and model model to obtain the processed result. First, simply provide an action field with the value generate, and then enter the model. Currently, the main options are the image-to-video model minimax-i2v and the text-to-video model minimax-t2v. The details are as follows:

As you can see, we have set the Request Headers here, including:

  • accept: The format in which you want to receive the response. Enter application/json here, meaning JSON format.
  • authorization: The key used to call the API. After applying, you can select it directly from the drop-down list.

We have also set the Request Body, including:

  • model: The model used to generate the video. There are mainly two types: the image-to-video model minimax-i2v and the text-to-video model minimax-t2v.
  • action: The action for this video generation task.
  • first_image_url: The link to the first-frame reference image that must be uploaded when the image-to-video model minimax-i2v is selected. Base64 encoding is not supported.
  • prompt: The prompt.
  • callback_url: The URL to which the result should be sent.
  • async: Optional. When set to true, the API immediately returns a task_id without requiring a callback_url. The result can then be obtained by polling the corresponding task query API.

After making the selections, you can see that the corresponding code has also been generated on the right, as shown below:

Click the "Try" button to test it. As shown above, we obtained the following result:

{
  "success": true,
  "task_id": "baf1034c-684c-46be-ae6d-89ebb89b690d",
  "trace_id": "3221eb74-1a25-447a-ba69-7d9b310e306c",
  "data": [
    {
      "id": "0pv8yhe4fdrge0cmckpv23pd2g",
      "model": "minimax-t2v",
      "prompt": "Internal heat",
      "video_url": "https://platform.cdn.acedata.cloud/czjl/qoueLWBokF3ud6tdVD6VJTZuXTnK5HaMO2qAOS46Ef8VSBFUA/tmp9e3u11c1.output.mp4",
      "state": "succeeded"
    }
  ]
}

The returned result contains several fields, described as follows:

  • success, the status of the video generation task.
  • task_id, the ID of the video generation task.
  • trace_id, the trace ID of the video generation task.
  • data, the list of results from the video generation task.
    • id, the video ID of the video generation task.
    • prompt, the prompt for the video generation task.
    • model, the cover link for the video generation task.
    • video_url, the video link for the video generation task.
    • state, the status of the video generation task.

As you can see, we obtained satisfactory video information. We only need to use the video link in data in the result to retrieve the generated Hailuo video.

In addition, if you want to generate the corresponding integration code, you can copy the generated code directly. For example, the CURL code is as follows:

curl -X POST 'https://api.acedata.cloud/hailuo/videos' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
  "action": "generate",
  "prompt": "Internal heat"
}'

Asynchronous Callback

Since the Hailuo Videos Generation API takes a relatively long time to generate a video, approximately 1–2 minutes, the HTTP request will remain connected if the API does not respond for a long time, resulting in additional system resource consumption. Therefore, this API also provides support for asynchronous callbacks.

The overall process is as follows: when the client initiates a request, it additionally specifies a callback_url field. After the client initiates the API request, the API immediately returns a result containing a task_id field, which represents the current task ID. Once the task is completed, the video generation result is sent via POST JSON to the callback_url specified by the client. It also includes the task_id field, so the task result can be associated using the ID.

Below, we will use an example to understand how to do this.

First, a Webhook callback is a service that can receive HTTP requests, and developers should replace it with the URL of their own HTTP server. For convenience in this demonstration, we use a public Webhook sample website, https://webhook.site/. Open the website to obtain a Webhook URL, as shown below:

Copy this URL to use it as a Webhook. The example here is https://webhook.site/580b81f5-596e-4321-b03f-606770b0bb83.

Next, we can set the callback_url field to the Webhook URL above and fill in the corresponding parameters. The details are shown below:

Click Run, and you will see that a result is returned immediately, as follows:

{
  "task_id": "05aff65c-5e84-442b-8e29-3a5d27130840"
}

After waiting a moment, we can observe the video generation result at https://webhook.site/580b81f5-596e-4321-b03f-606770b0bb83, as shown below:

The content is as follows:

{
    "success": true,
    "task_id": "05aff65c-5e84-442b-8e29-3a5d27130840",
    "trace_id": "b9856b8a-725d-45c9-befe-e789d9fd9ffb",
    "data": [
        {
            "id": "t80jhsf96srg80cmcm6b0rk8gm",
            "model": "minimax-t2v",
            "prompt": "Internal heat",
            "video_url": "https://platform.cdn.acedata.cloud/czjl/YPaUz2DcwpJqItTXAG9XHAoEoj3dbF0XPU69LT5nefCMzBFUA/tmp8s_59jez.output.mp4",
            "state": "succeeded"
        }
    ]
}

You can see that the result contains a task_id field. The other fields are similar to those above, and this field can be used to associate tasks.

Error Handling

When calling the API, if an error occurs, the API will return the corresponding error code and message. For example:

  • 400 token_mismatched: Bad request, possibly due to missing or invalid parameters.
  • 400 api_not_implemented: Bad request, possibly due to missing or invalid parameters.
  • 401 invalid_token: Unauthorized, invalid or missing authorization token.
  • 429 too_many_requests: Too many requests, you have exceeded the rate limit.
  • 500 api_error: Internal server error, something went wrong on the server.

Error Response Example

{
  "success": false,
  "error": {
    "code": "api_error",
    "message": "fetch failed"
  },
  "trace_id": "2cf86e86-22a4-46e1-ac2f-032c0f2a4e89"
}

Conclusion

Through this document, you have learned how to use the Hailuo Videos Generation API to generate videos by entering a prompt and a first-frame reference image. We hope this document helps you better integrate and use the API. If you have any questions, please feel free to contact our technical support team.