提交图片增强任务
1. 接口地址
https://www.hidreamai.com/api-pub/gw/v3/image/image_upscaler/async
2. 请求方式
POST
3. 请求参数
Header
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
Authorization(用户授权) | string | 是 | 客户授权Token |
Content-Type(传递内容) | string | 是 | 使用json传参 |
X-accept-language | string | 否 | 语言偏好,支持['en', 'zh'],en:英文,zh:中文,默认为"zh" |
API-User-ID | string | 否 | 用户唯一标识 |
Body
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
image | string | 是 | 原始图片,支持传入图片的base64值/URL地址 |
upsale_ratio | int | 是 | 图片的增强倍数,默认值为2,可选值为4 |
version | string | 否 | 模型版本,默认为"v1",可选范围为{"v1"} |
notify_url | string | 否 | 任务完成回调通知接口(需公网能访问),请求参数与task result 一致 |
request_id | string | 否 | 请求的ID,默认为"" |
说明:
curl示例
curl -H 'Authorization: Bearer {USER_Authorization}' \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"image": "https://storage.hidreamai.com/image/p_ec2e8446-3a94-11ef-8f5b-6a40833e9843.png",
"upsale_ratio": 2,
"version": "v1",
}' \
-v 'https://www.hidreamai.com/api-pub/gw/v3/image/image_upscaler/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://storage.hidreamai.com/image/p_ec2e8446-3a94-11ef-8f5b-6a40833e9843.png",
"upsale_ratio": 2,
"version": "v1",
}
# 发送POST请求
url = 'https://www.hidreamai.com/api-pub/gw/v3/image/image_upscaler/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":"Success",
"request_id":"ccfc092e-8430-11ee-97ff-f60f825045d5",
"result":{
"sub_task_ids":["3244ad82-2e3a-40a3-b4e2-d7797b32bf41"],
"task_id":"ccc894f2-3a9e-11ef-b843-cad358304ee0"
}
}