Begrijp het kernconcept
De MidJourney API simuleert Discord-knopinteracties. In tegenstelling tot typische REST APIโs werkt deze als een state machine waarbij elke bewerking nieuwe knoppen teruggeeft voor de volgende stap.
De 4 kern-APIโs
| API | Doel | Wanneer gebruiken |
|---|
POST /mj/submit/imagine | Tekst-naar-afbeelding-generatie | Startpunt voor alle workflows |
GET /mj/task/\{id\}/fetch | Taskstatus opvragen en knoppen ophalen | Na elke submit (poll tot voltooid) |
POST /mj/submit/action | Op een knop klikken (upscale, vary, zoom, enz.) | Wanneer je een bewerking op een afbeelding wilt uitvoeren |
POST /mj/submit/modal | Extra invoer versturen | Alleen wanneer status MODAL is |
Volledig workflowdiagram
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 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 โ
โโโโโโโโโโโโโโโโโโโโ
Kernconcept: knoppen en customId
Elke succesvolle task geeft een buttons-array terug. Elke knop heeft een customId die je gebruikt om de volgende actie te triggeren.
Voorbeeldresponse van /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 is geen vaste waarde. Deze verandert voor elke task. Haal deze altijd op uit de buttons-array.
Knoppenreferentie per fase
Na IMAGINE (4-grid afbeelding)
Deze knoppen worden teruggegeven wanneer je eerste afbeeldingsgeneratie is voltooid:
| Button | customId Pattern | Action | Result |
|---|
| U1-U4 | MJ::JOB::upsample::1::xxx | Enkele afbeelding upscalen | Enkele afbeelding in hoge resolutie |
| V1-V4 | MJ::JOB::variation::1::xxx | Variaties genereren | Nieuwe 4-grid |
| ๐ | MJ::JOB::reroll::0::xxx::SOLO | Alles opnieuw genereren | Nieuwe 4-grid |
Na UPSCALE (enkele afbeelding)
Na het upscalen krijg je toegang tot bewerkingstools:
| Label | Needs Modal? |
|---|
| Upscale (Subtle) / Upscale (2x) | โ Nee |
| Upscale (Creative) / Upscale (4x) | โ Nee |
| Vary (Subtle) ๐ช | โ Nee |
| Vary (Strong) ๐ช | โ Nee |
| Vary (Region) ๐๏ธ | โ
Ja (masker) |
| Zoom Out 2x / 1.5x ๐ | โ Nee |
| Custom Zoom ๐ | โ
Ja (prompt) |
| โฌ
๏ธโก๏ธโฌ๏ธโฌ๏ธ Pan | โ Nee |
| Animate ๐๏ธ | โ Nee |
| ๐ Reroll | โ Nee |
Opmerking: Knoplabels en customId-indelingen kunnen variรซren afhankelijk van de MJ-versie die in je prompt is opgegeven (bijv. --v 6.1 versus --v 5.2). Lees de knoppen altijd uit het API-response.
De Inpaint-knop (Vary Region) verschijnt alleen na Upscale.
Volledig voorbeeld: Genereren en upscalen
Stap 1: Imagine-verzoek indienen
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"] }
}'
Response:
{ "code": 1, "result": "1768464763141701" }
Stap 2: Taskstatus pollen
curl -X GET 'https://api.cometapi.com/mj/task/1768464763141701/fetch' \
-H 'Authorization: Bearer <YOUR_COMETAPI_KEY>'
Response (wanneer voltooid):
{
"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" },
...
]
}
Stap 3: Klik op U1 om te upscalen
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"
}'
Response:
{ "code": 1, "result": "1768464800000000" }
Stap 4: Poll de nieuwe taak en haal het resultaat op
curl -X GET 'https://api.cometapi.com/mj/task/1768464800000000/fetch' \
-H 'Authorization: Bearer <YOUR_COMETAPI_KEY>'
Wanneer is Modal vereist?
Wanneer je /mj/submit/action aanroept en de taakstatus MODAL wordt in plaats van SUCCESS, moet je /mj/submit/modal aanroepen om extra invoer te geven.
Bevestigde Modal-bewerkingen
| Operation | Button | What to Submit |
|---|
| Inpaint | Vary (Region) | maskBase64 (PNG-masker) + prompt |
| Custom Zoom | ๐ Custom Zoom | prompt (bijv. โyour prompt โzoom 2โ) |
Voorbeeld: Inpaint-flow
# 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,..."
}'
Snelheidsmodus selecteren
Voeg een snelheidsvoorvoegsel toe aan het pad:
| Modus | Padvoorvoegsel | Voorbeeld |
|---|
| Snel | /mj-fast | /mj-fast/mj/submit/imagine |
| Turbo | /mj-turbo | /mj-turbo/mj/submit/imagine |
| Relax | (standaard) | /mj/submit/imagine |
Andere entry points
Deze APIโs zijn onafhankelijke entry points die de imagine โ action-flow niet volgen:
| API | Doel |
|---|
POST /mj/submit/blend | Meng 2-5 afbeeldingen tot รฉรฉn |
POST /mj/submit/describe | Genereer een prompt uit een afbeelding |
POST /mj/submit/video | Converteer afbeelding naar video |
POST /mj/submit/edits | Bewerk afbeelding met masker |
Tips voor probleemoplossing
Op basis van het API-ontwerp en de workflow zijn dit veelvoorkomende problemen die je kunt tegenkomen:
| Probleem | Waarschijnlijke oorzaak | Oplossing |
|---|
| Kan de knop Vary (Region) niet vinden | Kijkt naar een 4-grid-afbeelding | Eerst upscalen (klik op U1-U4), controleer daarna de knoppen |
Taakstatus blijft hangen op MODAL | Bewerking vereist extra invoer | Roep /mj/submit/modal aan met de vereiste gegevens |
customId werkt niet | Verouderde of hardcoded waarde gebruikt | Haal altijd een verse customId op uit het antwoord van /mj/task/\{id\}/fetch |
Lege buttons-array | Taak is nog in uitvoering | Wacht op status: "SUCCESS" voordat je buttons benadert |