提交模特套图任务
1. 接口地址
https://hidreamai.com/api-pub/ec/v3/image/variation/async
2. 请求方式
POST
3. 请求参数
Header
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
Authorization | string | 是 | 客户授权Token |
Content-Type | string | 是 | 使用json传参 |
Body
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
image | string | 是 | 模特图片,支持图片url和图片base64两种格式数据,base64数据需去除·data:image/*;base64,·格式前缀。仅支持宽高比3:4的图片,最大分辨率2K |
template_id | int | 是 | 模版ID |
request_id | str | 否 | 请求唯一标识 |
notify_url | string | 否 | 任务完成回调通知接口(需公网能访问),请求参数与task result 一致 |
curl示例
curl -H 'Authorization: Bearer {USER_Authorization}' -H 'Content-Type: application/json' -X POST -d '{
"image": "https://img0.baidu.com/it/u=3162963441,624224718&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=800",
"template_id": 20,
"request_id": "96cf0c6a-5d2b-11ee-abe3-3a8d18c35977"
}' -v 'https://hidreamai.com/api-pub/ec/v3/image/vton/async'
Python示例
import requests
import json
import uuid
USER_Authorization = <token>
# 请求头
headers = {
'Authorization': f'Bearer {USER_Authorization}',
'Content-Type': 'application/json',
}
# 请求体参数
data = {
"person": "https://img0.baidu.com/it/u=3162963441,624224718&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=800",
"template_id": 20,
"request_id": str(uuid.uuid4())
}
# 发送POST请求
url = 'https://hidreamai.com/api-pub/ec/v3/image/variation/async'
response = requests.post(url, headers=headers, json=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. 返回参数
参数 | 类型 | 说明 |
---|---|---|
code | int | 返回状态码 |
message | string | 返回状态信息 |
request_id | string | 本次请求的ID |
result | dict | 返回结果 |
其中返回结果 result
字段具体为:
参数 | 类型 | 说明 |
---|---|---|
task_id | string | 返回任务ID |
sub_task_ids | list | 返回子任务ID的列表,子任务定义为生成单张图片的任务 |
示例:
{
"code": 0,
"message": "请求成功",
"request_id": "96cf0c6a-5d2b-11ee-abe3-3a8d18c35977",
"result": {
"sub_task_ids": [
"94ecd4e4-7d90-4daa-8edb-f3ee02fafa19"
],
"task_id": "97004e6a-5d2b-11ee-abe3-3a8d18c35963"
}
}