Video generation and editing

Updated at:
Copy as MD

AI_VIDEO_EDIT is an asynchronous service for generating and editing videos, supporting text-to-video, first-frame-to-video, and reference-based editing workflows. Create a task through the video_edit endpoint to obtain a task ID, then poll tasks/describe until the status reaches SUCCEEDED to retrieve the output video URL.

Prerequisites

  • A Milvus cluster address and authentication token. Replace the MILVUS_REST_BASE_URL and MILVUS_AUTH_TOKEN placeholders in all examples with your actual cluster address and token.

  • jq installed on your system (required by the REST/bash scripts).

Command format

The video generation and editing API supports both REST and Python interfaces. Both methods follow a two-step workflow: create an asynchronous task through POST /v2/vectordb/ai/video_edit, then query the task status through POST /v2/vectordb/ai/tasks/describe.

REST interface

REST interface

First, call POST /v2/vectordb/ai/video_edit to create an asynchronous task:

{
  "model_name": "<model_name>",
  "prompt": "<instruction>",
  "media": [
    {"type": "first_frame | video | reference_image", "url": "<media_url>"}
  ],
  "params": {
    "resolution": "720P",
    "audio_setting": "none | origin",
    "watermark": false,
    "timeout_sec": 180
  }
}

Then, call POST /v2/vectordb/ai/tasks/describe to query a single task:

{
  "provider": "aliyun_milvus",
  "model_name": "<model_name>",
  "task_id": "<task_id>"
}

For batch creation, replace media with media_inputs, where each inner array represents one task. The two fields cannot be provided at the same time.

Python

Python

create_status, create_data = post_json(
    "/v2/vectordb/ai/video_edit",
    {
        "model_name": "<model_name>",
        "prompt": "<instruction>",
        "media": [{"type": "video", "url": "<media_url>"}],
        "params": {"resolution": "720P", "audio_setting": "origin"},
    },
)
describe_status, describe_data = post_json(
    "/v2/vectordb/ai/tasks/describe",
    {
        "provider": "aliyun_milvus",
        "model_name": "<model_name>",
        "task_id": create_data["data"]["output"]["task_id"],
    },
)

Parameter description

ParameterDescription
model_nameRequired. The model to use. Pass the same model name when creating and querying a task. Valid values: happyhorse-1.1-t2v (text-to-video), happyhorse-1.1-i2v (first-frame-to-video, image input), happyhorse-1.1-r2v (image input), happyhorse-1.0-video-edit (video editing).
promptOptional. Describes the video content or editing objective.
mediaProvide per the model's input requirements. Can be omitted for text-to-video. Pass one first_frame entry for first-frame-to-video. Pass one video entry for video editing, with up to four additional reference_image entries optionally.
media_inputsTwo-dimensional media array for batch creation. Cannot be used together with media.
task_idRequired when querying. The task query interface supports only one task_id at a time; task_ids batch querying is not supported.
providerOptional when querying. Fixed as aliyun_milvus.
resolution, audio_setting, watermarkOptional. Control resolution, audio policy, and watermark respectively. Supported range is subject to model capabilities.
timeout_sec, max_concurrencyOptional. Control request timeout and batch creation concurrency. max_concurrency range is 1–64.
negative_prompt, prompt_extend, etc.Passed through per model capabilities. Media URLs must not be empty and must be accessible by the model service.

Return value description

A successful creation immediately returns task_id and the initial task_status. Poll the query interface until the status is SUCCEEDED to retrieve video_url. A status of FAILED or CANCELED indicates the task has ended without producing a result.

{
  "code": 0,
  "data": {
    "output": {
      "task_id": "<task_id>",
      "task_status": "SUCCEEDED",
      "video_url": "https://<result-host>/videos/result.mp4"
    },
    "usage": {"duration": 5, "output_video_duration": 5, "video_count": 1}
  }
}

Example 1: Generate a product concept video from marketing copy (text)

The operations team provides only marketing copy to generate a product concept video.

REST interface

REST interface

#!/usr/bin/env bash
set -euo pipefail

MILVUS_REST_BASE_URL="http://c-xxxx.milvus.aliyuncs.com:19530"
MILVUS_AUTH_TOKEN="<yourUsername>:<yourPassword>"

post_json() {
  local path="$1"
  local body="$2"
  curl -X POST \
    "$MILVUS_REST_BASE_URL$path" \
    -H "Authorization: Bearer $MILVUS_AUTH_TOKEN" \
    -H "Content-Type: application/json" \
    -d "$body"
}

MODEL_NAME="happyhorse-1.1-t2v"
PROMPT="${AIFUNC_VIDEO_EDIT_PROMPT:-A stylish cat astronaut walks slowly on the moon, cinematic lighting.}"

BODY=$(cat <<JSON
{"model_name":"$MODEL_NAME","prompt":"$PROMPT","params":{"resolution":"720P","audio_setting":"none","watermark":false,"timeout_sec":180}}
JSON
)
RESPONSE_BODY="$(post_json "/v2/vectordb/ai/video_edit" "$BODY")"
echo "$RESPONSE_BODY" | jq .
TASK_ID="$(echo "$RESPONSE_BODY" | jq -r '.data.output.task_id // empty')"
[ -n "$TASK_ID" ] || exit 1
post_json "/v2/vectordb/ai/tasks/describe" "{\"provider\":\"aliyun_milvus\",\"model_name\":\"$MODEL_NAME\",\"task_id\":\"$TASK_ID\"}" | jq .

Python

Python

from __future__ import annotations

import json
import os
import sys
from typing import Any
from urllib.error import HTTPError
from urllib.request import Request, urlopen

MILVUS_REST_BASE_URL = "http://c-xxxx.milvus.aliyuncs.com:19530"
MILVUS_AUTH_TOKEN = "<yourUsername>:<yourPassword>"

def post_json(path: str, body: dict[str, Any], timeout: int = 120) -> tuple[int, dict[str, Any]]:
    base_url = MILVUS_REST_BASE_URL.rstrip("/")
    token = MILVUS_AUTH_TOKEN
    request = Request(
        f"{base_url}{path}",
        data=json.dumps(body, ensure_ascii=False).encode("utf-8"),
        headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json"},
        method="POST",
    )
    try:
        with urlopen(request, timeout=timeout) as response:
            status = response.status
            raw = response.read().decode("utf-8")
    except HTTPError as exc:
        status = exc.code
        raw = exc.read().decode("utf-8")
    return status, json.loads(raw)

MODEL_NAME = "happyhorse-1.1-t2v"
PROMPT = os.getenv("AIFUNC_VIDEO_EDIT_PROMPT", "A stylish cat astronaut walks slowly on the moon, cinematic lighting.")

status, data = post_json(
    "/v2/vectordb/ai/video_edit",
    {"model_name": MODEL_NAME, "prompt": PROMPT, "params": {"resolution": "720P", "audio_setting": "none", "watermark": False, "timeout_sec": 180}},
)
print(json.dumps(data, ensure_ascii=False, indent=2))
if status != 200 or data.get("code") != 0:
    sys.exit(1)
task_id = data.get("data", {}).get("output", {}).get("task_id")
if not task_id:
    sys.exit(1)
status, data = post_json("/v2/vectordb/ai/tasks/describe", {"provider": "aliyun_milvus", "model_name": MODEL_NAME, "task_id": task_id})
print(json.dumps(data, ensure_ascii=False, indent=2))
if status != 200 or data.get("code") != 0:
    sys.exit(1)

Both call types return data.output.video_url when the terminal state is SUCCEEDED.

Example 2: Generate a showcase video from a clothing reference image (image)

The fashion operations team generates showcase videos for initial material review based on clothing reference images. The default asset is a publicly available clothing reference image. Use AIFUNC_VIDEO_EDIT_IMAGE_URL to specify a custom asset.

REST interface

REST interface

#!/usr/bin/env bash
set -euo pipefail

MILVUS_REST_BASE_URL="http://c-xxxx.milvus.aliyuncs.com:19530"
MILVUS_AUTH_TOKEN="<yourUsername>:<yourPassword>"

post_json() {
  local path="$1"
  local body="$2"
  curl -X POST \
    "$MILVUS_REST_BASE_URL$path" \
    -H "Authorization: Bearer $MILVUS_AUTH_TOKEN" \
    -H "Content-Type: application/json" \
    -d "$body"
}

MODEL_NAME="happyhorse-1.1-i2v"
IMAGE_URL="${AIFUNC_VIDEO_EDIT_IMAGE_URL:-https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260415/hynnff/wan-video-edit-clothes.webp}"

BODY=$(cat <<JSON
{"model_name":"$MODEL_NAME","prompt":"Animate the subject in the first-frame image with gentle camera movement.","media":[{"type":"first_frame","url":"$IMAGE_URL"}],"params":{"resolution":"720P","audio_setting":"none","watermark":false,"timeout_sec":180}}
JSON
)
RESPONSE_BODY="$(post_json "/v2/vectordb/ai/video_edit" "$BODY")"
echo "$RESPONSE_BODY" | jq .
TASK_ID="$(echo "$RESPONSE_BODY" | jq -r '.data.output.task_id // empty')"
[ -n "$TASK_ID" ] || exit 1
post_json "/v2/vectordb/ai/tasks/describe" "{\"provider\":\"aliyun_milvus\",\"model_name\":\"$MODEL_NAME\",\"task_id\":\"$TASK_ID\"}" | jq .

Python

Python

from __future__ import annotations

import json
import os
import sys
from typing import Any
from urllib.error import HTTPError
from urllib.request import Request, urlopen

MILVUS_REST_BASE_URL = "http://c-xxxx.milvus.aliyuncs.com:19530"
MILVUS_AUTH_TOKEN = "<yourUsername>:<yourPassword>"

def post_json(path: str, body: dict[str, Any], timeout: int = 120) -> tuple[int, dict[str, Any]]:
    base_url = MILVUS_REST_BASE_URL.rstrip("/")
    token = MILVUS_AUTH_TOKEN
    request = Request(
        f"{base_url}{path}",
        data=json.dumps(body, ensure_ascii=False).encode("utf-8"),
        headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json"},
        method="POST",
    )
    try:
        with urlopen(request, timeout=timeout) as response:
            status = response.status
            raw = response.read().decode("utf-8")
    except HTTPError as exc:
        status = exc.code
        raw = exc.read().decode("utf-8")
    return status, json.loads(raw)

MODEL_NAME = "happyhorse-1.1-i2v"
IMAGE_URL = os.getenv("AIFUNC_VIDEO_EDIT_IMAGE_URL", "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260415/hynnff/wan-video-edit-clothes.webp")

status, data = post_json(
    "/v2/vectordb/ai/video_edit",
    {"model_name": MODEL_NAME, "prompt": "Animate the subject in the first-frame image with gentle camera movement.", "media": [{"type": "first_frame", "url": IMAGE_URL}], "params": {"resolution": "720P", "audio_setting": "none", "watermark": False, "timeout_sec": 180}},
)
print(json.dumps(data, ensure_ascii=False, indent=2))
if status != 200 or data.get("code") != 0:
    sys.exit(1)
task_id = data.get("data", {}).get("output", {}).get("task_id")
if not task_id:
    sys.exit(1)
status, data = post_json("/v2/vectordb/ai/tasks/describe", {"provider": "aliyun_milvus", "model_name": MODEL_NAME, "task_id": task_id})
print(json.dumps(data, ensure_ascii=False, indent=2))
if status != 200 or data.get("code") != 0:
    sys.exit(1)

Both call types return a non-empty clothing showcase video URL when the terminal state is SUCCEEDED. The generated camera movements and effects are non-deterministic; perform a manual review of style and brand requirements before publishing.

Example 3: Replace clothing in a character concept video (video)

The brand creative team replaces the clothing on a character in a concept video with a black-and-white striped sweater from a reference image, for internal creative review. Use AIFUNC_VIDEO_EDIT_VIDEO_URL and AIFUNC_VIDEO_EDIT_IMAGE_URL to override the default assets.

REST interface

REST interface

#!/usr/bin/env bash
set -euo pipefail

MILVUS_REST_BASE_URL="http://c-xxxx.milvus.aliyuncs.com:19530"
MILVUS_AUTH_TOKEN="<yourUsername>:<yourPassword>"

post_json() {
  local path="$1"
  local body="$2"
  curl -X POST \
    "$MILVUS_REST_BASE_URL$path" \
    -H "Authorization: Bearer $MILVUS_AUTH_TOKEN" \
    -H "Content-Type: application/json" \
    -d "$body"
}

MODEL_NAME="happyhorse-1.0-video-edit"
VIDEO_URL="${AIFUNC_VIDEO_EDIT_VIDEO_URL:-https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260409/dozxak/Wan_Video_Edit_33_1.mp4}"
IMAGE_URL="${AIFUNC_VIDEO_EDIT_IMAGE_URL:-https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260415/hynnff/wan-video-edit-clothes.webp}"

BODY=$(cat <<JSON
{"model_name":"$MODEL_NAME","prompt":"Make the character in the video wear the striped sweater from the reference image.","media":[{"type":"video","url":"$VIDEO_URL"},{"type":"reference_image","url":"$IMAGE_URL"}],"params":{"resolution":"720P","audio_setting":"origin","watermark":false,"timeout_sec":180}}
JSON
)
RESPONSE_BODY="$(post_json "/v2/vectordb/ai/video_edit" "$BODY")"
echo "$RESPONSE_BODY" | jq .
TASK_ID="$(echo "$RESPONSE_BODY" | jq -r '.data.output.task_id // empty')"
[ -n "$TASK_ID" ] || exit 1
post_json "/v2/vectordb/ai/tasks/describe" "{\"provider\":\"aliyun_milvus\",\"model_name\":\"$MODEL_NAME\",\"task_id\":\"$TASK_ID\"}" | jq .

Python

Python

from __future__ import annotations

import json
import os
import sys
from typing import Any
from urllib.error import HTTPError
from urllib.request import Request, urlopen

MILVUS_REST_BASE_URL = "http://c-xxxx.milvus.aliyuncs.com:19530"
MILVUS_AUTH_TOKEN = "<yourUsername>:<yourPassword>"

def post_json(path: str, body: dict[str, Any], timeout: int = 120) -> tuple[int, dict[str, Any]]:
    base_url = MILVUS_REST_BASE_URL.rstrip("/")
    token = MILVUS_AUTH_TOKEN
    request = Request(
        f"{base_url}{path}",
        data=json.dumps(body, ensure_ascii=False).encode("utf-8"),
        headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json"},
        method="POST",
    )
    try:
        with urlopen(request, timeout=timeout) as response:
            status = response.status
            raw = response.read().decode("utf-8")
    except HTTPError as exc:
        status = exc.code
        raw = exc.read().decode("utf-8")
    return status, json.loads(raw)

MODEL_NAME = "happyhorse-1.0-video-edit"
VIDEO_URL = os.getenv("AIFUNC_VIDEO_EDIT_VIDEO_URL", "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260409/dozxak/Wan_Video_Edit_33_1.mp4")
IMAGE_URL = os.getenv("AIFUNC_VIDEO_EDIT_IMAGE_URL", "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260415/hynnff/wan-video-edit-clothes.webp")

status, data = post_json(
    "/v2/vectordb/ai/video_edit",
    {"model_name": MODEL_NAME, "prompt": "Make the character in the video wear the striped sweater from the reference image.", "media": [{"type": "video", "url": VIDEO_URL}, {"type": "reference_image", "url": IMAGE_URL}], "params": {"resolution": "720P", "audio_setting": "origin", "watermark": False, "timeout_sec": 180}},
)
print(json.dumps(data, ensure_ascii=False, indent=2))
if status != 200 or data.get("code") != 0:
    sys.exit(1)
task_id = data.get("data", {}).get("output", {}).get("task_id")
if not task_id:
    sys.exit(1)
status, data = post_json("/v2/vectordb/ai/tasks/describe", {"provider": "aliyun_milvus", "model_name": MODEL_NAME, "task_id": task_id})
print(json.dumps(data, ensure_ascii=False, indent=2))
if status != 200 or data.get("code") != 0:
    sys.exit(1)

Both call types return a non-empty creative clothing replacement video URL when the terminal state is SUCCEEDED. Replacement results are non-deterministic; do not use example outputs as accurate representations of real product appearance.

Exception handling and media security

  • FAILED or CANCELED are terminal states. Stop polling and retain the error information in the complete response. Do not retry indefinitely.

  • When the local polling limit is reached, log the task_id and resume querying later according to your business policy. Do not treat a local timeout as a server-side failure.

  • If task creation fails, verify that the media URL is directly accessible by the model service, has not expired, and is in a format supported by the model. Then check whether the model matches the media.type.

  • Before using personal portraits, products, audio, or branded assets, ensure you have obtained the necessary authorizations. (Recommended) Use short-lived, least-privilege media URLs and delete original assets and unused generated results according to your retention policy.