跳到导航

Midjourney V8.2

以 Markdown 格式查看

用一个模型 ID 使用 Midjourney V8.2。用文字和图片提示一次生成四张图,再对其中一张做变体或放大,或整组重绘;也可以对图片重塑风格、编辑、混合和反推提示词。

  • 所有 Midjourney 操作共用一个模型 ID。由 action 选择操作,默认是 generate;Midjourney 在结果下方显示的按钮也都是操作。
  • 异步:创建请求会立即返回任务 ID。fast 生成通常 1 到 3 分钟完成;最多轮询 10 分钟。
  • 一次生成返回四张图。续作用 source_task_id 指定你之前的任务;需要选图时,用 index(1 到 4)指定位置。
  • --ar、--s、--sref、--no 等 Midjourney 参数写在 prompt 里。版本、速度、质量和草图由字段设置。
  • 按次计价,价格由 speed 和 quality 决定;upscale 和 describe 是一个较低的固定价。被拒绝的请求和失败的任务不收费。
  • 结果 7 天后删除。需要保留的图片请及时下载。
POST/v1/images/tasks试一试

在调试窗口里打开本模型,填入你的 BeatAPI API 密钥即可创建任务。调用是真实的,费用从你自己的余额中扣除。

接口与鉴权

POST https://api.beatapi.io/v1/images/tasks

Authorization

string · 必需

你的 BeatAPI API 密钥,以 Bearer <BEATAPI_API_KEY> 形式发送。在控制台创建密钥。密钥只能保存在你的服务端,不要放进浏览器或移动端应用。

请求体使用 JSON,并设置 Content-Type: application/json。Idempotency-Key 为可选:每个逻辑请求发送一个唯一值(最长 255 个字符),仅在重试完全相同的请求体时复用。24 小时内,用相同的键和请求体重试会再次返回第一次的响应,并带上 Idempotent-Replayed: true;相同的键搭配不同的请求体则返回 409 idempotency_conflict。非 2xx 的响应不会被保存,因此 400 或 402 之后的重试会重新执行。

请求流程

  1. 创建任务 向接口 POST 下方的参数。返回 201 表示任务已被接受,其价格已从你的余额中预留;任务在后台运行。保存 data.id。
  2. 等待任务完成 调用 GET /v1/tasks/{task_id},两次调用之间等待 data.poll_after_seconds 秒(图片 5 秒,视频 8 秒),直到 status 为 succeeded 或 failed。也可以为 task.succeeded 和 task.failed 注册 Webhook;仍需保留轮询作为兜底,因为因处理超时而终止的任务不会发送事件。
  3. 保存结果 状态为 succeeded 时,下载每个 data.output.media[].url 并保存你需要的文件;BeatAPI 不承诺结果链接的保留时长。状态为 failed 时,读取 data.error_code 和 data.error_message:预扣的金额已退回你的余额,data.retryable 表示再次发送相同请求是否可能成功。

输入模式

模式必填输入说明
生成model, prompt默认操作。可选 images(1 到 5 张图片提示)、aspect_ratio、quality、speed、draft。返回四张图。只有 images 含两个或更多链接时才可以不传 prompt。
变体model, action, source_task_id, index四宫格结果中某一张的 V 按钮。返回四张新图。
放大model, action, source_task_id, index从四宫格结果中选出一张,单独返回,像素尺寸不变。它不能再续作。
重绘model, action, source_task_id按四宫格结果的提示词整体重画四张新图。不传 index。
重塑风格model, action, images, prompt恰好一张图。保留构图并改换风格。返回四张图,这些图不能再续作。
编辑(beta)model, action, images, prompt恰好一张带透明区域的 PNG,只重画透明部分。返回四张图,这些图不能再续作。
混合model, action, images把 2 到 5 张图合成一幅画面;aspect_ratio 为 1:1、3:2 或 2:3。由 Midjourney V7 渲染。
反推提示词model, action, images恰好一张图。在 output.data.prompts 返回四条提示词,不返回图片。

请求参数

model

string · 必需

要调用的模型。

取值:mj-v8.2

取值有误时

  • 未传:"model" is required
  • 未知的模型 ID:"model" mj-v7 is not catalogued
  • 把视频模型发到了这个端点:"model" seedance-2.5 is served by POST /v1/videos/tasks, not this endpoint

prompt

string · 可选

要画什么,写法与 midjourney.com 相同:先写描述,再写 Midjourney 参数,例如 --ar 3:2 --s 250。对 retexture 和 edit,它描述新的样子。

长度:1–2048 个字符

  • generate 必须传(images 含两个或更多链接时除外),retexture 和 edit 也必须传。其他操作不接受它。
  • 对 generate,去掉链接和 -- 参数后的文字最多 1024 个字符。
  • 由字段设置的参数以及本 API 不支持的参数写在提示词里会被拒绝;见下文的参数表。

取值有误时

  • 生成时没传,且图片少于两张:generate needs "prompt"; only two or more images may go without one
  • retexture 或 edit 没传:"prompt" is required for action retexture
  • 随不接受它的操作一起传:prompt is not used by action upscale; leave it out
  • 为空或超过长度上限:"prompt" has an unsupported length
  • 去掉链接和参数后的文字过长:the prompt's text (without links and --parameters) is at most 1024 characters
  • 写了版本参数:remove --v from the prompt: the version is fixed at 8.2; leave it out
  • 写了速度参数:remove --fast from the prompt: set the speed field to fast instead
  • 比例写成小数:--ar takes whole numbers, like 139:100 instead of 1.39:1
  • --q 不在 1 到 4 之间:--q takes 1, 2, 3 or 4 (detail; 4 is the most detailed); for a bigger picture set quality hd

action

string · 可选 · 默认值: generate

要执行的操作。每个操作只接受它自己的字段(见上面的输入模式);其他字段会被拒绝,免得你为一个没起作用的设置付费。

可选值:generate, variation, upscale, reroll, retexture, edit, blend, describe
默认值:generate

  • generate 从头开始。variation、upscale 和 reroll 作用于四宫格结果;放大图不能再续作。
  • retexture、edit、blend 和 describe 从你在 images 里提供的图片开始。
  • 输入不区分大小写;文档写小写形式。

取值有误时

  • 不在可选值列表中:"action" must be one of: [generate variation upscale reroll retexture edit blend describe]
  • 传了该操作不接受的字段:quality is not used by action retexture; leave it out

images

string[] · 可选

你自己的图片,使用公网 HTTPS 链接。对 generate 是图片提示(1 到 5 张);retexture、edit 和 describe 恰好一张;blend 为 2 到 5 张。

数量:1–5
每一项都必须是公网 https:// 链接。本地文件请先上传(POST /v1/files),再传入返回的 data.url。

  • 链接必须公开,且能在几秒内下载完。本地文件请先用 POST /v1/files 上传,再传返回的链接。
  • 对 edit,请传 PNG,并把要修改的部分抠成透明。没有透明区域的图片(例如任何 JPEG)仍会被绘制并计费。
  • 续作(variation、upscale、reroll)作用于 source_task_id,不接受 images。
  • 报错信息中的位置从 0 开始:images[0] 是第一个链接。

取值有误时

  • retexture、edit、blend 或 describe 没传:"images" is required for action describe
  • 少于 blend 所需的张数:action blend needs at least 2 image(s) in "images"
  • describe、retexture 或 edit 传了多于一张:action describe takes at most 1 image(s) in "images"
  • 多于五张:"images" accepts at most 5 items
  • 不是 https:// 链接:"images[0]" must be a public HTTPS URL

aspect_ratio

string · 可选

图片的宽高比(宽:高),用于 generate 和 blend。

可选值:1:1, 4:3, 3:4, 3:2, 2:3, 16:9, 9:16, 21:9, 9:21, 5:4, 4:5, 2:1, 1:2

  • 生成时不传则按 1:1 绘制。
  • blend 只接受 1:1(默认)、3:2 或 2:3。
  • 其他比例请在 prompt 里写整数的 --ar W:H,例如 --ar 7:4;它会覆盖本字段。

取值有误时

  • 不在可选值列表中:"aspect_ratio" must be one of: [1:1 4:3 3:4 3:2 2:3 16:9 9:16 21:9 9:21 5:4 4:5 2:1 1:2]
  • blend 用了其他比例:"aspect_ratio" for blend is one of: 1:1, 3:2, 2:3

quality

string · 可选 · 默认值: standard

hd 约为 2K,大于标准尺寸。它在生成时设定,之后无法再加。

可选值:standard, hd
默认值:standard

  • fast 下 hd 更贵;relax 下价格相同。
  • upscale 按绘制时的像素尺寸返回图片,不会放大分辨率。想要更大的图,请在第一次调用时就设 hd。
  • 续作沿用源任务的质量。续作时不要传该字段,或传相同的值。
  • retexture、edit、blend 和 describe 不接受它。

取值有误时

  • 不在可选值列表中:"quality" must be one of: [standard hd]
  • 与 draft 同时使用:draft cannot be combined with quality hd
  • 续作要求的质量与源任务不同:source_task_id was made at quality hd and a follow-up runs the same; leave quality out

speed

string · 可选 · 默认值: fast

fast(默认)生成通常 1 到 3 分钟完成;relax 需要 2 到 5 分钟,价格更低。

可选值:fast, relax
默认值:fast

  • 续作沿用源任务的速度,并按该速度计费。续作时不要传该字段,或传相同的值。
  • describe 不接受它。

取值有误时

  • 不在可选值列表中:"speed" must be one of: [fast relax]
  • 续作要求的速度与源任务不同:source_task_id was made at speed relax and a follow-up runs the same; leave speed out

draft

boolean · 可选

仅用于 generate。为 true 时以一次生成的价格返回 24 张 512 px 的快速草图,用于在正式出图前试探提示词。

  • 两种 speed 都可用;不能与 quality hd 同时使用。
  • 草图不能续作,其中的图片也不能被选取。要正式出图,请去掉 draft 再发一次;在草图的提示词里写 --seed N,可得到相近(但不完全相同)的构图。

取值有误时

  • 不是布尔值:"draft" must be a boolean
  • 对草图续作:source_task_id is a draft, which takes no follow-up; send the prompt again without draft (add --seed N to keep a similar composition)

source_task_id

string · 可选

续作时填写:它所基于的、你自己之前的 Midjourney 任务的 id。该任务必须已成功。

  • 先读该任务的 output.data.follow_ups:它列出这个结果接受的操作。其他续作会被拒绝,不收费。
  • 放大图不能再续作。要对它做变体,请用它所在四宫格结果的 source_task_id 和相同的 index 发送 variation。
  • upscale、retexture、edit、describe 的结果和草图都不能续作。

取值有误时

  • 不是任务 ID:"source_task_id" must be the id of one of your earlier tasks: "task_" followed by 32 letters or digits
  • 续作时没传:"source_task_id" is required for action upscale: the id of your own Midjourney task it works on
  • 源任务还在运行或已失败:source_task_id has not finished successfully; wait for it to succeed and try again
  • 其他模型的任务:source_task_id was made by seedream-5.5, not Midjourney; name one of your Midjourney tasks
  • 对放大图续作:an upscaled image takes no follow-up; to vary it, send action variation with source_task_id of its four-image result and the same index
  • retexture、edit 或 describe 的结果:source_task_id is the result of retexture, which takes no follow-up
  • 再次放大同一结果的同一张图:that image of source_task_id was already upscaled in task_Up4Rk9Ns2Wq7Zx5Mc8Hv1Lb6Tj3Fd0Gy; use that task's result
  • 该结果的 follow_ups 没有列出这个操作:this result does not support action upscale; generate the image again and continue from the new result

index

integer · 可选

作用于四宫格结果中的哪一张,1 到 4。从 1 开始,按源任务的 output.media 计数。

范围:1–4

  • upscale 和 variation 必须传。
  • reroll 以及不带 source_task_id 的操作都不使用。

取值有误时

  • upscale 或 variation 没传:"index" is required for action upscale
  • 不是 1 到 4 的整数:"index" is outside its supported range

callback_url

string · 可选

任务成功或失败时通知的地址:公网 HTTPS URL,协议、主机和端口必须与你某个已启用的 Webhook 端点相同,并由该端点的 secret 签名。

长度:≤ 2048 个字符

  • 请先用 POST /v1/webhooks 注册端点。BeatAPI 会推送 task.succeeded 或 task.failed,事件体、请求头和重试规则与账户 Webhook 相同;订阅了该事件的账户端点也会收到,与该端点地址完全相同时只通知一次。
  • 签名端点被删除、停用或改到别的主机后,这条回调作废。

取值有误时

  • 值不是字符串:"callback_url" must be a string.
  • 地址超过 2048 个字符:"callback_url" must be at most 2048 characters.
  • 不是 URL,或没有主机、没有 http 或 https 协议:"callback_url" must be a valid https URL.
  • 使用了 http,或指向私有等非公网地址:"callback_url" must be a public HTTPS URL.
  • 没有任何已启用的 Webhook 端点与之协议、主机和端口相同:"callback_url" must be on the host of one of your active webhook endpoints, whose secret signs it; register one with POST /v1/webhooks.

网关还会在创建任务之前检查以下组合:

  • action 选择操作,默认为 generate;每个操作只接受这里为它列出的字段,其他字段一律拒绝。
  • 被拒绝的请求(HTTP 400)和失败的任务不收费。
  • generate:prompt(images 含 2 个或更多链接时可不传),可选 images(1–5 个公开图片链接,作为图片提示)、aspect_ratio(不传为 1:1)、quality、speed、draft;返回四张图。
  • quality 为 hd 时在生成时约按 2K 绘制;之后无法再加,想要更大的图请在第一次调用时就设定。
  • variation:四宫格结果的 source_task_id 和 index(1–4);即 Midjourney 该图的 V 按钮,返回四张新图。
  • upscale:四宫格结果的 source_task_id 和 index(1–4);选出该图并单独返回,像素尺寸不变(不会放大),放大图不能再续作。
  • reroll:四宫格结果的 source_task_id,不传 index;把整个提示词重画为四张新图。
  • retexture 和 edit:images(恰好 1 张)和 prompt;retexture 保留构图、按提示词改换风格;edit(beta)重画 PNG 的透明区域,所以要把需修改的部分抠掉:没有透明区域的图片(任何 JPEG)仍会绘制并计费;两者都返回四张图,这些图不能再续作。
  • blend:images(2–5 张)和可选的 aspect_ratio:1:1(默认)、3:2 或 2:3;它由 Midjourney V7 渲染,效果可能与 V8.2 的图不同;describe:images(恰好 1 张),在 output.data.prompts 返回四条提示词,不返回图片。
  • index 从 1 开始,按源任务的 output.media 计数;output.data.kind(grid、single 或 text)和 output.data.follow_ups 列出已完成任务接受的操作(任务由溢出线路处理时,偶尔会更少或没有),其他续作会被拒绝且不收费;规划串联前请先读它。
  • 续作沿用源任务的 speed 和 quality(两者都不传,或传相同的值),并按这些设置作为一张新图计费;upscale 和 describe 例外,它们是一个固定价。
  • 草图结果不能续作,其中的图片也不能被选取:要正式出图,请去掉 draft 再发一次提示词(在草图的提示词里写 —seed N,可得到相近但不完全相同的构图)。
  • Midjourney 参数按 midjourney.com 的写法放在 prompt 里:—ar W:H 用整数(覆盖 aspect_ratio)、—s 0-1000、—c 0-100、—seed 0-4294967295、—exp 0-100、—q 1-4、—raw、—no、—tile、—weird 0-3000、—iw 0-3、—sref(链接或代码)和 —sw;generate 去掉链接和参数后的文字最多 1024 个字符。
  • 版本(8.2)、speed、quality 和 draft 只能用字段设置:提示词中带 —v、—niji、—fast、—relax、—turbo、—hd 或 —draft 会被拒绝;—oref、—cref、—stop、—p、—bs、—repeat、—edit、—stealth 和 —public 本 API 不支持,同样会被拒绝。
  • speed 为 fast(默认)时通常 1–3 分钟,relax 为 2–5 分钟、价格更低,edit 和 retexture 最多 5 分钟,upscale 和 describe 只需几秒;最多轮询 10 分钟;quality 为 hd 时 fast 更贵、relax 同价;draft 两种速度都可用,以一次生成的价格返回 24 张 512 px 快速图,且不能为 hd。
  • 图片链接必须公开,并能在几秒内下载完;本地文件请用 POST /v1/files 上传后传链接;需要保留的结果请保存:图片 7 天后删除。

操作一览

每个操作都是同一端点上的一个新任务。结果的 output.data.kind 说明它是什么:grid(四张图)、single(一张放大图)或 text。

操作作用对象除 model 和 action 外的字段返回
generate文字和图片提示prompt, images, aspect_ratio, quality, speed, draft四张图
variation四宫格结果source_task_id, index, speed, quality四张图
upscale四宫格结果source_task_id, index, speed, quality一张图,不能续作
reroll四宫格结果source_task_id, speed, quality四张图
retexture你的一张图images, prompt, speed四张图,不能续作
edit(beta)你的一张 PNGimages, prompt, speed四张图,不能续作
blend你的 2 到 5 张图images, aspect_ratio, speed四张图
describe你的一张图images四条提示词,没有图片
  • 操作不接受的字段会被拒绝而不是被忽略:否则,生成时误传的 index 会被计费却毫无作用。
  • blend 由 Midjourney V7 渲染,效果可能与 V8.2 的图不同。

串联续作

续作在 source_task_id 中指定你自己的一个已完成的 Midjourney 任务。它作用于四宫格结果,index 选出其中一张:1 是该任务 output.media 的第一项,4 是最后一项。

  • 带 index 的 variation:即 V 按钮,生成四张与该图相近的新图。
  • 带 index 的 upscale:即 U 按钮,单独取出该图。再次放大同一结果的同一张图会被拒绝,并告诉你已经放大过它的任务。
  • reroll:用同一提示词生成四张新图。

放大图不能再续作;要对它做变体,请用它所在的四宫格结果和相同的 index 发送 variation。retexture、edit、describe 的结果和草图同样不能续作。

规划串联之前,先读要继续的任务的 output.data.follow_ups:它准确列出这个结果接受的操作。由备用线路生成的结果可能列出更少的操作,甚至没有;其他续作会被拒绝,不收费,你可以重新生成,再从新结果继续。

续作沿用源任务的速度和质量,并按此计费。不要传 speed 和 quality,或传相同的值;不同的值会被拒绝。

速度、质量与草图

设置作用价格
speed fast(默认)生成通常需要 1 到 3 分钟。较高
speed relax通常 2 到 5 分钟。较低
quality hd约 2K。在生成时设定,之后无法再加。fast 下更高,relax 下相同
draft true24 张 512 px 快速图,用于试探提示词;不能续作,不能 hd。与该速度下一次生成同价
  • edit 和 retexture 可能需要 5 分钟;upscale 和 describe 只需几秒。放弃一个任务之前,最多轮询 10 分钟。
  • upscale 是选图,不会放大分辨率。放大图保持绘制时的像素尺寸。

写在提示词里的 Midjourney 参数

Midjourney 自己的参数写在 prompt 末尾,写法与 midjourney.com 相同,会原样传递。

参数取值说明
--ar W:H整数,例如 7:4覆盖 aspect_ratio。1.39:1 这样的小数会被拒绝;请写 139:100。
--s0 到 1000风格化强度。
--c0 到 100混乱度:四张图之间的差异程度。
--seed0 到 4294967295可复现的初始噪声。
--q1 到 4细节程度;4 最细。想要更大的图请用 quality hd。
--sref 和 --sw图片链接或风格代码;权重风格参考及其权重。
--iw0 到 3images 中图片提示的权重。
--exp0 到 100实验性美学。
--weird0 到 3000非常规的效果。
--no词语要排除的内容。
--raw, --tile无取值减少默认风格化;生成无缝拼贴图。
  • 版本(8.2)、速度、质量和草图由字段设置:提示词中出现 --v、--niji、--fast、--relax、--turbo、--hd 或 --draft 会被拒绝。
  • 本 API 不支持、会被拒绝的参数:--oref、--cref、--stop、--p、--bs、--repeat、--edit、--stealth、--public。
  • 对 generate,去掉链接和参数后的文字最多 1024 个字符。

结果与保存期限

图片保存 7 天后删除;需要保留的请下载。describe 不保存文件:四条提示词在 output.data.prompts 里。

你传入的图片链接必须公开,且能在几秒内下载完。无法获取的链接会让任务失败,失败的任务不收费。

请求示例

cURL
curl --request POST \
--url https://api.beatapi.io/v1/images/tasks \
--header "Authorization: Bearer $BEATAPI_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "mj-v8.2",
"prompt": "A lighthouse on a basalt cliff at dusk, storm clouds breaking, cinematic light --s 250",
"aspect_ratio": "16:9"
}'
Python
import os
import requests
response = requests.post(
"https://api.beatapi.io/v1/images/tasks",
headers={"Authorization": f"Bearer {os.environ['BEATAPI_API_KEY']}"},
json={
"model": "mj-v8.2",
"prompt": "A lighthouse on a basalt cliff at dusk, storm clouds breaking, cinematic light --s 250",
"aspect_ratio": "16:9"
},
timeout=60,
)
body = response.json()
if not response.ok:
raise RuntimeError(f"{response.status_code} {body['error']['code']}: {body['error']['message']}")
task = body["data"]
print(task["id"], task["status"])
JavaScript
const response = await fetch('https://api.beatapi.io/v1/images/tasks', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.BEATAPI_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"model": "mj-v8.2",
"prompt": "A lighthouse on a basalt cliff at dusk, storm clouds breaking, cinematic light --s 250",
"aspect_ratio": "16:9"
}),
});
const body = await response.json();
if (!response.ok) throw new Error(`${response.status} ${body.error.code}: ${body.error.message}`);
console.log(body.data.id, body.data.status);

生成四张图

默认操作。Midjourney 参数写在提示词末尾。

curl --request POST \
--url https://api.beatapi.io/v1/images/tasks \
--header "Authorization: Bearer $BEATAPI_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "mj-v8.2",
"prompt": "A lighthouse on a basalt cliff at dusk, storm clouds breaking, cinematic light --s 250",
"aspect_ratio": "16:9"
}'

对第 3 张做变体

即 V3 按钮:生成四张与上面生成结果第三张相近的新图。

curl --request POST \
--url https://api.beatapi.io/v1/images/tasks \
--header "Authorization: Bearer $BEATAPI_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "mj-v8.2",
"action": "variation",
"source_task_id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
"index": 3
}'

放大第 2 张

在变体结果上按 U2:单独取出第二张,保持绘制时的像素尺寸。它不能再续作。

curl --request POST \
--url https://api.beatapi.io/v1/images/tasks \
--header "Authorization: Bearer $BEATAPI_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "mj-v8.2",
"action": "upscale",
"source_task_id": "task_Vb3nK8wQ2mZr5Tx9Lc4Hd7Jf1Ps6Ya0E",
"index": 2
}'

反推一张图的提示词

在 output.data.prompts 中返回四条能画出类似图片的提示词。

curl --request POST \
--url https://api.beatapi.io/v1/images/tasks \
--header "Authorization: Bearer $BEATAPI_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "mj-v8.2",
"action": "describe",
"images": [
"https://cdn.beatapi.io/samples/smart-bottle.png"
]
}'

relax 速度下用图片提示和风格参考出 HD 图

产品图作为图片提示,风格参考写在提示词里;relax 更便宜,且此时 hd 不额外收费。

curl --request POST \
--url https://api.beatapi.io/v1/images/tasks \
--header "Authorization: Bearer $BEATAPI_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "mj-v8.2",
"prompt": "The bottle on a sunlit kitchen counter, soft morning light --sref https://cdn.beatapi.io/samples/neon-singer.png --sw 200",
"images": [
"https://cdn.beatapi.io/samples/smart-bottle.png"
],
"aspect_ratio": "4:5",
"speed": "relax",
"quality": "hd"
}'

混合两张图

把这些图合成一幅画面,由 Midjourney V7 渲染。不传提示词。

curl --request POST \
--url https://api.beatapi.io/v1/images/tasks \
--header "Authorization: Bearer $BEATAPI_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "mj-v8.2",
"action": "blend",
"images": [
"https://cdn.beatapi.io/samples/smart-bottle.png",
"https://cdn.beatapi.io/samples/neon-singer.png"
],
"aspect_ratio": "3:2"
}'

响应

创建任务(201)

任务对象。任务成功之前 output 为 null。标注“运行中”的字段会在任务结束后消失。

{
"data": {
"id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
"object": "task",
"task_kind": "image",
"capability_id": "mj-v8.2",
"capability_version": 1,
"media_type": "image",
"model": "mj-v8.2",
"status": "queued",
"stage": "queued",
"created_at": 1791993600,
"updated_at": 1791993600,
"completed_at": null,
"poll_after_seconds": 5,
"output": null,
"usage": {
"credits_reserved": 0.08,
"credits_settled": 0,
"credits_refunded": 0,
"credits_charged": 0.08
},
"request_id": "202611260732156684925978268d9d6yOLdMCKV",
"error_code": null,
"error_message": null
}
}
字段类型说明
data.idstring任务 ID:task_ 后接 32 位字母和数字。用于轮询以及匹配 Webhook 事件。
data.objectstring固定为 task。
data.task_kindstringimage 或 video。
data.capability_idstring你发送的模型 ID。
data.capability_versioninteger模型的契约版本,当前为 1。
data.media_typestringimage 或 video。
data.modelstring你发送的模型 ID(与 capability_id 相同)。
data.statusstringqueued、processing、succeeded 或 failed。只有后两个是终态。
data.stagestring与 status 相同;为旧版客户端保留。
data.created_atinteger任务创建时间,Unix 秒。
data.updated_atinteger最后一次变更时间,Unix 秒。
data.completed_atinteger | null任务结束时间,Unix 秒;运行中为 null。
data.poll_after_secondsinteger运行中:下一次轮询前需要等待的秒数(图片 5,视频 8)。
data.typical_secondsobject运行中且近期样本足够时出现:在最近的 window 内,根据 samples 个任务统计的完成时间 p50 和 p90,单位为秒。
data.outputobject | null任务结果;status 为 succeeded 之前为 null。见下方输出字段。
data.usage.credits_reservednumber创建任务时从你的余额中预扣的美元金额。
data.usage.credits_chargednumber该任务的费用(美元);失败的任务为 0。
data.usage.credits_settlednumber最终结算扣除的美元金额;任务成功时设置,否则为 0。
data.usage.credits_refundednumber退回你余额的美元金额;失败的任务在退款记录完成后等于预扣金额。
data.usage.billable_duration_secondsinteger仅视频:计价所依据的秒数。模型未上报时长时不出现。
data.request_idstring请求 ID。联系支持时请附上。
data.error_codestring | null失败码;任务未失败时为 null。
data.error_messagestring | null出了什么问题以及该改什么;任务未失败时为 null。

任务完成

GET /v1/tasks/{task_id} 返回 HTTP 200 和 status: "succeeded",结果在 data.output 中。

{
"data": {
"id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
"object": "task",
"task_kind": "image",
"capability_id": "mj-v8.2",
"capability_version": 1,
"media_type": "image",
"model": "mj-v8.2",
"status": "succeeded",
"stage": "succeeded",
"created_at": 1791993600,
"updated_at": 1791993690,
"completed_at": 1791993690,
"output": {
"media": [
{
"type": "image",
"url": "https://media.beatapi.io/outputs/task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ/0.png",
"mime_type": "image/png"
},
{
"type": "image",
"url": "https://media.beatapi.io/outputs/task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ/1.png",
"mime_type": "image/png"
},
{
"type": "image",
"url": "https://media.beatapi.io/outputs/task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ/2.png",
"mime_type": "image/png"
},
{
"type": "image",
"url": "https://media.beatapi.io/outputs/task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ/3.png",
"mime_type": "image/png"
}
],
"url": "https://media.beatapi.io/outputs/task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ/0.png",
"r2_url": "https://media.beatapi.io/outputs/task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ/0.png",
"data": {
"kind": "grid",
"follow_ups": [
"variation",
"upscale",
"reroll"
]
}
},
"usage": {
"credits_reserved": 0.08,
"credits_settled": 0.08,
"credits_refunded": 0,
"credits_charged": 0.08
},
"request_id": "202611260732156684925978268d9d6yOLdMCKV",
"error_code": null,
"error_message": null
}
}

输出字段

字段类型说明
output.mediaobject[]图片:四宫格为四张,放大为一张,describe 没有。index 从 1 开始对它们计数。
output.media[].typestring固定为 image。
output.media[].urlstring已存储图片的 HTTPS 链接。7 天后删除;需要保留的请下载。
output.media[].mime_typestring存储的文件类型,image/png。
output.urlstring主资产:第一张图片的链接。describe 时为空。
output.r2_urlstringoutput.url 的旧名称,值相同;请读取 output.url。
output.data.kindstringgrid(四张图)、single(一张放大图)或 text(describe)。
output.data.follow_upsstring[]这个结果作为 source_task_id 时接受的操作。不能续作时为空。
output.data.promptsstring[]仅 describe:四条提示词。

任务失败

失败的任务在 GET /v1/tasks/{task_id} 上仍然是 HTTP 200:失败信息在响应体里。预扣金额会全额退回,因此不会扣费。

{
"data": {
"id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
"object": "task",
"task_kind": "image",
"capability_id": "mj-v8.2",
"capability_version": 1,
"media_type": "image",
"model": "mj-v8.2",
"status": "failed",
"stage": "failed",
"created_at": 1791993600,
"updated_at": 1791993690,
"completed_at": 1791993690,
"output": null,
"usage": {
"credits_reserved": 0.08,
"credits_settled": 0,
"credits_refunded": 0.08,
"credits_charged": 0
},
"retryable": true,
"request_id": "202611260732156684925978268d9d6yOLdMCKV",
"error_code": "processing_failed",
"error_message": "The task failed during processing on our side. Retry; a failed task is refunded.",
"error": {
"code": "processing_failed",
"message": "The task failed during processing on our side. Retry; a failed task is refunded.",
"retryable": true
}
}
}
字段类型说明
data.error_codestringbad_request 和 content_policy_violation(需修改请求)之一,或 processing_unavailable、processing_timeout、processing_failed 和 result_transfer_failed(稍后重试)之一。见错误码。
data.error_messagestring一句话,指出问题和处理方式。
data.retryableboolean仅在任务失败时出现:为 true 表示再次发送相同请求可能成功。
data.errorobject仅失败的任务才有:code、message 和 retryable 合成一个对象,值与 data.error_code、data.error_message 和 data.retryable 相同。
data.usageobject退款记录完成后(通常就在任务失败的那一刻):credits_charged 和 credits_settled 为 0;credits_refunded 等于 credits_reserved。

完整示例

创建任务,按服务端给出的轮询提示等待,然后打印结果链接。请在环境变量中设置 BEATAPI_API_KEY 并安装 requests。

import os
import time
import uuid
import requests
API = "https://api.beatapi.io"
HEADERS = {"Authorization": f"Bearer {os.environ['BEATAPI_API_KEY']}"}
def create_task(body: dict) -> dict:
# One Idempotency-Key per logical request: a retry with the same key cannot create a second task.
headers = {**HEADERS, "Idempotency-Key": str(uuid.uuid4())}
for attempt in range(3):
response = requests.post(f"{API}/v1/images/tasks", headers=headers, json=body, timeout=60)
if response.status_code in (429, 503) and attempt < 2:
time.sleep(int(response.headers.get("Retry-After", 10)))
continue
break
try:
payload = response.json()
except ValueError: # an edge error page is not JSON
response.raise_for_status()
raise
if not response.ok:
error = payload["error"]
raise RuntimeError(f"{response.status_code} {error['code']}: {error['message']} (request_id={error.get('request_id')})")
return payload["data"]
def wait_for_task(task_id: str, timeout_seconds: int = 1800) -> dict:
deadline = time.monotonic() + timeout_seconds
while time.monotonic() < deadline:
response = requests.get(f"{API}/v1/tasks/{task_id}", headers=HEADERS, timeout=30)
if response.status_code == 429 or response.status_code >= 500:
time.sleep(int(response.headers.get("Retry-After", 10)))
continue
response.raise_for_status()
task = response.json()["data"]
if task["status"] in ("succeeded", "failed"):
return task
time.sleep(task.get("poll_after_seconds", 5))
raise TimeoutError(f"task {task_id} is still running; keep polling later")
task = create_task({
"model": "mj-v8.2",
"prompt": "A lighthouse on a basalt cliff at dusk, storm clouds breaking, cinematic light --s 250",
"aspect_ratio": "16:9"
})
print("created", task["id"])
task = wait_for_task(task["id"])
if task["status"] == "failed":
raise SystemExit(f"{task['error_code']}: {task['error_message']}")
for item in task["output"]["media"]:
print(item["url"])

计费

  • 每次调用是一个任务、一个价格,由 speed 和 quality 决定(见下表)。生成、变体、重绘、重塑风格、编辑、混合或草图,都按该设置计一次调用,与返回的图片数量无关。
  • 续作按源任务的速度和质量计费。upscale 和 describe 在任何速度下都是一个固定价。
  • 价格在创建任务时预留。以 HTTP 400 拒绝的请求不收费;失败的任务全额退还预留:此时 credits_refunded 等于 credits_reserved。
  • 用没有透明区域的图片做 edit,仍会绘制并计费。

当前牌价,与价格页一致。享有协商折扣的账户实付更低;任务的 data.usage 始终显示实际扣费金额。

选项牌价(美元)
1 张图片 · fast_hd$0.11
1 张图片 · relax$0.055
1 张图片 · relax_hd$0.055
1 张图片 · upscale$0.02
1 张图片 · describe$0.02
1 张图片 · fast$0.08

常见错误

错误或现象原因处理方式
400 "index" is required for action upscale放大时没有指定要选哪一张。传 1 到 4 的 index,即在源任务 output.media 中的位置。
400 an upscaled image takes no follow-up; to vary it, send action variation with source_task_id of its four-image result and the same index对放大结果发送了续作。用四宫格任务的 id 和相同的 index 发送 variation。
400 that image of source_task_id was already upscaled in task_Up4Rk9Ns2Wq7Zx5Mc8Hv1Lb6Tj3Fd0Gy; use that task's result同一结果的同一张图之前已经放大过。读取报错中指出的那个任务的结果。被拒绝的请求不收费。
400 prompt is not used by action upscale; leave it out传了该操作不接受的字段。只传该操作列出的字段。
400 remove --v from the prompt: the version is fixed at 8.2; leave it out从 midjourney.com 复制的提示词带有 --v、--fast、--hd 或其他由本 API 字段设置的参数。删掉它,改用字段(speed、quality、draft)。
400 source_task_id is a draft, which takes no follow-up; send the prompt again without draft (add --seed N to keep a similar composition)对草图结果续作。去掉 draft 再发一次提示词。
400 source_task_id was made at speed relax and a follow-up runs the same; leave speed out续作的 speed 或 quality 与源任务不同。续作时不要传这两个字段。
edit 后的四张图看起来没变图片没有透明区域,所以没有可重画的部分。仍然计费。传一张把要修改的部分抠成透明的 PNG。
传入图片后任务 failed链接打开的是网页、登录页或已过期的 URL,或没能在几秒内下载完。直接链接到图片文件,或用 POST /v1/files 上传。不收费。
任务 failed,错误码 content_policy_violation提示词或图片被内容审核拒绝。修改提示词或图片。原样重试仍会失败;不收费。
图片链接打不开了结果 7 天后删除。任务成功后尽快下载结果。

HTTP 错误速查

任务生成之前的错误会以非 2xx 响应返回,不扣费。请根据 error.code 或 error.retryable 判断处理方式;message 会指出问题所在。完整列表和重试策略见错误码。

{
"error": {
"code": "bad_request",
"message": "\"prompt\" is required",
"retryable": false,
"request_id": "202611260732156684925978268d9d6yOLdMCKV"
}
}
HTTP 状态码error.code处理方式
400bad_request, content_policy_violation修改请求;message 会点名出错的字段。不要原样重试。
401missing_api_key, invalid_api_key(旧版客户端可能看到 unauthorized)以 Authorization: Bearer <key> 发送有效的密钥。
402insufficient_credits充值,或提高密钥的额度,然后重新发送。
403forbidden该密钥或账户不能使用此模型(例如免费额度只覆盖部分模型)。不要原样重试。
404not_found在 GET /v1/tasks/{task_id} 上:该任务在此密钥所属账户下不存在。请检查 ID。
409idempotency_conflict换一个新的 Idempotency-Key,或等待使用该键的第一个请求完成。
429rate_limit_exceeded等待 Retry-After 秒(也见 error.retry_after_seconds)后重试。
500internal_error退避重试;若持续出现,请带上 request_id 联系支持。
503processing_unavailable, processing_timeout, processing_failed, result_transfer_failed未扣费。使用指数退避重试。

身份验证

AuthorizationBearer

通过 Authorization: Bearer <BEATAPI_API_KEY> 发送 API 密钥。

请求头

Idempotency-Keystring可选<=255 characters

请求体使用 JSON,并设置 Content-Type: application/json。Idempotency-Key 为可选:每个逻辑请求发送一个唯一值(最长 255 个字符),仅在重试完全相同的请求体时复用。24 小时内,用相同的键和请求体重试会再次返回第一次的响应,并带上 Idempotent-Replayed: true;相同的键搭配不同的请求体则返回 409 idempotency_conflict。非 2xx 的响应不会被保存,因此 400 或 402 之后的重试会重新执行。

请求

This endpoint expects an object.
modelenum必需

要调用的模型。

取值:mj-v8.2

取值有误时

  • 未传:"model" is required
  • 未知的模型 ID:"model" mj-v7 is not catalogued
  • 把视频模型发到了这个端点:"model" seedance-2.5 is served by POST /v1/videos/tasks, not this endpoint
允许的值:
actionenum可选默认为 generate

要执行的操作。每个操作只接受它自己的字段(见上面的输入模式);其他字段会被拒绝,免得你为一个没起作用的设置付费。

可选值:generate, variation, upscale, reroll, retexture, edit, blend, describe

默认值:generate

  • generate 从头开始。variation、upscale 和 reroll 作用于四宫格结果;放大图不能再续作。
  • retexture、edit、blend 和 describe 从你在 images 里提供的图片开始。
  • 输入不区分大小写;文档写小写形式。

取值有误时

  • 不在可选值列表中:"action" must be one of: [generate variation upscale reroll retexture edit blend describe]
  • 传了该操作不接受的字段:quality is not used by action retexture; leave it out
aspect_ratioenum可选

图片的宽高比(宽:高),用于 generate 和 blend。

可选值:1:1, 4:3, 3:4, 3:2, 2:3, 16:9, 9:16, 21:9, 9:21, 5:4, 4:5, 2:1, 1:2

  • 生成时不传则按 1:1 绘制。
  • blend 只接受 1:1(默认)、3:2 或 2:3。
  • 其他比例请在 prompt 里写整数的 --ar W:H,例如 --ar 7:4;它会覆盖本字段。

取值有误时

  • 不在可选值列表中:"aspect_ratio" must be one of: [1:1 4:3 3:4 3:2 2:3 16:9 9:16 21:9 9:21 5:4 4:5 2:1 1:2]
  • blend 用了其他比例:"aspect_ratio" for blend is one of: 1:1, 3:2, 2:3
draftboolean可选

仅用于 generate。为 true 时以一次生成的价格返回 24 张 512 px 的快速草图,用于在正式出图前试探提示词。

  • 两种 speed 都可用;不能与 quality hd 同时使用。
  • 草图不能续作,其中的图片也不能被选取。要正式出图,请去掉 draft 再发一次;在草图的提示词里写 --seed N,可得到相近(但不完全相同)的构图。

取值有误时

  • 不是布尔值:"draft" must be a boolean
  • 对草图续作:source_task_id is a draft, which takes no follow-up; send the prompt again without draft (add --seed N to keep a similar composition)
imageslist of strings可选

你自己的图片,使用公网 HTTPS 链接。对 generate 是图片提示(1 到 5 张);retexture、edit 和 describe 恰好一张;blend 为 2 到 5 张。

数量:1–5

每一项都必须是公网 https:// 链接。本地文件请先上传(POST /v1/files),再传入返回的 data.url。

  • 链接必须公开,且能在几秒内下载完。本地文件请先用 POST /v1/files 上传,再传返回的链接。
  • 对 edit,请传 PNG,并把要修改的部分抠成透明。没有透明区域的图片(例如任何 JPEG)仍会被绘制并计费。
  • 续作(variation、upscale、reroll)作用于 source_task_id,不接受 images。
  • 报错信息中的位置从 0 开始:images[0] 是第一个链接。

取值有误时

  • retexture、edit、blend 或 describe 没传:"images" is required for action describe
  • 少于 blend 所需的张数:action blend needs at least 2 image(s) in "images"
  • describe、retexture 或 edit 传了多于一张:action describe takes at most 1 image(s) in "images"
  • 多于五张:"images" accepts at most 5 items
  • 不是 https:// 链接:"images[0]" must be a public HTTPS URL
indexinteger可选1-4

作用于四宫格结果中的哪一张,1 到 4。从 1 开始,按源任务的 output.media 计数。

范围:1–4

  • upscale 和 variation 必须传。
  • reroll 以及不带 source_task_id 的操作都不使用。

取值有误时

  • upscale 或 variation 没传:"index" is required for action upscale
  • 不是 1 到 4 的整数:"index" is outside its supported range
promptstring可选1-2048 characters

要画什么,写法与 midjourney.com 相同:先写描述,再写 Midjourney 参数,例如 --ar 3:2 --s 250。对 retexture 和 edit,它描述新的样子。

长度:1–2048 个字符

  • generate 必须传(images 含两个或更多链接时除外),retexture 和 edit 也必须传。其他操作不接受它。
  • 对 generate,去掉链接和 -- 参数后的文字最多 1024 个字符。
  • 由字段设置的参数以及本 API 不支持的参数写在提示词里会被拒绝;见下文的参数表。

取值有误时

  • 生成时没传,且图片少于两张:generate needs "prompt"; only two or more images may go without one
  • retexture 或 edit 没传:"prompt" is required for action retexture
  • 随不接受它的操作一起传:prompt is not used by action upscale; leave it out
  • 为空或超过长度上限:"prompt" has an unsupported length
  • 去掉链接和参数后的文字过长:the prompt's text (without links and --parameters) is at most 1024 characters
  • 写了版本参数:remove --v from the prompt: the version is fixed at 8.2; leave it out
  • 写了速度参数:remove --fast from the prompt: set the speed field to fast instead
  • 比例写成小数:--ar takes whole numbers, like 139:100 instead of 1.39:1
  • --q 不在 1 到 4 之间:--q takes 1, 2, 3 or 4 (detail; 4 is the most detailed); for a bigger picture set quality hd
qualityenum可选默认为 standard

hd 约为 2K,大于标准尺寸。它在生成时设定,之后无法再加。

可选值:standard, hd

默认值:standard

  • fast 下 hd 更贵;relax 下价格相同。
  • upscale 按绘制时的像素尺寸返回图片,不会放大分辨率。想要更大的图,请在第一次调用时就设 hd。
  • 续作沿用源任务的质量。续作时不要传该字段,或传相同的值。
  • retexture、edit、blend 和 describe 不接受它。

取值有误时

  • 不在可选值列表中:"quality" must be one of: [standard hd]
  • 与 draft 同时使用:draft cannot be combined with quality hd
  • 续作要求的质量与源任务不同:source_task_id was made at quality hd and a follow-up runs the same; leave quality out
允许的值:
source_task_idstring可选格式: "task-id"

续作时填写:它所基于的、你自己之前的 Midjourney 任务的 id。该任务必须已成功。

  • 先读该任务的 output.data.follow_ups:它列出这个结果接受的操作。其他续作会被拒绝,不收费。
  • 放大图不能再续作。要对它做变体,请用它所在四宫格结果的 source_task_id 和相同的 index 发送 variation。
  • upscale、retexture、edit、describe 的结果和草图都不能续作。

取值有误时

  • 不是任务 ID:"source_task_id" must be the id of one of your earlier tasks: "task_" followed by 32 letters or digits
  • 续作时没传:"source_task_id" is required for action upscale: the id of your own Midjourney task it works on
  • 源任务还在运行或已失败:source_task_id has not finished successfully; wait for it to succeed and try again
  • 其他模型的任务:source_task_id was made by seedream-5.5, not Midjourney; name one of your Midjourney tasks
  • 对放大图续作:an upscaled image takes no follow-up; to vary it, send action variation with source_task_id of its four-image result and the same index
  • retexture、edit 或 describe 的结果:source_task_id is the result of retexture, which takes no follow-up
  • 再次放大同一结果的同一张图:that image of source_task_id was already upscaled in task_Up4Rk9Ns2Wq7Zx5Mc8Hv1Lb6Tj3Fd0Gy; use that task's result
  • 该结果的 follow_ups 没有列出这个操作:this result does not support action upscale; generate the image again and continue from the new result
speedenum可选默认为 fast

fast(默认)生成通常 1 到 3 分钟完成;relax 需要 2 到 5 分钟,价格更低。

可选值:fast, relax

默认值:fast

  • 续作沿用源任务的速度,并按该速度计费。续作时不要传该字段,或传相同的值。
  • describe 不接受它。

取值有误时

  • 不在可选值列表中:"speed" must be one of: [fast relax]
  • 续作要求的速度与源任务不同:source_task_id was made at speed relax and a follow-up runs the same; leave speed out
允许的值:
callback_urlstring可选<=2048 characters

任务成功或失败时通知的地址:公网 HTTPS URL,协议、主机和端口必须与你某个已启用的 Webhook 端点相同,并由该端点的 secret 签名。

长度:≤ 2048 个字符

  • 请先用 POST /v1/webhooks 注册端点。BeatAPI 会推送 task.succeeded 或 task.failed,事件体、请求头和重试规则与账户 Webhook 相同;订阅了该事件的账户端点也会收到,与该端点地址完全相同时只通知一次。
  • 签名端点被删除、停用或改到别的主机后,这条回调作废。

取值有误时

  • 值不是字符串:"callback_url" must be a string.
  • 地址超过 2048 个字符:"callback_url" must be at most 2048 characters.
  • 不是 URL,或没有主机、没有 http 或 https 协议:"callback_url" must be a valid https URL.
  • 使用了 http,或指向私有等非公网地址:"callback_url" must be a public HTTPS URL.
  • 没有任何已启用的 Webhook 端点与之协议、主机和端口相同:"callback_url" must be on the host of one of your active webhook endpoints, whose secret signs it; register one with POST /v1/webhooks.

响应

任务对象。任务成功之前 output 为 null。标注“运行中”的字段会在任务结束后消失。

dataobject
Accepted or current BeatAPI task state.

错误

400
Bad Request Error
401
Unauthorized Error
402
Payment Required Error
403
Forbidden Error
409
Conflict Error
429
Too Many Requests Error
500
Internal Server Error
503
Service Unavailable Error