เอกสารนี้อธิบายวิธีการใช้โค้ดเพื่อให้ได้ผลลัพธ์เช่นเดียวกับบนเว็บ หลังจากเอกสารจะให้เฉพาะ 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
},
...
]
}
}
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"
}
}
หากต้องการใช้ 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
ก่อนใช้ฟังก์ชัน ControlNet คุณต้องเรียก API /job/model/list เพื่อรับหมวดหมู่ 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"
},
...
}
}
จากนั้นเรียก API /job/create:
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/job/upload-image
วิธีการ: POST
ส่วนหัว
ชื่อ | ค่า | จำเป็น | ตัวอย่าง |
---|---|---|---|
Content-Type | multipart/form-data | ใช่ | |
Authorization | Bearer {YOUR KEY} | ใช่ | Bearer 37f333a2d5f811edb248acde48001122 |
เนื้อหา
ชื่อ | ค่า | จำเป็น |
---|---|---|
image | ไฟล์ | ใช่ |
ชื่อ | ประเภท | จำเป็น | ค่าเริ่มต้น | หมายเหตุ | อื่นๆ |
---|---|---|---|---|---|
code | integer | ใช่ | code=0 -> สำเร็จ | ||
info | string | ไม่ | ข้อมูลข้อผิดพลาด | ||
data | object | ไม่ | |||
├─path | string | ไม่ | เส้นทางรูปภาพของ AliYun OSS |
เส้นทาง: /api/job/create
วิธีการ: POST
ส่วนหัว
ชื่อ | ค่า | จำเป็น | ตัวอย่าง |
---|---|---|---|
Content-Type | application/json | ใช่ | |
Authorization | Bearer {YOUR KEY} | ใช่ | Bearer 37f333a2d5f811edb248acde48001122 |
เนื้อหา
ชื่อ | ประเภท | จำเป็น | ค่าเริ่มต้น | หมายเหตุ | อื่นๆ |
---|---|---|---|---|---|
imagePath | string | ไม่ | เส้นทางของรูปภาพที่อัปโหลด (url/oss ทั้งคู่) | ||
maskImage | string | ไม่ | AI Editor ควรส่งฟิลด์นี้ | ||
modelId | string | ไม่ | หาก controlModel เป็น null ควรกรอกฟิลด์นี้ | ||
prompt | string | ใช่ | พร้อมท์ | ||
negativePrompt | string | ไม่ | พร้อมท์เชิงลบ | ||
controlModel | string | ไม่ | canny / scribble / openpose / mlsd / hed / seg / depth / normal | ||
controlStrength | number | ไม่ | 1 | [0, 2] | |
controlFilter | string | ไม่ | preprecessor of control image, for example: openpose / openpose_full / openpose_hand / openpose_face / openpose_faceonly | ||
strength | number | ไม่ | 0.8 | [0.1, 1] | |
width | integer | ไม่ | 512 | ||
height | integer | ไม่ | 512 | ||
steps | integer | ไม่ | 30 | 10 <= value <= 50 | |
guidanceScale | integer | ไม่ | 7.5 | 0 < value <= 20 | |
count | integer | ไม่ | 4 | จำนวนรูปภาพที่สร้างขึ้น |
ชื่อ | ประเภท | จำเป็น | ค่าเริ่มต้น | หมายเหตุ | อื่นๆ |
---|---|---|---|---|---|
code | number | ใช่ | 0 -> สำเร็จ;1000 -> เครดิตไม่เพียงพอ | ||
info | string | ไม่ | ข้อมูลข้อผิดพลาด | ||
data | object | ใช่ | |||
├─id | string | ใช่ | ID งาน | ||
├─credit | integer | ใช่ | เครดิตรวมของผู้ใช้ | ||
├─consumedCredit | integer | ใช่ | เครดิตที่ใช้ไปของงาน |
เส้นทาง: /api/job/get
วิธีการ: GET
แบบสอบถาม
ชื่อ | จำเป็น | ตัวอย่าง | หมายเหตุ |
---|---|---|---|
id | ใช่ | 642ba091592245d79a645b39 | ID งาน |
ชื่อ | Type | จำเป็น | Default | หมายเหตุ | Others |
---|---|---|---|---|---|
code | integer | ใช่ | 0 -> สำเร็จ | ||
info | string | ไม่ | ข้อมูลข้อผิดพลาด | ||
data | object | ใช่ | |||
├─id | string | ใช่ | ID งาน | ||
├─createAt | string | ใช่ | เวลาที่สร้างขึ้นของงาน | ||
├─status | integer | ใช่ | สถานะของงาน 0 -> ไม่พร้อม; 1 -> กำลังดำเนินการ; 2 -> สำเร็จ; 3 -> ล้มเหลว | ||
├─result | object | ไม่ | |||
├─├─info | string | ไม่ | |||
├─├─data | object | ไม่ | |||
├─├─├─images | string [] | ไม่ | เส้นทางสัมพัทธ์ของรูปภาพ (ต้องเชื่อมต่อกับฟิลด์โดเมน) | item Type:string | |
├─├─├─artIds | string [] | ไม่ | Picture corresponding artID | item Type:string | |
├─├─├─domain | string | ไม่ | oss url, you need to concatenate the relative path of the picture | ||
├─args | object | ไม่ | |||
├─├─prompt | string | ไม่ | |||
├─├─negativePrompt | string | ไม่ | |||
├─├─model | string | ไม่ | |||
├─├─strength | integer | ไม่ | |||
├─├─width | integer | ไม่ | |||
├─├─height | integer | ไม่ |
เส้นทาง: /api/job/models
วิธีการ: GET
ชื่อ | ประเภท | จำเป็น | ค่าเริ่มต้น | หมายเหตุ | อื่นๆ |
---|---|---|---|---|---|
code | integer | ใช่ | 0 -> สำเร็จ | ||
info | string | ไม่ | ข้อมูลข้อผิดพลาด | ||
data | object | ใช่ | |||
├domain | string | ใช่ | ชื่อโดเมน oss ของรูปภาพ ต้องเชื่อมต่อกับฟิลด์ไอคอนด้านล่าง | ||
├models | object [] | ใช่ | item Type:object | ||
id | string | ใช่ | model id, The controlModel parameter value is this ID when creating a job | ||
name | string | ใช่ | ชื่อภาษาอังกฤษ | ||
cname | string | ใช่ | ชื่อภาษาจีน | ||
icon | string | ใช่ | รูปภาพตัวอย่าง เส้นทางสัมพัทธ์ oss คุณต้องเชื่อมต่อโดเมน |
เส้นทาง: /api/job/list
วิธีการ: GET
ส่วนหัว
ชื่อ | ค่า | จำเป็น | ตัวอย่าง | หมายเหตุ |
---|---|---|---|---|
Content-Type | application/json | ใช่ | ||
Authorization | Bearer {YOUR KEY} | ใช่ | Bearer 37f333a2d5f811edb248acde48001122 |
Query
ชื่อ | จำเป็น | ตัวอย่าง | หมายเหตุ |
---|---|---|---|
pageIndex | ใช่ | เริ่มจาก 1 | |
pageSize | ใช่ |
ชื่อ | ประเภท | จำเป็น | ค่าเริ่มต้น | หมายเหตุ | อื่นๆ |
---|---|---|---|---|---|
code | integer | ใช่ | 0 -> สำเร็จ | ||
info | string | ไม่ | ข้อมูลข้อผิดพลาด | ||
data | object | ใช่ | |||
├─jobs | object [] | ใช่ | อาร์เรย์งาน | item Type:object | |
├─├─id | string | ใช่ | ID งาน | ||
├─├─createdAt | string | ใช่ | |||
├─├─args | object | ใช่ | |||
├─├─├─prompt | string | ใช่ | |||
├─├─├─negativePrompt | string | ใช่ | |||
├─├─├─strength | integer | ใช่ | |||
├─├─├─width | integer | ใช่ | |||
├─├─├─height | integer | ใช่ | |||
├─├─├─count | integer | ใช่ | |||
├─├─├─steps | integer | ใช่ | |||
├─├─arts | object [] | ใช่ | อาร์เรย์ของรูปภาพที่สร้างขึ้น | item Type:object | |
├─├─├─id | string | ใช่ | id ของรูปภาพที่สร้างขึ้น | ||
├─├─├─images | object [] | ใช่ | อาร์เรย์รูปภาพหลากหลาย | item Type:object | |
├─├─├─├─spec | string | ใช่ | variant type. o -> origin; 2x/3x/4x -> 2/3/4 scale image | ||
├─├─├─├─path | string | ใช่ | เส้นทางรูปภาพ โดเมนที่จะเชื่อมต่อ | ||
├─├─├─├─size | integer | ใช่ | ขนาดรูปภาพ หน่วย: ไบต์ | ||
├─domain | string | ใช่ | โดเมนรูปภาพ oss |
เส้นทาง: /api/model/list
วิธีการ: GET
ส่วนหัว
ชื่อ | ค่า | จำเป็น | ตัวอย่าง | หมายเหตุ |
---|---|---|---|---|
Authorization | Bearer {YOUR KEY} | ใช่ | Bearer 37f333a2d5f811edb248acde48001122 |
แบบสอบถาม
ชื่อ | จำเป็น | ตัวอย่าง | หมายเหตุ |
---|---|---|---|
pageIndex | ใช่ | เริ่มจาก 1 | |
pageSize | ใช่ | ||
type | ไม่ | platform/community |
ชื่อ | ประเภท | จำเป็น | ค่าเริ่มต้น | หมายเหตุ | อื่นๆ |
---|---|---|---|---|---|
code | integer | ใช่ | 0 -> สำเร็จ | ||
info | string | ไม่ | ข้อมูลข้อผิดพลาด | ||
data | object | ใช่ | |||
├─domain | string | ใช่ | โดเมน oss | ||
├─total | integer | ใช่ | จำนวนรุ่นทั้งหมดที่กรองสำหรับการแบ่งหน้า | ||
├─models | object [] | ใช่ | item Type:object | ||
├─├─id | string | ใช่ | ID รุ่น | ||
├─├─name | string | ใช่ | ชื่อรุ่น | ||
├─├─username | string | ใช่ | model’s author name | ||
├─├─desc | string | ใช่ | คำอธิบายรุ่น | ||
├─├─cover | string | ใช่ | ปกของรุ่น | ||
├─├─isFavourite | boolean | ใช่ | ผู้ใช้ชื่นชอบรุ่นหรือไม่ | ||
├─├─controlNet | boolean | ใช่ | รุ่นรองรับ ControlNet หรือไม่ |
เส้นทาง: /api/job/upscale
วิธีการ: POST
ส่วนหัว
ชื่อ | ค่า | จำเป็น | ตัวอย่าง | หมายเหตุ |
---|---|---|---|---|
Content-Type | application/json | ใช่ | ||
Authorization | Bearer {YOUR KEY} | ใช่ | Bearer 37f333a2d5f811edb248acde48001122 |
เนื้อหา
ชื่อ | ประเภท | จำเป็น | ค่าเริ่มต้น | หมายเหตุ | อื่นๆ |
---|---|---|---|---|---|
model | string | ไม่ | ชื่อรุ่น upscale | ||
RealESRGAN _x4plus / RealESRGAN_x4plus_anime_6B | |||||
imagePath | string | ใช่ | เส้นทางรูปภาพ โดเมนที่จะเชื่อมต่อ | ||
upscaleFactor | integer | ใช่ | 2 <= factor <= 4 | ||
beauty | boolean | ไม่ | เปิดใช้งานการปรับปรุงใบหน้าหรือไม่ | ||
artId | string | ใช่ | ต้องการ artID รูปภาพจุดสุดยอด |
ชื่อ | ประเภท | จำเป็น | ค่าเริ่มต้น | หมายเหตุ | อื่นๆ |
---|---|---|---|---|---|
code | number | ใช่ | 0 -> สำเร็จ;1000 -> เครดิตไม่เพียงพอ | ||
info | string | ไม่ | ข้อมูลข้อผิดพลาด | ||
data | object | ใช่ | |||
├─id | string | ไม่ | upscale job id | ||
├─credit | integer | ใช่ | เครดิตรวมของผู้ใช้ | ||
├─consumedCredit | integer | ใช่ | เครดิตที่ใช้ไปของงาน |
เส้นทาง: /api/art/segment
วิธีการ: POST
ส่วนหัว
ชื่อ | ค่า | จำเป็น | ตัวอย่าง | หมายเหตุ |
---|---|---|---|---|
Content-Type | application/json | ใช่ | ||
Authorization | Bearer {YOUR KEY} | ใช่ | Bearer 37f333a2d5f811edb248acde48001122 |
เนื้อหา
ชื่อ | ประเภท | จำเป็น | ค่าเริ่มต้น | หมายเหตุ | อื่นๆ |
---|---|---|---|---|---|
image | string | ใช่ | เส้นทางรูปภาพ เส้นทางสัมบูรณ์/สัมพัทธ์ |
ชื่อ | ประเภท | จำเป็น | ค่าเริ่มต้น | หมายเหตุ | อื่นๆ |
---|---|---|---|---|---|
code | number | ใช่ | 0 -> สำเร็จ | ||
info | string | ไม่ | ข้อมูลข้อผิดพลาด | ||
data | object | ใช่ | |||
├─image | string | ใช่ | URL ของรูปภาพหลังจากการแบ่งส่วน |
เส้นทาง: /api/user/profile
วิธีการ: GET
ส่วนหัว
ชื่อ | ค่า | จำเป็น | ตัวอย่าง | หมายเหตุ |
---|---|---|---|---|
Content-Type | application/json | ใช่ | ||
Authorization | Bearer {YOUR KEY} | ใช่ | Bearer 37f333a2d5f811edb248acde48001122 |
ชื่อ | ประเภท | จำเป็น | ค่าเริ่มต้น | หมายเหตุ | อื่นๆ |
---|---|---|---|---|---|
code | number | ใช่ | 0 -> สำเร็จ | ||
info | string | ไม่ | ข้อมูลข้อผิดพลาด | ||
data | object | ใช่ | |||
├─name | string | ใช่ | |||
string | ใช่ | ||||
├─avatar | string | ใช่ | |||
├─phone | string | ใช่ | |||
├─credit | integer | ใช่ | เครดิตรวมของผู้ใช้ | ||
├─displayNSFW | boolean | ใช่ | |||
├─discord | boolean | ใช่ |
เส้นทาง: api/transform/list
วิธีการ: GET
ชื่อ | ประเภท | จำเป็น | ค่าเริ่มต้น | หมายเหตุ | อื่นๆ |
---|---|---|---|---|---|
code | number | ใช่ | 0 -> สำเร็จ | ||
info | string | ไม่ | ข้อมูลข้อผิดพลาด | ||
data | object | ใช่ | |||
├─domain | string | ใช่ | ชื่อโดเมน oss ของรูปภาพ ต้องเชื่อมต่อกับฟิลด์ไอคอนด้านล่าง | ||
├─tags | string[] | ใช่ | แท็กเทมเพลต | ||
├─transform | object | ใช่ | |||
├─├─tag | object[] | ใช่ | |||
├─├─├─id | string | ใช่ | |||
├─├─├─name | string | ใช่ | |||
├─├─├─image | string | ใช่ | รูปภาพต้นฉบับ | ||
├─├─├─art | string | ใช่ | รูปภาพผลลัพธ์ | ||
├─├─├─cost | number | ใช่ | ใช้เครดิต | ||
├─├─├─pro | boolean | ใช่ | เป็นโปร | ||
├─├─├─tag | string | ใช่ | แท็ก |
เส้นทาง: api/transform/create-headshot
วิธีการ: POST
ส่วนหัว
ชื่อ | ค่า | จำเป็น | ตัวอย่าง | หมายเหตุ |
---|---|---|---|---|
Content-Type | application/json | ใช่ | ||
Authorization | Bearer {YOUR KEY} | ใช่ | Bearer 37f333a2d5f811edb248acde48001122 |
เนื้อหา
ชื่อ | ประเภท | จำเป็น | ค่าเริ่มต้น | หมายเหตุ | อื่นๆ |
---|---|---|---|---|---|
imagePath | string | ใช่ | เส้นทางรูปภาพที่ส่งคืนเมื่อถูกเรียก upload-image api | ||
transformId | string | ใช่ | |||
width | integer | ไม่ | |||
height | integer | ไม่ | |||
keepHair | boolean | ไม่ | false | ||
keepPose | boolean | ไม่ | true |
ชื่อ | ประเภท | จำเป็น | ค่าเริ่มต้น | หมายเหตุ | อื่นๆ |
---|---|---|---|---|---|
code | number | ใช่ | 0 -> สำเร็จ;1000 -> เครดิตไม่เพียงพอ | ||
info | string | ไม่ | ข้อมูลข้อผิดพลาด | ||
data | object | ใช่ | |||
├─id | string | ใช่ | ID งาน | ||
├─credit | integer | ใช่ | เครดิตรวมของผู้ใช้ | ||
├─consumedCredit | integer | ใช่ | เครดิตที่ใช้ไปของงาน |