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) |
| auto_generate_prompt |
布尔值 |
否 |
是否自动生成提示词(默认:false) |
响应
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 # 矢量图颜色数量
auto_generate_prompt = False # 是否自动生成提示词
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,
"auto_generate_prompt": auto_generate_prompt,
},
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':
# 检查是否有多图片支持(如提取印花任务)
if 'images_urls' in status_info:
print(f"完成任务,获得 {len(status_info['images_urls'])} 张图片:")
for i, image_url in enumerate(status_info['images_urls']):
print(f" 图片 {i+1}: {image_url}")
else:
print(f"完成任务,图片链接: {status_info.get('images_url')}")
if status_info.get('vector_url'): # 如果有矢量图结果
print(f"矢量图链接: {status_info.get('vector_url')}")
if status_info.get('grid_url'): # 如果有网格图结果
print(f"网格图链接: {status_info.get('grid_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)。值越大,拼接处的过渡越平滑,但可能导致图像细节丢失;值越小,保留的细节越多,但可能在拼接处有明显痕迹 |
| direction |
整数 |
否 |
无缝拼接方向(0-2,默认:0)。0=四周无缝,1=仅上下无缝,2=仅左右无缝 |
| expand_top |
浮点数 |
否 |
向上扩图比例(0.0-0.3,默认:0.0) |
| expand_bottom |
浮点数 |
否 |
向下扩图比例(0.0-0.3,默认:0.0) |
| expand_left |
浮点数 |
否 |
向左扩图比例(0.0-0.3,默认:0.0) |
| expand_right |
浮点数 |
否 |
向右扩图比例(0.0-0.3,默认:0.0) |
| 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}" |
任务提交失败,附带具体的错误信息 |
注意事项
- 处理完成后会生成两个结果:无缝图和网格展示图
- direction参数决定无缝拼接的方向:
- 0: 四周无缝,生成2x2网格展示图
- 1: 仅上下无缝,生成1x2网格展示图(垂直排列)
- 2: 仅左右无缝,生成2x1网格展示图(水平排列)
- 网格展示图用于展示图片进行平铺后的效果
- 可以通过 check_task_status API 查询任务状态和获取结果
- 完成后通过 images_url 获取无缝图,通过 grid_url 获取网格展示图
- 如果不需要扩图,则把四个方向的扩图比例都设置为0即可
示例代码
def test_submit_seamless_task():
# 准备测试数据
fit = 0.3
direction = 0 # 四周无缝
expand_top = 0.2 # 向上扩图20%
expand_bottom = 0.1 # 向下扩图10%
expand_left = 0.0 # 不向左扩图
expand_right = 0.0 # 不向右扩图
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,
"direction": direction,
"expand_top": expand_top,
"expand_bottom": expand_bottom,
"expand_left": expand_left,
"expand_right": expand_right,
},
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/submit_remove_fabric_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 时存在) |
错误代码
| 错误消息 |
描述 |
| "账户不存在" |
无效或不存在的用户密钥 |
| "账户剩余次数不足" |
账户余额不足 |
| "文件大小不能超过16MB" |
上传的文件大小超过了16MB限制 |
| "任务提交失败:{err_msg}" |
任务提交失败,附带具体的错误信息 |
注意事项
- 此API专门用于移除图像中的布纹理,同时保留完整的图案
- 适用于有布纹影响的服装图案图像
- 文件大小不能超过16MB
- 可以通过 check_task_status API 查询任务状态和获取结果
示例代码
def test_submit_remove_fabric_task():
# 准备测试数据
input_image_path = "input/fabric_pattern.png" # 替换为有效的图像路径
with open(input_image_path, "rb") as image_file:
try:
response = httpx.post(
f"{BASE_URL}/api/submit_remove_fabric_task",
data={
"user_key": USER_KEY,
},
files={"input_image": image_file},
timeout=httpx.Timeout(
connect=5.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_remove_fabric_task()
if task_id == -1:
exit()
# 使用之前定义的函数检查任务状态
test_check_task_status(task_id)
提交改图任务
向服务器提交一个AI改图任务,根据用户提供的文本指令对图片进行AI编辑。
端点
POST /api/submit_edit_image_task
请求
- 内容类型:
multipart/form-data
参数
| 参数 |
类型 |
是否必须 |
描述 |
| user_key |
字符串 |
是 |
API 用户认证密钥 |
| prompt |
字符串 |
是 |
AI编辑指令(例如:"将这张图片转换为水彩画风格") |
| model_version |
字符串 |
否 |
模型版本("v1"或"v2",默认:"v1") |
| 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根据用户提供的文本指令对图片进行AI编辑
- 支持多种编辑指令,如风格转换、色彩调整、添加/移除元素等
- 可以通过 check_task_status API 查询任务状态和获取结果
- v2模型版本提供更高质量的编辑效果
示例代码
def test_submit_edit_image_task():
# 准备测试数据
prompt = "将这张图片转换为水彩画风格"
model_version = "v2" # 模型版本,默认v1
input_image_path = "input/flower2.jpg" # 替换为有效的图像路径
with open(input_image_path, "rb") as image_file:
try:
response = httpx.post(
f"{BASE_URL}/api/submit_edit_image_task",
data={
"user_key": USER_KEY,
"prompt": prompt,
"model_version": model_version,
},
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"提交AI改图任务成功,任务ID: {task_id}")
return task_id
if __name__ == "__main__":
# 提交AI改图任务
task_id = test_submit_edit_image_task()
if task_id == -1:
exit()
# 使用之前定义的函数检查任务状态
test_check_task_status(task_id)
提交提取印花任务
向服务器提交一个提取印花任务,从服装图片中提取印花图案,生成可无缝拼接的图案。
端点
POST /api/submit_extract_pattern_task
请求
- 内容类型:
multipart/form-data
参数
| 参数 |
类型 |
是否必须 |
描述 |
| user_key |
字符串 |
是 |
API 用户认证密钥 |
| aspect_ratio |
字符串 |
否 |
出图比例(例如:"1:1", "4:3", "16:9",默认:"1:1") |
| 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专门用于从服装图片中提取印花图案
- 提取的图案可以进行无缝拼接,适用于纺织品设计
- 适用于有清晰图案的服装图像
- 支持多图片返回:任务可能生成1-2张(或更多)结果图片
- 可以通过 check_task_status API 查询任务状态和获取结果
- 如果生成多张图片,将通过
images_urls 字段返回所有图片的URL列表
示例代码
def test_submit_extract_pattern_task():
# 准备测试数据
aspect_ratio = "1:1" # 出图比例,可选值:1:1, 4:3, 16:9 等
input_image_path = "input/flower.jpeg" # 替换为有效的服装图像路径
with open(input_image_path, "rb") as image_file:
try:
response = httpx.post(
f"{BASE_URL}/api/submit_extract_pattern_task",
data={
"user_key": USER_KEY,
"aspect_ratio": aspect_ratio,
},
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_extract_pattern_task()
if task_id == -1:
exit()
# 使用之前定义的函数检查任务状态
test_check_task_status(task_id)
提交移除烫钻任务
向服务器提交一个移除烫钻任务,移除图片中的水钻、烫钻和闪光装饰,保持图案完整。
端点
POST /api/submit_remove_diamonds_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_remove_diamonds_task():
# 准备测试数据
input_image_path = "input/diamonds.jpg" # 替换为有效的图像路径
with open(input_image_path, "rb") as image_file:
try:
response = httpx.post(
f"{BASE_URL}/api/submit_remove_diamonds_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_remove_diamonds_task()
if task_id == -1:
exit()
# 使用之前定义的函数检查任务状态
test_check_task_status(task_id)
提交扩图任务
向服务器提交一个扩图任务,可以在图片四周进行智能扩展,生成符合原图风格的额外内容。
端点
POST /api/submit_expand_image_task
请求
- 内容类型:
multipart/form-data
参数
| 参数 |
类型 |
是否必须 |
描述 |
| user_key |
字符串 |
是 |
API 用户认证密钥 |
| expand_top |
浮点数 |
否 |
向上扩图比例(0.0-0.3,默认:0.0) |
| expand_bottom |
浮点数 |
否 |
向下扩图比例(0.0-0.3,默认:0.0) |
| expand_left |
浮点数 |
否 |
向左扩图比例(0.0-0.3,默认:0.0) |
| expand_right |
浮点数 |
否 |
向右扩图比例(0.0-0.3,默认:0.0) |
| prompt |
字符串 |
否 |
AI生成扩展部分的提示词(默认:"") |
| 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 时存在) |
错误代码
| 错误消息 |
描述 |
| "账户不存在" |
无效或不存在的用户密钥 |
| "账户剩余次数不足" |
账户余额不足 |
| "文件大小不能超过16MB" |
上传的文件大小超过了16MB限制 |
| "扩展参数错误:expand_xxx必须在0.0-0.3之间" |
扩展参数超出了允许范围 |
| "任务提交失败:{err_msg}" |
任务提交失败,附带具体的错误信息 |
注意事项
- 此API用于对图片进行智能扩展,可在图片四周添加新内容
- 扩展比例表示在该方向上增加原图相应边长的百分比(例如:0.2表示增加20%)
- 所有扩展参数范围为0.0-0.3,即最多可扩展原图尺寸的30%
- 可以通过prompt参数提供提示词,指导AI生成扩展部分的内容
- 文件大小不能超过16MB
- 可以通过 check_task_status API 查询任务状态和获取结果
示例代码
def test_submit_expand_image_task():
# 准备测试数据
expand_top = 0.2 # 向上扩图20%
expand_bottom = 0.1 # 向下扩图10%
expand_left = 0.0 # 不向左扩图
expand_right = 0.0 # 不向右扩图
prompt = "延续原图的风格和内容" # 扩展部分的生成提示
input_image_path = "input/test.png" # 替换为有效的图像路径
with open(input_image_path, "rb") as image_file:
try:
response = httpx.post(
f"{BASE_URL}/api/submit_expand_image_task",
data={
"user_key": USER_KEY,
"expand_top": expand_top,
"expand_bottom": expand_bottom,
"expand_left": expand_left,
"expand_right": expand_right,
"prompt": prompt
},
files={"input_image": image_file},
timeout=300.0
)
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_expand_image_task()
if task_id == -1:
exit()
# 使用之前定义的函数检查任务状态
test_check_task_status(task_id)
提交去水印任务
向服务器提交一个去水印任务,可以智能移除图片中的水印元素。
端点
POST /api/submit_remove_watermark_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 时存在) |
错误代码
| 错误消息 |
描述 |
| "账户不存在" |
无效或不存在的用户密钥 |
| "账户剩余次数不足" |
账户余额不足 |
| "文件大小不能超过16MB" |
上传的文件大小超过了16MB限制 |
| "任务提交失败:{err_msg}" |
任务提交失败,附带具体的错误信息 |
注意事项
- 此API用于智能移除图片中的水印元素
- 文件大小不能超过16MB
- 可以通过 check_task_status API 查询任务状态和获取结果
示例代码
def test_submit_remove_watermark_task():
# 准备测试数据
input_image_path = "input/watermarked.png" # 替换为有效的图像路径
with open(input_image_path, "rb") as image_file:
try:
response = httpx.post(
f"{BASE_URL}/api/submit_remove_watermark_task",
data={
"user_key": USER_KEY
},
files={"input_image": image_file},
timeout=300.0
)
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_remove_watermark_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 |
响应
单图片任务响应示例
{
"err_code": 0,
"status": "Completed",
"images_url": "https://api.domain.com/api/images/xxx/task123",
"vector_url": "https://api.domain.com/api/images/xxx/task123/vector",
"grid_url": "https://api.domain.com/api/images/xxx/task123/grid",
"generated_prompt": "high quality, detailed, sharp, professional photography, beautiful lighting",
"remaining_count": 5,
"remaining_money": 300
}
多图片任务响应示例(提取印花等)
{
"err_code": 0,
"status": "Completed",
"images_url": "https://api.domain.com/api/images/xxx/task123",
"images_urls": [
"https://api.domain.com/api/images/xxx/task123",
"https://api.domain.com/api/images/xxx/task123/alternative/1"
],
"vector_url": "",
"grid_url": "",
"generated_prompt": "vibrant pattern, textile design, seamless repeat, colorful motifs",
"remaining_count": 5,
"remaining_money": 300
}
响应字段
| 字段 |
类型 |
描述 |
| err_code |
整数 |
状态码 (0 = 成功, 1 = 错误) |
| status |
字符串 |
任务当前状态 |
| images_url |
字符串 |
处理结果的主图片URL (仅当状态为 "COMPLETED" 时存在) |
| images_url_1m |
字符串 |
处理结果的1倍图URL (仅当状态为 "COMPLETED" 且为无缝拼图任务时存在) |
| images_urls |
字符串数组 |
所有结果图片的URL列表 (仅当多图任务如提取印花完成时存在) |
| vector_url |
字符串 |
处理结果的矢量图URL (仅当状态为 "COMPLETED" 且开启矢量图时存在) |
| grid_url |
字符串 |
处理结果的网格图URL (仅当状态为 "COMPLETED" 且为无缝拼图任务时存在) |
| generated_prompt |
字符串 |
AI自动生成的提示词 (仅当状态为 "COMPLETED" 且启用自动生成提示词时存在) |
| remaining_count |
整数 |
剩余的套餐次数(仅在有结果时返回) |
| remaining_money |
整数 |
剩余的金额(单位:元,仅在有结果时返回) |
| err_msg |
字符串 |
错误消息 (仅当 err_code = 1 时存在) |
错误代码
| 错误消息 |
描述 |
| "账户不存在" |
无效或不存在的用户密钥 |
| "任务未找到或状态未知" |
任务未找到或状态未知 |
注意事项
- API 对状态检查实施了3秒缓存,以防止请求过多。
- 只有当任务状态为 "COMPLETED" 时才提供图像URL 和 剩余次数/金额。
- 矢量图功能为测试功能,仅适用于颜色较少、线条简单的图形。
- 矢量图将以 EPS 格式提供下载。
- 多图片支持:对于提取印花等任务,如果生成多张图片,会额外返回
images_urls 字段包含所有图片URL。
images_urls 数组的第一个元素总是与 images_url 相同,确保向后兼容性。
- 客户端应优先检查
images_urls 字段以获取完整的图片列表,如果该字段不存在则使用 images_url。