一、权限认证
1、Token获取
基于AKSK的用户权限校验,具体如下
2.1 请求头(Request Header)
在请求头里,添加 Authorization
字段,如下所示:
python("Authorization: Bearer $YOUR_TOKEN")
2.2 Authorization 生成方式
遵循JWT(Json Web Token, RFC 7519)标准。
JWT由三个部分组成:Header
、Payload
、Signature
。
• JWT Header
的构建方式
{"typ":"JWT","alg":"HS256"}手动生成JWT,JWT Header中alg填写HS256
• JWT Payload
的构建方式
名称 | 类型 | 必须 | 描述 |
---|---|---|---|
iss | String | 是 | AK(Access Key ID,获取方式请参考使用手册-“获取访问密钥”) |
exp | Integer | 是 | 超时时间(Unix时间戳,单位秒) |
nbf | Integer | 否 | 生效时间(Unix时间戳,单位秒),在此时间前无法使用 |
• JWT Signature
的构建方式
SK(Access Key Secret,获取方式请参考使用手册-“获取访问密钥”)
2.3、生成示例
1) Python Sample Code
首先,您可以通过 pip
安装的方式将 PyJWT
安装到您的环境中,在命令行中执行如下命令:
python("pip3 install PyJWT==2.6.0")
然后,可按照以下样例生成 Authorization
:
python("import time
import jwt
ak = "" 填写您的ak
sk = "" 填写您的sk
def encode_jwt_token(ak, sk):
headers = {"alg": "HS256","typ": "JWT"
}
payload = {"iss": ak,"exp": int(time.time()) + 1800, 填写您期望的有效时间,此处示例代表当前时间+30分钟"nbf": int(time.time()) - 5 填写您期望的生效时间,此处示例代表当前时间-5秒
}
token = jwt.encode(payload, sk, headers=headers)
return token
authorization = encode_jwt_token(ak, sk)
print(authorization) 打印生成的YOUR_TOKEN")
2) Java Sample Code
python("package test;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class JWTDemo {
static String ak = ""; // 填写您的akstatic String sk = ""; // 填写您的skpublic static void main(String[] args) {String token = sign(ak, sk);
System.out.println(token); // 打印生成的YOUR_TOKEN
}static String sign(String ak,String sk) {try {Date expiredAt = new Date(System.currentTimeMillis() + 1800*1000);Date notBefore = new Date(System.currentTimeMillis() - 5*1000);Algorithm algo = Algorithm.HMAC256(sk);
Map<String, Object> header = new HashMap<String, Object>();
header.put("alg", "HS256");return JWT.create()
.withIssuer(ak)
.withHeader(header)
.withExpiresAt(expiredAt)
.withNotBefore(notBefore)
.sign(algo);
} catch (Exception e) {
e.printStackTrace();return null;
}
}
}")
3) Golang Sample Code
javascript('package main
import ("encoding/json""fmt""time""github.com/golang-jwt/jwt/v4"
)
func EncodeJwtToken(ak string, sk string) (string, error) {
payload := jwt.MapClaims{"iss": ak,"exp": time.Now().Add(1800time.Second).Unix(),"nbf": time.Now().Add(-5time.Second).Unix(),
}
token := jwt.NewWithClaims(jwt.SigningMethodHS256, payload)
signedToken, err := token.SignedString([]byte(sk))if err != nil {
fmt.Println("Error encoding JWT token:", err)return "", err
}return signedToken, nil
}
func main() {
ak := "" // 填写您的ak
sk := "" // 填写您的sk
token, err := EncodeJwtToken(ak, sk)if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("Encoded JWT token:", token) // 打印生成的YOUR_TOKEN
}
}');
二、生图接口
包含:文生图、图生图、lora生图、CN控制生图
1、获取模型列表接口
• PATH: https://mhapi.sensetime.com/v1/imgenstd/models
• Method: GET
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
size | int | 否 | 0 | 1~100 | 最多返回多少个模型 |
offset | int | 否 | 0 | 0~Inf | 跳过多少记录 |
mtp | string | 否 | ALL | LORA, Checkpoint,ALL | 类型筛选,为ALL则不筛选,可以不传 |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/imgenstd/models?size=10&offset=0&mtp=ALL' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
• 返回
名称 | 类型 | 描述 |
---|---|---|
have_next | bool | false表示已是最后一页 |
data | list | 模型数据 |
• id | string | 模型唯一标识 |
• name | string | 模型名称 |
• description | string | 模型描述 |
• 示例
{
"have_next": false,
"data": [
{
"id": "xxxx",
"name": "xxxx",
"description": "xxxx",
"base_model_type": "xxxxx",
"model_type": "LORA",
"trigger_words": ""
}
]
}
2、获取模型支持cn列表接口
• 仅支持通过基模获取支持的cn
• 如果传入lora则返回”请使用相应基础模型查询“
• PATH: https://mhapi.sensetime.com/v1/imgenstd/model_cn/:model_id
• Method: GET
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
size | int | 否 | 10 | 1~100 | 最多返回多少个模型 |
offset | int | 否 | 0 | 0~Inf | 跳过多少记录 |
• 请求示例
curl -X GET 'https://mhapi.sensetime.com/v1/imgenstd/model_cn/xxxxxx' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
• 返回
名称 | 类型 | 描述 |
---|---|---|
have_next | bool | false表示已是最后一页 |
data | list | cn数据 |
• cn | string | 唯一标识,比如 canny |
• name | string | cn名称 |
• description | string | cn描述 |
• 示例
{
"have_next": false,
"data": [
{
"cn": "xxxx",
"name": "xxxx",
"description": "xxxx",
}
]
}
3、提交生图接口
• PATH: https://mhapi.sensetime.com/v1/imgenstd/imgen
• Method: POST
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 请求
• 参数说明
名称 | 类型 | 必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
model_id | string | 是 | - | - | 模型唯一id |
prompt | string | 是 | - | - | 正向提示词(utf-8编码),小于等于2000个字符(1000个汉字) |
force_translation | bool | 否 | false | true, false | true强制开启翻译prompt、neg_prompt, false采取默认行为。(V1.0/V0.6.0默认不翻译,其它默认翻译) |
add_prompt | bool | 否 | false | true, false | 是否开启prompt补词 |
neg_prompt | string | 否 | - | - | 反向提示词(utf-8编码),小于等于2000个字符(1000个汉字) |
cfg_scale | float | 否 | 7 | [1,20] | 提示文本的控制力度(数字越大,生成的图片跟提示词相关性越强) |
samples | int | 否 | 1 | [1,8] | 生成图片数量 |
height | int | 否 | 960 | [640, 6000] | 生成图片的高度(单位:像素) |
width | int | 否 | 960 | [640, 6000] | 生成图片的宽度(单位:像素) |
seed | int | 否 | 0 | [0, 99999999) | 随机数种子,0代表随机,一个种子对应一张图,如果传递的值为x,需要生成4张图,则4张结果的种子数分别为x,x+1、x+2、x+3 |
steps | int | 否 | 30 | (0,70] | 要运行的扩散步骤数 |
format | string | 否 | JPG | Enum: JPG, PNG | 生成图片的格式 |
img_url | string | 否 | - | - | 图生图的原图必须是公开可访目前仅支持256x256 ~6000x6000 px图片目前仅支持jpg,jpeg,png,webp等常见格式,存储占用小于8MB。 |
image_strength | float | 否 | 0.6 | [0, 1] | 参考图片的控制力度(数字越大,自由发挥度越大) |
watermark_config | object | 否 | - | - | 生成图片的水印 |
- type | string | 否 | Default | Default MakaLogo | Default: 图片由 AI 生成 MakaLogo: 秒画的 logo |
controlnet_configs | object[] | 否 | - | - | controlnet 的配置,最多可以同时使用三个controlnet模型 |
- type | string | 是 | - | "canny depth ip2p lineart lineart_anime mlsd normal openpose scribble shuffle softedge tile seg brightness reference_only ip_adapter_faceid" | "cn 类型 Enum(见表下方)" |
- img_url | string | 是 | - | - | cn模型的输入参考图片,oss地址,必须是公开可访目前仅支持256x256 ~6000x6000 px图片目前仅支持jpg,jpeg,png,webp等常见格式,存储占用小于8MB。 |
- weight | float | 否 | 1 | (0, 2] | cn模型的控制权重 |
- pre_processor | string | 否 | - | - | cn的预处理器,不同的cn模型可选值不一样,有的cn模型没有预处理器(见表下方) |
- guidance_start | float | 否 | 0 | [0, 1] | ControlNet开始参与生图的步数 |
- guidance_end | float | 否 | 1 | [0, 1] | ControlNet结束参与生图的步数 |
- canny_low_threshold | int | 否 | 100 | [1, 255] | Canny类型内部参数,低阈值,数值越低线条越复杂,数值越高线条越简单 |
- canny_high_threshold | int | 否 | 200 | [1, 255] | Canny类型内部参数,高阈值,数值越低线条越复杂,数值越高线条越简单 |
- tile_down_sample_rate | float | 否 | 1 | [1, 8] | Tile类型内部参数,下采样率 |
lora_configs | object[] | 否 | - | - | 微调模型使用此配置 |
- model_id | string | 是 | - | - | 微调模型的 model.id;lora_configs.model_id和model_id 必须是基于同一个底模生成 |
- merge_weight | float | 否 | 1 | (0, 2) | lora的权重 |
Controlnet type和pre_processer具体说明: pre_processer默认支持pass ,允许用户传入预处理后的图片
type | 说明 | pre_processer(标蓝的为默认) |
---|---|---|
canny | 边缘控制:根据用户上传的图片,提取线稿。再结合文本和线稿进行重绘。可保留线稿中的设计细节。 | canny, invert, pass |
depth | 深度控制:根据用户上传的人物、建筑、场景等图片,提取其中的深度信息,然后结合文本和深度信息生成新的图像。可保留深度图中的结构和层次细节。 | - |
normal | 法线控制:根据用户上传图片,预处理后获得适用于建模的法线图,再结合文本生成新图片。这种模式可保留参考图中的一些三维信息。 | - |
openpose | 姿势控制:根据用户上传的人物图片,提取人物的骨骼姿态,生成一幅相同姿势的图片。 | openpose, openpose_face, openpose_faceonly, openpose_full, openpose_hand, pass |
mlsd | 直线控制:根据用户上传的建筑、物体、场景图片,提取其中的线条、轮廓。再结合文本重新生成新图片。适用于有较多物体的场景。 | - |
lineart | 线稿控制:相比边缘控制模式,可以更精细地提取线稿,局部细节更加丰富,还原度更高。 | lineart_coarse, lineart_realistic, pass, lineart_standard |
lineartanime | 动画线稿控制:二次元线稿上色专用。 | lineart_anime, lineart_anime_denoise, pass |
softedge | 柔性边缘控制:根据用户上传的图片,提取线稿,并将线稿转换为几个不同的级别,相比”边缘控制”模式,会忽路一些次要细节。与原图相比,这种模式会使最终图像产生更多的变化。 | - |
scribble | 涂鸦:根据用户上传的图片,提取原图中的大致轮廓,再结合文本进行着色。相比”边缘控制”模式,这种模式的线稿提取结果更加粗犷,可保留构图并对人物、场景进行重绘。 | - |
seg | 语义分割:根据用户上传的图片,进行语义分析,识别图片信息后,分割画面内容。再结合文本,对分割内容进行重绘。 | - |
shuffle | 颜色风格迁移:根据用户上传的图片,随机洗牌其中的信息并重新扩散图像。适用于保留参考图中的颜色风格。 | - |
tile | 细节增强:重绘图片中较模糊的细节,并使图像更加清晰。适合处理图像放大后引起的模糊。 | tile_colorfix, tile_colorfix_sharp, pass, tile_resample |
ip2p | 图像转换:根据用户输入的文本指令,对用户上传的图片进行编辑,转换图片中的部分元素。 | - |
brightness | 亮度控制:对图片进行亮度控制。 | - |
reference_only | 风格迁移:固定人物、场景或特征,保留图片的风格 | - |
ip_adapter_faceid | IP迁移:保留原图人脸的五官等特征 | face_id_plus plus_vith |
• 备注:
• 模型支持的生图类型如下:
文生图:V1.0模型、0.5.0模型、0.4.0极速版、 0.4.0模型
图生图:050模型、040模型
姿势控制:0.4.0极速版、040模型
深度控制:0.4.0极速版、040模型
边缘控制:0.4.0极速版、040模型
柔性边缘控制:0.4.0极速版、040模型
法线控制:0.4.0极速版、040模型
涂鸦:0.4.0极速版、040模型
语义分割:0.4.0极速版、040模型
lora生图:040模型
• 模型推荐参数如下,其它参数选择默认值:
V1.0模型:steps: 50,cfg_scale: 8.0
0.5.0模型极速版:steps: 6,cfg_scale: 1.5
0.5.0模型:steps: 50,cfg_scale: 6.0
0.4.0极速版:steps: 5,cfg_scale: 1.2
040模型:steps: 50,cfg_scale: 7.0
• 示例1
curl -X POST 'https://mhapi.sensetime.com/v1/imgenstd/imgen' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
-d '{"img_url": "https://xxxx.jpg", "model_id": "xxxv0.1", "prompt": "晚餐"}'
• 示例2
curl --location 'https://test.mhapi.sensetime.com/v1/imgenstd/imgen' \
--header 'Content-Type: application/json' \
--header 'Authorization: ••••••' \
--data '{
"model_id":"cq71d1kq0d02r73hadf0",
"prompt": "in a futuristic, neon lit environment, A young girl with short white hair drinking at a bar, wearing colorful clothes, future technology, vehicles, from the waist up",
"steps":45,
"cfg_scale":8.0,
"samples":3,
"width":816,
"height":1449,
"seed":0
,"force_translation":false
,"format":"PNG"
,"watermark_config": {"type": "MakaLogo"}
,"controlnet_configs": [
{
"type": "canny",
"img_url": "https://bkmksh.oss-accelerate.aliyuncs.com/da4925d3-295a-11ef-a777-960a9b8c832a.jpg?Expires=317078265565&OSSAccessKeyId=LTAI5t8GmQec8vxNsiGKcYBT&Signature=8h8YaAprxthc%2FGacSUpiX1N8ObQ%3D"
}
]
,"lora_configs":[{
"model_id":"ctdaev4vgbeka9k7dq2g"
,"merge_weight":1.2
}
]
}'
• 返回
名称 | 类型 | 描述 |
---|---|---|
task_id | string | 任务id |
• 示例
{
"task_id": "aabbccdd"
}
4、查询任务结果接口
PATH: https://mhapi.sensetime.com/v1/imgenstd/result/:id
Method: GET
RequiredHeader:
Authorization: Bearer $YOUR_TOKEN
Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
task_id | string | 是 | - | - | 任务id |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/imgenstd/result/aabbccdd' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
• 返回
名称 | 类型 | 描述 |
---|---|---|
state | string | 任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED |
state_message | string | 任务状态描述 |
task_id | string | 任务id |
images | list | 图片列表 |
-index | int | 序号, 0~7,与samples入参对应 |
-seed | int | 实际种子数,基于任务种子数 |
-small | string | 小图图片链接 |
-raw | string | 原图图片链接 |
-error_code | string | 错误枚举,Sensitive(生成的为敏感图), InternalError(内部错误), CallEngineError(内部错误:生成引擎调用), EngineGenError(内部错误:生图出错) |
• 示例
{
"state": "SUCCESS",
"state_message": "OK",
"task_id": "aabbccdd",
"images": [
{
"index": 0,
"small": "https://xxx.jpg",
"raw": "https://xxx.jpg",
"error_code": "",
}
]
}
5、批量查询任务结果接口
PATH: https://mhapi.sensetime.com/v1/imgenstd/results
Method: GET
RequiredHeader:
Authorization: Bearer $YOUR_TOKEN
Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
task_ids | list | 是 | - | - | 任务id列表,最多50条["id1", "id2", "id3"] |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/imgenstd/results' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
-d '{"task_ids": ["id1", "id2", ...]}'
• 返回
• 结构体类似任务结果获取接口
名称 | 类型 | 描述 |
---|---|---|
state | string | 任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED |
state_message | string | 任务状态描述 |
task_id | string | 任务id |
images | list | 图片列表 |
-index | int | 序号,0~7,与samples入参对应 |
-seed | int | 实际种子数,基于任务种子数 |
-small | string | 小图图片链接 |
-raw | string | 原图图片链接 |
-error_code | string | 错误枚举,Sensitive(生成的为敏感图), InternalError(内部错误), CallEngineError(内部错误:生成引擎调用), EngineGenError(内部错误:生图出错) |
• 示例
{
"results": [
{
"state": "SUCCESS",
"state_message": "OK",
"task_id": "aabbccdd",
"images": [
{
"index": 0,
"small": "https://xxx.jpg",
"raw": "https://xxx.jpg",
"error_code": "",
}
]
},
...
]
}
三、合拍换脸
1、客户端接入
客户端通过人脸识别和换脸接口实现人脸替换、合拍等效果
• 人脸识别: 通过人脸检测接口识别图片中的人脸坐标,底图和人脸图均可通过此接口识别
• 换脸: 通过换脸接口,将图片中的人脸替换。 人脸信息需要通过上述人脸识别接口获取
2、底图检测提交接口
- PATH:
https://mhapi.sensetime.com/v1/face/detect
• Method: POST
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 请求
名称 | 类型 | 必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
img_url | string | 是 | - | - | 图片URL,注意: • 必须是公开可访 • 目前仅支持256x256 ~6000x6000 px图片 • 目前仅支持jpg,jpeg,png,webp等常见格式 |
type | string | 否 | normal | normal anime | 检测类型,换脸提交接口如果使用“faceswap_v1”,则建议使用“normal”,支持通用图片人脸检测,如果使用“faceswap_yw”,则建议使用“anime”,支持二次元图片人脸检测。faceswap_v1、faceswap_yw为换脸模型的model_id。 |
• 示例
- curl --location --request POST 'https://mhapi.sensetime.com/v1/face/detect' \
- --header 'Authorization: Bearer $YOUR_TOKEN' \
- --header 'Content-Type: application/json' \
- --data-raw '{
- "img_url": "https://xxxx.jpg"
- }'
• 返回
- {
- "task_id": "string" // 任务id
- }
3、底图检测结果查询接口
• PATH: https://mhapi.sensetime.com/v1/face/detect/{task_id}
• Method: GET
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 返回
名称 | 类型 | 描述 |
---|---|---|
state | int | 任务状态 • 0:进行中 • 1:完成 |
faces | list | 人脸信息 |
- index | int | 编号,人脸识别接口获取 |
- coords | object | 坐标信息左上点坐标到右下点坐标,见示例 |
• 示例
-
curl --location --request GET 'https://mhapi.sensetime.com/v1/face/detect/aabbccdd' \
-
--header 'Authorization: Bearer $YOUR_TOKEN
4、模型查询接口
• PATH: https://mhapi.sensetime.com/v1/face/models
• Method: GET
• RequiredHeader:
• Authorization: Bearer
• Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
size | int | 否 | 10 | 1~100 | 最多返回多少个模型 |
offset | int | 否 | 0 | 0~Inf | 跳过多少记录 |
• 返回
名称 | 类型 | 描述 |
---|---|---|
have_next | bool | false表示已是最后一页 |
data | list | 模型数据 |
id | string | 模型唯一标识 |
name | string | 模型名称 |
description | string | 模型描述 |
• 示例
{
"have_next": false,
"data": [
{
"id": "xxxx",
"name": "xxxx",
"description": "xxxx",
}
]
}
5、换脸提交接口(异步)
5.1、任务接口提交
• PATH: https://mhapi.sensetime.com/v1/face/imggen
• Method: POST
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
•Content-Type: application/json
WARNING: 目前换脸接口最多支持换4张人脸
• 请求
名称 | 类型 | 必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
model_id | string | 是 | - | - | 模型ID |
base_img | object | 是 | - | - | 底图人脸信息,可通过“2、底图检测提交接口”识别 |
- url | string | 是 | - | - | 底图图片链接 • 必须是公开可访 • 目前仅支持256x256 ~6000x6000 px图片 • 目前仅支持jpg,jpeg,png,webp等常见格式,存储占用小于8MB。 |
faces | list | 是 | - | - | 需要换的人脸(参考脸)图片信息, • 必须是公开可访 • 目前仅支持256x256 ~6000x6000 px图片 • 目前仅支持jpg,jpeg,png,webp等常见格式,存储占用小于8MB。 • 目前最多支持置换4张人脸 |
• url | string | 是 | - | - | 人脸图片链接,必须是公开可访问的链接 |
• index | int | 是 | - | - | 编号,从0开始。参考图人脸的位置编号 |
• base_index | int | 是 | - | - | 编号,从0开始。底图目标人脸的位置编号。见base_img.faces.index |
dino_scale | double | 否 | 0.2 | [0-1.0] | 换脸相关,细粒度特征,越大越像参考脸,不建议大于0.4 |
guidance_scale | int | 否 | 30 | [10-100] | 换脸相关,越小越像参考脸 |
prompt | string | 否 | - | - | 添加额外提示词(utf-8编码),小于等于1000个字符(500个汉字) |
format | string | 否 | JPG | JPG,PNG | 出图格式 |
watermark_config | object | 否 | - | - | 水印相关配置 |
• type | string | 否 | Default | Default,MakaLogo | Default: 图片由 AI 生成 MakaLogo: 秒画的 logo |
• 示例
curl --location --request POST 'https://test.mhapi.sensetime.com/v1/face/imggen' \
--header 'Authorization: Bearer $YOUR_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
"base_img": { // 目标底图
"url": "xxx" // 图片URL
},
"faces": [ // 需要换的脸列表
{
"url": "xxx", // 图片URL
"index": 0, // 人脸编号
"base_index": 0 // 对应底图需要换脸的编号
}
]
}'
• 返回
{
"task_id": "string" // 任务id
}
5.2、换脸结果查询接口
• PATH: https://mhapi.sensetime.com/v1/face/imggen/{task_id}
• Method: GET
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 返回
名称 | 类型 | 描述 |
---|---|---|
state | int | 任务状态, 0:进行中, 1:完成 |
img_url | string | 生成结果图 |
img_raw_url | string | 生成结果图原图 |
• 示例
{
"task": {
"state": 1, // 任务状态(0:进行中,1:已完成)
"img_url": "string" // 结果图URL
"img_raw_url": "string"
}
}
6、任务接口提交(同步)
• PATH: https://mhapi.sensetime.com/v1/face/imggen_sync
• Method: POST
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
•Content-Type: application/json
WARNING: 目前换脸接口最多支持换4张人脸
• 请求
名称 | 类型 | 必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
model_id | string | 是 | - | - | 模型ID |
base_img | object | 是 | - | - | 底图人脸信息,可通过“2、底图检测提交接口”识别 |
- url | string | 是 | - | - | 底图图片链接 • 必须是公开可访 • 目前仅支持256x256 ~6000x6000 px图片 • 目前仅支持jpg,jpeg,png,webp等常见格式,存储占用小于8MB。 |
faces | list | 是 | - | - | 需要换的人脸(参考脸)图片信息, • 必须是公开可访 • 目前仅支持256x256 ~6000x6000 px图片 • 目前仅支持jpg,jpeg,png,webp等常见格式,存储占用小于8MB。 • 目前最多支持置换4张人脸 |
• url | string | 是 | - | - | 人脸图片链接,必须是公开可访问的链接 |
• index | int | 是 | - | - | 编号,从0开始。参考图人脸的位置编号 |
• base_index | int | 是 | - | - | 编号,从0开始。底图目标人脸的位置编号。见base_img.faces.index |
dino_scale | double | 否 | 0.2 | [0-1.0] | 换脸相关,细粒度特征,越大越像参考脸,不建议大于0.4 |
guidance_scale | int | 否 | 30 | [10-100] | 换脸相关,越小越像参考脸 |
prompt | string | 否 | - | - | 添加额外提示词(utf-8编码),小于等于1000个字符(500个汉字) |
format | string | 否 | JPG | JPG,PNG | 出图格式 |
watermark_config | object | 否 | - | - | 水印相关配置 |
• type | string | 否 | Default | Default,MakaLogo | Default: 图片由 AI 生成MakaLogo: 秒画的 logo |
• 示例
curl --location --request POST 'https://test.mhapi.sensetime.com/v1/face/imggen' \
--header 'Authorization: Bearer $YOUR_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
"model_id":"faceswap_**",
"base_img": { // 目标底图
"url": "xxx" // 图片URL
},
"faces": [ // 需要换的脸列表
{
"url": "xxx", // 图片URL
"index": 0, // 人脸编号
"base_index": 1 // 对应底图需要换脸的编号
]
}
}'
• 返回
{
"task": {
"state": 0,
"img_url": "",
"img_raw_url": "*"
}
}
四、擦除
1、模型查询接口
• PATH: https://mhapi.sensetime.com/v1/erase/models
• Method: GET
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
size | int | 否 | 10 | 1~100 | 最多返回多少个模型 |
offset | int | 否 | 0 | 0~Inf | 跳过多少记录 |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/erase/models?size=10&offset=0' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
• 返回
名称 | 类型 | 描述 |
---|---|---|
have_next | bool | false表示已是最后一页 |
data | list | 模型数据 |
• id | string | 模型唯一标识 |
• name | string | 模型名称 |
• description | string | 模型描述 |
• 示例
{
"have_next": false,
"data": [
{
"id": "xxxx",
"name": "xxxx",
"description": "xxxx"
}
]
}
2、擦除主体智能识别任务接口
• PATH: https://mhapi.sensetime.com/v1/erase/cutout
• Method: POST
• RequiredHeader:
• Authorization: Bearer
• Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
model_id | string | 是 | - | - | 模型唯一id |
img_url | string | 是 | - | - | "图生图的原图 --必须是公开可访 --目前仅支持256x256 ~6000x6000 px图片 --目前仅支持jpg,jpeg,png,webp,HEIF等常见格式" |
mask_img_url | string | 是 | - | - | "擦除位置的图片 --必须是公开可访 --目前仅支持256x256 ~6000x6000 px图片,需要与原图保持相同比例 --目前仅支持jpg,jpeg,png,webp,HEIF常见格式 --图片为黑白图,黑色是被擦除区域 ----黑色:rgb(0,0,0)/#000000 ----白色:rgb(255,255,255)/#FFFFFF ----示例: 示例图片" |
format | string | 否 | JPG | JPG PNG | 出图格式 |
watermark_config | object | 否 | - | - | 水印相关配置 |
-type | string | 否 | Default | Default MakaLogo | Default: 图片由 AI 生成 MakaLogo: 秒画的 logo |
mask_type | string | 否 | smear | smear box circle line point | 取值为:smear(智能涂抹)、box(框选)、circle(圈选)、line(划线)、point(点选) |
• 示例
curl -X POST 'https://mhapi.sensetime.com/v1/erase/imgen' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
-d '{"img_url": "https://xxxx.jpg", "model_id": "*****", "mask_img_url": "https://xxx.jpg"}'
• 返回
名称 | 类型 | 描述 |
---|---|---|
task_id | string | 任务id |
• 示例
{
"task_id": "aabbccdd"
}
3、提交擦除接口
• PATH: https://mhapi.sensetime.com/v1/erase/imgen
• Method: POST
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
model_id | string | 是 | - | - | 模型唯一id |
samples | int | 否 | 1 | 1~8 | 生成多少张图片 输出图片宽和高和输入图片的宽和高一致 |
img_url | string | 是 | - | - | 图生图的原图 • 必须是公开可访 • 目前仅支持256x256 ~6000x6000 px图片 • 目前仅支持jpg,jpeg,png,webp等常见格式,存储占用小于8MB。 |
mask_img_url | string | 是 | - | - | 擦除位置的图片 • 必须是公开可访 • 目前仅支持256x256 ~6000x6000 px图片,需要与原图保持相同比例 • 目前仅支持jpg,jpeg,png,webp常见格式 • 图片为黑白图,黑色是被擦除区域 • 黑色:rgb(0,0,0)/#000000 • 白色:rgb(255,255,255)/#FFFFFF • 示例: 示例图片 |
mask_type | string | 否 | free | free smear box circle line point | 取值为:free自由、smear(智能涂抹)、box(框选)、circle(圈选)、line(划线)、point(点选) |
format | string | 否 | JPG | JPG PNG | 出图格式 |
watermark_config | object | 否 | - | - | 水印相关配置 |
- type | string | 否 | Default | Default MakaLogo | Default: 图片由 AI 生成 MakaLogo: 秒画的 logo |
• 示例
curl -X POST 'https://mhapi.sensetime.com/v1/erase/imgen' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
-d '{"img_url": "https://xxxx.jpg", "model_id": "erase_v0.1", "mask_img_url": "https://xxx.jpg"}'
• 返回
名称 | 类型 | 描述 |
---|---|---|
task_id | string | 任务id |
• 示例
{
"task_id": "aabbccdd"
}
4、结果查询接口
• PATH: https://mhapi.sensetime.com/v1/erase/result/:id
• Method: GET
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
task_id | string | 是 | - | - | 任务id |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/erase/result/aabbccdd' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
• 返回
名称 | 类型 | 描述 |
---|---|---|
state | string | 任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED |
state_message | string | 任务状态描述 |
task_id | string | 任务id |
images | list | 图片列表 |
• index | int | 序号, 0~7,与samples入参对应 |
• seed | int | 实际种子数,基于任务种子数 |
• small | string | 小图图片链接 |
• raw | string | 原图图片链接 |
• error_code | string | 错误枚举,Sensitive(生成的为敏感图), InternalError(内部错误), CallEngineError(内部错误:生成引擎调用), EngineGenError(内部错误:生图出错) |
• 示例
{
"state": "SUCCESS",
"state_message": "OK",
"task_id": "aabbccdd",
"images": [
{
"index": 0,
"small": "https://xxx.jpg",
"raw": "https://xxx.jpg",
"error_code": "",
}
]
}
5、批量结果查询接口
• PATH: https://mhapi.sensetime.com/v1/erase/results
• Method: GET
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
task_ids | list | 是 | - | - | 任务id列表, 最多50条 ["id1", "id2", "id3"] |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/erase/results' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
-d '{"task_ids": ["id1", "id2", ...]}'
• 返回
结构体类似任务结果获取接口
名称 | 类型 | 描述 |
---|---|---|
state | string | 任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED |
state_message | string | 任务状态描述 |
task_id | string | 任务id |
images | list | 图片列表 |
- index | int | 序号, 0~7,与samples入参对应 |
- seed | int | 实际种子数,基于任务种子数 |
- small | string | 小图图片链接 |
- raw | string | 原图图片链接 |
- error_code | string | 错误枚举,Sensitive(生成的为敏感图), InternalError(内部错误), CallEngineError(内部错误:生成引擎调用), EngineGenError(内部错误:生图出错) |
• 示例
{
"results": [
{
"state": "SUCCESS",
"state_message": "OK",
"task_id": "aabbccdd",
"images": [
{
"index": 0,
"small": "https://xxx.jpg",
"raw": "https://xxx.jpg",
"error_code": "",
}
]
},
...
]
}
五、扩图
1、模型查询接口
• PATH: https://mhapi.sensetime.com/v1/outpaint/models
• Method: GET
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
size | int | 否 | 10 | 1~100 | 最多返回多少个模型 |
offset | int | 否 | 0 | 0~Inf | 跳过多少记录 |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/outpaint/models?size=10&offset=0' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
• 返回
名称 | 类型 | 描述 |
---|---|---|
have_next | bool | false表示已是最后一页 |
data | list | 模型数据 |
- id | string | 模型唯一标识 |
- name | string | 模型名称 |
- description | string | 模型描述 |
• 示例
{
"have_next": false,
"data": [
{
"id": "xxxx",
"name": "xxxx",
"description": "xxxx"
}
]
}
2、提交扩图接口
2.1、等比例扩图
• PATH: https://mhapi.sensetime.com/v1/outpaint/imgen
• Method: POST
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
model_id | string | 是 | - | - | 模型唯一id |
img_url | string | 是 | - | - | 图生图的原图 • 必须是公开可访 • 目前仅支持256x256 ~6000x6000 px图片 • 目前仅支持jpg,jpeg,png,webp等格式,存储占用小于8MB。 |
samples | int | 否 | 1 | 1~8 | 生成多少张图片 |
outpaint_ratio | float | 否 | 1.5 | (1.0,5.0] | 缩放比例,长、宽的倍数。 |
height | int | 否 | - | [640, 6000] | 生成图片的高度(单位:像素),默认为原图尺寸乘扩图倍数(像素按照四舍五入取整,如果大于6000,则最长边为6000),长宽比和原图比例一致,允许偏差在1%以内 。 |
width | int | 否 | - | [640, 6000] | 生成图片的宽度(单位:像素),默认为原图尺寸乘扩图倍数(像素按照四舍五入取整,如果大于6000,则最长边为6000),长宽比和原图比例一致,允许偏差在1%以内 。 |
align_position 或者type | string | 否 | middle | topleft, topmiddle, topright, middleleft, middle, middleright, bottomleft, bottommiddle, bottomright | 原图位置 |
format | string | 否 | JPG | JPG,PNG | 出图格式 |
watermark_config | object | 否 | - | - | 水印相关配置 |
• type | string | 否 | Default | Default,MakaLogo | Default: 图片由 AI 生成 MakaLogo: 秒画的 logo |
• 示例
curl -X POST 'https://mhapi.sensetime.com/v1/outpaint/imgen' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
-d '{"model_id": "$MODEL_ID", "img_url": "https://xxx.jpg"}'
• 返回
名称 | 类型 | 描述 |
---|---|---|
task_id | string | 任务id |
• 示例
{
"task_id": "aabbccdd"
}
2.2、自由尺寸扩图
提交自由扩图
• PATH: https://mhapi.sensetime.com/v1/outpaint/imgen_free
• Method: POST
• RequiredHeader:
• Authorization: Bearer
• Content-Type: application/json
• 请求
名称 | 类型 | 必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
model_id | string | 是 | - | - | 模型ID |
img_url | string | 是 | - | - | "原图地址 -图片格式必须为JPEG/JPG、PNG、TIFF、WEBP、HEIF -像素值必须大于等于256256,小于60006000,大小不超过8MB。" |
samples | int | 否 | 1 | [1-8] | 生成图片数量 |
height | Int | 是 | - | [640, 6000] | 生成图片的高,需要大于原图的高度加上“free_y”。需要是64的倍数(如不是8的倍数,则忽略余数) |
width | int | 是 | - | [640, 6000] | 生成图片的宽,需要大于原图的高度加上“free_x”。需要是64的倍数(如不是8的倍数,则忽略余数) |
free_x | Int | 否 | 0 | [0,6000] | 在扩图区域,“原图左上角的位置”相对“扩图区域左上角(坐标0,0)”的X轴像素数值,free_x需要是8的倍数(如不是8的倍数,则忽略余数) |
free_y | int | 否 | 0 | [0,6000] | 在扩图区域,“原图左上角的位置”相对“扩图区域左上角(坐标0,0)”的Y轴像素数值,free_y需要是8的倍数(如不是8的倍数,则忽略余数) |
format | string | 否 | JPG | JPG,PNG | 出图格式 |
watermark_config | object | 否 | - | - | 生成图片的显形水印 |
-type | string | 否 | Default | "Default MakaLogo" | "Default: 图片由 AI 生成 MakaLogo: 秒画的 logo" |
• 示例
curl -X POST 'https://mhapi.sensetime.com/v1/outpaint/imgen_free' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
-d '{"model_id": "$MODEL_ID", "img_url": "https://xxx.jpg","height":1000, "width":1000}'
3、结果查询接口
• PATH: https://mhapi.sensetime.com/v1/outpaint/result/:id
• Method: GET
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
task_id | string | 是 | - | - | 任务id |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/outpaint/result/aabbccdd' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
• 返回
名称 | 类型 | 描述 |
---|---|---|
state | string | 任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED |
state_message | string | 任务状态描述 |
task_id | string | 任务id |
images | list | 图片列表 |
- index | int | 序号, 0~7,与samples入参对应 |
- seed | int | 实际种子数,基于任务种子数 |
- small | string | 小图图片链接 |
- raw | string | 原图图片链接 |
- error_code | string | 错误枚举,Sensitive(生成的为敏感图), InternalError(内部错误), CallEngineError(内部错误:生成引擎调用), EngineGenError(内部错误:生图出错) |
• 示例
{
"state": "SUCCESS",
"state_message": "OK",
"task_id": "aabbccdd",
"images": [
{
"index": 0,
"seed": 2341451345,
"small": "https://xxx.jpg",
"raw": "https://xxx.jpg",
"error_code": "",
}
]
}
4、批量结果查询接口
• PATH: https://mhapi.sensetime.com/v1/outpaint/results
• Method: GET
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
task_ids | list | 是 | - | - | 任务id列表,最多50条 ["id1", "id2", "id3"] |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/outpaint/results' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
-d '{"task_ids": ["id1", "id2", ...]}'
• 返回
结构体类似任务结果获取接口
名称 | 类型 | 描述 |
---|---|---|
state | string | 任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED |
state_message | string | 任务状态描述 |
task_id | string | 任务id |
images | list | 图片列表 |
- index | int | 序号, 0~7,与samples入参对应 |
- seed | int | 实际种子数,基于任务种子数 |
- small | string | 小图图片链接 |
- raw | string | 原图图片链接 |
- error_code | string | 错误枚举,Sensitive(生成的为敏感图), InternalError(内部错误), CallEngineError(内部错误:生成引擎调用), EngineGenError(内部错误:生图出错) |
• 示例
{
"results": [
{
"state": "SUCCESS",
"state_message": "OK",
"task_id": "aabbccdd",
"images": [
{
"index": 0,
"seed": 2341451345,
"small": "https://xxx.jpg",
"raw": "https://xxx.jpg",
"error_code": "",
}
]
},
...
]
}
六、风格化
1、模型查询接口
• PATH: https://mhapi.sensetime.com/v1/stylization/models
• Method: GET
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
size | int | 否 | 10 | 1~100 | 最多返回多少个模型 |
offset | int | 否 | 0 | 0~Inf | 跳过多少记录 |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/stylization/models?size=10&offset=0' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
• 返回
名称 | 类型 | 描述 |
---|---|---|
have_next | bool | false表示已是最后一页 |
data | list | 模型数据 |
• id | string | 模型唯一标识 |
• name | string | 模型名称 |
• description | string | 模型描述 |
• 示例
{
"have_next": false,
"data": [
{
"id": "xxxx",
"name": "xxxx",
"description": "xxxx"
}
]
}
2、生图接口(异步)
2.1、异步生图接口
• PATH: https://mhapi.sensetime.com/v1/stylization/imgen
• Method: POST
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
samples | int | 否 | 1 | 1~8 | 生成多少张图片 |
height | int | 否 | - | [640,6000] | 出图像素-高度 • 默认原尺寸 • height和width比例必须与原图比例一致 • height和width需要同时传入 |
width | int | 否 | - | [640,6000] | 出图像素-宽度 • 默认原尺寸 • height和width比例必须与原图比例一致 • height和width需要同时传入 |
model_id | string | 是 | - | - | 模型唯一id |
format | string | 否 | JPG | JPG,PNG | 出图格式 |
img_url | string | 是 | - | - | 图生图的原图 • 必须是公开可访 • 目前仅支持256x256 ~6000x6000 px图片 • 目前仅支持jpg,jpeg,png,webp格式,存储占用小于8MB。 |
img_base64 | string | 否 | - | - | 图生图的原图base64编码后数据 • 当img_url为空时,使用img_base64 • 大小限制7MB • 支持Data URL Scheme规范的数据: • data:image/xxxx;base64,xxxxxx • 也兼容对文件进行base64编码的数据 • 目前仅支持256x256 ~6000x6000 px图片 • 目前仅支持jpg,jpeg,png,webp格式 |
watermark_config | object | 否 | - | - | 水印相关配置 |
- type | string | 否 | Default | Default,MakaLogo | Default: 图片由 AI 生成 MakaLogo: 秒画的 logo |
• 示例
curl -X POST 'https://mhapi.sensetime.com/v1/stylization/imgen' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
-d '{"model_id": "$MODEL_ID", "img_url": "https://xxx.jpg"}'
• 返回
名称 | 类型 | 描述 |
---|---|---|
task_id | string | 任务id |
• 示例
{
"task_id": "aabbccdd"
}
2.2、生图结果查询接口
• PATH:https://mhapi.sensetime.com/v1/stylization/result/:id?get_type=url
• Method: GET
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
task_id | string | 是 | - | - | 任务id |
get_type | string | 否 | url | url, base64 | 数据返回的方式 - url指返回值的raw、small字段内容为生成图片的url(有效期) - base64指返回值的raw、small字段内容为生成图片的base64编码数据 - 使用Data URL Scheme规范 - 即data:image/xxxx;base64,xxxxxx格式 |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/stylization/result/aabbccdd' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
• 返回
名称 | 类型 | 描述 |
---|---|---|
state | string | 任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED |
state_message | string | 任务状态描述 |
task_id | string | 任务id |
images | list | 图片列表 |
• index | int | 序号, 0~7,与samples入参对应 |
• seed | int | 实际种子数,基于任务种子数 |
• small | string | 小图图片: • 入参get_type=url时,这里是图片链接 • 入参get_type=base64时,这里是图片base64编码结果 |
• raw | string | 大图图片: • 入参get_type=url时,这里是图片链接 • 入参get_type=base64时,这里是图片base64编码结果 |
• error_code | string | 错误枚举,Sensitive(生成的为敏感图), InternalError(内部错误), CallEngineError(内部错误:生成引擎调用), EngineGenError(内部错误:生图出错) |
• 示例
{
"state": "SUCCESS",
"state_message": "OK",
"task_id": "aabbccdd",
"images": [
{
"index": 0,
"seed": 2341451345,
"small": "https://xxx.jpg",
"raw": "https://xxx.jpg",
"error_code": "",
}
]
}
2.3、批量结果查询接口
• PATH: https://mhapi.sensetime.com/v1/stylization/results
• Method: GET
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
task_ids | list | 是 | - | - | 任务id列表, 最多50条,如下 ["id1", "id2", "id3"] |
get_type | string | 否 | url | url, base64 | 数据返回的方式 • url指返回值的raw、small字段内容为生成图片的url • base64指返回值的raw、small字段内容为生成图片的base64编码数据 • 使用Data URL Scheme规范 • 即data:image/xxxx;base64,xxxxxx格式 |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/stylization/results' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
-d '{"task_ids": ["id1", "id2", ...]}'
• 返回
结构体类似任务结果获取接口
名称 | 类型 | 描述 |
---|---|---|
state | string | 任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED |
state_message | string | 任务状态描述 |
task_id | string | 任务id |
images | list | 图片列表 |
• index | int | 序号, 0~7,与samples入参对应 |
• seed | int | 实际种子数,基于任务种子数 |
• small | string | 小图图片: • 入参get_type=url时,这里是图片链接 • 入参get_type=base64时,这里是图片base64编码结果 |
• raw | string | 大图图片: • 入参get_type=url时,这里是图片链接 • 入参get_type=base64时,这里是图片base64编码结果 |
• error_code | string | 错误枚举,Sensitive(生成的为敏感图), InternalError(内部错误), CallEngineError(内部错误:生成引擎调用), EngineGenError(内部错误:生图出错) |
• 示例
{
"results": [
{
"state": "SUCCESS",
"state_message": "OK",
"task_id": "aabbccdd",
"images": [
{
"index": 0,
"seed": 2341451345,
"small": "https://xxx.jpg",
"raw": "https://xxx.jpg",
"error_code": "",
}
]
},
...
]
}
3、生图接口(同步)
• PATH: https://mhapi.sensetime.com/v1/stylization/imgen_sync
• Method: POST
• RequiredHeader:
• Authorization: Bearer
•Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
samples | int | 否 | 1 | 1~8 | 生成多少张图片 |
height | int | 否 | - | [640,6000] | 出图像素-高度: 默认原尺寸 height和width比例必须与原图比例一致 |
width | int | 否 | - | [640,6000] | "出图像素-宽度: 默认原尺寸 height和width比例必须与原图比例一致" |
model_id | string | 是 | - | - | 模型唯一id |
format | string | 否 | JPG | JPG,PNG | 出图格式 |
img_url | string | 否 | - | - | 图生图的原图 img_url优先于img_base64 必须是公开可访 目前仅支持256x256 ~6000x6000 px图片 目前仅支持jpg,jpeg,png,webp 格式 |
img_base64 | string | 否 | - | - | 图生图的原图base64编码后数据 当img_url为空时,使用img_base64 大小限制7MB 支持Data URL Scheme规范的数据:data:image/xxxx;base64,xxxxxx 兼容对文件进行base64编码的数据 目前仅支持256x256 ~6000x6000 px图片 目前仅支持jpg,jpeg,png,webp格式 |
get_type | string | 否 | url | url, base64 | "数据返回的方式 url指返回值的raw、small字段内容为生成图片的url base64指返回值的raw、small字段内容为生成图片的base64编码数据 使用Data URL Scheme规范 即data:image/xxxx;base64,xxxxxx格式" |
watermark_config | object | 否 | - | - | 水印相关配置 |
type | string | 否 | Default | Default,MakaLogo | "Default: 图片由 AI 生成 MakaLogo:秒画的 logo" |
• 示例
curl -X POST 'https://mhapi.sensetime.com/v1/stylization/imgen_sync' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
-d '{"model_id": "$MODEL_ID", "img_url": "https://xxx.jpg"}'
• 返回
error | struct | 接口失败时,error结构体不为空 |
---|---|---|
code | int | 错误码 |
message | string | 错误描述 |
details | list of string | 错误详细信息 |
state | string | 任务状态:SUCCESS |
task_id | string | 任务id |
images | list | 图片列表 |
index | int | 序号, 0~7,与samples入参对应 |
small | string | "小图图片: 入参get_type=url时,这里是图片链接 入参get_type=base64时,这里是图片base64编码结果" |
raw | string | 大图图片: 入参get_type=url时,这里是图片链接 入参get_type=base64时,这里是图片base64编码结果 |
error_code | string | 错误枚举,Sensitive(生成的为敏感图), InternalError(内部错误), CallEngineError(内部错误:生成引擎调用), EngineGenError(内部错误:生图出错) |
• 示例
成功:
{
"state": "SUCCESS",
"task_id": "b03d5a4f-21f9-4d56-9a4d-899f576dd4cf",
"images": [
{
"index": 0,
"raw": "https://xxxx",
"small": "https://xxxx",
"error_code": ""
},
{
"index": 1,
"raw": "https://xxxx",
"small": "https://xxxx",
"error_code": ""
}
]
}
失败:
{
"error": {
"code": 3,
"message": "Invalid Params",
"details": [
"trace_id:c77cd9220637ca07353489e1882e9b65"
]
}
}
七、局部重绘
1、模型查询接口
• PATH: https://mhapi.sensetime.com/v1/inpaint/models
• Method: GET
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
size | int | 否 | 10 | 1~100 | 最多返回多少个模型 |
offset | int | 否 | 0 | 0~Inf | 跳过多少记录 |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/inpaint/models?size=10&offset=10' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
• 返回
名称 | 类型 | 描述 |
---|---|---|
have_next | bool | false表示已是最后一页 |
data | list | 模型数据 |
id | string | 模型唯一标识 |
name | string | 模型名称 |
description | string | 模型描述 |
• 示例
{
"have_next": false,
"data": [
{
"id": "xxxx",
"name": "xxxx",
"description": "xxxx",
"base_model_type": "minixl",
"model_type": "LORA",
"trigger_words": ""
}
]
}
2、提交局部重绘
• PATH: https://mhapi.sensetime.com/v1/inpaint/imgen
• Method: POST
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
model_id | string | 是 | - | - | 模型唯一id |
samples | int | 否 | 1 | 1~8 | 生成多少张图片 输出图片宽和高和输入图片的宽和高一致 |
img_url | string | 是 | - | - | 必须是公开可访 目前仅支持256x256 ~6000x6000 px图片 目前仅支持jpg,jpeg,png,webp等常见格式 |
mask_img_url | string | 是 | - | - | 局部重绘的位置图片 必须是公开可访 目前仅支持256x256 ~6000x6000 px图片,需要与原图保持相同比例 目前仅支持jpg,jpeg,png,webp常见格式 图片为黑白图,黑色是被局部重绘区域 黑色:rgb(0,0,0)/#000000 白色:rgb(255,255,255)/#FFFFFF 示例: 示例图片 |
format | string | 否 | JPG | JPG,PNG | 出图格式 |
prompt | string | 是 | 正向提示词(utf-8编码),小于等于2000个字符(1000个汉字) | ||
force_translation | bool | 否 | false | true, false | true强制开启翻译prompt、neg_prompt, false采取默认行为(默认翻译) |
add_prompt | bool | 否 | false | true, false | 是否开启prompt补词 |
neg_prompt | string | 否 | 反向提示词(utf-8编码),小于等于2000个字符(1000个汉字) | ||
repaint_strength | float | 否 | 1 | [0.1, 1] | 局部绘制程度,值越大重绘幅度越大 |
cfg_scale | float | 否 | 8.0 | [1,20] | 提示文本的控制力度(数字越大,生成的图片跟提示词相关性越强) |
seed | int | 否 | 0 | [0, 9999999) | 随机数种子,0代表随机,一个种子对应一张图,如果传递的值为x,需要生成4张图,则4张结果的种子数分别为x,x+1、x+2、x+3 |
steps | int | 否 | 30 | (0,70] | 要运行的扩散步骤数 |
watermark_config | object | 否 | - | - | 水印相关配置 |
type | string | 否 | Default | Default,MakaLogo | "Default: 图片由 AI 生成 MakaLogo: 秒画的 logo" |
• 示例
curl -X POST 'https://mhapi.sensetime.com/v1/inpaint/imgen' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
-d '{"img_url": "https://xxxx.jpg", "model_id": "inpaint_v0.1", "mask_img_url": "https://xxx.jpg", "prompt": "苹果"}'
• 返回
名称 | 类型 | 描述 |
---|---|---|
task_id | string | 任务id |
• 示例
{
"task_id": "aabbccdd"
}
3.结果查询
PATH: https://mhapi.sensetime.com/v1/inpaint/result/:id
Method: GET
RequiredHeader:
Authorization: Bearer $YOUR_TOKEN
Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
task_id | string | 是 | - | - | 任务id |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/inpaint/result/aabbccdd' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
• 返回
名称 | 类型 | 描述 |
---|---|---|
state | string | 任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED |
state_message | string | 任务状态描述 |
task_id | string | 任务id |
images | list | 图片列表 |
index | int | 序号, 0~7,与samples入参对应 |
seed | int | 实际种子数,基于任务种子数 |
small | string | 小图图片链接 |
raw | string | 原图图片链接 |
error_code | string | 错误枚举,Sensitive(生成的为敏感图), InternalError(内部错误), CallEngineError(内部错误:生成引擎调用), EngineGenError(内部错误:生图出错) |
• 示例
{
"state": "SUCCESS",
"state_message": "OK",
"task_id": "aabbccdd",
"images": [
{
"index": 0,
"small": "https://xxx.jpg",
"raw": "https://xxx.jpg",
"error_code": "",
}
]
}
4、批量结果查询
• PATH: https://mhapi.sensetime.com/v1/inpaint/results
• Method: GET
• RequiredHeader:
• Authorization: Bearer $YOUR_TOKEN
• Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
task_ids | list | 是 | - | - | 任务id列表, 最多50条["id1", "id2", "id3"] |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/inpaint/results' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
-d '{"task_ids": ["id1", "id2", ...]}'
• 返回
结构体类似任务结果获取接口
名称 | 类型 | 描述 |
---|---|---|
state | string | 任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED |
state_message | string | 任务状态描述 |
task_id | string | 任务id |
images | list | 图片列表 |
index | int | 序号, 0~7,与samples入参对应 |
seed | int | 实际种子数,基于任务种子数 |
small | string | 小图图片链接 |
raw | string | 原图图片链接 |
error_code | string | 错误枚举,Sensitive(生成的为敏感图), InternalError(内部错误), CallEngineError(内部错误:生成引擎调用), EngineGenError(内部错误:生图出错) |
• 示例
{
"results": [
{
"state": "SUCCESS",
"state_message": "OK",
"task_id": "aabbccdd",
"images": [
{
"index": 0,
"small": "https://xxx.jpg",
"raw": "https://xxx.jpg",
"error_code": "",
}
]
},
...
]
}
八、超分
1、模型查询接口
• PATH: https://mhapi.sensetime.com/v1/sup_res/models
• Method: GET
• RequiredHeader:
Authorization: Bearer $YOUR_TOKEN
Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
size | int | 否 | 10 | 1~100 | 最多返回多少个模型 |
offset | int | 否 | 0 | 0~Inf | 跳过多少记录 |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/sup_res/models?size=10&offset=10' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
• 返回
名称 | 类型 | 描述 |
---|---|---|
have_next | bool | false表示已是最后一页 |
data | list | 模型数据 |
id | string | 模型唯一标识 |
name | string | 模型名称 |
description | string | 模型描述 |
• 示例
{
"have_next": false,
"data": [
{
"id": "xxxx",
"name": "xxxx",
"description": "xxxx",
"base_model_type": "minixl",
"model_type": "LORA",
"trigger_words": ""
}
]
}
2、提交超分接口
• PATH: https://mhapi.sensetime.com/v1/sup_res/imgen
• Method: POST
• RequiredHeader:
- Authorization: Bearer $YOUR_TOKEN
- Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
model_id | string | 是 | - | - | 模型唯一id |
img_url | string | 是 | - | - | "必须是公开可访 目前仅支持256x256 ~2000x2000 px图片 目前仅支持jpg,jpeg,png,webp,HEIF等常见格式” |
hd_ratio | float | 否 | 1.5 | (1.0,3.0] | 分辨率放大倍数,原始分辨率*倍数,不超过6000(通过输入尺寸限制) |
format | string | 否 | JPG | JPG,PNG | 出图格式 |
watermark_config | object | 否 | - | - | 水印相关配置 |
type | string | 否 | Default | Default,MakaLogo | "Default: 图片由 AI 生成 MakaLogo: 秒画的 logo" |
• 示例
curl -X POST 'https://mhapi.sensetime.com/v1/sup_res/imgen' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
-d '{"img_url": "https://xxxx.jpg", "model_id": "super_resolution_v1" }'
• 返回
名称 | 类型 | 描述 |
---|---|---|
task_id | string | 任务id |
• 示例
{
"task_id": "aabbccdd"
}
3、结果查询
• PATH: https://mhapi.sensetime.com/v1/sup_res/result/:id
• Method: GET
• RequiredHeader:
- Authorization: Bearer $YOUR_TOKEN
- Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 默认值 | 描述 |
---|---|---|---|---|---|
task_id | string | 是 | - | - | 任务id |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/sup_res/result/aabbccdd' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
• 返回
名称 | 类型 | 描述 |
---|---|---|
state | string | 任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED |
state_message | string | 任务状态描述 |
task_id | string | 任务id |
images | list | 图片列表 |
index | int | 序号, 0~7,与samples入参对应 |
seed | int | 实际种子数,基于任务种子数 |
small | string | 小图图片链接 |
raw | string | 原图图片链接 |
error_code | string | 错误枚举,Sensitive(生成的为敏感图), InternalError(内部错误), CallEngineError(内部错误:生成引擎调用), EngineGenError(内部错误:生图出错) |
• 示例
{
"state": "SUCCESS",
"state_message": "OK",
"task_id": "aabbccdd",
"images": [
{
"index": 0,
"small": "https://xxx.jpg",
"raw": "https://xxx.jpg",
"error_code": "",
}
]
}
4、批量结果查询
• PATH: https://mhapi.sensetime.com/v1/sup_res/results
• Method: GET
• RequiredHeader:
- Authorization: Bearer $YOUR_TOKEN
- Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
task_ids | list | 是 | - | - | 任务id列表, 最多50条["id1", "id2", "id3"] |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/sup_res/results' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
-d '{"task_ids": ["id1", "id2", ...]}'
• 返回
结构体类似任务结果获取接口
名称 | 类型 | 描述 |
---|---|---|
state | string | 任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED |
state_message | string | 任务状态描述 |
task_id | string | 任务id |
images | list | 图片列表 |
index | int | 序号, 0~7,与samples入参对应 |
seed | int | 实际种子数,基于任务种子数 |
small | string | 小图图片链接 |
raw | string | 原图图片链接 |
error_code | string | 错误枚举,Sensitive(生成的为敏感图), InternalError(内部错误), CallEngineError(内部错误:生成引擎调用), EngineGenError(内部错误:生图出错) |
• 示例
{
"results": [
{
"state": "SUCCESS",
"state_message": "OK",
"task_id": "aabbccdd",
"images": [
{
"index": 0,
"small": "https://xxx.jpg",
"raw": "https://xxx.jpg",
"error_code": "",
}
]
},
...
]
}
九、图像分割
1、模型查询接口
• PATH: https://mhapi.sensetime.com/v1/split/models
• Method: GET
• RequiredHeader:
Authorization: Bearer $YOUR_TOKEN
Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
size | int | 否 | 10 | 1~100 | 最多返回多少个模型 |
offset | int | 否 | 0 | 0~Inf | 跳过多少记录 |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/split/models?size=10&offset=10' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
• 返回
名称 | 类型 | 描述 |
---|---|---|
have_next | bool | false表示已是最后一页 |
data | list | 模型数据 |
id | string | 模型唯一标识 |
name | string | 模型名称 |
description | string | 模型描述 |
• 示例
{
"have_next": false,
"data": [
{
"id": "xxxx",
"name": "xxxx",
"description": "xxxx",
"base_model_type": "minixl",
"model_type": "LORA",
"trigger_words": ""
}
]
}
2、提交分割接口
• PATH: https://mhapi.sensetime.com/v1/split/imgen
• Method: POST
• RequiredHeader:
- Authorization: Bearer $YOUR_TOKEN
- Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 可选值 |
---|---|---|---|---|---|
model_id | string | 是 | - | - | 模型唯一id |
img_url | string | 是 | - | - | "必须是公开可访 目前仅支持256x256 ~2000x2000 px图片 目前仅支持jpg,jpeg,png,webp,HEIF等常见格式” |
hd_ratio | string | 否 | 1.5 | (1.0,3.0] | 分辨率放大倍数,原始分辨率*倍数,不超过6000(通过输入尺寸限制) |
format | string | 否 | PNG | JPG,PNG | "出图格式(JPG不带透明通道)" |
• 示例
yamlcurl -X POST 'https://mhapi.sensetime.com/v1/split/imgen' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
-d '{"img_url": "https://xxxx.jpg", "model_id": "super_resolution_v1" }'
• 返回
名称 | 类型 | 描述 |
---|---|---|
task_id | string | 任务id |
• 示例
{
"task_id": "aabbccdd"
}
3、结果查询
• PATH: https://mhapi.sensetime.com/v1/split/result/:id
• Method: GET
• RequiredHeader:
- Authorization: Bearer $YOUR_TOKEN
- Content-Type: application/json
• 请求
名称 | 名称 | 是否必须 | 默认值 | 默认值 | 描述 |
---|---|---|---|---|---|
task_id | string | 是 | - | - | 任务id |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/split/result/aabbccdd' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
• 返回
名称 | 类型 | 描述 |
---|---|---|
state | string | 任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED |
state_message | string | 任务状态描述 |
task_id | string | 任务id |
images | list | 图片列表 |
index | int | 序号, 0~7,与samples入参对应 |
seed | int | 实际种子数,基于任务种子数 |
small | string | 小图图片链接 |
raw | string | 原图图片链接 |
error_code | string | 错误枚举,Sensitive(生成的为敏感图), InternalError(内部错误), CallEngineError(内部错误:生成引擎调用), EngineGenError(内部错误:生图出错) |
• 示例
{
"state": "SUCCESS",
"state_message": "OK",
"task_id": "aabbccdd",
"images": [
{
"index": 0,
"small": "https://xxx.jpg",
"raw": "https://xxx.jpg",
"error_code": "",
}
]
}
4、批量结果查询
• PATH: https://mhapi.sensetime.com/v1/sup_res/results
• Method: GET
• RequiredHeader:
- Authorization: Bearer $YOUR_TOKEN
- Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
task_ids | list | 是 | - | - | 任务id列表, 最多50条["id1", "id2", "id3"] |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/sup_res/results' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'
-d '{"task_ids": ["id1", "id2", ...]}'
• 返回
结构体类似任务结果获取接口
名称 | 类型 | 描述 |
---|---|---|
state | string | 任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED |
state_message | string | 任务状态描述 |
task_id | string | 任务id |
images | list | 图片列表 |
index | int | 序号, 0~7,与samples入参对应 |
seed | int | 实际种子数,基于任务种子数 |
small | string | 小图图片链接 |
raw | string | 原图图片链接 |
error_code | string | 错误枚举,Sensitive(生成的为敏感图), InternalError(内部错误), CallEngineError(内部错误:生成引擎调用), EngineGenError(内部错误:生图出错) |
• 示例
{
"results": [
{
"state": "SUCCESS",
"state_message": "OK",
"task_id": "aabbccdd",
"images": [
{
"index": 0,
"small": "https://xxx.jpg",
"raw": "https://xxx.jpg",
"error_code": "",
}
]
},
...
]
}
十、Lora训练
1、模型查询接口
获取模型列表接口
• PATH: https://mhapi.sensetime.com/v1/lora/models
• Method: GET
• Required Header:
- Authorization: Bearer
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
size | int | 否 | 10 | 1~100 | 最多返回多少个模型 |
offset | int | 否 | 0 | 0~Inf | 跳过多少记录 |
type | string | 否 | Checkpoint | LORACheckpoint |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/lora/models?size=10&offset=10' \
-H 'Authorization: Bearer $YOUR_TOKEN'
• 返回
名称 | 类型 | 描述 |
---|---|---|
have_next | bool | false表示已是最后一页 |
data | list | 模型数据 |
id | string | 模型唯一标识 |
name | string | 模型名称 |
description | string | 模型描述 |
base_model_type | string | 基模类型, 如mini1.5、artist_v1.0。默认空 |
model_type | string | 模型类型,如Checkpoint, LORA。默认空 |
trigger_words | string | 触发词,如 "机甲"。默认空 |
• 示例
{
"have_next": false,
"data": [
{
"id": "cq71d1kq0d02r73hadf0",
"name": "blindbox/大概是盲盒_blindbox_v1_mix",
"description": "多样化可爱盲盒风格",
"base_model_type": "mini1.5",
"model_type": "Checkpoint",
"trigger_word": ""
}
]
}
2、创建训练
提交接口
• PATH: https://mhapi.sensetime.com/v1/lora/train
• Method: POST
• RequiredHeader:
-
- Authorization: Bearer
-
- Content-Type: application/json
• 请求
• 参数说明
名称 | 类型 | 必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
base_model_id | string | 是 | - | - | 微调需要的基模型ID |
model_name | string | 否 | - | - | 微调模型名称,长度不超过64个字符 |
description | string | 否 | - | - | 微调模型描述,长度不超过1024个字符 |
trigger_word | string | 否 | - | - | 触发词,长度不超过256个字符 |
main_object | string | 否 | Human | [Human, Style] | 模型固化的特征来自于图片的哪个对象,目前只支持Human,Style可以为空*注意,若为Human,数据集中的图片必须包含人像,否则会报错。 |
task_type | string | 否 | NORMAL | NORMAL, VIP | 任务类型,VIP任务优先训练。 |
images | string | 是 | - | - | 请填充多个url地址或者key(参考图片上传接口),总共不能超过1000张不重复的图片 |
• 示例
curl -X POST 'https://mhapi.sensetime.com/v1/lora/models' \
-H 'Authorization: Bearer $YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"base_model_id": "required_base_model_id",
"model_name": "My Custom Model",
"description": "This is a custom model for specific style training",
"trigger_word": "custom_style",
"main_object": "Human",
"task_type": "NORMAL",
"images": [
"https://example.com/image1.jpg",
"https://example.com/image2.jpg"
]
}'
• 返回
名称 | 类型 | 描述 |
---|---|---|
task_id | string | 任务id |
• 示例
{
"task_id": "aabbccdd"
}
3、查询lora 训练进度
查询任务结果接口
• PATH: https://mhapi.sensetime.com/v1/lora/result/:task_id
• Method: GET
• RequiredHeader:
Authorization: Bearer
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
task_id | string | 是 | - | - | 任务id,在提交生图的返回结果中 |
• 示例
curl -X GET 'https://mhapi.sensetime.com/v1/lora/result/aabbccdd' \
-H 'Authorization: Bearer $YOUR_TOKEN'
• 返回
名称 | 类型 | 描述 |
---|---|---|
state | string | 任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED |
state_message | string | 任务状态描述 |
task_id | string | 任务id |
lora_id | string | 微调模型ID。微调后模型的model_id |
training_progress | float | 0未开始, 1 代表完成 |
• 示例
{
"state": "RUNNING",
"state_msg": "Images were not avaliable for main object 'Human', pleases update your images or choose another main object",
"task_id": "a92904f2-bd23-11ef-8356-acde48001122",
"lora_id": "******",
"training_progress": 0
}
批量查询任务结果接口
• PATH: https://mhapi.sensetime.com/v1/lora/results
• Method: GET
• RequiredHeader:
Authorization: Bearer
Content-Type: application/json
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
task_ids | list | 是 | - | - | 任务id列表, 最多50条["id1", "id2", "id3"] |
• 示例
curl --location --request GET 'https://localhost:8888/v1/lora/results' \
--header 'Authorization: Bearer ******' \
--header 'Content-Type: application/json' \
--data-raw '{
"task_ids":["45edaf16-b835-11ef-ab6c-acde48001122"]
}'
• 返回
• 结构体类似任务结果获取接口
名称 | 类型 | 描述 |
---|---|---|
state | string | 任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED |
state_message | string | 任务状态描述 |
task_id | string | 任务id |
lora_id | string | 微调模型ID。微调后模型的model_id |
training_progress | float | 0未开始, 1 代表完成 |
• 示例
{
"results": [
{
"state": "DONE",
"state_msg": "",
"task_id": "45edaf16-b835-11ef-ab6c-acde48001122",
"lora_id": "****",
"training_progress": 1
}
]
}
4、取消lora
• 接口
• PATH: https://mhapi.sensetime.com/v1/lora/cancel
• Method: POST
• RequiredHeader:
Authorization: Bearer
• 请求
名称 | 类型 | 是否必须 | 默认值 | 可选值 | 描述 |
---|---|---|---|---|---|
task_id | string | 是 | - | - | 任务id,在提交生图的返回结果中,等待状态才能被取消 |
• 示例
curl --location --request POST 'https://localhost:8888/v1/lora/cancel' \
--header 'Authorization: Bearer ****' \
--header 'Content-Type: application/json' \
--data-raw '{
"task_id": "1dc017e3-b84f-11ef-be2e-626427c3b172"
}'
• 返回
名称 | 类型 | 描述 |
---|---|---|
success | bool | 是否成功 |
• 示例
{
"success": true
}
十一、错误码整理
1、错误信息结构体
{
"error":{
"code": 0, //错误码
"message": "string", //错误信息
"details": [] //错误细节
}
}
2、错误码
code | 解释 | 报错原因 |
---|---|---|
1 | 取消调用 | 客户端取消调用; |
2 | 内部错误 | 服务器内部错误; |
3 | 参数无效 | 请求的参数名不对; 请求的参数值不符合校验规则; 调用超时输入/输出触发敏感词; |
4 | 调用超时 | 服务器内部超时; |
5 | 资源无效 | 请求的资源是无效的; |
6 | 资源冲突 | 请求的资源是重复的; |
7 | 没有权限 | 账户没有访问对应资源权限; |
8 | 超出限制 | 请求的速度太快; 请求的资源数量超过限制; |
9 | 请求失败 | 请求无法在当前系统状态下执行; |
10 | 并发冲突 | 并发冲突,例如读取/修改/写入错误; |
11 | 范围无效 | 请求指定的范围无效; |
12 | 未实现 | 请求的方法/功能未实现; |
13 | 内部错误 | 服务器内部错误; |
14 | 内部错误 | 服务器内部错误; |
15 | 内部错误 | 服务器内部错误; |
16 | 鉴权失败 | 请求的API鉴权信息不正确,可能是令牌错误,或者生成的 YOUR_TOKEN 过期; |
18 | 触发敏感词 | 触发敏感词导致任务失败 |
409 | 网站试用限制 | 上一个任务正在处理,请等待 |
429 | 网站试用限制 | 已达到每日使用上限,请尝试申请API调用 |
503 | 网站试用限制 | 超时或服务异常 |