入门基础
欢迎使用 Midjourney API!本节将为您介绍如何开始使用 Midjourney 的 API 服务,包括必要的准备工作和基本的使用步骤。
开始之前
在使用API之前,您需要准备以下内容:
- 注册大模型API聚合平台:https://DMXAPI.com 5元用上全球100个大模型,聚合全球LLM模型、生图模型、视频模型、音乐模型等等
- 具备 Midjourney 使用经验:在 Discord 或其他平台使用 Midjourney 各项功能和服务,这将大大有助于你理解下面的各个API接口。
获取 API 密钥
- 登录 DMXAPI.com
- 在 “令牌” 页面新增一个令牌,例如令牌取名:MJkey。
- 复制生成的令牌备用并妥善保管。
基本使用步骤
- 发送提示词:首先通过 API 提交提示词,获得任务ID。
- 获得四选一:读取任务 ID 的四张图,获得 U 和 V 两种方式的 customId
- 执行四选一:通过任务 ID 和 customId 告诉模型你让他下一步优化那张图。
- 循环修改/获得最终图片:反复通过上面步骤进行调整,获得最终图片 URL
示例:提交一个 Imagine 任务
{
"mode": "RELAX",
"notifyHook": "https://your.callback.url",
"base64Array": [
"data:image/png;base64,xxx1",
"data:image/png;base64,xxx2"
],
"prompt": "Cat",
"state": "custom_state_info"
}
轮询任务状态
提交任务后,您可以通过任务 ID 查询任务的状态,或者设置回调地址以接收任务完成的通知。详见 1.9 指定 ID 查询任务 和 1.13 回调地址 章节。
常见问题
- 如何获取任务 ID? 提交任务成功后,API 将返回一个任务 ID。您可以使用该 ID 查询任务状态和结果。
- API 请求失败怎么办? 请检查您的 API 密钥是否正确,参数是否符合要求,并确保网络连接正常。如问题依旧,请联系 Midjourney 支持团队。
进一步学习
阅读本文档的详细 API 接口说明,了解如何使用更多功能,如 Blend 操作、FaceSwap 等。通过掌握这些接口,您可以更好地集成 Midjourney 的绘图能力到您的应用中。
一、Midjourney 绘图
Midjourney 提供强大的绘图API,帮助开发者轻松集成图像生成、编辑等功能。本节详细介绍各个API端点的使用方法、请求参数及响应结构。
1.1 提交 Imagine 任务
接口地址: https://www.dmxapi.com/mj/submit/imagine
请求方式: POST
请求数据类型: application/json
响应数据类型: */*
接口描述: 执行 Imagine 操作,提交绘图任务。
请求示例:
{
"mode": "RELAX",
"notifyHook": "",
"base64Array": [
"data:image/png;base64,xxx1",
"data:image/png;base64,xxx2"
],
"prompt": "Cat", #提示词用英文
"state": ""
}
请求参数:
参数名称 | 参数含义 | 是否必选 | 参数类型 | 备注 |
---|---|---|---|---|
mode | 调用模式,默认 RELAX | 否 | string | RELAX: 慢速模式, FAST: 快速模式 |
notifyhook | 回调地址,为空时不进行回调通知 | 否 | string | |
base64Array | 垫图 base64 数组 | 否 | array | base64 的数据,可以使用 base64 图片在线转换工具 |
prompt | 提示词, 示例值 (Cat) | 是 | string | |
state | 自定义参数 | 否 | string |
响应示例:
{
"code": 1,
"description": "Submit success",
"result": "1712158011464906"
}
响应参数:
参数名称 | 参数说明 | 类型 |
---|---|---|
code | 状态码: 1(提交成功), 22(排队中), 23(队列已满,请稍后尝试), 24(prompt 包含敏感词), other(错误) | integer(int32) |
description | 描述 | string |
result | 任务 ID | string |
1.2 提交 Action 任务
接口地址: https://www.dmxapi.com/mj/submit/action
请求方式: POST
请求数据类型: application/json
响应数据类型: */*
接口描述: 该接口用于点击图片下方的按钮,customId 通过任务查询接口获取。
请求示例:
{
"notifyHook": "",
"customId": "MJ::JOB::upsample::2::3dbbd469-36af-4a0f-8f02-df6c579e7011",
"taskId": "14001934816969359",
"state": ""
}
请求参数:
参数名称 | 参数含义 | 是否必选 | 参数类型 | 备注 |
---|---|---|---|---|
notifyhook | 回调地址,为空时不进行回调通知 | 否 | string | |
customId | 动作标识, 示例值(MJ::JOB::upsample::2::3dbbd469-36af-4a0f-8f02-df6c579e7011) | 是 | string | |
botType | bot 类型 | 否 | string | mj: MID_JOURNEY, niji: NIJI_JOURNEY |
taskId | 任务 ID | 是 | string | |
state | 自定义参数 | 否 | string | |
enableRemix | 是否使用 remix | 否 | boolean |
响应示例:
{
"code": 1,
"description": "Submit success",
"result": "1712203779820810"
}
响应参数:
参数名称 | 参数说明 | 类型 |
---|---|---|
code | 状态码: 1(提交成功), 22(排队中), 23(队列已满,请稍后尝试), 24(prompt 包含敏感词), other(错误) | integer(int32) |
description | 描述 | string |
result | 任务 ID | string |
1.3 提交 Blend 任务
接口地址: https://www.dmxapi.com/mj/submit/blend
请求方式: POST
请求数据类型: application/json
响应数据类型: */*
接口描述: 执行 Blend 操作,提交融图任务。
请求示例:
{
"mode": "RELAX",
"notifyHook": "",
"base64Array": [
"data:image/png;base64,xxx1",
"data:image/png;base64,xxx2"
],
"dimensions": "SQUARE",
"state": ""
}
请求参数:
参数名称 | 参数含义 | 是否必选 | 参数类型 | 备注 |
---|---|---|---|---|
mode | 调用模式,默认 RELAX | 否 | string | RELAX: 慢速模式, FAST: 快速模式 |
notifyhook | 回调地址,为空时不进行回调通知 | 否 | string | |
base64Array | 图片 base64 数组, 示例值 ([ "data:image/png;base64,xxx1", "data:image/png;base64,xxx2" ]) | 是 | array | string |
dimensions | 比例: PORTRAIT(2:3); SQUARE(1:1); LANDSCAPE(3:2), 可用值: PORTRAIT, SQUARE, LANDSCAPE, 示例值 (SQUARE) | 否 | string | |
botType | bot 类型 | 否 | string | mj: MID_JOURNEY, niji: NIJI_JOURNEY |
state | 自定义参数 | 否 | string |
响应示例:
{
"code": 1,
"description": "Submit success",
"result": "1712204995849323"
}
响应参数:
参数名称 | 参数说明 | 类型 |
---|---|---|
code | 状态码: 1(提交成功), 22(排队中), 23(队列已满,请稍后尝试), 24(prompt 包含敏感词), other(错误) | integer(int32) |
description | 描述 | string |
result | 任务 ID | string |
1.4 提交 Modal 任务
接口地址: https://www.dmxapi.com/mj/submit/modal
请求方式: POST
请求数据类型: application/json
响应数据类型: */*
接口描述: 当执行其他任务,code 返回 21 时,需要执行 Modal 接口,传入新的提示词用来修改细节。
请求示例:
{
"maskBase64": "data:image/png;base64,xxx1",
"prompt": "Cat",
"taskId": "1712204995849323"
}
请求参数:
参数名称 | 参数含义 | 是否必选 | 参数类型 | 备注 |
---|---|---|---|---|
taskId | 任务 ID, 示例值 (14001934816969359) | 是 | string | |
maskBase64 | 局部重绘的蒙版 base64 | 否 | string | 该字段用于局部重绘时传入 |
prompt | 提示词 | 否 | string | 大部分时候都需要传 |
响应示例:
{
"code": 1,
"description": "Submit success",
"result": "1712204995849323"
}
响应参数:
参数名称 | 参数说明 | 类型 |
---|---|---|
code | 状态码: 1(提交成功), 22(排队中), 23(队列已满,请稍后尝试), 24(prompt 包含敏感词), other(错误) | integer(int32) |
description | 描述 | string |
result | 任务 ID | string |
1.5 提交 Describe 任务
接口地址: https://www.dmxapi.com/mj/submit/describe
请求方式: POST
请求数据类型: application/json
响应数据类型: */*
接口描述: 执行 Describe 操作,提交图生文任务。
请求示例:
{
"mode": "RELAX",
"notifyHook": "",
"base64": "data:image/png;base64,xxx",
"state": ""
}
请求参数:
参数名称 | 参数含义 | 是否必选 | 参数类型 | 备注 |
---|---|---|---|---|
mode | 调用模式,默认 RELAX | 否 | string | RELAX: 慢速模式, FAST: 快速模式 |
notifyhook | 回调地址,为空时不进行回调通知 | 否 | string | |
base64 | 图片 base64, 示例值(data:image/png;base64,xxx) | 是 | string | |
botType | bot 类型 | 否 | string | mj: MID_JOURNEY, niji: NIJI_JOURNEY |
state | 自定义参数 | 否 | string |
响应示例:
{
"code": 1,
"description": "Submit success",
"result": "1712205491372224"
}
响应参数:
参数名称 | 参数说明 | 类型 |
---|---|---|
code | 状态码: 1(提交成功), 22(排队中), 23(队列已满,请稍后尝试), 24(prompt 包含敏感词), other(错误) | integer(int32) |
description | 描述 | string |
result | 任务 ID | string |
1.6 提交 Shorten 任务
接口地址: https://www.dmxapi.com/mj/submit/shorten
请求方式: POST
请求数据类型: application/json
响应数据类型: */*
接口描述: 执行 shorten 操作。
请求示例:
{
"mode": "RELAX",
"notifyHook": "",
"prompt": "Cat",
"state": ""
}
请求参数:
参数名称 | 参数含义 | 是否必选 | 参数类型 | 备注 |
---|---|---|---|---|
mode | 调用模式,默认 RELAX | 否 | string | RELAX: 慢速模式, FAST: 快速模式 |
notifyhook | 回调地址,为空时不进行回调通知 | 否 | string | |
botType | bot 类型 | 否 | string | mj: MID_JOURNEY, niji: NIJI_JOURNEY |
prompt | 提示词, 示例值 (Cat) | 是 | string | |
state | 自定义参数 | 否 | string |
响应示例:
{
"code": 1,
"description": "Submit success",
"result": "1712205491372224"
}
响应参数:
参数名称 | 参数说明 | 类型 |
---|---|---|
code | 状态码: 1(提交成功), 22(排队中), 23(队列已满,请稍后尝试), 24(prompt 包含敏感词), other(错误) | integer(int32) |
description | 描述 | string |
result | 任务 ID | string |
1.7 提交 FaceSwap 任务
接口地址: https://www.dmxapi.com/mj/insight-face/swap
请求方式: POST
请求数据类型: application/json
响应数据类型: */*
接口描述: 提交 FaceSwap 任务,进行换脸操作。
请求示例:
{
"mode": "RELAX",
"notifyHook": "",
"sourceBase64": "data:image/png;base64,xxx1",
"targetBase64": "data:image/png;base64,xxx2",
"state": ""
}
请求参数:
参数名称 | 参数含义 | 是否必选 | 参数类型 | 备注 |
---|---|---|---|---|
mode | 调用模式,默认 RELAX | 否 | string | RELAX: 慢速模式, FAST: 快速模式 |
notifyhook | 回调地址,为空时不进行回调通知 | 否 | string | |
sourceBase64 | 人脸源图片 base64, 示例值(data:image/png;base64,xxx1) | 是 | string | |
targetBase64 | 目标图片 base64, 示例值(data:image/png;base64,xxx2) | 是 | string | |
state | 自定义参数 | 否 | string |
响应示例:
{
"code": 1,
"description": "Submit success",
"result": "1712211887200849"
}
响应参数:
参数名称 | 参数说明 | 类型 |
---|---|---|
code | 状态码: 1(提交成功), 22(排队中), 23(队列已满,请稍后尝试), 24(prompt 包含敏感词), other(错误) | integer(int32) |
description | 描述 | string |
result | 任务 ID | string |
1.8 上传文件到 Discord
接口地址: https://www.dmxapi.com/mj/submit/upload-discord-images
请求方式: POST
请求数据类型: application/json
响应数据类型: */*
接口描述: 上传文件到 Discord。
请求示例:
{
"mode": "RELAX",
"base64Array": [
"data:image/png;base64,xxx1"
]
}
请求参数:
参数名称 | 参数含义 | 是否必选 | 参数类型 | 备注 |
---|---|---|---|---|
mode | 调用模式,默认 RELAX | 否 | string | RELAX: 慢速模式, FAST: 快速模式 |
base64Array | base64 数组 | 是 | array |
响应示例:
{
"code": 1,
"description": "success",
"result": [
"https://cdn.discordapp.com/attachments/1235333617467789395/1237020337057828935/1508569645328691200.jpg?ex=663a2077&is=6638cef7&hm=991c97a66f00ee5b5714848ccf0cded22929d58f0d809f0057c71c4b29ee469d&"
]
}
响应参数:
参数名称 | 参数说明 | 类型 |
---|---|---|
code | 状态码: 1(提交成功), 22(排队中), 23(队列已满,请稍后尝试), 24(prompt 包含敏感词), other(错误) | integer(int32) |
description | 描述 | string |
result | 图片地址 | array |
1.9 指定 ID 查询任务
接口地址: https://www.dmxapi.com/mj/query/task/{id}
请求方式: GET
请求数据类型: application/json
响应数据类型: */*
接口描述: 通过任务 ID,查询任务信息。可以通过轮询调用该接口,实现任务进行的查询。也可以通过回调接口获取。
请求示例:
curl 'https://www.dmxapi.com/mj/query/task/1712205491372224'
请求参数:
参数名称 | 参数含义 | 是否必选 | 参数类型 | 备注 |
---|---|---|---|---|
id | 任务 ID | 是 | path |
响应示例:
{
"id": "1712205491372224",
"action": "DESCRIBE",
"prompt": "",
"promptEn": "1️⃣ White haired anime boy with blue eyes and black sweatshirt, small white dog in the background, anime style, aesthetic \n\n2️⃣ A cute anime boy with white hair and blue eyes, wearing black , is standing next to his small dog in the sunlight. The background features soft lighting and a simple composition. He has an adorable expression on his face, exuding cuteness., Anime style,Cute hairstyle \n\n3️⃣ A cute anime boy with white hair and blue eyes, wearing black sweatshirt vest, standing next to his small dog. The background is blurred and sunny, creating an atmosphere of calmness and happiness. \n\n4️⃣ White haired anime boy with blue eyes and small white dog, anime style, aesthetic, cute",
"description": "Submit success",
"submitTime": 1712205491372,
"startTime": 1712205494313,
"finishTime": 1712205499534,
"imageUrl": "https://cdn.discordapp.com/ephemeral-attachments/1092492867185950852/1225303391505485904/1712205491372224.jpg?ex=6620a3b5&is=660e2eb5&hm=14ed57f41dce6178c65757ee58a84e8314fde1bf294da32fac2d8ea991dd3e52&",
"status": "SUCCESS",
"progress": "100%",
"failReason": "",
"buttons": [
{
"customId": "MJ::Job::PicReader::1",
"emoji": "1️⃣",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Job::PicReader::2",
"emoji": "2️⃣",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Job::PicReader::3",
"emoji": "3️⃣",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Job::PicReader::4",
"emoji": "4️⃣",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Picread::Retry",
"emoji": "🔄",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Job::PicReader::all",
"emoji": "🎉",
"label": "Imagine all",
"type": 2,
"style": 2
}
],
"state": ""
}
响应参数:
参数名称 | 参数说明 | 类型 |
---|---|---|
action | 任务类型, 可用值: IMAGINE, UPSCALE, VARIATION, ZOOM, PAN, DESCRIBE, BLEND, SHORTEN, SWAP_FACE | string |
buttons | 按钮数组:图片下方对应的各个按钮数组,需要点击按钮时,将 customId 传给 action 接口 | array |
description | 任务描述 | string |
failReason | 失败原因 | string |
finishTime | 结束时间 | integer(int64) |
id | ID | string |
imageUrl | 图片 URL | string |
progress | 任务进度 | string |
prompt | 提示词 | string |
promptEn | 提示词-英文 | string |
startTime | 开始执行时间 | integer(int64) |
status | 任务状态, 可用值: NOT_START, SUBMITTED, MODAL, IN_PROGRESS, FAILURE, SUCCESS, CANCEL | string |
submitTime | 提交时间 | integer(int64) |
state | 自定义参数 | string |
customId | 动作标识 | string |
emoji | 图标 | string |
label | 文本 | string |
style | 样式: 2(Primary)、3(Green) | integer(int32) |
type | 类型,系统内部使用 | integer(int32) |
1.10 指定 ID 查询任务(fetch)
接口地址: https://www.dmxapi.com/mj/task/{id}/fetch
请求方式: GET
请求数据类型: application/json
响应数据类型: */*
接口描述: 通过任务 ID,查询任务信息。可以通过轮询调用该接口,实现任务进行的查询。也可以通过回调接口获取。
请求示例:
curl 'https://www.dmxapi.com/mj/task/1712205491372224/fetch'
请求参数:
参数名称 | 参数含义 | 是否必选 | 参数类型 | 备注 |
---|---|---|---|---|
id | 任务 ID | 是 | path |
响应示例:
{
"id": "1712205491372224",
"action": "DESCRIBE",
"prompt": "",
"promptEn": "1️⃣ White haired anime boy with blue eyes and black sweatshirt, small white dog in the background, anime style, aesthetic \n\n2️⃣ A cute anime boy with white hair and blue eyes, wearing black , is standing next to his small dog in the sunlight. The background features soft lighting and a simple composition. He has an adorable expression on his face, exuding cuteness., Anime style,Cute hairstyle \n\n3️⃣ A cute anime boy with white hair and blue eyes, wearing black sweatshirt vest, standing next to his small dog. The background is blurred and sunny, creating an atmosphere of calmness and happiness. \n\n4️⃣ White haired anime boy with blue eyes and small white dog, anime style, aesthetic, cute",
"description": "Submit success",
"submitTime": 1712205491372,
"startTime": 1712205494313,
"finishTime": 1712205499534,
"imageUrl": "https://cdn.discordapp.com/ephemeral-attachments/1092492867185950852/1225303391505485904/1712205491372224.jpg?ex=6620a3b5&is=660e2eb5&hm=14ed57f41dce6178c65757ee58a84e8314fde1bf294da32fac2d8ea991dd3e52&",
"status": "SUCCESS",
"progress": "100%",
"failReason": "",
"buttons": [
{
"customId": "MJ::Job::PicReader::1",
"emoji": "1️⃣",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Job::PicReader::2",
"emoji": "2️⃣",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Job::PicReader::3",
"emoji": "3️⃣",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Job::PicReader::4",
"emoji": "4️⃣",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Picread::Retry",
"emoji": "🔄",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Job::PicReader::all",
"emoji": "🎉",
"label": "Imagine all",
"type": 2,
"style": 2
}
],
"state": ""
}
响应参数:
参数名称 | 参数说明 | 类型 |
---|---|---|
action | 任务类型, 可用值: IMAGINE, UPSCALE, VARIATION, ZOOM, PAN, DESCRIBE, BLEND, SHORTEN, SWAP_FACE | string |
buttons | 按钮数组:图片下方对应的各个按钮数组,需要点击按钮时,将 customId 传给 action 接口 | array |
description | 任务描述 | string |
failReason | 失败原因 | string |
finishTime | 结束时间 | integer(int64) |
id | ID | string |
imageUrl | 图片 URL | string |
progress | 任务进度 | string |
prompt | 提示词 | string |
promptEn | 提示词-英文 | string |
startTime | 开始执行时间 | integer(int64) |
status | 任务状态, 可用值: NOT_START, SUBMITTED, MODAL, IN_PROGRESS, FAILURE, SUCCESS, CANCEL | string |
submitTime | 提交时间 | integer(int64) |
state | 自定义参数 | string |
customId | 动作标识 | string |
emoji | 图标 | string |
label | 文本 | string |
style | 样式: 2(Primary)、3(Green) | integer(int32) |
type | 类型,系统内部使用 | integer(int32) |
1.10 指定 ID 查询任务(fetch)
接口地址: https://www.dmxapi.com/mj/task/{id}/fetch
请求方式: GET
请求数据类型: application/json
响应数据类型: */*
接口描述: 通过任务 ID,查询任务信息。可以通过轮询调用该接口,实现任务进行的查询。也可以通过回调接口获取。
请求示例:
curl 'https://www.dmxapi.com/mj/task/1712205491372224/fetch'
请求参数:
参数名称 | 参数含义 | 是否必选 | 参数类型 | 备注 |
---|---|---|---|---|
id | 任务 ID | 是 | path |
响应示例:
{
"id": "1712205491372224",
"action": "DESCRIBE",
"prompt": "",
"promptEn": "1️⃣ White haired anime boy with blue eyes and black sweatshirt, small white dog in the background, anime style, aesthetic \n\n2️⃣ A cute anime boy with white hair and blue eyes, wearing black , is standing next to his small dog in the sunlight. The background features soft lighting and a simple composition. He has an adorable expression on his face, exuding cuteness., Anime style,Cute hairstyle \n\n3️⃣ A cute anime boy with white hair and blue eyes, wearing black sweatshirt vest, standing next to his small dog. The background is blurred and sunny, creating an atmosphere of calmness and happiness. \n\n4️⃣ White haired anime boy with blue eyes and small white dog, anime style, aesthetic, cute",
"description": "Submit success",
"submitTime": 1712205491372,
"startTime": 1712205494313,
"finishTime": 1712205499534,
"imageUrl": "https://cdn.discordapp.com/ephemeral-attachments/1092492867185950852/1225303391505485904/1712205491372224.jpg?ex=6620a3b5&is=660e2eb5&hm=14ed57f41dce6178c65757ee58a84e8314fde1bf294da32fac2d8ea991dd3e52&",
"status": "SUCCESS",
"progress": "100%",
"failReason": "",
"buttons": [
{
"customId": "MJ::Job::PicReader::1",
"emoji": "1️⃣",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Job::PicReader::2",
"emoji": "2️⃣",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Job::PicReader::3",
"emoji": "3️⃣",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Job::PicReader::4",
"emoji": "4️⃣",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Picread::Retry",
"emoji": "🔄",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Job::PicReader::all",
"emoji": "🎉",
"label": "Imagine all",
"type": 2,
"style": 2
}
],
"state": ""
}
响应参数:
参数名称 | 参数说明 | 类型 |
---|---|---|
action | 任务类型, 可用值: IMAGINE, UPSCALE, VARIATION, ZOOM, PAN, DESCRIBE, BLEND, SHORTEN, SWAP_FACE | string |
buttons | 按钮数组:图片下方对应的各个按钮数组,需要点击按钮时,将 customId 传给 action 接口 | array |
description | 任务描述 | string |
failReason | 失败原因 | string |
finishTime | 结束时间 | integer(int64) |
id | ID | string |
imageUrl | 图片 URL | string |
progress | 任务进度 | string |
prompt | 提示词 | string |
promptEn | 提示词-英文 | string |
startTime | 开始执行时间 | integer(int64) |
status | 任务状态, 可用值: NOT_START, SUBMITTED, MODAL, IN_PROGRESS, FAILURE, SUCCESS, CANCEL | string |
submitTime | 提交时间 | integer(int64) |
state | 自定义参数 | string |
customId | 动作标识 | string |
emoji | 图标 | string |
label | 文本 | string |
style | 样式: 2(Primary)、3(Green) | integer(int32) |
type | 类型,系统内部使用 | integer(int32) |
1.10 指定 ID 查询任务(fetch)
接口地址: https://www.dmxapi.com/mj/task/{id}/fetch
请求方式: GET
请求数据类型: application/json
响应数据类型: */*
接口描述: 通过任务 ID,查询任务信息。可以通过轮询调用该接口,实现任务进行的查询。也可以通过回调接口获取。
请求示例:
curl 'https://www.dmxapi.com/mj/task/1712205491372224/fetch'
请求参数:
参数名称 | 参数含义 | 是否必选 | 参数类型 | 备注 |
---|---|---|---|---|
id | 任务 ID | 是 | path |
响应示例:
{
"id": "1712205491372224",
"action": "DESCRIBE",
"prompt": "",
"promptEn": "1️⃣ White haired anime boy with blue eyes and black sweatshirt, small white dog in the background, anime style, aesthetic \n\n2️⃣ A cute anime boy with white hair and blue eyes, wearing black , is standing next to his small dog in the sunlight. The background features soft lighting and a simple composition. He has an adorable expression on his face, exuding cuteness., Anime style,Cute hairstyle \n\n3️⃣ A cute anime boy with white hair and blue eyes, wearing black sweatshirt vest, standing next to his small dog. The background is blurred and sunny, creating an atmosphere of calmness and happiness. \n\n4️⃣ White haired anime boy with blue eyes and small white dog, anime style, aesthetic, cute",
"description": "Submit success",
"submitTime": 1712205491372,
"startTime": 1712205494313,
"finishTime": 1712205499534,
"imageUrl": "https://cdn.discordapp.com/ephemeral-attachments/1092492867185950852/1225303391505485904/1712205491372224.jpg?ex=6620a3b5&is=660e2eb5&hm=14ed57f41dce6178c65757ee58a84e8314fde1bf294da32fac2d8ea991dd3e52&",
"status": "SUCCESS",
"progress": "100%",
"failReason": "",
"buttons": [
{
"customId": "MJ::Job::PicReader::1",
"emoji": "1️⃣",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Job::PicReader::2",
"emoji": "2️⃣",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Job::PicReader::3",
"emoji": "3️⃣",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Job::PicReader::4",
"emoji": "4️⃣",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Picread::Retry",
"emoji": "🔄",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::Job::PicReader::all",
"emoji": "🎉",
"label": "Imagine all",
"type": 2,
"style": 2
}
],
"state": ""
}
响应参数:
参数名称 | 参数说明 | 类型 |
---|---|---|
action | 任务类型, 可用值: IMAGINE, UPSCALE, VARIATION, ZOOM, PAN, DESCRIBE, BLEND, SHORTEN, SWAP_FACE | string |
buttons | 按钮数组:图片下方对应的各个按钮数组,需要点击按钮时,将 customId 传给 action 接口 | array |
description | 任务描述 | string |
failReason | 失败原因 | string |
finishTime | 结束时间 | integer(int64) |
id | ID | string |
imageUrl | 图片 URL | string |
progress | 任务进度 | string |
prompt | 提示词 | string |
promptEn | 提示词-英文 | string |
startTime | 开始执行时间 | integer(int64) |
status | 任务状态, 可用值: NOT_START, SUBMITTED, MODAL, IN_PROGRESS, FAILURE, SUCCESS, CANCEL | string |
submitTime | 提交时间 | integer(int64) |
state | 自定义参数 | string |
customId | 动作标识 | string |
emoji | 图标 | string |
label | 文本 | string |
style | 样式: 2(Primary)、3(Green) | integer(int32) |
type | 类型,系统内部使用 | integer(int32) |
1.11 指定 ID 列表查询任务
接口地址: https://www.dmxapi.com/mj/task/list-by-condition
请求方式: POST
请求数据类型: application/json
响应数据类型: */*
接口描述: 通过任务 ID 数组,查询任务信息。可以通过轮询调用该接口,实现任务进行的查询。也可以通过回调接口获取。
请求示例:
{
"ids": [
"1712158011464906"
]
}
请求参数:
参数名称 | 参数含义 | 是否必选 | 参数类型 | 备注 |
---|---|---|---|---|
ids | 任务 ID 数 | 是 | array |
响应示例:
[
{
"id": "1712158011464906",
"action": "IMAGINE",
"prompt": "a cat",
"promptEn": "a cat",
"description": "Submit success",
"state": "",
"submitTime": 1712158011464,
"startTime": 1712158012279,
"finishTime": 1712158069485,
"imageUrl": "https://dl.deepwl.net/attachments/1224565686630875148/1225104478341042197/8bls4f1w_85275_a_cat_639e5abd-a032-45d9-a49e-f53f2382fbb0.png?ex=661fea74&is=660d7574&hm=34265daf2885402f17c5a5117d8711b72e27f0f70233e33a1948d83be5bda71f&",
"status": "SUCCESS",
"progress": "100%",
"failReason": "",
"buttons": [
{
"customId": "MJ::JOB::upsample::1::639e5abd-a032-45d9-a49e-f53f2382fbb0",
"emoji": "",
"label": "U1",
"type": 2,
"style": 2
},
{
"customId": "MJ::JOB::upsample::2::639e5abd-a032-45d9-a49e-f53f2382fbb0",
"emoji": "",
"label": "U2",
"type": 2,
"style": 2
},
{
"customId": "MJ::JOB::upsample::3::639e5abd-a032-45d9-a49e-f53f2382fbb0",
"emoji": "",
"label": "U3",
"type": 2,
"style": 2
},
{
"customId": "MJ::JOB::upsample::4::639e5abd-a032-45d9-a49e-f53f2382fbb0",
"emoji": "",
"label": "U4",
"type": 2,
"style": 2
},
{
"customId": "MJ::JOB::reroll::0::639e5abd-a032-45d9-a49e-f53f2382fbb0::SOLO",
"emoji": "🔄",
"label": "",
"type": 2,
"style": 2
},
{
"customId": "MJ::JOB::variation::1::639e5abd-a032-45d9-a49e-f53f2382fbb0",
"emoji": "",
"label": "V1",
"type": 2,
"style": 2
},
{
"customId": "MJ::JOB::variation::2::639e5abd-a032-45d9-a49e-f53f2382fbb0",
"emoji": "",
"label": "V2",
"type": 2,
"style": 2
},
{
"customId": "MJ::JOB::variation::3::639e5abd-a032-45d9-a49e-f53f2382fbb0",
"emoji": "",
"label": "V3",
"type": 2,
"style": 2
},
{
"customId": "MJ::JOB::variation::4::639e5abd-a032-45d9-a49e-f53f2382fbb0",
"emoji": "",
"label": "V4",
"type": 2,
"style": 2
}
]
}
]
响应参数:
参数名称 | 参数说明 | 类型 |
---|---|---|
action | 任务类型, 可用值: IMAGINE, UPSCALE, VARIATION, ZOOM, PAN, DESCRIBE, BLEND, SHORTEN, SWAP_FACE | string |
buttons | 按钮数组:图片下方对应的各个按钮数组,需要点击按钮时,将 customId 传给 action 接口 | array |
description | 任务描述 | string |
failReason | 失败原因 | string |
finishTime | 结束时间 | integer(int64) |
id | ID | string |
imageUrl | 图片 URL | string |
progress | 任务进度 | string |
prompt | 提示词 | string |
promptEn | 提示词-英文 | string |
startTime | 开始执行时间 | integer(int64) |
status | 任务状态, 可用值: NOT_START, SUBMITTED, MODAL, IN_PROGRESS, FAILURE, SUCCESS, CANCEL | string |
submitTime | 提交时间 | integer(int64) |
state | 自定义参数 | string |
customId | 动作标识 | string |
emoji | 图标 | string |
label | 文本 | string |
style | 样式: 2(Primary)、3(Green) | integer(int32) |
type | 类型,系统内部使用 | integer(int32) |
1.12 获取任务图片的 seed
接口地址: https://www.dmxapi.com/mj/task/{id}/image-seed
请求方式: GET
请求数据类型: application/json
响应数据类型: */*
接口描述: 通过任务 ID,查询图片 seed。
请求示例:
curl 'https://www.dmxapi.com/mj/task/1712205491372224/image-seed'
请求参数:
参数名称 | 参数含义 | 是否必选 | 参数类型 | 备注 |
---|---|---|---|---|
id | 任务 ID | 是 | path |
响应示例:
{
"code": 1,
"description": "",
"result": ""
}
响应参数:
参数名称 | 参数说明 | 类型 |
---|---|---|
code | 状态码: 1(提交成功), 22(排队中), 23(队列已满,请稍后尝试), 24(prompt 包含敏感词), other(错误) | integer(int32) |
description | 描述 | string |
result | 图片 seed | string |
二、任务查询
Midjourney API 提供多种任务查询方式,帮助开发者实时监控任务状态和获取结果。您可以通过指定任务 ID 或者任务 ID 列表来查询任务信息。
详细信息请参考上面的 1.9 指定 ID 查询任务 和 1.10 指定 ID 查询任务(fetch) 节。
三、回调地址
1.13 回调地址
描述: 提交任务的时候,可以通过 notifyHook
填上自己的回调地址,这样任务在状态变化时,会不断地向该地址推送更新。您可以通过回调地址实时更新任务状态,或者通过任务 ID 定期获取最新信息。
回调请求参数: 与任务查询接口的响应参数一致。
使用场景:
- 实时监控任务状态变化
- 在任务完成后自动触发后续操作
- 集成到您的应用程序中,实现自动化流程
确保您的回调地址能够处理来自 Midjourney API 的 POST 请求,并根据接收到的数据更新您的系统状态。