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 请求体字段

参数类型必填说明
modelstring是平台模型 ID(如 MJ-v7、MJ-v8.1、MJ-v8.2,请以平台实际模型列表为准)
promptstring是提示词及官方参数后缀(如 --ar 16:9 --q 2)
imagestring / 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-v7MJ-v8.1MJ-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;本附录通过链接自动指向最新内容。

Raw Markdown (.md) · llms.txt