文档
图生视频请求接口

提交图生视频任务

1. 接口地址

https://www.hidreamai.com/api-pub/gw/v3/video/img2video/async

 

2. 请求方式

POST

 

3. 请求参数

Header

参数类型是否必填说明
Authorizationstring客户授权Token
Content-Typestring使用json传参
API-User-IDstring用户唯一标识

Body

参数类型是否必填说明
imagestring生成视频的参考图,支持传入图片URL或者Base64
promptstring生成视频的提示词, 默认为""
negative_promptstring禁止生成的提示词,默认为""
versionstring模型版本,默认为"v2",可选范围为{"v2"}
resolutionstring分辨率"宽*高",可选范围为{"960*960", "1280*720", "720*1280"}
request_idstring请求的ID,默认为""
camera_move_horizontalint水平运镜参数,参数范围(-5, 5),默认为0
camera_move_verticalint垂直运镜参数,参数范围(-5, 5),默认为0
camera_move_depthint纵深运镜参数,参数范围(-5, 5),默认为0
motion_strengthfloat运动强度,参数范围(0,30),默认为9.0
notify_urlstring任务完成回调通知接口(需公网能访问),请求参数与task result 一致

curl示例

curl -H 'Authorization: Bearer {USER_Authorization}' -H 'Content-Type: application/json' -X POST -d '{
    "image": "https://img0.baidu.com/it/u=1706291158,1032631466&fm=253&fmt=auto&app=120&f=JPEG?w=1280&h=800",
    "version": "v2",
    "resolution": "960*960",
    "camera_move_depth": -5,
    "camera_move_vertical": 0,
    "camera_move_horizontal": 5, 
    "motion_strength": 10.0,
    "request_id": "c1b18500-f3cc-11ed-aa62-5bbc7ccc3f99",
    "notify_url": "https://{replace me}/api/callback"
}' -v 'https://www.hidreamai.com/api-pub/gw/v3/video/img2video/async'

Python示例

import requests
import json
import uuid
 
USER_Authorization = <token>
 
 
# 请求头
headers = {
    'Authorization': f'Bearer {USER_Authorization}',
    'Content-Type': 'application/json',
    'API-User-ID': ''  # 可选的用户唯一标识
}
 
# 请求体参数
data = {
    "image": "https://img0.baidu.com/it/u=1706291158,1032631466&fm=253&fmt=auto&app=120&f=JPEG?w=1280&h=800",  # 必要参数
    "version": "v2",
    "resolution": "960*960",
    "camera_move_horizontal": 0,
    "camera_move_vertical": 0,
    "camera_move_depth": 0,
    "motion_strength": 9.0,
    "request_id": str(uuid.uuid4())
}
 
# 发送POST请求
url = 'https://www.hidreamai.com/api-pub/gw/v3/video/img2video/async'
response = requests.post(url, headers=headers, data=json.dumps(data))
 
# 处理响应
if response.status_code == 200:
    if response.json()['code'] == 0:
        task_id = response.json()['result']['task_id']
        print(task_id)
    else:
        print(response.json()['message'])
else:
    print(response.status_code)
 
 

 

4. 返回参数

参数类型说明
codeint返回状态码
messagestring返回状态信息
request_idstring本次请求的ID
resultdict返回结果

其中返回结果 result字段具体为:

参数类型说明
task_idstring返回任务ID
sub_task_idslist返回子任务ID的列表,子任务定义为生成单张图片的任务

示例:

{
    "code": 0,
    "message": "Success",
    "request_id": "c1b18500-f3cc-11ed-aa62-5bbc7ccc3f99",
    "result": {
       "sub_task_ids": [
            "85ef86f0-ac3e-4b1b-be22-0d71a3d636f5"
        ],
        "task_id": "57185018-3a76-11ee-b2ba-f24fe878dbc8"
    }
}