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檔案

回應資料

名稱類型必填預設備註其他
codeintegercode=0 -> 成功
infostring錯誤資訊
dataobject
├─pathstringAliYun 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 <= 因子 <= 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]