# Midjourney Image Generation

OpenAI compatible: `POST /v1/images/generations`. [Midjourney Official Parameters](https://docs.midjourney.com/hc/en-us/articles/32859204029709-Parameter-List)

> [!IMPORTANT]
> **Must-Read Before Integration**:
> * **Model Name Replacement**: `MJ-v7`, `MJ-v8.1`, and `MJ-v8.2` in this guide are **sample names only**—replace them with the real model IDs from the platform's "Model Marketplace / Available Models List" when calling.
> * **Fixed 4 Images Generated**: Each request always generates and returns **4** 2×2 grid candidate image URLs (in the `data` array); custom per-request image counts are not supported.
> * **Prompt-Defined Parameters**: Arbitrary pixel resolutions cannot be passed directly; aspect ratio (`--ar`), quality (`--q`), style/character references, etc. are all controlled via suffix flags at the end of the `prompt` text.

---

## 1. Image Generation Request Examples (POST)

* **Request Path**: `https://www.tokenpad.ai/v1/images/generations`
* **Headers**: `Authorization: Bearer sk-your_token`, `Content-Type: application/json`

### ① Text-to-Image
```bash
curl -X POST https://www.tokenpad.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MJ-v7",
    "prompt": "Futuristic cyberpunk city at night, neon lights, flying drones, rainy street --ar 16:9 --q 2"
  }'
```

### ② Image-to-Image (Single Image Reference)
Supports 1 base reference image per request (JPEG/PNG/WEBP, ≤10MB), passed via the `image` field, with `--iw 0-3` (default `1`) adjusting the image weight:
```json
{
  "model": "MJ-v7",
  "image": "https://example.com/reference.png",
  "prompt": "Sample prompt --ar 16:9 --iw 1.5"
}
```

### ③ Multi-Image Reference (Subject / Composition / Color)
Place multiple image URLs directly at the very beginning of `prompt` (separated by spaces), paired with `--iw` to control how strongly the reference images influence the output:
```json
{
  "model": "MJ-v7",
  "prompt": "https://example.com/1.png https://example.com/2.png Two people dancing --ar 16:9 --q 2 --iw 1.5"
}
```

### ④ Multiple Style Reference Images (`--sref`)
Used to inherit the overall style (color palette, brushwork, camera feel, textures, etc.) of multiple images. Separate multiple URLs with spaces, and use `--sw` (`0`–`1000`, default `100`) to control style weight:
```json
{
  "model": "MJ-v8.1",
  "prompt": "A luxury electric SUV driving through a futuristic smart city, cinematic advertising photography --ar 16:9 --q 2 --sref https://example.com/style_car_ad_01.jpg https://example.com/style_neon_city_02.jpg https://example.com/style_lighting_03.jpg --sw 300"
}
```

### ⑤ Multiple Character Reference Images (`--cref`)
Used to maintain consistency across characters, IP mascots, virtual avatars, and products. Provide multi-angle URLs (front, side, close-up, separated by spaces) and use `--cw` to control character consistency weight:
```json
{
  "model": "MJ-v8.2",
  "prompt": "A young female sci-fi explorer standing in a desert alien planet, wearing a white futuristic spacesuit, cinematic lighting, ultra detailed --ar 9:16 --q 2 --cref https://example.com/character_front.jpg https://example.com/character_side.jpg https://example.com/character_closeup.jpg --cw 80"
}
```

### ⑥ Content Reference + Style Reference Combination
Image URLs at the start of `prompt` act as **content/subject references** (weight controlled by `--iw`), while image URLs after `--sref` act as **style references** (weight controlled by `--sw`):
```json
{
  "model": "MJ-v7",
  "prompt": "https://example.com/product_reference_01.jpg https://example.com/product_reference_02.jpg A premium wireless headphone floating above a reflective black surface, commercial product photography, dramatic studio lighting --ar 1:1 --q 2 --iw 1.3 --sref https://example.com/style_luxury_ad_01.jpg https://example.com/style_black_gold_02.jpg --sw 250"
}
```

### ⑦ Character Reference + Style Reference Combination
Ideal for consistent generation of short-drama characters, virtual humans, anime characters, and brand spokespersons:
```json
{
  "model": "MJ-v8.2",
  "prompt": "A handsome young male fantasy warrior walking through a burning battlefield, heroic pose, detailed armor, cinematic composition --ar 16:9 --q 2 --cref https://example.com/hero_face_01.jpg https://example.com/hero_body_02.jpg --cw 90 --sref https://example.com/style_epic_fantasy_01.jpg https://example.com/style_movie_color_02.jpg --sw 200"
}
```

---

## 2. Parameters & Capabilities

### 2.1 Request Body Fields
| Param | Type | Required | Description |
| :--- | :--- | :---: | :--- |
| `model` | `string` | **Yes** | Platform model ID (e.g., `MJ-v7`, `MJ-v8.1`, `MJ-v8.2`; check the platform's actual model list) |
| `prompt` | `string` | **Yes** | Prompt text plus official parameter suffixes (e.g., `--ar 16:9 --q 2`) |
| `image` | `string / array` | No | Single reference image URL or Base64 (for multi-image reference, `--sref`, and `--cref`, put URLs directly in `prompt`) |

### 2.2 Standard Aspect Ratios (`--ar`) & Resolution Rules
Control image proportions via `--ar W:H` (integer ratio; decimal non-standard ratios are not supported and will be automatically approximated; native resolution max ~1.04 million pixels):
* `1:1` (default square, avatars/icons): `1024×1024` (`2048×2048` after upscale)
* `16:9` (landscape wallpapers/videos): `1456×816` / `1024×576` (`2048×1152` after upscale)
* `9:16` (mobile portrait/vertical feeds): `816×1456` / `576×1024` (`1152×2048` after upscale)
* `3:2` (landscape photography): `1344×896` / `1024×682` (`2048×1364` after upscale)
* `2:3` (portrait posters): `682×1024` (`1364×2048` after upscale)
* `4:3`: `1232×928`; `4:5` (standard portrait): `819×1024` (`1638×2048` after upscale); `21:9` (ultrawide): `1024×432` (`2048×864` after upscale)

### 2.3 Prompt Parameter Version Compatibility Matrix
| Parameter | Description | `MJ-v7` | `MJ-v8.1` | `MJ-v8.2` |
| :--- | :--- | :---: | :---: | :---: |
| `--ar` | Aspect ratio (e.g., `--ar 16:9`) | ✅ | ✅ | ✅ |
| `--q` / `--quality` | Rendering quality tier | ✅ (`1,2,4`) | ✅ (`1,4`) | ✅ (`1,2,3,4`) |
| `--raw` / `--style raw` | Raw mode, reduces default MJ beautification | ✅ | ✅ | ✅ |
| `--hd` | Native 2K HD rendering | ❌ | ✅ | ✅ |
| `--chaos` / `--c` | Result randomness & variety (`0`–`100`) | ✅ | ✅ | ✅ |
| `--seed` | Random seed for reproducible images | ✅ | ✅ | ✅ |
| `--stylize` / `--s` | Stylization strength (`0`–`1000`, default `250`) | ✅ | ✅ | ✅ |
| `--iw` | Reference image weight (default `1`) | ✅ (`0`–`3`) | ✅ (`0`–`3`) | ✅ (`0`–`3`) |
| `--no` | Exclude elements | ✅ | ✅ | ✅ |
| `--sref` | Style reference images (with `--sw 0-1000`, default `100`) | ✅ | ✅ | ✅ |
| `--oref` | Omni-reference (object / character consistency) | ✅ | ❌ | ❌ |
| `--cref` | Character reference (with `--cw` for character consistency strength) | ❌ | ❌ | ❌ |
| `--stop` | Stop rendering partway through | ✅ | ❌ | ❌ |
| `--tile` | Seamless tiling patterns | ✅ | ✅ | ✅ |
| `--exp` | Dynamic tone enhancement | ✅ | ✅ | ✅ |
| `--weird` | Surreal weirdness (`0`–`3000`) | ✅ | ✅ | ✅ |
| `--draft` | Draft mode | ✅ | ✅ (different rules) | ✅ |
| `::` | Multi-prompt segment weighting | ✅ | ❌ | ❌ |

---

## 3. Response Example (200 OK)

```json
{
  "created": 1719441600,
  "data": [
    { "url": "https://example.com/output/mj_1.png", "size": "1456x816" },
    { "url": "https://example.com/output/mj_2.png", "size": "1456x816" },
    { "url": "https://example.com/output/mj_3.png", "size": "1456x816" },
    { "url": "https://example.com/output/mj_4.png", "size": "1456x816" }
  ]
}
```



### 5. Common Error Codes & Troubleshooting

HTTP codes, error body format, and troubleshooting are **maintained in one dedicated page** (not duplicated under each example).

👉 **[Gateway Error Codes & Troubleshooting](/docs/errors/error-codes)**

**Quick reference**:

| Code | Meaning |
| :---: | :--- |
| **400** | Invalid parameters / content moderation or copyright block |
| **402** | Insufficient account balance (**not** 429) |
| **429** | RPS/RPM limits or in-flight task cap (low balance) |
| **403** | Token / IP / model permission (balance → 402; content filter → 400) |
| **200 + `status: failed`** | Async video/long-task business failure on poll |

HTTP status matches call log `status_code` for traceability by `log_id`.

> **Maintenance**: update the `error-codes` article only; this appendix links to it.
