首页 > 产品服务 > API服务 > 文档中心

文档中心
融合模态模型
实时交互融合模态模型
文生图模型
拟人对话模型
文生图模型
本文自2024年10月29日起生效

一、权限认证

1、Token获取

基于AKSK的用户权限校验,具体如下


2.1 请求头(Request Header)

在请求头里,添加 Authorization 字段,如下所示:


python
("Authorization: Bearer $YOUR_TOKEN")

2.2 Authorization 生成方式

遵循JWT(Json Web Token, RFC 7519)标准。

JWT由三个部分组成:HeaderPayloadSignature

• JWT Header 的构建方式

{"typ":"JWT","alg":"HS256"}手动生成JWT,JWT Header中alg填写HS256

• JWT Payload 的构建方式

名称类型必须描述
issStringAK(Access Key ID,获取方式请参考使用手册-“获取访问密钥”)
expInteger超时时间(Unix时间戳,单位秒)
nbfInteger生效时间(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

• 请求

名称类型是否必须默认值可选值描述
sizeint01~100最多返回多少个模型
offsetint00~Inf跳过多少记录
mtpstringALLLORA, 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_nextboolfalse表示已是最后一页
datalist模型数据
• idstring模型唯一标识
• namestring模型名称
• descriptionstring模型描述

• 示例


{
  "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


名称类型是否必须默认值可选值描述
sizeint101~100最多返回多少个模型
offsetint00~Inf跳过多少记录

• 请求示例


curl -X GET 'https://mhapi.sensetime.com/v1/imgenstd/model_cn/xxxxxx' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'

• 返回

名称类型描述
have_nextboolfalse表示已是最后一页
datalistcn数据
• cnstring唯一标识,比如 canny
• namestringcn名称
• descriptionstringcn描述

• 示例


{
  "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_idstring--模型唯一id
promptstring--正向提示词(utf-8编码),小于等于2000个字符(1000个汉字)
force_translationboolfalsetrue, falsetrue强制开启翻译prompt、neg_prompt, false采取默认行为。(V1.0/V0.6.0默认不翻译,其它默认翻译)
add_promptboolfalsetrue, false是否开启prompt补词
neg_promptstring--反向提示词(utf-8编码),小于等于2000个字符(1000个汉字)
cfg_scalefloat7[1,20]提示文本的控制力度(数字越大,生成的图片跟提示词相关性越强)
samplesint1[1,8]生成图片数量
heightint960[640, 6000]生成图片的高度(单位:像素)
widthint960[640, 6000]生成图片的宽度(单位:像素)
seedint0[0, 99999999)随机数种子,0代表随机,一个种子对应一张图,如果传递的值为x,需要生成4张图,则4张结果的种子数分别为x,x+1、x+2、x+3
stepsint30(0,70]要运行的扩散步骤数
formatstringJPGEnum: JPG, PNG生成图片的格式
img_urlstring--图生图的原图必须是公开可访目前仅支持256x256 ~6000x6000 px图片目前仅支持jpg,jpeg,png,webp等常见格式,存储占用小于8MB。
image_strengthfloat0.6[0, 1]参考图片的控制力度(数字越大,自由发挥度越大)
watermark_configobject--生成图片的水印
- typestringDefaultDefault MakaLogoDefault: 图片由 AI 生成 MakaLogo: 秒画的 logo
controlnet_configsobject[]--controlnet 的配置,最多可以同时使用三个controlnet模型
- typestring-"canny depth ip2p lineart lineart_anime mlsd normal openpose scribble shuffle softedge tile seg brightness reference_only ip_adapter_faceid""cn 类型 Enum(见表下方)"
- img_urlstring--cn模型的输入参考图片,oss地址,必须是公开可访目前仅支持256x256 ~6000x6000 px图片目前仅支持jpg,jpeg,png,webp等常见格式,存储占用小于8MB。
- weightfloat1(0, 2]cn模型的控制权重
- pre_processorstring--cn的预处理器,不同的cn模型可选值不一样,有的cn模型没有预处理器(见表下方)
- guidance_startfloat0[0, 1]ControlNet开始参与生图的步数
- guidance_endfloat1[0, 1]ControlNet结束参与生图的步数
- canny_low_thresholdint100[1, 255]Canny类型内部参数,低阈值,数值越低线条越复杂,数值越高线条越简单
- canny_high_thresholdint200[1, 255]Canny类型内部参数,高阈值,数值越低线条越复杂,数值越高线条越简单
- tile_down_sample_ratefloat1[1, 8]Tile类型内部参数,下采样率
lora_configsobject[]--微调模型使用此配置
- model_idstring--微调模型的 model.id;lora_configs.model_id和model_id 必须是基于同一个底模生成
- merge_weightfloat1(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_faceidIP迁移:保留原图人脸的五官等特征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_idstring任务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_idstring--任务id

• 示例


curl -X GET 'https://mhapi.sensetime.com/v1/imgenstd/result/aabbccdd' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'

• 返回

名称类型描述
statestring任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED
state_messagestring任务状态描述
task_idstring任务id
imageslist图片列表
-indexint序号, 0~7,与samples入参对应
-seedint实际种子数,基于任务种子数
-smallstring小图图片链接
-rawstring原图图片链接
-error_codestring错误枚举,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_idslist--任务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", ...]}'

• 返回

• 结构体类似任务结果获取接口


名称类型描述
statestring任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED
state_messagestring任务状态描述
task_idstring任务id
imageslist图片列表
-indexint序号,0~7,与samples入参对应
-seedint实际种子数,基于任务种子数
-smallstring小图图片链接
-rawstring原图图片链接
-error_codestring错误枚举,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_urlstring--图片URL,注意:
• 必须是公开可访
• 目前仅支持256x256 ~6000x6000 px图片
• 目前仅支持jpg,jpeg,png,webp等常见格式
typestringnormalnormal anime检测类型,换脸提交接口如果使用“faceswap_v1”,则建议使用“normal”,支持通用图片人脸检测,如果使用“faceswap_yw”,则建议使用“anime”,支持二次元图片人脸检测。faceswap_v1、faceswap_yw为换脸模型的model_id。

• 示例


  1. curl --location --request POST 'https://mhapi.sensetime.com/v1/face/detect' \
  2. --header 'Authorization: Bearer $YOUR_TOKEN' \
  3. --header 'Content-Type: application/json' \
  4. --data-raw '{
  5. "img_url": "https://xxxx.jpg"
  6. }'

• 返回


  1. {
  2. "task_id": "string" // 任务id
  3. }

3、底图检测结果查询接口


• PATH: https://mhapi.sensetime.com/v1/face/detect/{task_id}

• Method: GET

• RequiredHeader:

Authorization: Bearer $YOUR_TOKEN

Content-Type: application/json


• 返回

名称类型描述
stateint任务状态
• 0:进行中
• 1:完成
faceslist人脸信息
- indexint编号,人脸识别接口获取
- coordsobject坐标信息左上点坐标到右下点坐标,见示例

• 示例


  1. curl --location --request GET 'https://mhapi.sensetime.com/v1/face/detect/aabbccdd' \

  2. --header 'Authorization: Bearer $YOUR_TOKEN


4、模型查询接口


• PATH: https://mhapi.sensetime.com/v1/face/models

• Method: GET

• RequiredHeader:

Authorization: Bearer

Content-Type: application/json


• 请求

名称类型是否必须默认值可选值描述
sizeint101~100最多返回多少个模型
offsetint00~Inf跳过多少记录

• 返回

名称类型描述
have_nextboolfalse表示已是最后一页
datalist模型数据
idstring模型唯一标识
namestring模型名称
descriptionstring模型描述

• 示例


{
  "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_idstring--模型ID
base_imgobject--底图人脸信息,可通过“2、底图检测提交接口”识别
- urlstring--底图图片链接
• 必须是公开可访
• 目前仅支持256x256 ~6000x6000 px图片
• 目前仅支持jpg,jpeg,png,webp等常见格式,存储占用小于8MB。
faceslist--需要换的人脸(参考脸)图片信息,
• 必须是公开可访
• 目前仅支持256x256 ~6000x6000 px图片
• 目前仅支持jpg,jpeg,png,webp等常见格式,存储占用小于8MB。
• 目前最多支持置换4张人脸
• urlstring--人脸图片链接,必须是公开可访问的链接
• indexint--编号,从0开始。参考图人脸的位置编号
• base_indexint--编号,从0开始。底图目标人脸的位置编号。见base_img.faces.index
dino_scaledouble0.2[0-1.0]换脸相关,细粒度特征,越大越像参考脸,不建议大于0.4
guidance_scaleint30[10-100]换脸相关,越小越像参考脸
promptstring--添加额外提示词(utf-8编码),小于等于1000个字符(500个汉字)
formatstringJPGJPG,PNG出图格式
watermark_configobject--水印相关配置
• typestringDefaultDefault,MakaLogoDefault: 图片由 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


• 返回

名称类型描述
stateint任务状态, 0:进行中, 1:完成
img_urlstring生成结果图
img_raw_urlstring生成结果图原图

• 示例


{
   "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_idstring--模型ID
base_imgobject--底图人脸信息,可通过“2、底图检测提交接口”识别
- urlstring--底图图片链接
• 必须是公开可访
• 目前仅支持256x256 ~6000x6000 px图片
• 目前仅支持jpg,jpeg,png,webp等常见格式,存储占用小于8MB。
faceslist--需要换的人脸(参考脸)图片信息,
• 必须是公开可访
• 目前仅支持256x256 ~6000x6000 px图片
• 目前仅支持jpg,jpeg,png,webp等常见格式,存储占用小于8MB。
• 目前最多支持置换4张人脸
• urlstring--人脸图片链接,必须是公开可访问的链接
• indexint--编号,从0开始。参考图人脸的位置编号
• base_indexint--编号,从0开始。底图目标人脸的位置编号。见base_img.faces.index
dino_scaledouble0.2[0-1.0]换脸相关,细粒度特征,越大越像参考脸,不建议大于0.4
guidance_scaleint30[10-100]换脸相关,越小越像参考脸
promptstring--添加额外提示词(utf-8编码),小于等于1000个字符(500个汉字)
formatstringJPGJPG,PNG出图格式
watermark_configobject--水印相关配置
• typestringDefaultDefault,MakaLogoDefault: 图片由 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


• 请求

名称类型是否必须默认值可选值描述
sizeint101~100最多返回多少个模型
offsetint00~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_nextboolfalse表示已是最后一页
datalist模型数据
• idstring模型唯一标识
• namestring模型名称
• descriptionstring模型描述

• 示例


{
  "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_idstring--模型唯一id
img_urlstring--"图生图的原图
--必须是公开可访
--目前仅支持256x256 ~6000x6000 px图片
--目前仅支持jpg,jpeg,png,webp,HEIF等常见格式"
mask_img_urlstring--"擦除位置的图片
--必须是公开可访
--目前仅支持256x256 ~6000x6000 px图片,需要与原图保持相同比例
--目前仅支持jpg,jpeg,png,webp,HEIF常见格式
--图片为黑白图,黑色是被擦除区域
----黑色:rgb(0,0,0)/#000000
----白色:rgb(255,255,255)/#FFFFFF
----示例: 示例图片"
formatstringJPGJPG
PNG
出图格式
watermark_configobject--水印相关配置
-typestringDefaultDefault
MakaLogo
Default: 图片由 AI 生成
MakaLogo: 秒画的 logo
mask_typestringsmearsmear
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_idstring任务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_idstring--模型唯一id
samplesint11~8生成多少张图片
输出图片宽和高和输入图片的宽和高一致
img_urlstring--图生图的原图
• 必须是公开可访
• 目前仅支持256x256 ~6000x6000 px图片
• 目前仅支持jpg,jpeg,png,webp等常见格式,存储占用小于8MB。
mask_img_urlstring--擦除位置的图片
• 必须是公开可访
• 目前仅支持256x256 ~6000x6000 px图片,需要与原图保持相同比例
• 目前仅支持jpg,jpeg,png,webp常见格式
• 图片为黑白图,黑色是被擦除区域
• 黑色:rgb(0,0,0)/#000000
• 白色:rgb(255,255,255)/#FFFFFF
• 示例: 示例图片
mask_typestringfreefree
smear
box
circle
line
point
取值为:free自由、smear(智能涂抹)、box(框选)、circle(圈选)、line(划线)、point(点选)
formatstringJPGJPG
PNG
出图格式
watermark_configobject--水印相关配置
- typestringDefaultDefault
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_idstring任务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_idstring--任务id

• 示例


curl -X GET 'https://mhapi.sensetime.com/v1/erase/result/aabbccdd' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'

• 返回

名称类型描述
statestring任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED
state_messagestring任务状态描述
task_idstring任务id
imageslist图片列表
• indexint序号, 0~7,与samples入参对应
• seedint实际种子数,基于任务种子数
• smallstring小图图片链接
• rawstring原图图片链接
• error_codestring错误枚举,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_idslist--任务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", ...]}'

• 返回


结构体类似任务结果获取接口

名称类型描述
statestring任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED
state_messagestring任务状态描述
task_idstring任务id
imageslist图片列表
- indexint序号, 0~7,与samples入参对应
- seedint实际种子数,基于任务种子数
- smallstring小图图片链接
- rawstring原图图片链接
- error_codestring错误枚举,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

• 请求

名称类型是否必须默认值可选值描述
sizeint101~100最多返回多少个模型
offsetint00~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_nextboolfalse表示已是最后一页
datalist模型数据
- idstring模型唯一标识
- namestring模型名称
- descriptionstring模型描述

• 示例


{
  "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_idstring--模型唯一id
img_urlstring--图生图的原图
• 必须是公开可访
• 目前仅支持256x256 ~6000x6000 px图片
• 目前仅支持jpg,jpeg,png,webp等格式,存储占用小于8MB。
samplesint11~8生成多少张图片
outpaint_ratiofloat1.5(1.0,5.0]缩放比例,长、宽的倍数。
heightint-[640, 6000]生成图片的高度(单位:像素),默认为原图尺寸乘扩图倍数(像素按照四舍五入取整,如果大于6000,则最长边为6000),长宽比和原图比例一致,允许偏差在1%以内 。
widthint-[640, 6000]生成图片的宽度(单位:像素),默认为原图尺寸乘扩图倍数(像素按照四舍五入取整,如果大于6000,则最长边为6000),长宽比和原图比例一致,允许偏差在1%以内 。
align_position 或者typestringmiddletopleft,
topmiddle,
topright,
middleleft,
middle,
middleright,
bottomleft,
bottommiddle,
bottomright
原图位置
formatstringJPGJPG,PNG出图格式
watermark_configobject--水印相关配置
• typestringDefaultDefault,MakaLogoDefault: 图片由 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_idstring任务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_idstring--模型ID
img_urlstring--"原图地址
-图片格式必须为JPEG/JPG、PNG、TIFF、WEBP、HEIF
-像素值必须大于等于256256,小于60006000,大小不超过8MB。"
samplesint1[1-8]生成图片数量
heightInt-[640, 6000]生成图片的高,需要大于原图的高度加上“free_y”。需要是64的倍数(如不是8的倍数,则忽略余数)
widthint-[640, 6000]生成图片的宽,需要大于原图的高度加上“free_x”。需要是64的倍数(如不是8的倍数,则忽略余数)
free_xInt0[0,6000]在扩图区域,“原图左上角的位置”相对“扩图区域左上角(坐标0,0)”的X轴像素数值,free_x需要是8的倍数(如不是8的倍数,则忽略余数)
free_yint0[0,6000]在扩图区域,“原图左上角的位置”相对“扩图区域左上角(坐标0,0)”的Y轴像素数值,free_y需要是8的倍数(如不是8的倍数,则忽略余数)
formatstringJPGJPG,PNG出图格式
watermark_configobject--生成图片的显形水印
-typestringDefault"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_idstring--任务id

• 示例


curl -X GET 'https://mhapi.sensetime.com/v1/outpaint/result/aabbccdd' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'

• 返回

名称类型描述
statestring任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED
state_messagestring任务状态描述
task_idstring任务id
imageslist图片列表
- indexint序号, 0~7,与samples入参对应
- seedint实际种子数,基于任务种子数
- smallstring小图图片链接
- rawstring原图图片链接
- error_codestring错误枚举,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_idslist--任务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", ...]}'

• 返回


结构体类似任务结果获取接口

名称类型描述
statestring任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED
state_messagestring任务状态描述
task_idstring任务id
imageslist图片列表
- indexint序号, 0~7,与samples入参对应
- seedint实际种子数,基于任务种子数
- smallstring小图图片链接
- rawstring原图图片链接
- error_codestring错误枚举,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


• 请求

名称类型是否必须默认值可选值描述
sizeint101~100最多返回多少个模型
offsetint00~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_nextboolfalse表示已是最后一页
datalist模型数据
• idstring模型唯一标识
• namestring模型名称
• descriptionstring模型描述

• 示例


{
  "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


• 请求

名称类型是否必须默认值可选值描述
samplesint11~8生成多少张图片
heightint-[640,6000]出图像素-高度
• 默认原尺寸
• height和width比例必须与原图比例一致
• height和width需要同时传入
widthint-[640,6000]出图像素-宽度
• 默认原尺寸
• height和width比例必须与原图比例一致
• height和width需要同时传入
model_idstring--模型唯一id
formatstringJPGJPG,PNG出图格式
img_urlstring--图生图的原图
• 必须是公开可访
• 目前仅支持256x256 ~6000x6000 px图片
• 目前仅支持jpg,jpeg,png,webp格式,存储占用小于8MB。
img_base64string--图生图的原图base64编码后数据
• 当img_url为空时,使用img_base64
• 大小限制7MB
• 支持Data URL Scheme规范的数据:
• data:image/xxxx;base64,xxxxxx
• 也兼容对文件进行base64编码的数据
• 目前仅支持256x256 ~6000x6000 px图片
• 目前仅支持jpg,jpeg,png,webp格式
watermark_configobject--水印相关配置
- typestringDefaultDefault,MakaLogoDefault: 图片由 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_idstring任务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_idstring--任务id
get_typestringurlurl, 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'

• 返回

名称类型描述
statestring任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED
state_messagestring任务状态描述
task_idstring任务id
imageslist图片列表
• indexint序号, 0~7,与samples入参对应
• seedint实际种子数,基于任务种子数
• smallstring小图图片:
• 入参get_type=url时,这里是图片链接
• 入参get_type=base64时,这里是图片base64编码结果
• rawstring大图图片:
• 入参get_type=url时,这里是图片链接
• 入参get_type=base64时,这里是图片base64编码结果
• error_codestring错误枚举,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_idslist--任务id列表, 最多50条,如下
["id1", "id2", "id3"]
get_typestringurlurl, 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", ...]}'

• 返回


结构体类似任务结果获取接口

名称类型描述
statestring任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED
state_messagestring任务状态描述
task_idstring任务id
imageslist图片列表
• indexint序号, 0~7,与samples入参对应
• seedint实际种子数,基于任务种子数
• smallstring小图图片:
• 入参get_type=url时,这里是图片链接
• 入参get_type=base64时,这里是图片base64编码结果
• rawstring大图图片:
• 入参get_type=url时,这里是图片链接
• 入参get_type=base64时,这里是图片base64编码结果
• error_codestring错误枚举,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


• 请求

名称类型是否必须默认值可选值描述
samplesint11~8生成多少张图片
heightint-[640,6000]出图像素-高度:
默认原尺寸
height和width比例必须与原图比例一致
widthint-[640,6000]"出图像素-宽度:
默认原尺寸
height和width比例必须与原图比例一致"
model_idstring--模型唯一id
formatstringJPGJPG,PNG出图格式
img_urlstring--图生图的原图
img_url优先于img_base64
必须是公开可访
目前仅支持256x256 ~6000x6000 px图片
目前仅支持jpg,jpeg,png,webp 格式
img_base64string--图生图的原图base64编码后数据
当img_url为空时,使用img_base64
大小限制7MB
支持Data URL Scheme规范的数据:data:image/xxxx;base64,xxxxxx
兼容对文件进行base64编码的数据
目前仅支持256x256 ~6000x6000 px图片
目前仅支持jpg,jpeg,png,webp格式
get_typestringurlurl, base64"数据返回的方式
url指返回值的raw、small字段内容为生成图片的url
base64指返回值的raw、small字段内容为生成图片的base64编码数据
使用Data URL Scheme规范
即data:image/xxxx;base64,xxxxxx格式"
watermark_configobject--水印相关配置
typestringDefaultDefault,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"}'

• 返回

errorstruct接口失败时,error结构体不为空
codeint错误码
messagestring错误描述
detailslist of string错误详细信息
statestring任务状态:SUCCESS
task_idstring任务id
imageslist图片列表
indexint序号, 0~7,与samples入参对应
smallstring"小图图片:
入参get_type=url时,这里是图片链接
入参get_type=base64时,这里是图片base64编码结果"
rawstring大图图片:
入参get_type=url时,这里是图片链接
入参get_type=base64时,这里是图片base64编码结果
error_codestring错误枚举,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


• 请求


名称类型是否必须默认值可选值描述
sizeint101~100最多返回多少个模型
offsetint00~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_nextboolfalse表示已是最后一页
datalist模型数据
idstring模型唯一标识
namestring模型名称
descriptionstring模型描述

• 示例


{
  "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_idstring--模型唯一id
samplesint11~8生成多少张图片
输出图片宽和高和输入图片的宽和高一致
img_urlstring--必须是公开可访
目前仅支持256x256 ~6000x6000 px图片
目前仅支持jpg,jpeg,png,webp等常见格式
mask_img_urlstring--局部重绘的位置图片
必须是公开可访
目前仅支持256x256 ~6000x6000 px图片,需要与原图保持相同比例
目前仅支持jpg,jpeg,png,webp常见格式
图片为黑白图,黑色是被局部重绘区域
黑色:rgb(0,0,0)/#000000
白色:rgb(255,255,255)/#FFFFFF
示例: 示例图片
formatstringJPGJPG,PNG出图格式
promptstring正向提示词(utf-8编码),小于等于2000个字符(1000个汉字)
force_translationboolfalsetrue, falsetrue强制开启翻译prompt、neg_prompt, false采取默认行为(默认翻译)
add_promptboolfalsetrue, false是否开启prompt补词
neg_promptstring反向提示词(utf-8编码),小于等于2000个字符(1000个汉字)
repaint_strengthfloat1[0.1, 1]局部绘制程度,值越大重绘幅度越大
cfg_scalefloat8.0[1,20]提示文本的控制力度(数字越大,生成的图片跟提示词相关性越强)
seedint0[0, 9999999)随机数种子,0代表随机,一个种子对应一张图,如果传递的值为x,需要生成4张图,则4张结果的种子数分别为x,x+1、x+2、x+3
stepsint30(0,70]要运行的扩散步骤数
watermark_configobject--水印相关配置
typestringDefaultDefault,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_idstring任务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_idstring--任务id

• 示例


curl -X GET 'https://mhapi.sensetime.com/v1/inpaint/result/aabbccdd' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'

• 返回


名称类型描述
statestring任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED
state_messagestring任务状态描述
task_idstring任务id
imageslist图片列表
indexint序号, 0~7,与samples入参对应
seedint实际种子数,基于任务种子数
smallstring小图图片链接
rawstring原图图片链接
error_codestring错误枚举,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_idslist--任务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", ...]}'

• 返回


结构体类似任务结果获取接口

名称类型描述
statestring任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED
state_messagestring任务状态描述
task_idstring任务id
imageslist图片列表
indexint序号, 0~7,与samples入参对应
seedint实际种子数,基于任务种子数
smallstring小图图片链接
rawstring原图图片链接
error_codestring错误枚举,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
• 请求

名称类型是否必须默认值可选值描述
sizeint101~100最多返回多少个模型
offsetint00~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_nextboolfalse表示已是最后一页
datalist模型数据
idstring模型唯一标识
namestring模型名称
descriptionstring模型描述

• 示例


{
  "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:

  1. Authorization: Bearer $YOUR_TOKEN
  2. Content-Type: application/json

• 请求

名称类型是否必须默认值可选值描述
model_idstring--模型唯一id
img_urlstring--"必须是公开可访
目前仅支持256x256 ~2000x2000 px图片
目前仅支持jpg,jpeg,png,webp,HEIF等常见格式”
hd_ratiofloat1.5(1.0,3.0]分辨率放大倍数,原始分辨率*倍数,不超过6000(通过输入尺寸限制)
formatstringJPGJPG,PNG出图格式
watermark_configobject--水印相关配置
typestringDefaultDefault,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_idstring任务id

• 示例


{
  "task_id": "aabbccdd"
}

3、结果查询

• PATH: https://mhapi.sensetime.com/v1/sup_res/result/:id
• Method: GET
• RequiredHeader:

  1. Authorization: Bearer $YOUR_TOKEN
  2. Content-Type: application/json

• 请求

名称类型是否必须默认值默认值描述
task_idstring--任务id

• 示例


curl -X GET 'https://mhapi.sensetime.com/v1/sup_res/result/aabbccdd' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'

• 返回

名称类型描述
statestring任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED
state_messagestring任务状态描述
task_idstring任务id
imageslist图片列表
indexint序号, 0~7,与samples入参对应
seedint实际种子数,基于任务种子数
smallstring小图图片链接
rawstring原图图片链接
error_codestring错误枚举,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:

  1. Authorization: Bearer $YOUR_TOKEN
  2. Content-Type: application/json

• 请求

名称类型是否必须默认值可选值描述
task_idslist--任务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", ...]}'

• 返回
结构体类似任务结果获取接口

名称类型描述
statestring任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED
state_messagestring任务状态描述
task_idstring任务id
imageslist图片列表
indexint序号, 0~7,与samples入参对应
seedint实际种子数,基于任务种子数
smallstring小图图片链接
rawstring原图图片链接
error_codestring错误枚举,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
• 请求

名称类型是否必须默认值可选值描述
sizeint101~100最多返回多少个模型
offsetint00~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_nextboolfalse表示已是最后一页
datalist模型数据
idstring模型唯一标识
namestring模型名称
descriptionstring模型描述

• 示例


{
  "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:

  1. Authorization: Bearer $YOUR_TOKEN
  2. Content-Type: application/json

• 请求

名称类型是否必须默认值可选值可选值
model_idstring--模型唯一id
img_urlstring--"必须是公开可访
目前仅支持256x256 ~2000x2000 px图片
目前仅支持jpg,jpeg,png,webp,HEIF等常见格式”
hd_ratiostring1.5(1.0,3.0]分辨率放大倍数,原始分辨率*倍数,不超过6000(通过输入尺寸限制)
formatstringPNGJPG,PNG"出图格式(JPG不带透明通道)"

• 示例


yaml
curl -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_idstring任务id

• 示例


{
  "task_id": "aabbccdd"
}

3、结果查询

• PATH: https://mhapi.sensetime.com/v1/split/result/:id
• Method: GET
• RequiredHeader:

  1. Authorization: Bearer $YOUR_TOKEN
  2. Content-Type: application/json

• 请求

名称名称是否必须默认值默认值描述
task_idstring--任务id

• 示例


curl -X GET 'https://mhapi.sensetime.com/v1/split/result/aabbccdd' \
-H 'Authorization: Bearer $YOUR_TOKEN'
-H 'Content-Type: application/json'

• 返回

名称类型描述
statestring任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED
state_messagestring任务状态描述
task_idstring任务id
imageslist图片列表
indexint序号, 0~7,与samples入参对应
seedint实际种子数,基于任务种子数
smallstring小图图片链接
rawstring原图图片链接
error_codestring错误枚举,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:

  1. Authorization: Bearer $YOUR_TOKEN
  2. Content-Type: application/json

• 请求

名称类型是否必须默认值可选值描述
task_idslist--任务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", ...]}'

• 返回
结构体类似任务结果获取接口

名称类型描述
statestring任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED
state_messagestring任务状态描述
task_idstring任务id
imageslist图片列表
indexint序号, 0~7,与samples入参对应
seedint实际种子数,基于任务种子数
smallstring小图图片链接
rawstring原图图片链接
error_codestring错误枚举,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:

  1. Authorization: Bearer

• 请求

名称类型是否必须默认值可选值描述
sizeint101~100最多返回多少个模型
offsetint00~Inf跳过多少记录
typestringCheckpointLORACheckpoint

• 示例


curl -X GET 'https://mhapi.sensetime.com/v1/lora/models?size=10&offset=10' \
-H 'Authorization: Bearer $YOUR_TOKEN'

• 返回

名称类型描述
have_nextboolfalse表示已是最后一页
datalist模型数据
idstring模型唯一标识
namestring模型名称
descriptionstring模型描述
base_model_typestring基模类型, 如mini1.5、artist_v1.0。默认空
model_typestring模型类型,如Checkpoint, LORA。默认空
trigger_wordsstring触发词,如 "机甲"。默认空

• 示例


{
    "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_idstring--微调需要的基模型ID
model_namestring--微调模型名称,长度不超过64个字符
descriptionstring--微调模型描述,长度不超过1024个字符
trigger_wordstring--触发词,长度不超过256个字符
main_objectstringHuman[Human, Style]模型固化的特征来自于图片的哪个对象,目前只支持Human,Style可以为空*注意,若为Human,数据集中的图片必须包含人像,否则会报错。
task_typestringNORMALNORMAL, VIP任务类型,VIP任务优先训练。
imagesstring--请填充多个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_idstring任务id

• 示例


{
  "task_id": "aabbccdd"
}

3、查询lora 训练进度

查询任务结果接口
• PATH: https://mhapi.sensetime.com/v1/lora/result/:task_id
• Method: GET
• RequiredHeader:
Authorization: Bearer


• 请求

名称类型是否必须默认值可选值描述
task_idstring--任务id,在提交生图的返回结果中

• 示例


curl -X GET 'https://mhapi.sensetime.com/v1/lora/result/aabbccdd' \
-H 'Authorization: Bearer $YOUR_TOKEN'

• 返回

名称类型描述
statestring任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED
state_messagestring任务状态描述
task_idstring任务id
lora_idstring微调模型ID。微调后模型的model_id
training_progressfloat0未开始, 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_idslist--任务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"]
}'

• 返回
• 结构体类似任务结果获取接口


名称类型描述
statestring任务状态,枚举:PENDING, RUNNING, SUCCESS, FAILED
state_messagestring任务状态描述
task_idstring任务id
lora_idstring微调模型ID。微调后模型的model_id
training_progressfloat0未开始, 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_idstring--任务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"
}'

• 返回

名称类型描述
successbool是否成功

• 示例


{
    "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网站试用限制超时或服务异常