提交图生图任务
1. 接口地址
https://www.hidreamai.com/api-pub/gw/v3/image/img2img/async
2. 请求方式
POST
3. 请求参数
Header
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
Authorization | string | 是 | 客户授权Token |
Content-Type | string | 是 | 使用json传参 |
API-User-ID | string | 否 | 用户唯一标识 |
Body
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
image | list | 是 | 生成图片的参考图,支持传入图片URL或者Base64(目前支持传入字符串列表类型) |
prompt | string | 否 | 生成图片的提示词,默认为"" |
negative_prompt | string | 否 | 禁止生成的提示词,默认为"" |
version | string | 否 | 模型版本,默认为"v1",可选范围为{"v1"} |
resolution | string | 否 | 分辨率"宽*高",默认为"2048*2048",可选范围为{"2048*2048", "2048*1152", "1152*2048", "2048*1536", "1536*2048", "2048*1365", "1365*2048"} |
img_count | int | 否 | 一次生成的图片数量,1-4,默认为1 |
request_id | string | 否 | 请求的ID,默认为"" |
notify_url | string | 否 | 任务完成回调通知接口(需公网能访问),请求参数与task result 一致 |
curl示例
curl -H 'Authorization: Bearer {USER_Authorization}' -H 'Content-Type: application/json' -X POST -d '{
"prompt": "Romantic painting of a ship sailing in a stromy sea, with dramatic lighting and powerful waves",
"image": ["https://img0.baidu.com/it/u=1706291158,1032631466&fm=253&fmt=auto&app=120&f=JPEG?w=1280&h=800"],
"img_count": 1,
"version": "v1",
"resolution": "2048*2048",
"request_id": "b146d886-5c57-11ee-bf2b-f6f8d60dadec"
}' -v 'https://www.hidreamai.com/api-pub/gw/v3/image/img2img/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", # 必要参数
"prompt": "Romantic painting of a ship sailing in a stromy sea, with dramatic lighting and powerful waves",
"negative_prompt": "sun",
"img_count": 1,
"version": "v1",
"resolution": "2048*2048",
"request_id": str(uuid.uuid4())
}
# 发送POST请求
url = 'https://www.hidreamai.com/api-pub/gw/v3/image/img2img/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. 返回参数
参数 | 类型 | 说明 |
---|---|---|
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": "b146d886-5c57-11ee-bf2b-f6f8d60dadec",
"result": {
"sub_task_ids": [
"d932ac2b-4591-4fc3-8995-adf81a87ce53"
],
"task_id": "b2781982-5c57-11ee-bf2b-f6f8d60dadec"
}
}