> ## 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.

# Aan de slag met Midjourney API

> Snelle start voor Midjourney API op CometAPI: verstuur /mj/submit/imagine, poll /mj/task/{id}/fetch en gebruik daarna /mj/submit/action en modale knoppen.

## Begrijp het kernconcept

De MidJourney API **simuleert Discord-knopinteracties**. In tegenstelling tot typische REST API's werkt deze als een **toestandsmachine** waarbij elke bewerking nieuwe knoppen teruggeeft voor de volgende stap.

### De 4 kern-API's

| API                                                                                      | Doel                                            | Wanneer te gebruiken                    |
| ---------------------------------------------------------------------------------------- | ----------------------------------------------- | --------------------------------------- |
| [`POST /mj/submit/imagine`](/api/image/midjourney/imagine)                               | Tekst-naar-afbeeldinggeneratie                  | Startpunt voor alle workflows           |
| [`GET /mj/task/\{id\}/fetch`](/api/image/midjourney/task-fetching-api/fetch-single-task) | Taskstatus opvragen en knoppen ophalen          | Na elke submit (poll tot klaar)         |
| [`POST /mj/submit/action`](/api/image/midjourney/action)                                 | Op een knop klikken (upscale, vary, zoom, enz.) | Wanneer je een afbeelding wilt bewerken |
| [`POST /mj/submit/modal`](/api/image/midjourney/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       │
           └──────────────────┘
```

***

## Belangrijk concept: Knoppen en customId

Elke succesvolle task retourneert een `buttons`-array. Elke knop heeft een `customId` die je gebruikt om de volgende actie te triggeren.

**Voorbeeldrespons van `/mj/task/\{id\}/fetch`:**

```json theme={null}
{
  "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": "🔄" }
  ]
}
```

<Warning>
  `customId` is geen vaste waarde. Deze verandert voor elke task. Haal deze altijd op uit de `buttons`-array.
</Warning>

***

## Knoppenreferentie per fase

### Na IMAGINE (4-grid-afbeelding)

Deze knoppen worden teruggegeven wanneer je initiële 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:** Button-labels en `customId`-indelingen kunnen variëren afhankelijk van de MJ-versie die in je prompt is opgegeven (bijvoorbeeld `--v 6.1` vs `--v 5.2`). Lees knoppen altijd uit de API-respons.

<Warning>
  De Inpaint-knop (Vary Region) verschijnt alleen na Upscale.
</Warning>

***

## Volledig voorbeeld: genereren en upscalen

### Stap 1: Imagine-aanvraag indienen

```bash theme={null}
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"] }
  }'
```

**Respons:**

```json theme={null}
{ "code": 1, "result": "1768464763141701" }
```

### Stap 2: Poll taakstatus

```bash theme={null}
curl -X GET 'https://api.cometapi.com/mj/task/1768464763141701/fetch' \
  -H "Authorization: Bearer $COMETAPI_KEY"
```

**Respons (wanneer voltooid):**

```json theme={null}
{
  "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

```bash theme={null}
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"
  }'
```

**Respons:**

```json theme={null}
{ "code": 1, "result": "1768464800000000" }
```

### Stap 4: Poll de nieuwe taak en haal het resultaat op

```bash theme={null}
curl -X GET 'https://api.cometapi.com/mj/task/1768464800000000/fetch' \
  -H "Authorization: Bearer $COMETAPI_KEY"
```

***

## Wanneer is Modal vereist?

Wanneer je [`/mj/submit/action`](/api/image/midjourney/action) aanroept en de taakstatus `MODAL` wordt in plaats van `SUCCESS`, moet je [`/mj/submit/modal`](/api/image/midjourney/modal) aanroepen om extra invoer te leveren.

### 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**

```bash theme={null}
# 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,..."
  }'
```

***

## Selectie van snelheidsmodus

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`](/api/image/midjourney/blend)         | Blend 2-5 afbeeldingen tot één   |
| [`POST /mj/submit/describe`](/api/image/midjourney/describe)   | Genereer prompt uit afbeelding   |
| [`POST /mj/submit/video`](/api/image/midjourney/submit-video)  | Converteer afbeelding naar video |
| [`POST /mj/submit/edits`](/api/image/midjourney/submit-editor) | 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                                                                                  |
| Task-status blijft hangen op `MODAL`  | Bewerking vereist aanvullende invoer    | Roep [`/mj/submit/modal`](/api/image/midjourney/modal) aan met de vereiste gegevens                                                           |
| `customId` werkt niet                 | Verouderde of hardcoded waarde gebruikt | Haal altijd een actuele `customId` op uit de respons van [`/mj/task/\{id\}/fetch`](/api/image/midjourney/task-fetching-api/fetch-single-task) |
| Lege `buttons`-array                  | Task is nog in uitvoering               | Wacht op `status: "SUCCESS"` voordat je knoppen opent                                                                                         |
