Midjourney 影像生成
OpenAI 相容:POST /v1/images/generations。Midjourney 官方參數說明
[!IMPORTANT] 串接必讀:
- 模型名稱替換:文件中的
MJ-v7、MJ-v8.1、MJ-v8.2僅為範例名稱,實際呼叫時請替換為平台「模型廣場 / 可用模型清單」中對應的真實模型 ID。- 固定生成 4 張圖:單次請求固定生成並回傳 4 張 2×2 網格候選圖 URL(
data陣列),不支援自訂單次出圖數量。- Prompt 定義參數:不支援直接指定任意像素解析度;長寬比(
--ar)、畫質(--q)、風格/角色參考等參數皆透過prompt文字後綴指令控制。
1. 生圖呼叫範例 (POST)
- 請求路徑:
https://www.tokenpad.ai/v1/images/generations - 請求標頭:
Authorization: Bearer sk-your_token、Content-Type: application/json
① 文字生圖
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"
}'
② 圖生圖(單圖參考)
單次支援 1 張基礎參考圖(JPEG/PNG/WEBP,≤10MB),可透過 image 欄位傳入,並以 --iw 0-3(預設 1)調整參考圖權重:
{
"model": "MJ-v7",
"image": "https://example.com/reference.png",
"prompt": "範例 Prompt --ar 16:9 --iw 1.5"
}
③ 多圖參考(主體 / 構圖 / 色彩)
多個圖片 URL 直接放在 prompt 最前面(以空格分隔),搭配 --iw 控制參考圖對結果的影響強度:
{
"model": "MJ-v7",
"prompt": "https://example.com/1.png https://example.com/2.png 兩個人在跳舞 --ar 16:9 --q 2 --iw 1.5"
}
④ 多張風格參考圖(--sref)
適用於繼承多張圖片的整體風格(色調、筆觸、鏡頭感、材質等)。多個 URL 以空格分隔,--sw(0–1000,預設 100)控制風格參考強度:
{
"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"
}
⑤ 多張角色參考圖(--cref)
適用於維持人物、IP 角色、虛擬人、產品形象一致性。可提供正面、側面、特寫等多角度 URL(空格分隔),--cw 控制角色一致性強度:
{
"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"
}
⑥ 內容參考圖 + 風格參考圖組合
prompt 開頭的圖片 URL 作為內容/主體參考(--iw 控制強度),--sref 後的圖片 URL 作為風格參考(--sw 控制強度):
{
"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"
}
⑦ 角色參考圖 + 風格參考圖組合
適用於短劇角色、虛擬人、動漫角色、品牌代言人等一致性生成:
{
"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. 參數與能力說明
2.1 請求主體欄位
| 參數 | 型別 | 必填 | 說明 |
|---|---|---|---|
model | string | 是 | 平台模型 ID(如 MJ-v7、MJ-v8.1、MJ-v8.2,請以平台實際模型清單為準) |
prompt | string | 是 | 提示詞及官方參數後綴(如 --ar 16:9 --q 2) |
image | string / array | 否 | 單圖參考圖片 URL 或 Base64(多圖參考、--sref、--cref 請將 URL 直接寫入 prompt) |
2.2 標準長寬比(--ar)與解析度規則
透過 --ar 最簡整數比 控制畫面比例(不支援小數非標準比例,輸入非標準比例將被自動近似修正;原生最大約 104 萬像素):
1:1(預設正方形,頭像/圖示):1024×1024(放大後2048×2048)16:9(橫式桌布/影片):1456×816/1024×576(放大後2048×1152)9:16(手機直式螢幕/小紅書):816×1456/576×1024(放大後1152×2048)3:2(橫式攝影):1344×896/1024×682(放大後2048×1364)2:3(直式海報):682×1024(放大後1364×2048)4:3:1232×928;4:5(直式常規):819×1024(放大後1638×2048);21:9(超寬螢幕):1024×432(放大後2048×864)
2.3 Prompt 參數版本支援矩陣
| 參數 | 說明 | MJ-v7 | MJ-v8.1 | MJ-v8.2 |
|---|---|---|---|---|
--ar | 畫面比例(如 --ar 16:9) | ✅ | ✅ | ✅ |
--q / --quality | 渲染品質檔位 | ✅ (1,2,4) | ✅ (1,4) | ✅ (1,2,3,4) |
--raw / --style raw | 原生模式,弱化 MJ 預設美化 | ✅ | ✅ | ✅ |
--hd | 原生 2K 高畫質渲染 | ❌ | ✅ | ✅ |
--chaos / --c | 結果隨機多樣性 (0–100) | ✅ | ✅ | ✅ |
--seed | 隨機種子,重現影像 | ✅ | ✅ | ✅ |
--stylize / --s | 風格強度 (0–1000,預設 250) | ✅ | ✅ | ✅ |
--iw | 參考圖權重(預設 1) | ✅ (0–3) | ✅ (0–3) | ✅ (0–3) |
--no | 排除元素 | ✅ | ✅ | ✅ |
--sref | 風格參考圖(搭配 --sw 0-1000,預設 100) | ✅ | ✅ | ✅ |
--oref | 萬物參考(物體 / 人物一致性) | ✅ | ❌ | ❌ |
--cref | 角色參考(搭配 --cw 控制角色一致性強度) | ❌ | ❌ | ❌ |
--stop | 中途停止渲染 | ✅ | ❌ | ❌ |
--tile | 無縫平鋪圖案 | ✅ | ✅ | ✅ |
--exp | 動態影調增強 | ✅ | ✅ | ✅ |
--weird | 超現實怪異度 (0–3000) | ✅ | ✅ | ✅ |
--draft | 草圖模式 | ✅ | ✅ (規則不同) | ✅ |
:: | 多提示詞分段加權 | ✅ | ❌ | ❌ |
3. 回傳結果範例 (200 OK)
{
"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. 常見錯誤碼與問題排解
HTTP 狀態碼、錯誤主體格式及分情境排解已 統一維護 於專頁,避免與各呼叫範例重複導致不同步。
速記(詳情見專頁):
| 碼 | 含義 |
|---|---|
| 400 | 參數無效 / 內容風控或版權攔截 |
| 402 | 帳戶餘額不足(不是 429) |
| 429 | 權杖 RPS/RPM 頻率限制,或低餘額在途任務過多 |
| 403 | 權杖/IP/模型權限(餘額見 402;內容攔截見 400) |
200 + status: failed | 非同步影片等長任務的業務失敗(輪詢時常見) |
HTTP 回應碼與控制台呼叫日誌 status_code 一致,可依 log_id 追溯。
維護約定:新增或調整錯誤說明時,請只更新專頁
error-codes;本附錄透過連結自動指向最新內容。