文档
商品图生成请求接口

提交商品图任务

1. 接口地址

https://hidreamai.com/api-pub/ec/v3/image/commerical/async

2. 请求方式

POST

3. 请求参数

Header

参数类型是否必填说明
Authorizationstring客户授权Token
Content-Typestring使用json传参

Body

参数类型是否必填说明
imagestring支持url和商品图Base64,注意去除"data:image/*;base64,"前缀
img_countint一次生成的图片数量,1-4,默认1
stylestr生图风格,经典风格:default,简洁风格:amozon,默认default
resolutionlist分辨率, 选择输出图片的分辨率( [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_imagelist参考图,支持url和图片base64(需去除格式前缀),最多支持5张参考图,字段异常将触发错误码1051
dedupebool如果为True,商品分割时会对图片中重复的商品去重,只保留一个商品
template_idUnion[str, int]与prompt二选一模板id
custom_templatebool与模板id绑定模板类型,是否为用户自定义的模板
promptstring与template_* 二选一生成图片的提示词, 最大长度500
negative_promptstring禁止生成的提示词, 最大长度500
sizefloat商品在图片中的大小比例(最长边占图片的比例)默认: 0.5, 取值范围(0, 1)
location_descdict是(使用prompt生图时需要提供位置参数)商品位置描述信息
notify_urlstring任务完成回调通知接口(需公网能访问),请求参数与task result 一致

其中location_desc字段具体为:

参数类型说明
horizontal_directionstring水平方向位置描述,取值为AlignLeft或AlignCenter或AlignRight
AlignLeft:商品图左边距背景图左边的比例
AlignCenter: 水平方向居中
AlignRight: 商品图右边距背景图右边的比例
horizontal_proportionfloat商品水平方向位置占比,AlignLeft和AlignRight的比例取值范围均为0-1(不含边界)的小数,居中时值为固定0.5
vertical_directionstring垂直方向位置描述,取值为AlignTop或AlignCenter或AlignBottom
AlignTop:商品图上顶边距背景图上顶边的比例,
AlignCenter: 垂直方向居中
AlignBottom: 商品图下底边距背景图下底边的比例
vertical_proportionfloat商品垂直方向位置占比,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. 返回参数

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

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

参数类型说明
task_idstring返回任务ID
sub_task_idslist返回子任务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"
    }
}