> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.beatapi.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.beatapi.io/_mcp/server.

# Midjourney V8.2

POST https://api.beatapi.io/v1/images/tasks
Content-Type: application/json

用一个模型 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>` 形式发送。在[控制台](https://beatapi.io/dashboard)创建密钥。密钥只能保存在你的服务端，不要放进浏览器或移动端应用。请求体使用 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](/webhooks)；仍需保留轮询作为兜底，因为因处理超时而终止的任务不会发送事件。
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://` 链接。本地文件请先[上传](/quick-guide#upload-an-input-file)（`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 端点](/webhooks)相同，并由该端点的 `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） | 你的一张 PNG    | `images`, `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` `true`     | 24 张 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`。 |
| `--s`             | 0 到 1000       | 风格化强度。                                             |
| `--c`             | 0 到 100        | 混乱度：四张图之间的差异程度。                                    |
| `--seed`          | 0 到 4294967295 | 可复现的初始噪声。                                          |
| `--q`             | 1 到 4          | 细节程度；4 最细。想要更大的图请用 `quality` `hd`。                 |
| `--sref` 和 `--sw` | 图片链接或风格代码；权重   | 风格参考及其权重。                                          |
| `--iw`            | 0 到 3          | `images` 中图片提示的权重。                                 |
| `--exp`           | 0 到 100        | 实验性美学。                                             |
| `--weird`         | 0 到 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` 里。你传入的图片链接必须公开，且能在几秒内下载完。无法获取的链接会让任务失败，失败的任务不收费。## 请求示例```bash title="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 title="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 title="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 参数写在提示词末尾。```bash
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 按钮：生成四张与上面生成结果第三张相近的新图。```bash
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：单独取出第二张，保持绘制时的像素尺寸。它不能再续作。```bash
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` 中返回四条能画出类似图片的提示词。```bash
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` 不额外收费。```bash
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 渲染。不传提示词。```bash
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`。标注“运行中”的字段会在任务结束后消失。```json
{
  "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.id`                              | `string`          | 任务 ID：`task_` 后接 32 位字母和数字。用于轮询以及匹配 Webhook 事件。                           |
| `data.object`                          | `string`          | 固定为 `task`。                                                               |
| `data.task_kind`                       | `string`          | `image` 或 `video`。                                                        |
| `data.capability_id`                   | `string`          | 你发送的模型 ID。                                                                |
| `data.capability_version`              | `integer`         | 模型的契约版本，当前为 `1`。                                                          |
| `data.media_type`                      | `string`          | `image` 或 `video`。                                                        |
| `data.model`                           | `string`          | 你发送的模型 ID（与 `capability_id` 相同）。                                          |
| `data.status`                          | `string`          | `queued`、`processing`、`succeeded` 或 `failed`。只有后两个是终态。                    |
| `data.stage`                           | `string`          | 与 `status` 相同；为旧版客户端保留。                                                   |
| `data.created_at`                      | `integer`         | 任务创建时间，Unix 秒。                                                            |
| `data.updated_at`                      | `integer`         | 最后一次变更时间，Unix 秒。                                                          |
| `data.completed_at`                    | `integer \| null` | 任务结束时间，Unix 秒；运行中为 `null`。                                                |
| `data.poll_after_seconds`              | `integer`         | 运行中：下一次轮询前需要等待的秒数（图片 5，视频 8）。                                             |
| `data.typical_seconds`                 | `object`          | 运行中且近期样本足够时出现：在最近的 `window` 内，根据 `samples` 个任务统计的完成时间 `p50` 和 `p90`，单位为秒。 |
| `data.output`                          | `object \| null`  | 任务结果；`status` 为 `succeeded` 之前为 `null`。见下方输出字段。                           |
| `data.usage.credits_reserved`          | `number`          | 创建任务时从你的余额中预扣的美元金额。                                                       |
| `data.usage.credits_charged`           | `number`          | 该任务的费用（美元）；失败的任务为 `0`。                                                    |
| `data.usage.credits_settled`           | `number`          | 最终结算扣除的美元金额；任务成功时设置，否则为 `0`。                                              |
| `data.usage.credits_refunded`          | `number`          | 退回你余额的美元金额；失败的任务在退款记录完成后等于预扣金额。                                           |
| `data.usage.billable_duration_seconds` | `integer`         | 仅视频：计价所依据的秒数。模型未上报时长时不出现。                                                 |
| `data.request_id`                      | `string`          | 请求 ID。联系支持时请附上。                                                           |
| `data.error_code`                      | `string \| null`  | 失败码；任务未失败时为 `null`。                                                       |
| `data.error_message`                   | `string \| null`  | 出了什么问题以及该改什么；任务未失败时为 `null`。                                              |### 任务完成`GET /v1/tasks/{task_id}` 返回 HTTP 200 和 `status: "succeeded"`，结果在 `data.output` 中。```json
{
  "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.media`             | `object[]` | 图片：四宫格为四张，放大为一张，describe 没有。`index` 从 1 开始对它们计数。 |
| `output.media[].type`      | `string`   | 固定为 `image`。                                     |
| `output.media[].url`       | `string`   | 已存储图片的 HTTPS 链接。7 天后删除；需要保留的请下载。                 |
| `output.media[].mime_type` | `string`   | 存储的文件类型，`image/png`。                             |
| `output.url`               | `string`   | 主资产：第一张图片的链接。describe 时为空。                       |
| `output.r2_url`            | `string`   | `output.url` 的旧名称，值相同；请读取 `output.url`。          |
| `output.data.kind`         | `string`   | `grid`（四张图）、`single`（一张放大图）或 `text`（describe）。   |
| `output.data.follow_ups`   | `string[]` | 这个结果作为 `source_task_id` 时接受的操作。不能续作时为空。          |
| `output.data.prompts`      | `string[]` | 仅 describe：四条提示词。                                |### 任务失败失败的任务在 `GET /v1/tasks/{task_id}` 上仍然是 HTTP 200：失败信息在响应体里。预扣金额会全额退回，因此不会扣费。```json
{
  "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_code`    | `string`  | `bad_request` 和 `content_policy_violation`（需修改请求）之一，或 `processing_unavailable`、`processing_timeout`、`processing_failed` 和 `result_transfer_failed`（稍后重试）之一。见[错误码](/errors)。 |
| `data.error_message` | `string`  | 一句话，指出问题和处理方式。                                                                                                                                                              |
| `data.retryable`     | `boolean` | 仅在任务失败时出现：为 `true` 表示再次发送相同请求可能成功。                                                                                                                                          |
| `data.error`         | `object`  | 仅失败的任务才有：`code`、`message` 和 `retryable` 合成一个对象，值与 `data.error_code`、`data.error_message` 和 `data.retryable` 相同。                                                             |
| `data.usage`         | `object`  | 退款记录完成后（通常就在任务失败的那一刻）：`credits_charged` 和 `credits_settled` 为 `0`；`credits_refunded` 等于 `credits_reserved`。                                                                 |## 完整示例创建任务，按服务端给出的轮询提示等待，然后打印结果链接。请在环境变量中设置 `BEATAPI_API_KEY` 并安装 `requests`。```python
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`，仍会绘制并计费。当前牌价，与[价格页](https://beatapi.io/pricing)一致。享有协商折扣的账户实付更低；任务的 `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` 会指出问题所在。完整列表和重试策略见[错误码](/errors)。```json
{
  "error": {
    "code": "bad_request",
    "message": "\"prompt\" is required",
    "retryable": false,
    "request_id": "202611260732156684925978268d9d6yOLdMCKV"
  }
}
```| HTTP 状态码 | `error.code`                                                                                  | 处理方式                                                   |
| -------- | --------------------------------------------------------------------------------------------- | ------------------------------------------------------ |
| 400      | `bad_request`, `content_policy_violation`                                                     | 修改请求；message 会点名出错的字段。不要原样重试。                          |
| 401      | `missing_api_key`, `invalid_api_key`（旧版客户端可能看到 `unauthorized`）                                | 以 `Authorization: Bearer <key>` 发送有效的密钥。               |
| 402      | `insufficient_credits`                                                                        | 充值，或提高密钥的额度，然后重新发送。                                    |
| 403      | `forbidden`                                                                                   | 该密钥或账户不能使用此模型（例如免费额度只覆盖部分模型）。不要原样重试。                   |
| 404      | `not_found`                                                                                   | 在 `GET /v1/tasks/{task_id}` 上：该任务在此密钥所属账户下不存在。请检查 ID。  |
| 409      | `idempotency_conflict`                                                                        | 换一个新的 `Idempotency-Key`，或等待使用该键的第一个请求完成。               |
| 429      | `rate_limit_exceeded`                                                                         | 等待 `Retry-After` 秒（也见 `error.retry_after_seconds`）后重试。 |
| 500      | `internal_error`                                                                              | 退避重试；若持续出现，请带上 `request_id` 联系支持。                      |
| 503      | `processing_unavailable`, `processing_timeout`, `processing_failed`, `result_transfer_failed` | 未扣费。使用指数退避重试。                                          |

Reference: https://docs.beatapi.io/api-reference/image-api/mj-v8-2

## Authentication

- `Authorization` header (bearer token, required) — 通过 `Authorization: Bearer <BEATAPI_API_KEY>` 发送 API 密钥。

## Servers

- `https://api.beatapi.io` (Direct, default)
- `https://api.beatapi.io` (API)

## Request

### Headers

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

### Body (application/json)

This endpoint expects a MjV82ImageRequest.

- `model` (enum, required) — 要调用的模型。 **取值**：`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`
  - Allowed values: `mj-v8.2`
- `action` (enum, optional, default: 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`
  - Allowed values: `generate`, `variation`, `upscale`, `reroll`, `retexture`, `edit`, `blend`, `describe`
- `aspect_ratio` (enum, optional) — 图片的宽高比（宽:高），用于 `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`
  - Allowed values: `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`
- `draft` (boolean, optional) — 仅用于 `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)`
- `images` (list of string, optional) — 你自己的图片，使用公网 HTTPS 链接。对 `generate` 是图片提示（1 到 5 张）；`retexture`、`edit` 和 `describe` 恰好一张；`blend` 为 2 到 5 张。 **数量**：1–5 每一项都必须是公网 `https://` 链接。本地文件请先[上传](/quick-guide#upload-an-input-file)（`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`
- `index` (integer, optional) — 作用于四宫格结果中的哪一张，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`
- `prompt` (string, optional) — 要画什么，写法与 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`
- `quality` (enum, optional, default: 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`
  - Allowed values: `standard`, `hd`
- `source_task_id` (string, optional) — 续作时填写：它所基于的、你自己之前的 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`
- `speed` (enum, optional, default: 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`
  - Allowed values: `fast`, `relax`
- `callback_url` (string, optional) — 任务成功或失败时通知的地址：公网 HTTPS URL，协议、主机和端口必须与你某个已启用的 [Webhook 端点](/webhooks)相同，并由该端点的 `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.`

## Response

### 201

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

- `data` (QueuedTask, required) — Accepted or current BeatAPI task state.

## Errors

### 400 Bad Request Error

`bad_request`, `content_policy_violation` 修改请求；message 会点名出错的字段。不要原样重试。

- `map from string to any`

### 401 Unauthorized Error

`missing_api_key`, `invalid_api_key`（旧版客户端可能看到 `unauthorized`） 以 `Authorization: Bearer <key>` 发送有效的密钥。

- `map from string to any`

### 402 Payment Required Error

`insufficient_credits` 充值，或提高密钥的额度，然后重新发送。

- `map from string to any`

### 403 Forbidden Error

`forbidden` 该密钥或账户不能使用此模型（例如免费额度只覆盖部分模型）。不要原样重试。

- `map from string to any`

### 409 Conflict Error

`idempotency_conflict` 换一个新的 `Idempotency-Key`，或等待使用该键的第一个请求完成。

- `map from string to any`

### 429 Too Many Requests Error

`rate_limit_exceeded` 等待 `Retry-After` 秒（也见 `error.retry_after_seconds`）后重试。

- `map from string to any`

### 500 Internal Server Error

`internal_error` 退避重试；若持续出现，请带上 `request_id` 联系支持。

- `map from string to any`

### 503 Service Unavailable Error

`processing_unavailable`, `processing_timeout`, `processing_failed`, `result_transfer_failed` 未扣费。使用指数退避重试。

- `map from string to any`

## Types

### QueuedTask

- `id` (string, required) — Stable BeatAPI task ID used for polling and support.
- `object` (enum, required) — Object discriminator; always `task`.
  - Allowed values: `task`
- `task_kind` (enum, required) — Public task family that determines which capability fields are present. `data` is a data capability run as a task (`data:web.research`), polled through `POST /v1/capabilities/run`.
  - Allowed values: `workflow`, `effect`, `image`, `video`, `audio`, `data`
- `capability_id` (string, required) — Stable BeatAPI workflow, Effect, generation model, or data capability ID (such as `web.research`) selected when the task was accepted.
- `capability_version` (integer, required) — Always `1`.
- `status` (enum, required) — Current task lifecycle status. Stop polling at `succeeded` or `failed`; Music Video can also require manual action.
  - Allowed values: `queued`, `processing`, `storyboard_ready`, `requires_action`, `editing`, `composing`, `succeeded`, `failed`
- `stage` (enum, required) — Always repeats `status`. Kept for compatibility; read `status`.
  - Allowed values: `queued`, `processing`, `storyboard_ready`, `requires_action`, `editing`, `composing`, `succeeded`, `failed`
- `created_at` (integer, required) — Unix timestamp when BeatAPI accepted the task.
- `updated_at` (integer, required) — Unix timestamp of the latest task update.
- `completed_at` (integer, required, nullable) — Terminal Unix timestamp, or null while work is in progress.
- `output` (QueuedTaskOutput, required, nullable) — Output is null until the task succeeds.
- `request_id` (string, required) — Correlation ID to retain for logs and BeatAPI support.
- `error_code` (string, required, nullable) — Machine-readable terminal failure code, or null when no task failure is recorded. `task_cancelled` marks a task you cancelled while it waited in its model's queue.
- `error_message` (string, required, nullable) — Human-readable terminal failure detail, or null when no task failure is recorded.
- `workflow` (enum, optional) — Present for workflow tasks; identifies the selected BeatAPI workflow.
  - Allowed values: `music-video`, `ecommerce-video`, `video-analysis`
- `effect_id` (string, optional) — Present for Effect tasks; stable selected Effect ID.
- `effect_version` (integer, optional) — Present for Effect tasks; immutable Effect version used for processing.
- `media_type` (enum, optional) — Present when task_kind is image or video.
  - Allowed values: `image`, `video`, `audio`
- `model` (string, optional) — Stable BeatAPI model alias. It is independent from internal execution routing.
- `storyboard` (Storyboard, optional) — Music Video storyboard metadata when available.
- `poll_after_seconds` (integer, optional) — Present while the task is running: how long to wait before the next status call (5 for images, 8 for video and Effects, 10 for workflows and data tasks). Follow it instead of a fixed interval. Absent on a terminal task.
- `typical_seconds` (QueuedTaskTypicalSeconds, optional) — Present while the task is running, when enough recent finishes exist: how long this task's model recently took from accepted to succeeded, measured on this gateway. Past `p90` with no change the task is running long; there is no ETA beyond that.
- `queue` (QueuedTaskQueue, optional) — Present only while the task waits for its model's capacity (read by id, not in the task list). A task still waiting at `deadline` fails with `processing_unavailable` and is refunded. Cancel it with `POST /v1/tasks/{task_id}/cancel`.
- `usage` (TaskUsage, optional) — USD reservation, settlement, refund, and optional billable duration for this task.
- `error` (QueuedTaskError, optional) — Present on a failed task: the terminal failure as one object. Its values are the same as the flat `error_code`, `error_message` and `retryable`, which stay.
- `retryable` (boolean, optional) — Present on a failed task: whether resubmitting could succeed. True when the task failed on our side or timed out (a failed task is not charged); false when it was refused for content or bad input. Same code-to-retryable rule as the error envelope.

### QueuedTaskOutput

Output is null until the task succeeds.

- QueuedTaskOutput0
- QueuedTaskOutput1
- QueuedTaskOutput2

### Storyboard

- `shots` (list of StoryboardShot, required) — Ordered Music Video storyboard shots. The array may be empty before storyboard generation completes.

### QueuedTaskTypicalSeconds

Present while the task is running, when enough recent finishes exist: how long this task's model recently took from accepted to succeeded, measured on this gateway. Past `p90` with no change the task is running long; there is no ETA beyond that.

- `p50` (integer, required) — Median seconds.
- `p90` (integer, required) — Ninetieth-percentile seconds.
- `samples` (integer, required) — Finished tasks the figures rest on.
- `window` (string, required) — The window measured, such as `7d`.

### QueuedTaskQueue

Present only while the task waits for its model's capacity (read by id, not in the task list). A task still waiting at `deadline` fails with `processing_unavailable` and is refunded. Cancel it with `POST /v1/tasks/{task_id}/cancel`.

- `position` (integer, required) — Place in the queue; 1 is next.
- `ahead` (integer, required) — Tasks of the same model ahead of this one.
- `queued_at` (integer, required) — Unix seconds when the task was queued.
- `deadline` (integer, required) — Unix seconds after which the task stops waiting.

### TaskUsage

- `credits_reserved` (double, required) — USD amount reserved for this task. The compatibility field name is retained; 1 Credit equals $1 USD.
- `credits_charged` (double, required) — USD amount charged. `0` on a failed task, because the reserved amount was returned.
- `credits_settled` (double, required) — USD amount settled after successful work.
- `credits_refunded` (double, required) — USD amount returned after a failed task. On a failed task `credits_reserved` is the amount held at create, `credits_charged` and `credits_settled` are `0`, and `credits_refunded` is the amount returned.
- `billable_duration_seconds` (integer, optional) — Server-detected or request-declared billable duration used for USD calculation.

### QueuedTaskError

Present on a failed task: the terminal failure as one object. Its values are the same as the flat `error_code`, `error_message` and `retryable`, which stay.

- `code` (string, required) — Machine-readable failure code, the same value as `error_code`.
- `message` (string, required) — English sentence that states the cause, the same value as `error_message`.
- `retryable` (boolean, optional) — Whether resubmitting could succeed, the same value as `retryable`. Absent when `retryable` is absent.

### QueuedTaskOutput0

- `media` (list of QueuedTaskOutputOneOf0MediaItems, required) — BeatAPI-hosted result assets.
- `url` (string, required) — The primary asset's URL, the one to read when you want a single file (the first video, else the first image). The same value as `r2_url`.
- `r2_url` (string, required, deprecated) — Deprecated — read `url`. The same value as `url`, kept only for clients that already read it.
- `tracks` (list of QueuedTaskOutputOneOf0TracksItems, optional) — Audio tasks only. One entry for each song or stem the call made, beside the files in `media`.
- `data` (any, optional) — Audio tasks only. What an action returns that is not a file, such as lyrics, aligned lyrics, a boosted style, a persona id or MIDI notes.

### QueuedTaskOutput1

- `text` (string, required) — Completed video analysis text.
- `usage` (QueuedTaskOutputOneOf1Usage, required) — Measured token usage used for final USD settlement.
- `finish_reason` (string, required, nullable) — Why the model stopped generating.

### QueuedTaskOutput2

A data task's result: the capability's own result object, such as `web.research` with `research_notes` and `sources` (in a view: `items`).

- `object` (string, required) — The result type, such as `web.research`.
- `request_id` (string, optional) — The ID of the task that produced the result.
- `query` (string, optional) — The question that was researched.
- `status` (enum, optional) — `partial` when part of the research could not be finished; `partial_reasons` says why.
  - Allowed values: `complete`, `partial`
- `research_notes` (string, optional) — The research notes.
- `sources` (list of map from string to any, optional) — The sources behind the notes.
- `partial_reasons` (list of string, optional) — Present when `status` is `partial`.
- `x_search` (map from string to any, optional) — How much X was searched, when the run searched X at all.

### StoryboardShot

- `id` (string, required) — BeatAPI shot id. Use this id for media retrieval, edit, and compose operations.
- `index` (integer, required) — Zero-based shot order in the storyboard.
- `status` (enum, required) — Current lifecycle state for this storyboard shot.
  - Allowed values: `queued`, `processing`, `storyboard_ready`, `requires_action`, `editing`, `composing`, `succeeded`, `failed`
- `created_at` (integer, required) — Unix timestamp when the shot record was created.
- `updated_at` (integer, required) — Unix timestamp when the shot record last changed.
- `duration_seconds` (integer, optional) — Planned or generated shot duration in seconds.
- `prompt` (string, optional) — Creative instruction used to generate this shot.
- `lyric_text` (string, optional) — Lyric segment aligned with this shot when available.
- `media` (StoryboardShotMedia, optional) — Present only after the shot media has been materialized or after a shot edit finishes.

### QueuedTaskOutputOneOf0MediaItems

- `type` (enum, required) — Result asset type.
  - Allowed values: `image`, `video`, `audio`
- `url` (string, required) — BeatAPI-hosted HTTPS result URL.
- `mime_type` (string, required) — Result asset MIME type.

### QueuedTaskOutputOneOf0TracksItems

- `id` (string, required) — The id a follow-up sends as `audio_id`.
- `title` (string, optional) — Song title.
- `name` (string, optional) — Stem name on a split result.
- `tags` (string, optional) — Style tags.
- `lyrics` (string, optional) — Lyrics of the song.
- `duration` (double, optional) — Length in seconds.
- `audio_url` (string, optional) — The song or stem file.
- `image_url` (string, optional) — Cover art.

### QueuedTaskOutputOneOf1Usage

Measured token usage used for final USD settlement.

- `input_tokens` (integer, required) — Tokens consumed by the prompt and video input.
- `output_tokens` (integer, required) — Tokens consumed by visible output and model reasoning.
- `total_tokens` (integer, required) — Total measured input and output tokens.

### StoryboardShotMedia

Present only after the shot media has been materialized or after a shot edit finishes.

- `type` (string, optional) — Hosted media type for the materialized shot.
- `url` (string, optional) — BeatAPI-hosted HTTPS URL for the materialized shot.
- `mime_type` (string, optional) — MIME type of the hosted shot media.

## Examples

### 生成四张图

**Request**

```json
{
  "model": "mj-v8.2",
  "aspect_ratio": "16:9",
  "prompt": "A lighthouse on a basalt cliff at dusk, storm clouds breaking, cinematic light --s 250"
}
```

**Response**

```json
{
  "data": {
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "object": "task",
    "task_kind": "image",
    "capability_id": "mj-v8.2",
    "capability_version": 1,
    "status": "queued",
    "stage": "queued",
    "created_at": 1791993600,
    "updated_at": 1791993600,
    "completed_at": null,
    "output": null,
    "request_id": "202611260732156684925978268d9d6yOLdMCKV",
    "error_code": null,
    "error_message": null,
    "media_type": "image",
    "model": "mj-v8.2",
    "poll_after_seconds": 5,
    "usage": {
      "credits_reserved": 0.08,
      "credits_charged": 0.08,
      "credits_settled": 0,
      "credits_refunded": 0
    }
  }
}
```

**SDK Code**

```python 生成四张图
import requests

url = "https://api.beatapi.io/v1/images/tasks"

payload = {
    "model": "mj-v8.2",
    "aspect_ratio": "16:9",
    "prompt": "A lighthouse on a basalt cliff at dusk, storm clouds breaking, cinematic light --s 250"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript 生成四张图
const url = 'https://api.beatapi.io/v1/images/tasks';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"model":"mj-v8.2","aspect_ratio":"16:9","prompt":"A lighthouse on a basalt cliff at dusk, storm clouds breaking, cinematic light --s 250"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go 生成四张图
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.beatapi.io/v1/images/tasks"

	payload := strings.NewReader("{\n  \"model\": \"mj-v8.2\",\n  \"aspect_ratio\": \"16:9\",\n  \"prompt\": \"A lighthouse on a basalt cliff at dusk, storm clouds breaking, cinematic light --s 250\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby 生成四张图
require 'uri'
require 'net/http'

url = URI("https://api.beatapi.io/v1/images/tasks")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"model\": \"mj-v8.2\",\n  \"aspect_ratio\": \"16:9\",\n  \"prompt\": \"A lighthouse on a basalt cliff at dusk, storm clouds breaking, cinematic light --s 250\"\n}"

response = http.request(request)
puts response.read_body
```

```java 生成四张图
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.beatapi.io/v1/images/tasks")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model\": \"mj-v8.2\",\n  \"aspect_ratio\": \"16:9\",\n  \"prompt\": \"A lighthouse on a basalt cliff at dusk, storm clouds breaking, cinematic light --s 250\"\n}")
  .asString();
```

```php 生成四张图
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.beatapi.io/v1/images/tasks', [
  'body' => '{
  "model": "mj-v8.2",
  "aspect_ratio": "16:9",
  "prompt": "A lighthouse on a basalt cliff at dusk, storm clouds breaking, cinematic light --s 250"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp 生成四张图
using RestSharp;

var client = new RestClient("https://api.beatapi.io/v1/images/tasks");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model\": \"mj-v8.2\",\n  \"aspect_ratio\": \"16:9\",\n  \"prompt\": \"A lighthouse on a basalt cliff at dusk, storm clouds breaking, cinematic light --s 250\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 生成四张图
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "mj-v8.2",
  "aspect_ratio": "16:9",
  "prompt": "A lighthouse on a basalt cliff at dusk, storm clouds breaking, cinematic light --s 250"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.beatapi.io/v1/images/tasks")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 对第 3 张做变体

**Request**

```json
{
  "model": "mj-v8.2",
  "action": "variation",
  "index": 3,
  "source_task_id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ"
}
```

**Response**

```json
{
  "data": {
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "object": "task",
    "task_kind": "image",
    "capability_id": "mj-v8.2",
    "capability_version": 1,
    "status": "queued",
    "stage": "queued",
    "created_at": 1791993600,
    "updated_at": 1791993600,
    "completed_at": null,
    "output": null,
    "request_id": "202611260732156684925978268d9d6yOLdMCKV",
    "error_code": null,
    "error_message": null,
    "media_type": "image",
    "model": "mj-v8.2",
    "poll_after_seconds": 5
  }
}
```

**SDK Code**

```python 对第 3 张做变体
import requests

url = "https://api.beatapi.io/v1/images/tasks"

payload = {
    "model": "mj-v8.2",
    "action": "variation",
    "index": 3,
    "source_task_id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript 对第 3 张做变体
const url = 'https://api.beatapi.io/v1/images/tasks';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"model":"mj-v8.2","action":"variation","index":3,"source_task_id":"task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go 对第 3 张做变体
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.beatapi.io/v1/images/tasks"

	payload := strings.NewReader("{\n  \"model\": \"mj-v8.2\",\n  \"action\": \"variation\",\n  \"index\": 3,\n  \"source_task_id\": \"task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby 对第 3 张做变体
require 'uri'
require 'net/http'

url = URI("https://api.beatapi.io/v1/images/tasks")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"model\": \"mj-v8.2\",\n  \"action\": \"variation\",\n  \"index\": 3,\n  \"source_task_id\": \"task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ\"\n}"

response = http.request(request)
puts response.read_body
```

```java 对第 3 张做变体
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.beatapi.io/v1/images/tasks")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model\": \"mj-v8.2\",\n  \"action\": \"variation\",\n  \"index\": 3,\n  \"source_task_id\": \"task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ\"\n}")
  .asString();
```

```php 对第 3 张做变体
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.beatapi.io/v1/images/tasks', [
  'body' => '{
  "model": "mj-v8.2",
  "action": "variation",
  "index": 3,
  "source_task_id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp 对第 3 张做变体
using RestSharp;

var client = new RestClient("https://api.beatapi.io/v1/images/tasks");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model\": \"mj-v8.2\",\n  \"action\": \"variation\",\n  \"index\": 3,\n  \"source_task_id\": \"task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 对第 3 张做变体
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "mj-v8.2",
  "action": "variation",
  "index": 3,
  "source_task_id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.beatapi.io/v1/images/tasks")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 放大第 2 张

**Request**

```json
{
  "model": "mj-v8.2",
  "action": "upscale",
  "index": 2,
  "source_task_id": "task_Vb3nK8wQ2mZr5Tx9Lc4Hd7Jf1Ps6Ya0E"
}
```

**Response**

```json
{
  "data": {
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "object": "task",
    "task_kind": "image",
    "capability_id": "mj-v8.2",
    "capability_version": 1,
    "status": "queued",
    "stage": "queued",
    "created_at": 1791993600,
    "updated_at": 1791993600,
    "completed_at": null,
    "output": null,
    "request_id": "202611260732156684925978268d9d6yOLdMCKV",
    "error_code": null,
    "error_message": null,
    "media_type": "image",
    "model": "mj-v8.2",
    "poll_after_seconds": 5
  }
}
```

**SDK Code**

```python 放大第 2 张
import requests

url = "https://api.beatapi.io/v1/images/tasks"

payload = {
    "model": "mj-v8.2",
    "action": "upscale",
    "index": 2,
    "source_task_id": "task_Vb3nK8wQ2mZr5Tx9Lc4Hd7Jf1Ps6Ya0E"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript 放大第 2 张
const url = 'https://api.beatapi.io/v1/images/tasks';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"model":"mj-v8.2","action":"upscale","index":2,"source_task_id":"task_Vb3nK8wQ2mZr5Tx9Lc4Hd7Jf1Ps6Ya0E"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go 放大第 2 张
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.beatapi.io/v1/images/tasks"

	payload := strings.NewReader("{\n  \"model\": \"mj-v8.2\",\n  \"action\": \"upscale\",\n  \"index\": 2,\n  \"source_task_id\": \"task_Vb3nK8wQ2mZr5Tx9Lc4Hd7Jf1Ps6Ya0E\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby 放大第 2 张
require 'uri'
require 'net/http'

url = URI("https://api.beatapi.io/v1/images/tasks")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"model\": \"mj-v8.2\",\n  \"action\": \"upscale\",\n  \"index\": 2,\n  \"source_task_id\": \"task_Vb3nK8wQ2mZr5Tx9Lc4Hd7Jf1Ps6Ya0E\"\n}"

response = http.request(request)
puts response.read_body
```

```java 放大第 2 张
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.beatapi.io/v1/images/tasks")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model\": \"mj-v8.2\",\n  \"action\": \"upscale\",\n  \"index\": 2,\n  \"source_task_id\": \"task_Vb3nK8wQ2mZr5Tx9Lc4Hd7Jf1Ps6Ya0E\"\n}")
  .asString();
```

```php 放大第 2 张
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.beatapi.io/v1/images/tasks', [
  'body' => '{
  "model": "mj-v8.2",
  "action": "upscale",
  "index": 2,
  "source_task_id": "task_Vb3nK8wQ2mZr5Tx9Lc4Hd7Jf1Ps6Ya0E"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp 放大第 2 张
using RestSharp;

var client = new RestClient("https://api.beatapi.io/v1/images/tasks");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model\": \"mj-v8.2\",\n  \"action\": \"upscale\",\n  \"index\": 2,\n  \"source_task_id\": \"task_Vb3nK8wQ2mZr5Tx9Lc4Hd7Jf1Ps6Ya0E\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 放大第 2 张
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "mj-v8.2",
  "action": "upscale",
  "index": 2,
  "source_task_id": "task_Vb3nK8wQ2mZr5Tx9Lc4Hd7Jf1Ps6Ya0E"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.beatapi.io/v1/images/tasks")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 反推一张图的提示词

**Request**

```json
{
  "model": "mj-v8.2",
  "action": "describe",
  "images": [
    "https://cdn.beatapi.io/samples/smart-bottle.png"
  ]
}
```

**Response**

```json
{
  "data": {
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "object": "task",
    "task_kind": "image",
    "capability_id": "mj-v8.2",
    "capability_version": 1,
    "status": "queued",
    "stage": "queued",
    "created_at": 1791993600,
    "updated_at": 1791993600,
    "completed_at": null,
    "output": null,
    "request_id": "202611260732156684925978268d9d6yOLdMCKV",
    "error_code": null,
    "error_message": null,
    "media_type": "image",
    "model": "mj-v8.2",
    "poll_after_seconds": 5
  }
}
```

**SDK Code**

```python 反推一张图的提示词
import requests

url = "https://api.beatapi.io/v1/images/tasks"

payload = {
    "model": "mj-v8.2",
    "action": "describe",
    "images": ["https://cdn.beatapi.io/samples/smart-bottle.png"]
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript 反推一张图的提示词
const url = 'https://api.beatapi.io/v1/images/tasks';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"model":"mj-v8.2","action":"describe","images":["https://cdn.beatapi.io/samples/smart-bottle.png"]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go 反推一张图的提示词
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.beatapi.io/v1/images/tasks"

	payload := strings.NewReader("{\n  \"model\": \"mj-v8.2\",\n  \"action\": \"describe\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\"\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby 反推一张图的提示词
require 'uri'
require 'net/http'

url = URI("https://api.beatapi.io/v1/images/tasks")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"model\": \"mj-v8.2\",\n  \"action\": \"describe\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\"\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java 反推一张图的提示词
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.beatapi.io/v1/images/tasks")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model\": \"mj-v8.2\",\n  \"action\": \"describe\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\"\n  ]\n}")
  .asString();
```

```php 反推一张图的提示词
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.beatapi.io/v1/images/tasks', [
  'body' => '{
  "model": "mj-v8.2",
  "action": "describe",
  "images": [
    "https://cdn.beatapi.io/samples/smart-bottle.png"
  ]
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp 反推一张图的提示词
using RestSharp;

var client = new RestClient("https://api.beatapi.io/v1/images/tasks");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model\": \"mj-v8.2\",\n  \"action\": \"describe\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\"\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 反推一张图的提示词
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "mj-v8.2",
  "action": "describe",
  "images": ["https://cdn.beatapi.io/samples/smart-bottle.png"]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.beatapi.io/v1/images/tasks")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

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

**Request**

```json
{
  "model": "mj-v8.2",
  "aspect_ratio": "4:5",
  "images": [
    "https://cdn.beatapi.io/samples/smart-bottle.png"
  ],
  "prompt": "The bottle on a sunlit kitchen counter, soft morning light --sref https://cdn.beatapi.io/samples/neon-singer.png --sw 200",
  "quality": "hd",
  "speed": "relax"
}
```

**Response**

```json
{
  "data": {
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "object": "task",
    "task_kind": "image",
    "capability_id": "mj-v8.2",
    "capability_version": 1,
    "status": "queued",
    "stage": "queued",
    "created_at": 1791993600,
    "updated_at": 1791993600,
    "completed_at": null,
    "output": null,
    "request_id": "202611260732156684925978268d9d6yOLdMCKV",
    "error_code": null,
    "error_message": null,
    "media_type": "image",
    "model": "mj-v8.2",
    "poll_after_seconds": 5
  }
}
```

**SDK Code**

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

url = "https://api.beatapi.io/v1/images/tasks"

payload = {
    "model": "mj-v8.2",
    "aspect_ratio": "4:5",
    "images": ["https://cdn.beatapi.io/samples/smart-bottle.png"],
    "prompt": "The bottle on a sunlit kitchen counter, soft morning light --sref https://cdn.beatapi.io/samples/neon-singer.png --sw 200",
    "quality": "hd",
    "speed": "relax"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript relax 速度下用图片提示和风格参考出 HD 图
const url = 'https://api.beatapi.io/v1/images/tasks';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"model":"mj-v8.2","aspect_ratio":"4:5","images":["https://cdn.beatapi.io/samples/smart-bottle.png"],"prompt":"The bottle on a sunlit kitchen counter, soft morning light --sref https://cdn.beatapi.io/samples/neon-singer.png --sw 200","quality":"hd","speed":"relax"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

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

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.beatapi.io/v1/images/tasks"

	payload := strings.NewReader("{\n  \"model\": \"mj-v8.2\",\n  \"aspect_ratio\": \"4:5\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\"\n  ],\n  \"prompt\": \"The bottle on a sunlit kitchen counter, soft morning light --sref https://cdn.beatapi.io/samples/neon-singer.png --sw 200\",\n  \"quality\": \"hd\",\n  \"speed\": \"relax\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby relax 速度下用图片提示和风格参考出 HD 图
require 'uri'
require 'net/http'

url = URI("https://api.beatapi.io/v1/images/tasks")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"model\": \"mj-v8.2\",\n  \"aspect_ratio\": \"4:5\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\"\n  ],\n  \"prompt\": \"The bottle on a sunlit kitchen counter, soft morning light --sref https://cdn.beatapi.io/samples/neon-singer.png --sw 200\",\n  \"quality\": \"hd\",\n  \"speed\": \"relax\"\n}"

response = http.request(request)
puts response.read_body
```

```java relax 速度下用图片提示和风格参考出 HD 图
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.beatapi.io/v1/images/tasks")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model\": \"mj-v8.2\",\n  \"aspect_ratio\": \"4:5\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\"\n  ],\n  \"prompt\": \"The bottle on a sunlit kitchen counter, soft morning light --sref https://cdn.beatapi.io/samples/neon-singer.png --sw 200\",\n  \"quality\": \"hd\",\n  \"speed\": \"relax\"\n}")
  .asString();
```

```php relax 速度下用图片提示和风格参考出 HD 图
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.beatapi.io/v1/images/tasks', [
  'body' => '{
  "model": "mj-v8.2",
  "aspect_ratio": "4:5",
  "images": [
    "https://cdn.beatapi.io/samples/smart-bottle.png"
  ],
  "prompt": "The bottle on a sunlit kitchen counter, soft morning light --sref https://cdn.beatapi.io/samples/neon-singer.png --sw 200",
  "quality": "hd",
  "speed": "relax"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp relax 速度下用图片提示和风格参考出 HD 图
using RestSharp;

var client = new RestClient("https://api.beatapi.io/v1/images/tasks");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model\": \"mj-v8.2\",\n  \"aspect_ratio\": \"4:5\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\"\n  ],\n  \"prompt\": \"The bottle on a sunlit kitchen counter, soft morning light --sref https://cdn.beatapi.io/samples/neon-singer.png --sw 200\",\n  \"quality\": \"hd\",\n  \"speed\": \"relax\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

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

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "mj-v8.2",
  "aspect_ratio": "4:5",
  "images": ["https://cdn.beatapi.io/samples/smart-bottle.png"],
  "prompt": "The bottle on a sunlit kitchen counter, soft morning light --sref https://cdn.beatapi.io/samples/neon-singer.png --sw 200",
  "quality": "hd",
  "speed": "relax"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.beatapi.io/v1/images/tasks")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 混合两张图

**Request**

```json
{
  "model": "mj-v8.2",
  "action": "blend",
  "aspect_ratio": "3:2",
  "images": [
    "https://cdn.beatapi.io/samples/smart-bottle.png",
    "https://cdn.beatapi.io/samples/neon-singer.png"
  ]
}
```

**Response**

```json
{
  "data": {
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "object": "task",
    "task_kind": "image",
    "capability_id": "mj-v8.2",
    "capability_version": 1,
    "status": "queued",
    "stage": "queued",
    "created_at": 1791993600,
    "updated_at": 1791993600,
    "completed_at": null,
    "output": null,
    "request_id": "202611260732156684925978268d9d6yOLdMCKV",
    "error_code": null,
    "error_message": null,
    "media_type": "image",
    "model": "mj-v8.2",
    "poll_after_seconds": 5
  }
}
```

**SDK Code**

```python 混合两张图
import requests

url = "https://api.beatapi.io/v1/images/tasks"

payload = {
    "model": "mj-v8.2",
    "action": "blend",
    "aspect_ratio": "3:2",
    "images": ["https://cdn.beatapi.io/samples/smart-bottle.png", "https://cdn.beatapi.io/samples/neon-singer.png"]
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript 混合两张图
const url = 'https://api.beatapi.io/v1/images/tasks';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"model":"mj-v8.2","action":"blend","aspect_ratio":"3:2","images":["https://cdn.beatapi.io/samples/smart-bottle.png","https://cdn.beatapi.io/samples/neon-singer.png"]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go 混合两张图
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.beatapi.io/v1/images/tasks"

	payload := strings.NewReader("{\n  \"model\": \"mj-v8.2\",\n  \"action\": \"blend\",\n  \"aspect_ratio\": \"3:2\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\",\n    \"https://cdn.beatapi.io/samples/neon-singer.png\"\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby 混合两张图
require 'uri'
require 'net/http'

url = URI("https://api.beatapi.io/v1/images/tasks")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"model\": \"mj-v8.2\",\n  \"action\": \"blend\",\n  \"aspect_ratio\": \"3:2\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\",\n    \"https://cdn.beatapi.io/samples/neon-singer.png\"\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java 混合两张图
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.beatapi.io/v1/images/tasks")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model\": \"mj-v8.2\",\n  \"action\": \"blend\",\n  \"aspect_ratio\": \"3:2\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\",\n    \"https://cdn.beatapi.io/samples/neon-singer.png\"\n  ]\n}")
  .asString();
```

```php 混合两张图
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.beatapi.io/v1/images/tasks', [
  'body' => '{
  "model": "mj-v8.2",
  "action": "blend",
  "aspect_ratio": "3:2",
  "images": [
    "https://cdn.beatapi.io/samples/smart-bottle.png",
    "https://cdn.beatapi.io/samples/neon-singer.png"
  ]
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp 混合两张图
using RestSharp;

var client = new RestClient("https://api.beatapi.io/v1/images/tasks");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model\": \"mj-v8.2\",\n  \"action\": \"blend\",\n  \"aspect_ratio\": \"3:2\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\",\n    \"https://cdn.beatapi.io/samples/neon-singer.png\"\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 混合两张图
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "mj-v8.2",
  "action": "blend",
  "aspect_ratio": "3:2",
  "images": ["https://cdn.beatapi.io/samples/smart-bottle.png", "https://cdn.beatapi.io/samples/neon-singer.png"]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.beatapi.io/v1/images/tasks")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```