API 文档
基于摩尔线程自研GPU算力底座,摩尔线程为开发者提供了高效的AIGC文生图在线API服务,使开发者可以方便的开发高质量文生图应用
在线手册
说明:
以下所有请求的请求头中必须包含 Authorization: .
用真实值替换,可向管理员申请
示例
curl -X POST \
-H 'Content-Type: application/json' \
-H "Authorization: " \
-d '{"text": "dog", "height": 512, "width": 512, "seed": 2022, "fast": false}' \
http://api.mthreads.com/maliang/general/submit
写实头像
http://api.mthreads.com/maliang/portrait-style/submit
| 名称 | 类型 | 备注 |
|---|---|---|
| task_type | string | portrait-style |
类型
Post
参数
| 名称 | 类型 | 备注 |
|---|---|---|
| image | string | 图像名称 |
| styles | string | 风格名称。 四选一:"电影时光机", "青春莱卡", "唯美东方", "复古油画" |
| hd (optional) | bool | 用户选择是否转为高清结果, 默认为false |
| callback_url (optional) | string | 指定的回调地址,用于POST任务结果。默认为None。 |
返回
| 名称 | 类型 | 备注 |
|---|---|---|
| status | int | 状态。0 成功,其他失败 |
| message | string | 信息。“success”成功 |
| data | json object | |
| data.task_id | string | 任务ID |
| data.queue_count | int | 排队位置 |
| data.filter_status | int | 0:正常;1:生成图片敏感内容;-1:无输出 |
示例
请求
curl -X POST \
-H 'Content-Type: application/json' \
-H "Authorization: "\
-d '{"image": "template_000.jpg", "styles": "唯美东方",
"hd": true,
"callback_url": null}'\
http://api.mthreads.com/maliang/portrait-style/submit
返回
{
"status": 0,
"message": "success",
"data": {
"task_id": "94f1af41-e5b3-4afd-8ddd-cf5435aca1fc",
"queue_count": 0
}
}
查询
http://api.mthreads.com/maliang/portrait-style/state/
示例:
curl -H "Authorization: "\
http://api.mthreads.com/maliang/portrait-style/state/4c1c76d2-419c-4674-89cf-0621437dc767
查询结果 :
{
"status": 0,
"message": "success",
"data": {
"task_id": "a827cc2f-3228-4c73-9239-b21f68c58c20",
"state": "SUCCESS",
"image": [
"af8ada9bf77f72e9bc816cddc2880725.png"
]
}
}
马良普通任务
公共参数
| 名称 | 类型 | 备注 |
|---|---|---|
| task_type | string | general:通用 25d:2.5D图片 anime:二次元 person:人像 prompts:提示词优化 |
提交普通任务
接口
http://api.mthreads.com/maliang/{task_type}/submit
prompts用户输入以英文,分割,如:小狗,猫咪
类型
Post
参数
| 名称 | 类型 | 备注 |
|---|---|---|
| text | string | 文本输入。目前没有限制,算法会截取77个单词 |
| image | string | 图像名称 |
| width | int | 图像宽度,默认值为 512,目前最大输入为 512,且必须为 64 的整数倍 |
| height | int | 图像高度,默认值为 384,目前最大输入为 512,且必须为 64 的整数倍 |
| steps | int | 采样次数,默认值为 30,取值范围 > 1。一般取值在 20 ~ 200 之间 |
| scale | float | 文本指导,默认值为 7.5,取值范围 > 1 |
| strength | float | 去噪强度,默认值 0.8,取值范围在 0 ~ 1 之间 编辑幅度 |
| seed | int | 随机采样种子,可实现复现效果。-1 为随机生成(前端生成随机数传入)。默认值为 0(前端不指定)。没有限制,整数就可以 |
| num_images | int | 生成采样图像数量,默认值为 1,目前只能为1 |
| negative_prompt | string | 反向文本输入 |
| use_extra_artist | bool | 用户选择是否随机生成风格选项。 |
| use_extra_positive_enhancer | bool | 用户选择是否随机生成风格选项。 |
| use_extra_neg_embeddings | bool | 用户选择是否随机生成风格选项。 |
| conditional_image | string | conditional_image mask |
| controlnet_type | `` | canny,depth,openpose,softedge,mlsd,lineart,tile,shuffle,ip2p,tilehd, inpaint |
| fast | bool | 是否使用加速 |
| lora_path | string | lora 路径名称 |
| lora_alpha | int | 权重 |
| inpaint_control_type | string | 'normal'/空,'depth','canny','pose' |
| dilate_factor | int | 膨胀系数 |
| controlnet_conditioning_scale | float | 控制强度 |
返回
| 名称 | 类型 | 备注 |
|---|---|---|
| status | int | 状态。0 成功,其他失败 |
| message | string | 信息。“success”成功 |
| data | json object | |
| data.task_id | string | 任务ID |
| data.queue_count | int | 排队位置 |
| data.filter_status | int | 0:正常;1:生成图片敏感内容;-1:无输出 |
示例
请求
curl -X POST \
-H 'Content-Type: application/json' \
-H "Authorization: " \
-d '{"text": "dog", "height": 512, "width": 512, "seed": 2022, "fast": false}' \
http://api.mthreads.com/maliang/general/submit
返回
{
"status":0,
"message":"success",
"data":{
"task_id":"bbbfc9b1-aee7-416b-9854-9d333b5f9ee9",
"state":"SUCCESS",
"filter_status": 0,
"image":[
"5f1dcb2dfb45f799cf7ccae07a6aa8f5.jpg"
],
"extra_content":{
"enhancer":"gorgeous, plain background, iridescent accents, centered, cel shaded, scenery, studio lighting, pincushion lens effect, intricate, hyper realism, cute, highly detailed",
"artist":""
}
}
}
提交人像卡通化任务
新增头像卡通化生成,支持一次性生成多种卡通风格的图片**。**
Updates(2023-11-23):
-
新增用户输入的文字描述。
-
新增可指定的图片输出尺寸。
-
新增回调。
-
优化图片返回格式。
接口
http://api.mthreads.com/maliang/portrait/submit
| 名称 | 类型 | 备注 |
|---|---|---|
| task_type | string | portrait |
类型
Post
参数
| 名称 | 类型 | 备注 |
|---|---|---|
| image | string | 图像名称 |
| styles (optional) | list[string] | 可选风格:["disney", "3dmm", "blind_box", "cool_kids", "moxin", "watercolor", "chinese_art", "ink_painting"] 默认为全部可选风格 |
| tilehd (optinal) | bool | 用户选择是否精绘放大图像, 默认为false |
| hd (optional) | bool | 用户选择是否转为高清结果, 默认为false |
| text_opt (optional]) | string | 用户输入的文字描述,默认为None。 |
| output_size (optional) | int | 指定的图片输出尺寸,用于裁剪输出图片。默认为None,不改变图片尺寸。 |
| callback_url (optional) | string | 指定的回调地址,用于POST任务结果。默认为None。 |
返回
| 名称 | 类型 | 备注 |
|---|---|---|
| status | int | 状态。0 成功,其他失败 |
| message | string | 信息。“success”成功 |
| data | json object | |
| data.task_id | string | 任务ID |
| data.queue_count | int | 排队位置 |
| data.filter_status | int | 0:正常;1:生成图片敏感内容;-1:无输出 |
示例
请求
curl -X POST \
-H 'Content-Type: application/json' \
-H "Authorization: " \
-d '{"image": "portrait_ty.png", "styles": ["disney"],
"tilehd": true, "hd": true,
"callback_url": null,
"text_opt": "butterfly", "output_size": 450}' \
http://api.mthreads.com/maliang/portrait/submit
返回
{
"status":0,
"message":"success",
"data":{
"task_id":"bc5652e7-854a-442a-a6b9-e318c09ed203",
"queue_count":0
}
}
查询
curl -H "Authorization: " \
http://api.mthreads.com/maliang/general/submit/portrait/state/e2f6be4c-99f1-4df4-8617-354e5eabe531
查询结果 (更新返回image格式)****:
{
"status": 0,
"message": "success",
"data": {
"task_id": "e2f6be4c-99f1-4df4-8617-354e5eabe531",
"state": "SUCCESS",
"image": [
"a16f0de3079e5f58212c9cf49c81c521.png"
]
}
}
回调POST的数据格式:
| data | json object | |
|---|---|---|
| data.task_id | string | 任务ID |
| data.state | string | 任务状态 SUCCESS。成功 |
| data.image | string list | 生成图片 |
示例:
{
"data": {
"task_id": "e2f6be4c-99f1-4df4-8617-354e5eabe531",
"state": "SUCCESS",
"image": [
"2dd9ba802c791f599d9f2d34dc4e7e25.png"
]
}
}
查询任务
接口
http://api.mthreads.com/maliang/{task_type}/state/{task_id}
类型
Get
参数
| 名称 | 类型 | 备注 |
|---|---|---|
| task_id | string | 任务类型 |
返回
| 名称 | 类型 | 备注 |
|---|---|---|
| status | int | 状态。0 成功,其他失败 |
| message | string | 信息。“success”成功 |
| data | json object | |
| data.task_id | string | 任务ID |
| data.state | string | 任务状态 PENDING。等待中 STARTED。开始 PROGRESS。进行中 RETRY。重试 FAILURE。失败 SUCCESS。成功 |
| data.image | string list | 生成图片 |
| data.info | json object | 进行中计算进度信息,只有在PROGRESS才会有此内容 |
| data.info.progress | string | 计算进度。如:10.00% |
| data.info.image | string list | 中间结果image |
| data.queue_count | int | 任务排队个数,如果超过100个等待任务返回为-1 |
| data.conditional_image | string list | control net中间过程图片 |
示例
请求
curl -H "Authorization: " \
http://api.mthreads.com/maliang/general/state/d4fe34df-ea21-44f2-997d-0808d4f3de88
返回
{
"status":0,
"message":"success",
"data":{
"task_id":"a5616240-ecd8-4ec5-801c-a05e9f3310ff",
"state":"PENDING",
"queue_count":8
}
}
{
"status":0,
"message":"success",
"data":{
"task_id":"385440f8-3888-4eb8-abaf-5095f72a9c83",
"state":"STARTED"
}
}
{
"status":0,
"message":"success",
"data":{
"task_id":"080fc2a3-0bb3-48d9-9efa-31c613fbb207",
"state":"PROGRESS",
"info":{
"progress":"12.50%",
"image":[
"0.00%_9539df9b3d957dc5dfa742f4012e23e8.jpg"
]
}
}
}
{
"status":0,
"message":"success",
"data":{
"task_id":"b072b1eb-3aa3-430a-8696-36ffcbe57d27",
"state":"SUCCESS",
"image":[
"1d3632edcd489935c878174ca36dfa2a.jpg"
],
"conditional_image":[
"None"
]
}
}
{
"status":0,
"message":"success",
"data":{
"task_id":"bd9e9436-e4a8-4b04-ac52-09c3490c860f",
"state":"REVOKED"
}
}
Control Net返回
{
"status":0,
"message":"success",
"data":{
"task_id":"559bae20-2858-4da2-b29c-d40c7cb52fde",
"state":"SUCCESS",
"filter_status":0,
"image":[
"2752e2cdda5a939dd690c17b19076974.jpg"
],
"conditional_image":[
"1de490885a4280e7d4f41bf0de6be51a.jpg"
],
"extra_content":{
"enhancer":"gorgeous, plain background, iridescent accents, centered, cel shaded, scenery, studio lighting, pincushion lens effect, intricate, hyper realism, cute, highly detailed",
"artist":""
}
}
}
批量查询任务
接口
http://api.mthreads.com/maliang/{task_type}/state
类型
Post
参数
| 名称 | 类型 | 备注 |
|---|---|---|
| task_id_array | list | 任务id List |
返回
| 名称 | 类型 | 备注 |
|---|---|---|
| status | int | 状态。0 成功,其他失败 |
| message | string | 信息。“success”成功 |
| data | json array | |
| data.task_id | string | 任务ID |
| data.state | string | 任务状态 PENDING。等待中 STARTED。开始 PROGRESS。进行中 RETRY。重试 FAILURE。失败 SUCCESS。成功 |
| data.image | string | 生成图片 |
| data.info | json object | 进行中计算进度信息,只有在PROGRESS才会有此内容 |
| data.info.progress | string | 计算进度。如:10.00% |
| data.info.image | string | 中间结果image |
| data.queue_count | int | 任务排队个数,如果超过100个等待任务返回为-1 |
示例
请求
curl -X POST \
-H 'Content-Type: application/json' \
-H "Authorization: "\
-d '["3f3a1a87-2b32-4624-a3e3-1301b7a4581b", "6f4a37bf-a81c-422b-8043-4dca823f379d", "7fafa424-5c92-49cb-8d38-e8d26c6446bc"]' \
http://api.mthreads.com/maliang/base/state
返回
{
"status":0,
"message":"success",
"data":[
{
"task_id":"a5616240-ecd8-4ec5-801c-a05e9f3310ff",
"state":"SUCCESS",
"image":[
"4937cf0887639647dbc912784b3066fd.jpg"
]
},
{
"task_id":"2fc7ad80-62e2-491f-8895-1309bc6c9139",
"state":"SUCCESS",
"image":[
"1bd6725c4c400e7459bf211853349ba4.jpg"
]
},
{
"task_id":"918ba5fb-0a3d-4329-9fbb-752bb6defd97",
"state":"SUCCESS",
"image":[
"0d33a42948d8062af3a1840929cfc662.jpg"
]
},
{
"task_id":"861d75cd-efa7-430e-aaab-01dbd1cd1efe",
"state":"SUCCESS",
"image":[
"ce52d78d16a1e969ed5b7c3502a92e57.jpg"
]
}
]
}µ
Control Net返回
{
"status":0,
"message":"success",
"data":[
{
"task_id":"e48eab3b-3e93-4cf9-9b57-ff54fc8624f5",
"state":"SUCCESS",
"filter_status":0,
"image":[
"29187d9198bb17306794502c6a322c69.jpg"
],
"conditional_image":[
"53c4f4f6cba12c92e4d3ce674c165e09.jpg"
],
"extra_content":{
"enhancer":"gorgeous, plain background, iridescent accents, centered, cel shaded, scenery, studio lighting, pincushion lens effect, intricate, hyper realism, cute, highly detailed",
"artist":""
}
},
{
"task_id":"230f9579-b429-4019-a125-96852d747e17",
"state":"SUCCESS",
"filter_status":0,
"image":[
"8ff073910be8edc44fb74ed8ee00b8d9.jpg"
],
"conditional_image":[
"7cdf89c624bc2d01860e58abc703463c.jpg"
],
"extra_content":{
"enhancer":"gorgeous, plain background, iridescent accents, centered, cel shaded, scenery, studio lighting, pincushion lens effect, intricate, hyper realism, cute, highly detailed",
"artist":""
}
},
{
"task_id":"7fdb0722-a455-4ab8-965c-2cbf4418c1ae",
"state":"STARTED",
"queue_count":-1
},
{
"task_id":"4e1ae32b-9b9b-417a-8185-8b3a22a30dc1",
"state":"PENDING",
"queue_count":1
}
]
}
提交超分任务
接口
http://api.mthreads.com/maliang/hd/submit
类型
Post
参数
| 名称 | 类型 | 备注 |
|---|---|---|
| image | string | 图像名称 |
task_type = hd
返回
| 名称 | 类型 | 备注 |
|---|---|---|
| status | int | 状态。0 成功,其他失败 |
| message | string | 信息。“success”成功 |
| data | json object | |
| data.task_id | string | 任务ID |
| data.queue_count | int | 排队位置 |
示例
请求
curl -X POST \
-H 'Content-Type: application/json' \
-H "Authorization: " \
-d '{"image": "5b0b03f0608289769a98dd7de0d5b0e1.jpg"}' \
http://api.mthreads.com/maliang/hd/submit
返回
{
"status":0,
"message":"success",
"data":{
"task_id":"a46faa42-bca2-478e-bcb6-7f17aa245dc1",
"queue_count":1
}
}
查询
curl -H "Authorization: " \
http://api.mthreads.com/maliang/hd/state/38aa3227-78a5-44fb-96da-744284898279
返回
{
"status":0,
"message":"success",
"data":{
"task_id":"38aa3227-78a5-44fb-96da-744284898279",
"state":"SUCCESS",
"image":[
"e1c44d05a658b0e277578eff42e09bf0.png"
]
}
}
查询当前任务总数
接口
http://api.mthreads.com/maliang/{task_type}/count
类型
Get
参数
返回
| 名称 | 类型 | 备注 |
|---|---|---|
| status | int | 状态。0 成功,其他失败 |
| message | string | 信息。“success”成功 |
| data | int | 当前任务总数 |
示例
请求
curl -H "Authorization: 6yoWvgqC9ycRXE4Ao8i7X2BKqCTMLvvLgifrzwSgZ2w6QVizLqJdHYHAsbGU7zTM" \
http://api.mthreads.com/maliang/general/count
返回
{
"status":0,
"message":"success",
"data":16
}
停止调度任务
接口
http://api.mthreads.com/maliang/{task_type}}/stop/{task_id}
类型
Get
参数
| 名称 | 类型 | 备注 |
|---|---|---|
| task_id | string | 任务id |
返回
| 名称 | 类型 | 备注 |
|---|---|---|
| status | int | 状态。0 成功,其他失败 |
| message | string | 信息。“success”成功 |
示例
请求
curl -H "Authorization: " \
http://api.mthreads.com/maliang/base/stop/bfa8019b-597f-496f-873d-4cd72eea2816
返回
{
"status":0,
"message":"success"
}
图片服务
im上传图片
接口
http://api.mthreads.com/image/upload_image
类型
Post
参数
返回
| 名称 | 类型 | 备注 |
|---|---|---|
| status | int | 状态。0 成功,其他失败 |
| message | string | 信息。“success”成功 |
| data | string | 图片名称 |
示例
请求
curl -i -X POST -H "Content-Type: multipart/form-data" -F "file=@example.jpg" -H "Authorization: " http://api.mthreads.com/image/upload_image
返回
{
"status":0,
"message":"success",
"data":"ea7d8346a31488a8e040bcf357bd91af-351.jpg"
}
下载图片
接口
http://api.mthreads.com/image/images/{image_name}
类型
Get
参数
| 名称 | 类型 | 备注 |
|---|---|---|
| image_name | string | 上传图片返回的image name |
返回
图片
示例
请求
注意在wget中,使用--header替换curl中的-H
wget --header "Authorization: "\ http://api.mthreads.com/image/images/c6a0024087a48b0135ca81b6d2f8a337.png
返回
#异常
{
"status":-1,
"message":"failed",
"data":"file type shoulbe be png, jpg or jpeg"
}
#正常
图片