API 文档
接口地址 和 user_key 请联系客服或者进群咨询。
目录
提交高清重绘任务
向服务器提交一个图像处理任务。
端点
POST /api/submit_task
请求
- 内容类型:
multipart/form-data
参数
参数 |
类型 |
是否必须 |
描述 |
user_key |
字符串 |
是 |
API 用户认证密钥 |
sdxl_model_dropdown |
字符串 |
是 |
处理模型选择(例如:"通用模型") |
style_dropdown |
字符串 |
是 |
处理风格选择(例如:"通用风格") |
upscale |
浮点数 |
是 |
图像放大倍数(1-8) |
s_noise |
浮点数 |
是 |
噪声强度参数(1-1.1) |
steps |
浮点数 |
是 |
采样步数(20-40,值越大越慢) |
high_fidelity |
布尔值 |
是 |
开启/关闭高保真度处理 |
strong_inpaint |
布尔值 |
是 |
开启/关闭强力修复功能 |
strong_inpaint_intensity |
浮点数 |
否 |
强力修复的强度(0-1,默认0.5) |
prompt |
字符串 |
否 |
图像生成的正面提示(默认:"") |
neg_prompt |
字符串 |
否 |
图像生成的负面提示(默认:"") |
input_image |
文件 |
是 |
要处理的图像文件 |
vector_switch |
布尔值 |
否 |
是否生成矢量图(默认:false) |
color_count |
整数 |
否 |
矢量图颜色数量(2-16,默认:5) |
响应
json
{
"err_code": 0,
"task_id": "字符串",
"remaining_count": 5,
"remaining_money": 300
}
响应字段
字段 |
类型 |
描述 |
err_code |
整数 |
状态码 (0 = 成功, 1 = 错误) |
task_id |
字符串 |
提交任务的唯一标识符 (仅当 err_code = 0 时存在) |
remaining_count |
整数 |
剩余的套餐次数 (仅当 err_code = 0 时存在) |
remaining_money |
整数 |
剩余的金额(单位:元,仅当 err_code = 0 时存在) |
err_msg |
字符串 |
错误消息 (仅当 err_code = 1 时存在) |
错误代码
错误消息 |
描述 |
"账户不存在" |
无效或不存在的用户密钥 |
"账户剩余次数不足" |
账户余额不足 |
"任务提交失败:{err_msg}" |
任务提交失败,附带具体的错误信息 |
示例代码
import time
import httpx
BASE_URL = "http://www.xxx.com" # 替换为真实的服务器地址
USER_KEY = "test-key" # 替换为有效的用户密钥
def test_submit_task():
# 准备测试数据
sdxl_model_dropdown = "通用模型"
style_dropdown = "通用风格"
prompt = ""
neg_prompt = ""
upscale = 1.0
s_noise = 1.003
steps = 30
high_fidelity = False
strong_inpaint = False
vector_switch = False # 是否生成矢量图
color_count = 5 # 矢量图颜色数量
input_image_path = "input/test3.png" # 替换为有效的图像路径
with open(input_image_path, "rb") as image_file:
try:
response = httpx.post(
f"{BASE_URL}/api/submit_task",
data={
"user_key": USER_KEY,
"sdxl_model_dropdown": sdxl_model_dropdown,
"style_dropdown": style_dropdown,
"prompt": prompt,
"neg_prompt": neg_prompt,
"upscale": upscale,
"s_noise": s_noise,
"steps": steps,
"high_fidelity": high_fidelity,
"strong_inpaint": strong_inpaint,
"vector_switch": vector_switch,
"color_count": color_count,
},
files={"input_image": image_file},
timeout=httpx.Timeout(
connect=5.0, # 连接超时
read=10.0, # 读取超时
write=30.0, # 写入超时
pool=None # 连接池超时
)
)
response.raise_for_status()
except httpx.TimeoutException:
print("请求超时,请检查网络连接或服务器状态")
return -1
except httpx.HTTPStatusError as e:
print(f"HTTP请求失败: {e.response.status_code}")
print(f"错误详情: {e.response.json()}")
return -1
except httpx.RequestError as e:
print(f"请求错误: {str(e)}")
return -1
except Exception as e:
print(f"发生未知错误: {str(e)}")
return -1
print(response.status_code)
result = response.json()
print(result)
err_code = result.get("err_code")
if err_code != 0:
print(f"提交任务失败,错误码: {result.get('err_msg')}")
return -1
task_id = result.get("task_id")
print(f"提交任务成功,任务ID: {task_id}")
return task_id
def test_check_task_status(task_id):
# 为了测试,这里使用了1个死循环,请修改为适当的轮询策略,请求间隔建议2-3秒
while True:
response = httpx.post(
f"{BASE_URL}/api/check_task_status",
data={
"user_key": USER_KEY,
"task_id": task_id
}
)
assert response.status_code == 200
status_info = response.json()
err_code = status_info.get("err_code")
if err_code != 0:
print(f"查询任务状态失败,错误码: {status_info.get('err_msg')}")
return -1
print(f"任务状态: {status_info['status']}")
if status_info['status'] == 'Completed':
print(f"完成任务,图片链接: {status_info.get('images_url')}")
if status_info.get('vector_url'): # 如果有矢量图结果
print(f"矢量图链接: {status_info.get('vector_url')}")
break
elif status_info['status'] in [None, 'Failed']:
break
time.sleep(1)
if __name__ == "__main__":
task_id = test_submit_task()
if task_id == -1:
exit()
test_check_task_status(task_id)
提交矢量图转换任务
向服务器提交一个位图转矢量图的任务,只能处理颜色较少的图片,不适合处理真实照片。
端点
POST /api/submit_vector_task
请求
- 内容类型:
multipart/form-data
参数
参数 |
类型 |
是否必须 |
描述 |
user_key |
字符串 |
是 |
API 用户认证密钥 |
color_count |
整数 |
否 |
矢量图颜色数量(2-16,默认:5) |
input_image |
文件 |
是 |
要转换的位图文件 |
响应
{
"err_code": 0,
"task_id": "字符串",
"remaining_count": 5,
"remaining_money": 300
}
响应字段
字段 |
类型 |
描述 |
err_code |
整数 |
状态码 (0 = 成功, 1 = 错误) |
task_id |
字符串 |
提交任务的唯一标识符 (仅当 err_code = 0 时存在) |
remaining_count |
整数 |
剩余的套餐次数 (仅当 err_code = 0 时存在) |
remaining_money |
整数 |
剩余的金额(单位:元,仅当 err_code = 0 时存在) |
err_msg |
字符串 |
错误消息 (仅当 err_code = 1 时存在) |
错误代码
错误消息 |
描述 |
"账户不存在" |
无效或不存在的用户密钥 |
"账户剩余次数不足" |
账户余额不足 |
"任务提交失败:{err_msg}" |
任务提交失败,附带具体的错误信息 |
注意事项
- 矢量图功能适用于颜色较少、线条简单的图形
- 生成的矢量图将以 EPS 格式提供
- 可以通过 check_task_status API 查询任务状态和获取结果
示例代码
def test_submit_vector_task():
# 准备测试数据
color_count = 5 # 矢量图颜色数量
input_image_path = "input/logo.png" # 替换为有效的图像路径
with open(input_image_path, "rb") as image_file:
try:
response = httpx.post(
f"{BASE_URL}/api/submit_vector_task",
data={
"user_key": USER_KEY,
"color_count": color_count,
},
files={"input_image": image_file},
timeout=httpx.Timeout(
connect=5.0, # 连接超时
read=10.0, # 读取超时
write=30.0, # 写入超时
pool=None # 连接池超时
)
)
response.raise_for_status()
except httpx.TimeoutException:
print("请求超时,请检查网络连接或服务器状态")
return -1
except httpx.HTTPStatusError as e:
print(f"HTTP请求失败: {e.response.status_code}")
print(f"错误详情: {e.response.json()}")
return -1
except httpx.RequestError as e:
print(f"请求错误: {str(e)}")
return -1
except Exception as e:
print(f"发生未知错误: {str(e)}")
return -1
print(response.status_code)
result = response.json()
print(result)
err_code = result.get("err_code")
if err_code != 0:
print(f"提交任务失败,错误码: {result.get('err_msg')}")
return -1
task_id = result.get("task_id")
print(f"提交任务成功,任务ID: {task_id}")
return task_id
if __name__ == "__main__":
# 提交矢量图转换任务
task_id = test_submit_vector_task()
if task_id == -1:
exit()
# 使用之前定义的函数检查任务状态
test_check_task_status(task_id)
提交人脸修复任务
向服务器提交一个人脸修复任务。
端点
POST /api/submit_face_enhance_task
请求
- 内容类型:
multipart/form-data
参数
参数 |
类型 |
是否必须 |
描述 |
user_key |
字符串 |
是 |
API 用户认证密钥 |
input_image |
文件 |
是 |
要处理的人脸图像文件 |
响应
{
"err_code": 0,
"task_id": "字符串",
"remaining_count": 5,
"remaining_money": 300
}
响应字段
字段 |
类型 |
描述 |
err_code |
整数 |
状态码 (0 = 成功, 1 = 错误) |
task_id |
字符串 |
提交任务的唯一标识符 (仅当 err_code = 0 时存在) |
remaining_count |
整数 |
剩余的套餐次数 (仅当 err_code = 0 时存在) |
remaining_money |
整数 |
剩余的金额(单位:元,仅当 err_code = 0 时存在) |
err_msg |
字符串 |
错误消息 (仅当 err_code = 1 时存在) |
错误代码
错误消息 |
描述 |
"账户不存在" |
无效或不存在的用户密钥 |
"账户剩余次数不足" |
账户余额不足 |
"任务提交失败:{err_msg}" |
任务提交失败,附带具体的错误信息 |
注意事项
- 此API专门用于人脸图像的修复和增强
- 建议上传正面人脸图像以获得最佳效果
- 可以通过 check_task_status API 查询任务状态和获取结果
示例代码
def test_submit_face_enhance_task():
# 准备测试数据
input_image_path = "input/face.png" # 替换为有效的人脸图像路径
with open(input_image_path, "rb") as image_file:
try:
response = httpx.post(
f"{BASE_URL}/api/submit_face_enhance_task",
data={
"user_key": USER_KEY,
},
files={"input_image": image_file},
timeout=httpx.Timeout(
connect=5.0, # 连接超时
read=10.0, # 读取超时
write=30.0, # 写入超时
pool=None # 连接池超时
)
)
response.raise_for_status()
except httpx.TimeoutException:
print("请求超时,请检查网络连接或服务器状态")
return -1
except httpx.HTTPStatusError as e:
print(f"HTTP请求失败: {e.response.status_code}")
print(f"错误详情: {e.response.json()}")
return -1
except httpx.RequestError as e:
print(f"请求错误: {str(e)}")
return -1
except Exception as e:
print(f"发生未知错误: {str(e)}")
return -1
print(response.status_code)
result = response.json()
print(result)
err_code = result.get("err_code")
if err_code != 0:
print(f"提交任务失败,错误码: {result.get('err_msg')}")
return -1
task_id = result.get("task_id")
print(f"提交任务成功,任务ID: {task_id}")
return task_id
if __name__ == "__main__":
# 提交人脸修复任务
task_id = test_submit_face_enhance_task()
if task_id == -1:
exit()
# 使用之前定义的函数检查任务状态
test_check_task_status(task_id)
提交无缝拼图任务
向服务器提交一个图像无缝拼图任务,可以将图片处理成可以无缝平铺的效果。
端点
POST /api/submit_seamless_task
请求
- 内容类型:
multipart/form-data
参数
参数 |
类型 |
是否必须 |
描述 |
user_key |
字符串 |
是 |
API 用户认证密钥 |
fit |
浮点数 |
否 |
接缝拼合度(0.1-0.9,默认:0.5)。值越大,拼接处的过渡越平滑,但可能导致图像细节丢失;值越小,保留的细节越多,但可能在拼接处有明显痕迹 |
input_image |
文件 |
是 |
要处理的图像文件 |
响应
{
"err_code": 0,
"task_id": "字符串",
"remaining_count": 5,
"remaining_money": 300
}
响应字段
字段 |
类型 |
描述 |
err_code |
整数 |
状态码 (0 = 成功, 1 = 错误) |
task_id |
字符串 |
提交任务的唯一标识符 (仅当 err_code = 0 时存在) |
remaining_count |
整数 |
剩余的套餐次数 (仅当 err_code = 0 时存在) |
remaining_money |
整数 |
剩余的金额(单位:元,仅当 err_code = 0 时存在) |
err_msg |
字符串 |
错误消息 (仅当 err_code = 1 时存在) |
错误代码
错误消息 |
描述 |
"账户不存在" |
无效或不存在的用户密钥 |
"账户剩余次数不足" |
账户余额不足 |
"任务提交失败:{err_msg}" |
任务提交失败,附带具体的错误信息 |
注意事项
- 处理完成后会生成两个结果:无缝图和网格展示图
- 网格展示图用于展示图片进行 2x2 平铺后的效果
- 可以通过 check_task_status API 查询任务状态和获取结果
- 完成后通过 images_url 获取无缝图,通过 grid_url 获取网格展示图
示例代码
def test_submit_seamless_task():
# 准备测试数据
fit = 0.3
input_image_path = "input/seamless.jpeg" # 替换为有效的图像路径
with open(input_image_path, "rb") as image_file:
try:
response = httpx.post(
f"{BASE_URL}/api/submit_seamless_task",
data={
"user_key": USER_KEY,
"fit": fit,
},
files={"input_image": image_file},
timeout=httpx.Timeout(
connect=5.0, # 连接超时
read=10.0, # 读取超时
write=30.0, # 写入超时
pool=None # 连接池超时
)
)
response.raise_for_status()
except httpx.TimeoutException:
print("请求超时,请检查网络连接或服务器状态")
return -1
except httpx.HTTPStatusError as e:
print(f"HTTP请求失败: {e.response.status_code}")
print(f"错误详情: {e.response.json()}")
return -1
except httpx.RequestError as e:
print(f"请求错误: {str(e)}")
return -1
except Exception as e:
print(f"发生未知错误: {str(e)}")
return -1
print(response.status_code)
result = response.json()
print(result)
err_code = result.get("err_code")
if err_code != 0:
print(f"提交任务失败,错误码: {result.get('err_msg')}")
return -1
task_id = result.get("task_id")
print(f"提交任务成功,任务ID: {task_id}")
return task_id
if __name__ == "__main__":
# 提交无缝拼图任务
task_id = test_submit_seamless_task()
if task_id == -1:
exit()
# 使用之前定义的函数检查任务状态
test_check_task_status(task_id)
检查任务状态
检查之前提交的任务的状态。
端点
POST /api/check_task_status
请求
- 内容类型:
multipart/form-data
参数
参数 |
类型 |
是否必须 |
描述 |
user_key |
字符串 |
是 |
API 用户认证密钥 |
task_id |
字符串 |
是 |
从 submit_task 返回的任务ID |
响应
json
{
"err_code": 0,
"status": "字符串",
"images_url": "字符串",
"vector_url": "字符串",
"remaining_count": 5,
"remaining_money": 300
}
响应字段
字段 |
类型 |
描述 |
err_code |
整数 |
状态码 (0 = 成功, 1 = 错误) |
status |
字符串 |
任务当前状态 |
images_url |
字符串 |
处理结果的图片URL (仅当状态为 "COMPLETED" 时存在) |
vector_url |
字符串 |
处理结果的矢量图URL (仅当状态为 "COMPLETED" 且开启矢量图时存在) |
grid_url |
字符串 |
处理结果的网格图URL (仅当状态为 "COMPLETED" 且为无缝拼图任务时存在) |
remaining_count |
整数 |
剩余的套餐次数(仅在有结果时返回) |
remaining_money |
整数 |
剩余的金额(单位:元,仅在有结果时返回) |
err_msg |
字符串 |
错误消息 (仅当 err_code = 1 时存在) |
错误代码
错误消息 |
描述 |
"账户不存在" |
无效或不存在的用户密钥 |
"任务未找到或状态未知" |
任务未找到或状态未知 |
注意事项
- API 对状态检查实施了3秒缓存,以防止请求过多。
- 只有当任务状态为 "COMPLETED" 时才提供图像URL 和 剩余次数/金额。
- 矢量图功能为测试功能,仅适用于颜色较少、线条简单的图形。
- 矢量图将以 EPS 格式提供下载。