Documentation Index
Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
Use this file to discover all available pages before exploring further.
理解核心概念
MidJourney API 模拟 Discord 按钮交互。与典型的 REST API 不同,它的工作方式类似于一个状态机,其中每一步操作都会返回下一步可用的新按钮。
4 个核心 API
| API | 用途 | 使用时机 |
|---|
POST /mj/submit/imagine | 文生图生成 | 所有工作流的起点 |
GET /mj/task/\{id\}/fetch | 查询任务状态并获取按钮 | 每次提交之后(轮询直到完成) |
POST /mj/submit/action | 点击按钮(放大、变体、缩放等) | 当你想对图像执行操作时 |
POST /mj/submit/modal | 提交额外输入 | 仅当状态为 MODAL 时 |
完整工作流图
┌─────────────────────────────────────────────────────────────────────────────┐
│ MIDJOURNEY API WORKFLOW │
└─────────────────────────────────────────────────────────────────────────────┘
┌──────────────────┐
│ POST /submit/ │ ← Step 1: Submit prompt, get task_id
│ imagine │
└────────┬─────────┘
│ Returns: { "result": "task_id_1" }
▼
┌──────────────────┐
│ GET /task/{id}/ │ ← Step 2: Poll until status = "SUCCESS"
│ fetch │
└────────┬─────────┘
│ Returns: imageUrl + buttons[] (U1,U2,U3,U4,V1,V2,V3,V4,🔄)
▼
┌──────────────────┐
│ POST /submit/ │ ← Step 3: Click a button using customId
│ action │
└────────┬─────────┘
│ Returns: { "result": "task_id_2" }
▼
┌──────────────────┐
│ GET /task/{id}/ │ ← Step 4: Poll the new task
│ fetch │
└────────┬─────────┘
│
├─── status = "SUCCESS" → Done! Get imageUrl
│
└─── status = "MODAL" → Need additional input (see Step 5)
│
▼
┌──────────────────┐
│ POST /submit/ │ ← Step 5: Submit mask/prompt for special operations
│ modal │
└────────┬─────────┘
│ Returns: { "result": "task_id_3" }
▼
┌──────────────────┐
│ GET /task/{id}/ │ ← Step 6: Poll until SUCCESS
│ fetch │
└──────────────────┘
关键概念:按钮和 customId
每个成功的任务都会返回一个 buttons 数组。每个按钮都有一个 customId,你可以用它来触发下一步操作。
来自 /mj/task/\{id\}/fetch 的示例响应:
{
"status": "SUCCESS",
"imageUrl": "https://api.cometapi.com/mj/image/xxx",
"buttons": [
{ "customId": "MJ::JOB::upsample::1::abc123", "label": "U1" },
{ "customId": "MJ::JOB::upsample::2::abc123", "label": "U2" },
{ "customId": "MJ::JOB::variation::1::abc123", "label": "V1" },
{ "customId": "MJ::JOB::reroll::0::abc123", "emoji": "🔄" }
]
}
customId 不是固定值。它会随每个任务而变化。始终从 buttons 数组中获取它。
按阶段划分的按钮参考
在 IMAGINE 之后(4 宫格图像)
当你的初始图像生成完成后,会返回这些按钮:
| Button | customId Pattern | Action | Result |
|---|
| U1-U4 | MJ::JOB::upsample::1::xxx | 放大单张图像 | 高分辨率单张图像 |
| V1-V4 | MJ::JOB::variation::1::xxx | 生成变体 | 新的 4 宫格 |
| 🔄 | MJ::JOB::reroll::0::xxx::SOLO | 重新生成全部 | 新的 4 宫格 |
在 UPSCALE 之后(单张图像)
放大后,你将可以使用编辑工具:
| Label | Needs Modal? |
|---|
| Upscale (Subtle) / Upscale (2x) | ❌ 否 |
| Upscale (Creative) / Upscale (4x) | ❌ 否 |
| Vary (Subtle) 🪄 | ❌ 否 |
| Vary (Strong) 🪄 | ❌ 否 |
| Vary (Region) 🖌️ | ✅ 是(mask) |
| Zoom Out 2x / 1.5x 🔍 | ❌ 否 |
| Custom Zoom 🔍 | ✅ 是(prompt) |
| ⬅️➡️⬆️⬇️ Pan | ❌ 否 |
| Animate 🎞️ | ❌ 否 |
| 🔄 Reroll | ❌ 否 |
注意: 按钮标签和 customId 格式可能会因你在 prompt 中指定的 MJ 版本不同而有所变化(例如,--v 6.1 与 --v 5.2)。请始终从 API 响应中读取按钮信息。
Inpaint(Vary Region)按钮仅会在 Upscale 之后出现。
完整示例:生成并放大
第 1 步:提交 imagine 请求
curl -X POST 'https://api.cometapi.com/mj/submit/imagine' \
-H 'Authorization: Bearer <YOUR_COMETAPI_KEY>' \
-H 'Content-Type: application/json' \
-d '{
"botType": "MID_JOURNEY",
"prompt": "a cute cat --v 6.1",
"accountFilter": { "modes": ["FAST"] }
}'
响应:
{ "code": 1, "result": "1768464763141701" }
第 2 步:轮询任务状态
curl -X GET 'https://api.cometapi.com/mj/task/1768464763141701/fetch' \
-H 'Authorization: Bearer <YOUR_COMETAPI_KEY>'
响应(完成时):
{
"status": "SUCCESS",
"imageUrl": "https://api.cometapi.com/mj/image/1768464763141701",
"buttons": [
{ "customId": "MJ::JOB::upsample::1::5f20922e-xxx", "label": "U1" },
{ "customId": "MJ::JOB::upsample::2::5f20922e-xxx", "label": "U2" },
...
]
}
第 3 步:点击 U1 进行放大
curl -X POST 'https://api.cometapi.com/mj/submit/action' \
-H 'Authorization: Bearer <YOUR_COMETAPI_KEY>' \
-H 'Content-Type: application/json' \
-d '{
"taskId": "1768464763141701",
"customId": "MJ::JOB::upsample::1::5f20922e-xxx"
}'
响应:
{ "code": 1, "result": "1768464800000000" }
第 4 步:轮询新任务并获取结果
curl -X GET 'https://api.cometapi.com/mj/task/1768464800000000/fetch' \
-H 'Authorization: Bearer <YOUR_COMETAPI_KEY>'
什么时候需要 Modal?
当你调用 /mj/submit/action 且任务状态变为 MODAL 而不是 SUCCESS 时,你必须调用 /mj/submit/modal 来提供额外输入。
已确认需要 Modal 的操作
| Operation | Button | What to Submit |
|---|
| Inpaint | Vary (Region) | maskBase64(PNG mask)+ prompt |
| Custom Zoom | 🔍 Custom Zoom | prompt(例如,“your prompt —zoom 2”) |
示例:Inpaint 流程
# 1. Click Vary (Region) button via Action API
curl -X POST 'https://api.cometapi.com/mj/submit/action' \
-H 'Authorization: Bearer <YOUR_COMETAPI_KEY>' \
-H 'Content-Type: application/json' \
-d '{"taskId": "xxx", "customId": "MJ::Inpaint::xxx", "enableRemix": true}'
# 2. Poll and see status = "MODAL"
curl -X GET 'https://api.cometapi.com/mj/task/new_task_id/fetch'
# Response: { "status": "MODAL" }
# 3. Submit mask and prompt via Modal API
curl -X POST 'https://api.cometapi.com/mj/submit/modal' \
-H 'Authorization: Bearer <YOUR_COMETAPI_KEY>' \
-H 'Content-Type: application/json' \
-d '{
"taskId": "new_task_id",
"prompt": "replace with golden crown",
"maskBase64": "data:image/png;base64,..."
}'
速度模式选择
在路径中添加速度前缀:
| 模式 | 路径前缀 | 示例 |
|---|
| Fast | /mj-fast | /mj-fast/mj/submit/imagine |
| Turbo | /mj-turbo | /mj-turbo/mj/submit/imagine |
| Relax | (默认) | /mj/submit/imagine |
其他入口点
这些 API 是独立入口点,不遵循 imagine → action 流程:
故障排查提示
根据 API 设计和工作流,以下是你可能遇到的常见问题:
| 问题 | 可能原因 | 解决方案 |
|---|
| 找不到 Vary (Region) 按钮 | 正在查看四宫格图片 | 先执行 Upscale(点击 U1-U4),然后再检查按钮 |
任务状态卡在 MODAL | 操作需要额外输入 | 使用所需数据调用 /mj/submit/modal |
customId 无法使用 | 使用了过期或硬编码的值 | 始终从 /mj/task/\{id\}/fetch 的响应中获取最新的 customId |
buttons 数组为空 | 任务仍在处理中 | 等待 status: "SUCCESS" 后再访问按钮 |