API 參考

Aitubo 的 API 文件

總覽

此文件描述如何使用程式碼來達到與網頁相同的結果。 之後的文件只會提供相對位址 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檔案是

回應資料

名稱類型必填預設備註其他
codeinteger是code=0 -> 成功
infostring否錯誤資訊
dataobject否
├─pathstring否AliYun OSS 的圖片路徑

2. 建立工作

基本資訊

路徑: /api/job/create

方法: POST

請求參數

標頭

名稱值必填範例
Content-Typeapplication/json是
AuthorizationBearer {YOUR KEY}是Bearer 37f333a2d5f811edb248acde48001122

主體

名稱類型必填預設備註其他
imagePathstring否已上傳影像的路徑(url/oss 均可)
maskImagestring否AI 編輯器應傳遞此欄位
modelIdstring否如果 controlModel 為 null,則應填寫此欄位
promptstring是提示
negativePromptstring否負面提示
controlModelstring否canny / scribble / openpose / mlsd / hed / seg / depth / normal
controlStrengthnumber否1[0, 2]
controlFilterstring否control 影像的預處理器,例如:openpose / openpose_full / openpose_hand / openpose_face / openpose_faceonly
strengthnumber否0.8[0.1, 1]
widthinteger否512
heightinteger否512
stepsinteger否3010 <= value <= 50
guidanceScaleinteger否7.50 < value <= 20
countinteger否4產生的圖片數量

回應資料

名稱類型必填預設備註其他
codenumber是0 -> 成功;1000 -> 信用額度不足
infostring否錯誤資訊
dataobject是
├─idstring是工作 ID
├─creditinteger是使用者的總信用額度
├─consumedCreditinteger是工作的已用信用額度

3. 取得工作

基本資訊

路徑: /api/job/get

方法: GET

請求參數

查詢

名稱必填範例備註
id是642ba091592245d79a645b39工作 ID

Response Data

名稱Type必填Default備註Others
codeinteger是0 -> 成功
infostring否錯誤資訊
dataobject是
├─idstring是工作 ID
├─createAtstring是工作的建立時間
├─statusinteger是工作的狀態。 0 -> 尚未準備好; 1 -> 處理中; 2 -> 成功; 3 -> 失敗
├─resultobject否
├─├─infostring否
├─├─dataobject否
├─├─├─imagesstring []否影像的結果相對路徑(需要與網域欄位串接)item Type:string
├─├─├─artIdsstring []否圖片對應的 artIDitem Type:string
├─├─├─domainstring否oss url,您需要串接圖片的相對路徑
├─argsobject否
├─├─promptstring否
├─├─negativePromptstring否
├─├─modelstring否
├─├─strengthinteger否
├─├─widthinteger否
├─├─heightinteger否

4. 列出 ControlNet 模型

基本資訊

路徑: /api/job/models

方法: GET

回應資料

名稱類型必填預設備註其他
codeinteger是0 -> 成功
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是

回應資料

名稱類型必填預設備註其他
codeinteger是0 -> 成功
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是影像大小。 單位:位元組
├─domainstring是oss 影像網域

6. 列出模型

基本資訊

路徑: /api/model/list

方法: GET

請求參數

標頭

名稱值必填範例備註
AuthorizationBearer {YOUR KEY}是Bearer 37f333a2d5f811edb248acde48001122

查詢

名稱必填範例備註
pageIndex是從 1 開始
pageSize是
type否platform/community

回應資料

名稱類型必填預設備註其他
codeinteger是0 -> 成功
infostring否錯誤資訊
dataobject是
├─domainstring是oss 網域
├─totalinteger是分頁篩選的模型總數
├─modelsobject []是item Type:object
├─├─idstring是模型 ID
├─├─namestring是模型名稱
├─├─usernamestring是model’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是影像路徑。 要串接的網域
upscaleFactorinteger是2 <= 因子 <= 4
beautyboolean否是否啟用臉部增強
artIdstring是需要超點圖片 artID

回應資料

名稱類型必填預設備註其他
codenumber是0 -> 成功;1000 -> 信用額度不足
infostring否錯誤資訊
dataobject是
├─idstring否放大工作 ID
├─creditinteger是使用者的總信用額度
├─consumedCreditinteger是工作的已用信用額度

8. 影像分割

基本資訊

路徑: /api/art/segment

方法: POST

請求參數

標頭

名稱值必填範例備註
Content-Typeapplication/json是
AuthorizationBearer {YOUR KEY}是Bearer 37f333a2d5f811edb248acde48001122

主體

名稱類型必填預設備註其他
imagestring是影像路徑。 絕對/相對路徑

回應資料

名稱類型必填預設備註其他
codenumber是0 -> 成功
infostring否錯誤資訊
dataobject是
├─imagestring是分割後影像的 URL

9. 取得使用者資訊

基本資訊

路徑: /api/user/profile

方法: GET

請求參數

標頭

名稱值必填範例備註
Content-Typeapplication/json是
AuthorizationBearer {YOUR KEY}是Bearer 37f333a2d5f811edb248acde48001122

回應資料

名稱類型必填預設備註其他
codenumber是0 -> 成功
infostring否錯誤資訊
dataobject是
├─namestring是
├─emailstring是
├─avatarstring是
├─phonestring是
├─creditinteger是使用者的總信用額度
├─displayNSFWboolean是
├─discordboolean是

10. 建立頭像

10.1 列出範本

基本資訊

路徑: api/transform/list

方法: GET

回應資料

名稱類型必填預設備註其他
codenumber是0 -> 成功
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否
keepHairboolean否false
keepPoseboolean否true

回應資料

名稱類型必填預設備註其他
codenumber是0 -> 成功;1000 -> 信用額度不足
infostring否錯誤資訊
dataobject是
├─idstring是工作 ID
├─creditinteger是使用者的總信用額度
├─consumedCreditinteger是工作的已用信用額度

商業服務-toB/API

[email protected]