Skip to main content

🎯 理解核心概念

MidJourney API 模拟 Discord 按钮交互。与普通 REST API 不同,它是一个状态机,每次操作都会返回新的按钮供下一步使用。

4 个核心接口

接口用途使用时机
POST /mj/submit/imagine文生图所有流程的起点
GET /mj/task/\{id\}/fetch查询任务状态 & 获取按钮每次提交后轮询
POST /mj/submit/action点击按钮(放大、变体、缩放等)对图片进行操作时
POST /mj/submit/modal提交额外输入仅当状态为 MODAL

📊 完整工作流程图

┌─────────────────────────────────────────────────────────────────────────────┐
│                         MIDJOURNEY API 工作流程                              │
└─────────────────────────────────────────────────────────────────────────────┘

  ┌──────────────────┐
  │  POST /submit/   │  ← 第1步:提交 prompt,获取 task_id
  │     imagine      │
  └────────┬─────────┘
           │ 返回: { "result": "task_id_1" }

  ┌──────────────────┐
  │ GET /task/{id}/  │  ← 第2步:轮询直到 status = "SUCCESS"
  │      fetch       │
  └────────┬─────────┘
           │ 返回: imageUrl + buttons[] (U1,U2,U3,U4,V1,V2,V3,V4,🔄)

  ┌──────────────────┐
  │  POST /submit/   │  ← 第3步:使用 customId 点击按钮
  │     action       │
  └────────┬─────────┘
           │ 返回: { "result": "task_id_2" }

  ┌──────────────────┐
  │ GET /task/{id}/  │  ← 第4步:轮询新任务
  │      fetch       │
  └────────┬─────────┘

           ├─── status = "SUCCESS" → 完成!获取 imageUrl

           └─── status = "MODAL" → 需要额外输入(见第5步)


           ┌──────────────────┐
           │  POST /submit/   │  ← 第5步:提交蒙版/提示词
           │      modal       │
           └────────┬─────────┘
                    │ 返回: { "result": "task_id_3" }

           ┌──────────────────┐
           │ GET /task/{id}/  │  ← 第6步:轮询直到 SUCCESS
           │      fetch       │
           └──────────────────┘

🔑 核心概念:按钮与 customId

每个成功的任务都会返回 buttons 数组。每个按钮都有一个 customId,用于触发下一个操作。 /mj/task/\{id\}/fetch 响应示例:
{
  "status": "SUCCESS",
  "imageUrl": "https://api.deerapi.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 宫格图)

初始图片生成完成后返回以下按钮:
按钮customId 格式操作结果
U1-U4MJ::JOB::upsample::1::xxx放大单张图片高清单图
V1-V4MJ::JOB::variation::1::xxx生成变体新的 4 宫格
🔄MJ::JOB::reroll::0::xxx::SOLO重新生成新的 4 宫格

UPSCALE 后(单张图片)

放大后可使用编辑工具:
按钮需要 Modal?
Upscale (Subtle) / Upscale (2x)❌ 否
Upscale (Creative) / Upscale (4x)❌ 否
Vary (Subtle) 🪄❌ 否
Vary (Strong) 🪄❌ 否
Vary (Region) 🖌️✅ 是(需要蒙版)
Zoom Out 2x / 1.5x 🔍❌ 否
Custom Zoom 🔍✅ 是(需要提示词)
⬅️➡️⬆️⬇️ Pan❌ 否
Animate 🎞️❌ 否
🔄 Reroll❌ 否
注意: 按钮名称和 customId 格式可能因 prompt 中指定的 MJ 版本而异(如 --v 6.1 vs --v 5.2)。务必从 API 响应中读取按钮。
⚠️ Inpaint (Vary Region) 按钮只有在 Upscale 后才会出现!

⚡ 完整示例:生成 & 放大

第 1 步:提交 Imagine 请求

curl -X POST 'https://api.deerapi.com/mj/submit/imagine' \
  -H 'Authorization: Bearer <YOUR_DEERAPI_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.deerapi.com/mj/task/1768464763141701/fetch' \
  -H 'Authorization: Bearer <YOUR_DEERAPI_KEY>'
响应(完成时):
{
  "status": "SUCCESS",
  "imageUrl": "https://api.deerapi.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.deerapi.com/mj/submit/action' \
  -H 'Authorization: Bearer <YOUR_DEERAPI_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.deerapi.com/mj/task/1768464800000000/fetch' \
  -H 'Authorization: Bearer <YOUR_DEERAPI_KEY>'

⚠️ 什么时候需要 Modal?

当调用 /mj/submit/action 后任务状态变为 MODAL 而非 SUCCESS 时,必须调用 /mj/submit/modal 提供额外输入。

需要 Modal 的操作

操作按钮需要提交
局部重绘Vary (Region)maskBase64(PNG 蒙版)+ prompt
自定义缩放🔍 Custom Zoomprompt(如 “your prompt —zoom 2”)
示例:局部重绘流程
# 1. 通过 Action API 点击 Vary (Region) 按钮
curl -X POST 'https://api.deerapi.com/mj/submit/action' \
  -H 'Authorization: Bearer <YOUR_DEERAPI_KEY>' \
  -H 'Content-Type: application/json' \
  -d '{"taskId": "xxx", "customId": "MJ::Inpaint::xxx", "enableRemix": true}'

# 2. 轮询发现 status = "MODAL"
curl -X GET 'https://api.deerapi.com/mj/task/new_task_id/fetch'
# 响应: { "status": "MODAL" }

# 3. 通过 Modal API 提交蒙版和提示词
curl -X POST 'https://api.deerapi.com/mj/submit/modal' \
  -H 'Authorization: Bearer <YOUR_DEERAPI_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 流程:
接口用途
POST /mj/submit/blend2-5 张图片融合
POST /mj/submit/describe图片反推提示词
POST /mj/submit/video图片转视频
POST /mj/submit/edits遮罩编辑图片

❓ 常见问题

问题可能原因解决方案
找不到 Vary (Region) 按钮正在查看 4 宫格图先点击 U1-U4 放大,再查看按钮
任务状态卡在 MODAL操作需要额外输入调用 /mj/submit/modal 提交数据
customId 无效使用了过期或硬编码的值/mj/task/\{id\}/fetch 响应获取最新值
buttons 数组为空任务仍在进行中等待 status: "SUCCESS" 后再读取按钮