API 参考

Aitubo 的 API 文档

概述

本文档描述了如何使用代码来实现与 Web 上相同的结果。 之后文档将只给出相对地址 API,您需要将其拼凑到主域名: https://api.aitubo.ai.

例如,如果要创建作业,您需要调用 https://api.aitubo.ai/api/job/create

该文档分为两部分,第一部分是示例,第二部分是特定 API。

示例

本节描述了如何创建作业和获取作业。 我们的用于创建作业的 API 提供了三个核心功能: Text2Image, Image2Image, and ControlNet(ControlNet 是一个神经网络结构,通过添加额外条件来控制扩散模型)。

无论您使用哪三个功能,首先您都必须获取我们支持的模型列表,然后在创建作业时,您需要传入 id 模型信息的字段

curl --request GET \
  --url 'https://api.aitubo.ai/api/model/list?type=platform' \
  --header 'Authorization: Bearer ced695cfd83811eda5e286850d1dc848'

结果是这样的:

{
    "code": 0,
    "data": {
        "domain": "https://file.aitubo.ai/",
        "total": 10,
        "models": [
            {
                "id": "6426f9c60ca4651b98b91a6d",
                "name": "ConceptCanvas",
                "username": "Aitubo",
                "desc": "A model that creates concept scenes with a European thick paint or CG style.",
                "cover": "assets/model/6426f9c60ca4651b98b91a6d/cover.jpg",
                "isFavourite": false,
                "controlNet": false
            },
            {
                "id": "642b977d2f2842537c09fe41",
                "name": "DreamShaper",
                "username": "Aitubo",
                "desc": "A model that can generate multiple styles of scenes, characters, and game assets.",
                "cover": "assets/model/642b977d2f2842537c09fe41/cover.jpg",
                "isFavourite": false,
                "controlNet": true
            },
            ...
        ]
    }
}

1. Text2Image

curl --request POST \
  --url https://api.aitubo.ai/api/job/create \
  --header 'Authorization: Bearer ced695cfd83811eda5e286850d1dc848' \
  --header 'content-type: application/json' \
  --data '{
    "prompt": "A cat sleeps on the plane",
    "modelId": "642b977d2f2842537c09fe41"
}

然后,您将获得这样的响应:

{
  "code": 0,
  "data": {
    "consumedCredit": 40,
    "credit": 120,
    "id": "64351e4d567bcd86773dc841"
  }
}

您可以通过轮询来检查任务创建的状态。 每张照片大约需要 2 秒钟才能完成,因此请控制您的查询频率。 最后,您将得到这样的结果:

{
  "code": 0,
  "data": {
    "id": "64351e4d567bcd86773dc841",
    "args": {
      "prompt": "A cat sleeps on the plane",
      "negativePrompt": "lowres, bad anatomy, cropped, worst quality, low quality",
      "strength": 0.8,
      "width": 512,
      "height": 512,
      "count": 4,
      "steps": 30,
      "modelId": "642b977d2f2842537c09fe41"
    },
    "result": {
      "info": "Warning: some images may contain NSFW content",
      "data": {
        "images": [
          "images/art/640076a4661aa1c0f81ba2d7/cgqhsljj5mf00080001g.png",
          "images/art/640076a4661aa1c0f81ba2d7/cgqhsljj5mf000800020.png",
          "images/art/640076a4661aa1c0f81ba2d7/cgqhsljj5mf00080002g.png",
          "images/art/640076a4661aa1c0f81ba2d7/cgqhsljj5mf000800030.png"
        ],
        "artIds": [
          "64351e56567bcd86773dc842",
          "64351e56567bcd86773dc843",
          "64351e56567bcd86773dc844",
          "64351e56567bcd86773dc845"
        ],
        "domain": "https://file.aitubo.ai/"
      }
    },
    "status": 2,
    "createAt": "2023-04-11T08:46:05.55Z"
  }
}

2. Image2Image

要使用 Image2Image,您可以调用我们的 上传图片 API 获取图片的 OSS 相对地址,或者您可以提供带有绝对地址的图片。

curl --request POST \
  --url https://api.aitubo.ai/api/job/create \
  --header 'Authorization: Bearer ced695cfd83811eda5e286850d1dc848' \
  --header 'content-type: application/json' \
  --data '{
    "imagePath": "images/tmp/cgqi1jntuq4000800040.png",
    "modelId": "642b977d2f2842537c09fe41",
    "prompt": "scene",
    "guidanceScale": 0.7
}'

您可以像 Text2Image 一样通过轮询来检查任务创建的状态。

3. ControlNet

在使用 ControlNet 功能之前,您必须首先调用 /job/model/list API 来获取相应的 ControlNet 类别:

{
    "code": 0,
    "data": {
        "domain": "https://file.aitubo.ai/",
        "models": [
            {
                "id": "canny",
                "name": "canny",
                "icon": "assets/template/control_canny.jpg"
            },
            {
                "id": "scribble",
                "name": "scribble",
                "icon": "assets/template/control_scribble.jpg"
            },
            ...
    }
}

然后调用 /job/create API:

curl --request POST \
  --url https://api.aitubo.ai/api/job/create \
  --header 'Authorization: Bearer ced695cfd83811eda5e286850d1dc848' \
  --header 'content-type: application/json' \
  --data '{    "imagePath": "https://ichef.bbci.co.uk/news/976/cpsprodpb/17638/production/_124800859_gettyimages-817514614.jpg.webp",
    "controlModel": "canny",
    "prompt": "a little dog"
}'

您也可以传递 modelId 字段(确保该模型支持 ControlNet):

curl --request POST \
  --url https://api.aitubo.ai/api/job/create \
  --header 'Authorization: Bearer ced695cfd83811eda5e286850d1dc848' \
  --header 'content-type: application/json' \
  --data '{
    "imagePath": "https://ichef.bbci.co.uk/news/976/cpsprodpb/17638/production/_124800859_gettyimages-817514614.jpg.webp",
    "controlModel": "canny",
    "prompt": "a little dog",
    "modelId": "642b977d2f2842537c09fe41"
}'

API

1. 上传图片

基本信息

路径: /api/job/upload-image

方法: POST

请求参数

标头

名称必需示例
Content-Typemultipart/form-data
AuthorizationBearer {YOUR KEY}Bearer 37f333a2d5f811edb248acde48001122

正文

名称必需
image文件

响应数据

名称类型必需默认注意其他
codeintegercode=0 -> 成功
infostring错误信息
dataobject
├─pathstring阿里云 OSS 的图片路径

2. 创建作业

基本信息

路径: /api/job/create

方法: POST

请求参数

标头

名称必需示例
Content-Typeapplication/json
AuthorizationBearer {YOUR KEY}Bearer 37f333a2d5f811edb248acde48001122

正文

名称类型必需默认注意其他
imagePathstring上传图片的路径(url/oss 均可)
maskImagestringAI 编辑器应该传递此字段
modelIdstring如果 controlModel 为 null,则应填写此字段
promptstring提示
negativePromptstring负面提示
controlModelstringcanny / scribble / openpose / mlsd / hed / seg / depth / normal
controlStrengthnumber1[0, 2]
controlFilterstringcontrol 图像的预处理器,例如:openpose / openpose_full / openpose_hand / openpose_face / openpose_faceonly
strengthnumber0.8[0.1, 1]
widthinteger512
heightinteger512
stepsinteger3010 <= value <= 50
guidanceScaleinteger7.50 < value <= 20
countinteger4生成的图片数量

响应数据

名称类型必需默认注意其他
codenumber0 -> 成功;1000 -> 积分不足
infostring错误信息
dataobject
├─idstring作业 ID
├─creditinteger用户的总积分
├─consumedCreditinteger作业消耗的积分

3. 获取作业

基本信息

路径: /api/job/get

方法: GET

请求参数

查询

名称必需示例注意
id642ba091592245d79a645b39作业 ID

Response Data

名称Type必需Default注意Others
codeinteger0 -> 成功
infostring错误信息
dataobject
├─idstring作业 ID
├─createAtstring作业的创建时间
├─statusinteger作业的状态。 0 -> 未准备好; 1 -> 处理中; 2 -> 成功; 3 -> 失败
├─resultobject
├─├─infostring
├─├─dataobject
├─├─├─imagesstring []图像的最终相对路径(需要与域字段连接)item Type:string
├─├─├─artIdsstring []图片对应的 artIDitem Type:string
├─├─├─domainstringoss url,您需要连接图片的相对路径
├─argsobject
├─├─promptstring
├─├─negativePromptstring
├─├─modelstring
├─├─strengthinteger
├─├─widthinteger
├─├─heightinteger

4. 列出 ControlNet 模型

基本信息

路径: /api/job/models

方法: GET

响应数据

名称类型必需默认注意其他
codeinteger0 -> 成功
infostring错误信息
dataobject
├domainstring图片 oss 域名,需要连接下面的图标字段
├modelsobject []item Type:object
idstring模型 ID,创建作业时 controlModel 参数值为此 ID
namestring英文名称
cnamestring中文名称
iconstring示例图片。 oss 相对路径,您需要连接域

5. 列出历史作业

基本信息

路径: /api/job/list

方法: GET

请求参数

标头

名称必需示例注意
Content-Typeapplication/json
AuthorizationBearer {YOUR KEY}Bearer 37f333a2d5f811edb248acde48001122

Query

名称必需示例注意
pageIndex从 1 开始
pageSize

响应数据

名称类型必需默认注意其他
codeinteger0 -> 成功
infostring错误信息
dataobject
├─jobsobject []作业数组item Type:object
├─├─idstring作业 ID
├─├─createdAtstring
├─├─argsobject
├─├─├─promptstring
├─├─├─negativePromptstring
├─├─├─strengthinteger
├─├─├─widthinteger
├─├─├─heightinteger
├─├─├─countinteger
├─├─├─stepsinteger
├─├─artsobject []生成的图像数组item Type:object
├─├─├─idstring生成的图像的 ID
├─├─├─imagesobject []多样化图片数组item Type:object
├─├─├─├─specstring变体类型。 o -> 原始; 2x/3x/4x -> 2/3/4 比例图像
├─├─├─├─pathstring图片路径。 要连接的域
├─├─├─├─sizeinteger图片大小。 单位:字节
├─domainstringoss 图片域

6. 列出模型

基本信息

路径: /api/model/list

方法: GET

请求参数

标头

名称必需示例注意
AuthorizationBearer {YOUR KEY}Bearer 37f333a2d5f811edb248acde48001122

查询

名称必需示例注意
pageIndex从 1 开始
pageSize
typeplatform/community

响应数据

名称类型必需默认注意其他
codeinteger0 -> 成功
infostring错误信息
dataobject
├─domainstringoss 域
├─totalinteger分页过滤的模型总数
├─modelsobject []item Type:object
├─├─idstring模型 ID
├─├─namestring模型名称
├─├─usernamestringmodel’s author name
├─├─descstring模型描述
├─├─coverstring模型封面
├─├─isFavouriteboolean用户是否收藏该模型
├─├─controlNetboolean模型是否支持 ControlNet

7. 超分辨率

基本信息

路径: /api/job/upscale

方法: POST

请求参数

标头

名称必需示例注意
Content-Typeapplication/json
AuthorizationBearer {YOUR KEY}Bearer 37f333a2d5f811edb248acde48001122

正文

名称类型必需默认注意其他
modelstring放大模型名称
RealESRGAN _x4plus / RealESRGAN_x4plus_anime_6B
imagePathstring图片路径。 要连接的域
upscaleFactorinteger2 <= factor <= 4
beautyboolean是否启用面部增强
artIdstring需要一个超级点图片 artID

响应数据

名称类型必需默认注意其他
codenumber0 -> 成功;1000 -> 积分不足
infostring错误信息
dataobject
├─idstring放大作业 ID
├─creditinteger用户的总积分
├─consumedCreditinteger作业消耗的积分

8. 图像分割

基本信息

路径: /api/art/segment

方法: POST

请求参数

标头

名称必需示例注意
Content-Typeapplication/json
AuthorizationBearer {YOUR KEY}Bearer 37f333a2d5f811edb248acde48001122

正文

名称类型必需默认注意其他
imagestring图片路径。 绝对/相对路径

响应数据

名称类型必需默认注意其他
codenumber0 -> 成功
infostring错误信息
dataobject
├─imagestring分割后图片的 URL

9. 获取用户信息

基本信息

路径: /api/user/profile

方法: GET

请求参数

标头

名称必需示例注意
Content-Typeapplication/json
AuthorizationBearer {YOUR KEY}Bearer 37f333a2d5f811edb248acde48001122

响应数据

名称类型必需默认注意其他
codenumber0 -> 成功
infostring错误信息
dataobject
├─namestring
├─emailstring
├─avatarstring
├─phonestring
├─creditinteger用户的总积分
├─displayNSFWboolean
├─discordboolean

10. 创建头像

10.1 列出模板

基本信息

路径: api/transform/list

方法: GET

响应数据

名称类型必需默认注意其他
codenumber0 -> 成功
infostring错误信息
dataobject
├─domainstring图片 oss 域名,需要连接下面的图标字段
├─tagsstring[]模板标签
├─transformobject
├─├─tagobject[]
├─├─├─idstring
├─├─├─namestring
├─├─├─imagestring原始图像
├─├─├─artstring结果图像
├─├─├─costnumber积分消耗
├─├─├─proboolean是专业版
├─├─├─tagstring标签

10.2 创建头像

基本信息

路径: api/transform/create-headshot

方法: POST

标头

名称必需示例注意
Content-Typeapplication/json
AuthorizationBearer {YOUR KEY}Bearer 37f333a2d5f811edb248acde48001122

正文

名称类型必需默认注意其他
imagePathstring调用时返回的图片路径 上传图片 api
transformIdstring
widthinteger
heightinteger
keepHairbooleanfalse
keepPosebooleantrue

响应数据

名称类型必需默认注意其他
codenumber0 -> 成功;1000 -> 积分不足
infostring错误信息
dataobject
├─idstring作业 ID
├─creditinteger用户的总积分
├─consumedCreditinteger作业消耗的积分

商业服务-toB/API

[email protected]