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 | 查詢任務狀態並取得按鈕 | 每次 submit 之後(輪詢直到完成) |
POST /mj/submit/action | 點擊按鈕(upscale、vary、zoom 等) | 當你想對圖片進行操作時 |
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) 🖌️ | ✅ 是(遮罩) |
| 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 $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 $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 $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 $COMETAPI_KEY"
何時需要 Modal?
當你呼叫 /mj/submit/action 且任務狀態變成 MODAL 而不是 SUCCESS 時,你必須呼叫 /mj/submit/modal 來提供額外輸入。
已確認需要 Modal 的操作
| Operation | Button | What to Submit |
|---|
| Inpaint | Vary (Region) | maskBase64(PNG 遮罩)+ 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 $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 $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) 按鈕 | 正在查看 4 宮格圖片 | 先進行 Upscale(點擊 U1-U4),然後再檢查按鈕 |
任務狀態卡在 MODAL | 操作需要額外輸入 | 使用必要資料呼叫 /mj/submit/modal |
customId 無法使用 | 使用了過期或硬編碼的值 | 務必從 /mj/task/\{id\}/fetch 回應中取得最新的 customId |
buttons 陣列為空 | 任務仍在處理中 | 等待 status: "SUCCESS" 後再存取按鈕 |