Midjourney API Quick Start
šÆ Understand the Core Concept#
The MidJourney API simulates Discord button interactions. Unlike typical REST APIs, it works as a state machine where each operation returns new buttons for the next step.The 4 Core APIs#
š Complete Workflow Diagram#
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā 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 ā
āāāāāāāāāāāāāāāāāāāā
Every successful task returns a buttons array. Each button has a customId that you use to trigger the next action.Example response from /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": "š" }
]
}
ā ļø Important: customId is NOT a fixed value. It changes for every task. Always get it from the buttons array.
After IMAGINE (4-grid image)#
These buttons are returned when your initial image generation completes:| Button | customId Pattern | Action | Result |
|---|
| U1-U4 | MJ::JOB::upsample::1::xxx | Upscale single image | High-res single image |
| V1-V4 | MJ::JOB::variation::1::xxx | Generate variations | New 4-grid |
| š | MJ::JOB::reroll::0::xxx::SOLO | Regenerate all | New 4-grid |
After UPSCALE (single image)#
After upscaling, you get access to editing tools:| Label | Needs Modal? |
|---|
| Upscale (Subtle) / Upscale (2x) | ā No |
| Upscale (Creative) / Upscale (4x) | ā No |
| Vary (Subtle) šŖ | ā No |
| Vary (Strong) šŖ | ā No |
| Vary (Region) šļø | ā
Yes (mask) |
| Zoom Out 2x / 1.5x š | ā No |
| Custom Zoom š | ā
Yes (prompt) |
| ā¬
ļøā”ļøā¬ļøā¬ļø Pan | ā No |
| Animate šļø | ā No |
| š Reroll | ā No |
Note: Button labels and customId formats may vary depending on the MJ version specified in your prompt (e.g., --v 6.1 vs --v 5.2). Always read buttons from the API response.
ā ļø Inpaint (Vary Region) button only appears after Upscale!
ā” Complete Example: Generate & Upscale#
Step 1: Submit Imagine Request#
{ "code": 1, "result": "1768464763141701" }
Step 2: Poll Task Status#
Response (when complete):{
"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" },
...
]
}
Step 3: Click U1 to Upscale#
{ "code": 1, "result": "1768464800000000" }
Step 4: Poll New Task & Get Result#
ā ļø When is Modal Required?#
Confirmed Modal Operations#
| Operation | Button | What to Submit |
|---|
| Inpaint | Vary (Region) | maskBase64 (PNG mask) + prompt |
| Custom Zoom | š Custom Zoom | prompt (e.g., "your prompt --zoom 2") |
š Speed Mode Selection#
Add speed prefix to the path:| Mode | Path Prefix | Example |
|---|
| Fast | /mj-fast | /mj-fast/mj/submit/imagine |
| Turbo | /mj-turbo | /mj-turbo/mj/submit/imagine |
| Relax | (default) | /mj/submit/imagine |
š Other Entry Points#
These APIs are independent entry points that don't follow the imagine ā action flow:
ā Troubleshooting Tips#
Based on the API design and workflow, here are common issues you may encounter:| Problem | Likely Cause | Solution |
|---|
| Can't find Vary (Region) button | Looking at 4-grid image | Upscale first (click U1-U4), then check buttons |
Task status stuck at MODAL | Operation requires additional input | Call /mj/submit/modal with required data |
customId not working | Using outdated or hardcoded value | Always get fresh customId from /mj/task/{id}/fetch response |
Empty buttons array | Task still in progress | Wait for status: "SUCCESS" before accessing buttons |
Modified atĀ 2026-01-16 08:44:15