提交商品图任务
1. 接口地址
https://hidreamai.com/api-pub/ec/v3/image/commerical/async
2. 请求方式
POST
3. 请求参数
Header
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
Authorization | string | 是 | 客户授权Token |
Content-Type | string | 是 | 使用json传参 |
Body
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
image | string | 是 | 支持url和商品图Base64,注意去除"data:image/*;base64,"前缀 |
img_count | int | 否 | 一次生成的图片数量,1-4,默认1 |
style | str | 否 | 生图风格,经典风格:default,简洁风格:amozon,默认default |
resolution | list | 否 | 分辨率, 选择输出图片的分辨率( [300, 300], [750, 1000], [800, 600], [970, 600], [1000, 1000], [1080, 1080], [1600, 1600], [1601, 1601],[1600, 2000], [2000, 1800], [2000, 2000], [2048, 2048] )(默认[2000, 2000]) |
ref_image | list | 否 | 参考图,支持url和图片base64(需去除格式前缀),最多支持5张参考图,字段异常将触发错误码1051 |
dedupe | bool | 否 | 如果为True,商品分割时会对图片中重复的商品去重,只保留一个商品 |
template_id | Union[str, int] | 与prompt二选一 | 模板id |
custom_template | bool | 与模板id绑定 | 模板类型,是否为用户自定义的模板 |
prompt | string | 与template_* 二选一 | 生成图片的提示词, 最大长度500 |
negative_prompt | string | 否 | 禁止生成的提示词, 最大长度500 |
size | float | 否 | 商品在图片中的大小比例(最长边占图片的比例)默认: 0.5, 取值范围(0, 1) |
location_desc | dict | 是(使用prompt生图时需要提供位置参数) | 商品位置描述信息 |
notify_url | string | 否 | 任务完成回调通知接口(需公网能访问),请求参数与task result 一致 |
其中location_desc字段具体为:
参数 | 类型 | 说明 |
---|---|---|
horizontal_direction | string | 水平方向位置描述,取值为AlignLeft或AlignCenter或AlignRight AlignLeft:商品图左边距背景图左边的比例 AlignCenter: 水平方向居中 AlignRight: 商品图右边距背景图右边的比例 |
horizontal_proportion | float | 商品水平方向位置占比,AlignLeft和AlignRight的比例取值范围均为0-1(不含边界)的小数,居中时值为固定0.5 |
vertical_direction | string | 垂直方向位置描述,取值为AlignTop或AlignCenter或AlignBottom AlignTop:商品图上顶边距背景图上顶边的比例, AlignCenter: 垂直方向居中 AlignBottom: 商品图下底边距背景图下底边的比例 |
vertical_proportion | float | 商品垂直方向位置占比,AlignTop和AlignBottom的比例取值范围均为0-1(不含边界)的小数。居中时值为固定0.5 |
curl示例, 使用模版:
curl -H 'Authorization: Bearer {token}' -H 'Content-Type: application/json' -X POST -d '{
"image": "/9j/4AAQSkZJRgABAQAAAQABA*******************************",
"template_id": 1,
"custom_template": false
"image_count": 2,
"resolution": [800, 600]
}' -v 'https://hidreamai.com/api-pub/ec/v3/image/commerical/async'
python示例,使用prompt:
import requests
# token获取方式详见 接口认证 api-key换取令牌小节
token = ''
# 请求头
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
url = "https://hidreamai.com/api-pub/ec/v3/image/commerical/async"
params = {
"image": "/9j/4AAQSkZJRgABAQAAAQABA*******************************",
"size": 0.4,
"location_desc": {
'horizontal_direction': "AlignCenter",
'horizontal_proportion': 0.5,
'vertical_direction': "AlignBottom",
"vertical_proportion": 0.1
},
"image_count": 1,
"prompt": "Romantic painting ...",
"negative_prompt": "Romantic painting ...",
"resolution": [800, 600],
"ref_image": ["image-base64-1", "image-base64-2"]
}
response = requests.post(url, json=params, headers=headers)
if response.status_code == 200:
if response.json().get('code') == 0:
print(response.json().get('result').get('task_id'))
else:
print(response.json())
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"
}
}