> 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.

# FLUX 3.1 Image

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

Black Forest Labs 于 2026 年 12 月发布的 FLUX 3.1。通过文字或最多 10 张参考图生成或编辑图片，支持 1K、2K、4K，分 quality 与 fast 两种模式。- 异步：创建调用会立即返回任务 ID；任务成功后才能拿到图片。
- 每个任务生成一张图片。需要多张图片时，请创建多个任务。
- 文生图，或编辑、合成最多 10 张以公开 HTTPS 链接提供的参考图片。
- `quality` 决定渲染方式：`quality`（默认）细节最多、文字最好；`fast` 更快更便宜。两种模式字段相同，都支持 1K、2K、4K。
- 按 `quality` 和 `resolution` 每张计价。参考图、宽高比和提示词长度不影响价格。
- 失败的任务不收费：预扣金额会全额退回。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`。不传 `aspect_ratio` 时出方图（`1:1`）。                                         |
| 编辑或合成图片 | `model`、`prompt`、`images` | 1 到 10 个公开的 HTTPS 图片链接。请在 `prompt` 中说明要修改、保留或合成的内容。不传 `aspect_ratio` 时，结果沿用第一张图的形状。 |## 请求参数### `model``string` · 必需要运行的模型。**取值**：`flux-3.1-image`**取值有误时**- 缺失：`"model" is required`
- 未知的模型 ID：`"model" flux-9 is not catalogued`
- 把视频模型发到了这个接口：`"model" seedance-2.5 is served by POST /v1/videos/tasks, not this endpoint`### `prompt``string` · 必需要画什么，或要在参考图片里改什么。用平常的话描述效果最好：主体、风格、光线、构图，以及必须出现在图里的文字。**长度**：1–5000 个字符- 长度按字符计算（一个汉字算一个字符）。
- 必须出现在图里的每个词都放进引号，按想要的拼写原样写出。
- 传了 `images` 时，请说明每张图的作用，例如“用第一张图里的产品，用第二张图做背景”。**取值有误时**- 缺失：`"prompt" is required`
- 为空或超过上限：`"prompt" has an unsupported length`
- 不是字符串：`"prompt" must be a string`### `images``string[]` · 可选要编辑或合成的参考图片。传了这个字段，请求就从文生图变成图片编辑。**数量**：1–10  \
每一项都必须是公网 `https://` 链接。本地文件请先[上传](/quick-guide#upload-an-input-file)（`POST /v1/files`），再传入返回的 `data.url`。- 每一项都必须是指向图片文件的公开 `https://` 链接，每边至少 256 像素。创建任务时 BeatAPI 只检查链接格式，不会下载图片，也不检查格式和大小（见素材限制下方的说明）。
- 指向网页、登录页、已过期的签名链接或禁止外链的主机时拿不到图片，任务会在创建后失败。
- 报错里的位置从 0 开始：`images[0]` 是第一个链接。
- 参考图不计费：编辑 10 张图与同样 `quality`、`resolution` 的文生图价格相同。**取值有误时**- 超过上限：`"images" accepts at most 10 items`
- 空数组：`"images" requires at least 1 item`
- 不是 https\:// 链接：`"images[0]" must be a public HTTPS URL`
- 不是数组：`"images" must be an array`**示例**```json
"images": [
  "https://cdn.beatapi.io/samples/smart-bottle.png",
  "https://cdn.beatapi.io/samples/neon-singer.png"
]
```### `quality``string` · 可选 · 默认值: `quality`图片的渲染方式：`quality` 细节最多、文字最好，`fast` 出图更快、更便宜。两种模式在每个分辨率上各有单价。**可选值**：`quality`, `fast`  \
**默认值**：`quality`* 不传时使用 `quality`，任务按 Quality 价格计费。
* 两种模式接受的字段、参考图数量和分辨率完全相同，只有细节、速度和价格不同。见下文「quality 与 fast 怎么选」。> **警告:** 不传 `quality` 会按较贵的 Quality 价格计费。想用便宜的模式，请明确传 `"quality": "fast"`。**取值有误时**- 取值不在列表中：`"quality" must be one of: [quality fast]`**示例**```json
"quality": "fast"
```### `resolution``string` · 可选 · 默认值: `1K`图片的尺寸档位：`1K`、`2K` 或 `4K`。档位越高越贵，价格还取决于 `quality`。**可选值**：`1K`, `2K`, `4K`  \
**默认值**：`1K`- 不传时使用 `1K`。
- 不接受 `2048x2048` 这类像素尺寸。具体像素随 `aspect_ratio` 而定；请以返回文件的实际尺寸为准，不要预设。**取值有误时**- 取值不在列表中：`"resolution" must be one of: [1K 2K 4K]`### `aspect_ratio``string` · 可选 · 默认值: `1:1`图片形状，写作宽:高，从 `21:9`（宽）到 `1:2`（高）。**可选值**：`21:9`, `2:1`, `16:9`, `3:2`, `7:5`, `4:3`, `5:4`, `1:1`, `4:5`, `3:4`, `5:7`, `2:3`, `9:16`, `1:2`  \
**默认值**：`1:1`- 不传时，文生图出方图（`1:1`），编辑则沿用 `images` 中第一张图的形状。
- 没有 `auto`。编辑时想要与第一张图不同的形状，请写明比例。**取值有误时**- 取值不在列表中（例如 `auto` 或 `9:21`）：`"aspect_ratio" must be one of: [21:9 2:1 16:9 3:2 7:5 4:3 5:4 1:1 4:5 3:4 5:7 2:3 9:16 1:2]`### `output_format``string` · 可选 · 默认值: `jpeg`结果的文件类型：`jpeg`（默认）或 `png`。**可选值**：`jpeg`, `png`  \
**默认值**：`jpeg`- 如果模型返回的是另一种类型，BeatAPI 会在保存前转换，所以文件通常就是你要求的格式；转换失败时按原样保存。转成 JPEG 时透明区域会变成白色。
- `output.media[].mime_type` 始终标明实际保存的类型。**取值有误时**- 取值不在列表中（例如 `webp` 或 `jpg`）：`"output_format" must be one of: [jpeg png]`### `callback_url``string` · 可选任务成功或失败时通知的地址：公网 HTTPS URL，协议、主机和端口必须与你某个已启用的 [Webhook 端点](/webhooks)相同，并由该端点的 `secret` 签名。**长度**：≤ 2048 个字符- 请先用 `POST /v1/webhooks` 注册端点。BeatAPI 会推送 `task.succeeded` 或 `task.failed`，事件体、请求头和重试规则与账户 Webhook 相同；订阅了该事件的账户端点也会收到，与该端点地址完全相同时只通知一次。
- 请在 10 秒内返回任意 `2xx`。投递失败会在约 1 分钟后、再约 5 分钟后重试，共 3 次；重试沿用同一个事件 `id`，请按它去重。处理事件前先校验 `x-beatapi-signature`。
- 签名端点被删除、停用或改到别的主机后，这条回调作废。**取值有误时**- 值不是字符串：`"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.`网关还会在创建任务之前检查以下组合：- `quality` 细节最多、文字最好；`fast` 出图更快、价格更低；两者都按所选分辨率每张计费。
- 每个任务一张图；`images` 为 1–10 个公网 HTTPS 链接，每张每边至少 256 像素，传了即为对这些图的编辑。
- 不传 `aspect_ratio` 时，带 `images` 则沿用第一张图的形状，不带图则为 1:1。## 输入素材限制网关会在创建任务之前读取每一项输入，超出这些限制的输入会被拒绝，并返回点名该输入的 `400 bad_request`。不扣费。- 参考图片：1 到 10 个公开 HTTPS 链接，每张每边至少 256 像素。
- 创建任务时 BeatAPI 不下载这些链接，也不检查格式、大小或像素尺寸，所以有问题的链接不会在创建时被拒绝。
- 无法获取或读取的链接会让任务在创建后失败，任务会退款。请使用无需登录、服务器可直接访问的普通图片文件链接。
- 只有本地文件？用 `POST /v1/files` 上传，再传入返回的 `data.url`。## quality 与 fast 怎么选两种模式的请求完全一样：同样的字段、最多 10 张参考图、1K、2K 或 4K。区别只在细节、速度和价格。- `quality`（默认）细节最多、文字最好。适合带文字的海报、包装、招牌和信息图，细腻的材质，需要在多张参考图之间保持一致的编辑，以及 4K 出图。
- `fast` 出图更快、价格更低。适合草稿和预览、大批量生成与编辑，以及等待时间比最后一点细节更重要的场景。`fast` 的价格在 1K 是 Quality 的一半，2K 是三分之二，4K 不到一半；计费部分的价目表列出了全部六个价格。常见做法是先用 `fast` 在 1K 试提示词，再用 `quality` 以 2K 或 4K 出最终图。不传 `quality` 会按 Quality 价格计费，所以想用便宜的模式时请明确传 `"quality": "fast"`。## 这个模型不接受的字段图片接口认识一些其他图片模型使用的字段。把它们发到这里会被拒绝而不是被忽略，这样你不会为没有效果的设置付费：- `seed`、`size`、`background`、`enhance_prompt` → `field "seed" is not supported by model flux-3.1-image`（报错里是你发送的字段）。
- `n` → `field "n" is not supported by model flux-3.1-image`。没有 `n`：一个任务只生成一张图。
- 其他未知字段，例如 `negative_prompt` → `unknown field: negative_prompt`。如果一个请求里有多个错误字段，报错只会指出其中一个；改好后再发一次。## 请求示例```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": "flux-3.1-image",
  "prompt": "A cinematic storefront campaign image at blue hour, warm light spilling from the windows onto wet pavement",
  "quality": "quality",
  "resolution": "1K",
  "aspect_ratio": "3:2"
}'
``````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": "flux-3.1-image",
      "prompt": "A cinematic storefront campaign image at blue hour, warm light spilling from the windows onto wet pavement",
      "quality": "quality",
      "resolution": "1K",
      "aspect_ratio": "3:2"
    },
    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": "flux-3.1-image",
    "prompt": "A cinematic storefront campaign image at blue hour, warm light spilling from the windows onto wet pavement",
    "quality": "quality",
    "resolution": "1K",
    "aspect_ratio": "3:2"
  }),
});
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);
```### 文生图默认的 `quality` 模式出 1K 图，这里明确写出。```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": "flux-3.1-image",
  "prompt": "A cinematic storefront campaign image at blue hour, warm light spilling from the windows onto wet pavement",
  "quality": "quality",
  "resolution": "1K",
  "aspect_ratio": "3:2"
}'
```### 2K 快速草稿`fast` 模式：更快更便宜，适合草稿和大批量任务。```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": "flux-3.1-image",
  "prompt": "A cosy reading corner by a rainy window, a cat asleep on a knitted blanket, soft lamp light",
  "quality": "fast",
  "resolution": "2K",
  "aspect_ratio": "16:9"
}'
```### 文字清晰的 4K 海报文字和细节正是 `quality` 的用武之地。把要出现的文字原样写进引号。```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": "flux-3.1-image",
  "prompt": "A retro travel poster of a coastal city at sunset, bold flat colours, large title text \"SEASIDE\" at the top and a small line \"Ferries daily from Pier 3\" at the bottom",
  "quality": "quality",
  "resolution": "4K",
  "aspect_ratio": "2:3"
}'
```### 编辑一张图不传 `aspect_ratio` 时，结果保持所发图片的形状。```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": "flux-3.1-image",
  "prompt": "Keep the bottle exactly as it is. Replace the background with a sunlit kitchen counter and add a soft reflection under the bottle.",
  "images": [
    "https://cdn.beatapi.io/samples/smart-bottle.png"
  ],
  "resolution": "2K"
}'
```### 合成多张图在提示词里按位置称呼每张参考图。```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": "flux-3.1-image",
  "prompt": "Place the bottle from the first image on a neon-lit stage like the one in the second image. Keep the bottle label readable.",
  "images": [
    "https://cdn.beatapi.io/samples/smart-bottle.png",
    "https://cdn.beatapi.io/samples/neon-singer.png"
  ],
  "aspect_ratio": "4:5",
  "resolution": "2K"
}'
```### 超宽 PNG 横幅21:9 的网站首屏图，以 PNG 交付。```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": "flux-3.1-image",
  "prompt": "A wide hero banner for an outdoor gear shop: a hiker on a ridge at sunrise, with open sky on the left for a headline",
  "resolution": "2K",
  "aspect_ratio": "21:9",
  "output_format": "png"
}'
```## 响应### 创建任务（201）任务对象。任务成功之前 `output` 为 `null`。标注“运行中”的字段会在任务结束后消失。```json
{
  "data": {
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "object": "task",
    "task_kind": "image",
    "capability_id": "flux-3.1-image",
    "capability_version": 1,
    "media_type": "image",
    "model": "flux-3.1-image",
    "status": "queued",
    "stage": "queued",
    "created_at": 1791993600,
    "updated_at": 1791993600,
    "completed_at": null,
    "poll_after_seconds": 5,
    "output": null,
    "usage": {
      "credits_reserved": 0.03,
      "credits_settled": 0,
      "credits_refunded": 0,
      "credits_charged": 0.03
    },
    "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": "flux-3.1-image",
    "capability_version": 1,
    "media_type": "image",
    "model": "flux-3.1-image",
    "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.jpg",
          "mime_type": "image/jpeg"
        }
      ],
      "url": "https://media.beatapi.io/outputs/task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ/0.jpg",
      "r2_url": "https://media.beatapi.io/outputs/task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ/0.jpg"
    },
    "usage": {
      "credits_reserved": 0.03,
      "credits_settled": 0.03,
      "credits_refunded": 0,
      "credits_charged": 0.03
    },
    "request_id": "202611260732156684925978268d9d6yOLdMCKV",
    "error_code": null,
    "error_message": null
  }
}
```#### 输出字段| 字段                         | 类型         | 说明                                                           |
| -------------------------- | ---------- | ------------------------------------------------------------ |
| `output.media`             | `object[]` | 生成的文件；这个模型只有一项。                                              |
| `output.media[].type`      | `string`   | 固定为 `image`。                                                 |
| `output.media[].url`       | `string`   | 已保存图片的 HTTPS 链接。请下载保存；不承诺保留期限。                               |
| `output.media[].mime_type` | `string`   | 保存的文件类型，通常就是 `output_format` 要求的：`image/jpeg` 或 `image/png`。 |
| `output.url`               | `string`   | 主资产：第一张图片的链接。结果请读 `output.url`；`media[]` 列出全部产物。             |
| `output.r2_url`            | `string`   | `output.url` 的旧名，值相同；请读 `output.url`。                        |### 任务失败失败的任务在 `GET /v1/tasks/{task_id}` 上仍然是 HTTP 200：失败信息在响应体里。预扣金额会全额退回，因此不会扣费。```json
{
  "data": {
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "object": "task",
    "task_kind": "image",
    "capability_id": "flux-3.1-image",
    "capability_version": 1,
    "media_type": "image",
    "model": "flux-3.1-image",
    "status": "failed",
    "stage": "failed",
    "created_at": 1791993600,
    "updated_at": 1791993690,
    "completed_at": 1791993690,
    "output": null,
    "usage": {
      "credits_reserved": 0.03,
      "credits_settled": 0,
      "credits_refunded": 0.03,
      "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": "flux-3.1-image",
  "prompt": "A cinematic storefront campaign image at blue hour, warm light spilling from the windows onto wet pavement",
  "quality": "quality",
  "resolution": "1K",
  "aspect_ratio": "3:2"
})
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"])
```## 计费- 每个任务一张图，按 `quality` 和 `resolution` 计价（见下表六个价格）。参考图、宽高比、输出格式和提示词长度都不影响价格。
- 不传 `quality` 时按 Quality 价格计费；想用便宜的模式请传 `"quality": "fast"`。
- 创建任务时会从余额中预扣费用；如果密钥设了额度，也会占用密钥额度。任务创建前就被拒绝的请求不收费。
- 成功的任务保留预扣金额。失败的任务全额退回：此时 `credits_refunded` 等于 `credits_reserved`，`credits_charged` 和 `credits_settled` 为 0。当前牌价，与[价格页](https://beatapi.io/pricing)一致。享有协商折扣的账户实付更低；任务的 `data.usage` 始终显示实际扣费金额。| 选项                   | 牌价（美元）  |
| -------------------- | ------- |
| 1 张图片 · Fast · 1K    | \$0.015 |
| 1 张图片 · Fast · 2K    | \$0.04  |
| 1 张图片 · Fast · 4K    | \$0.11  |
| 1 张图片 · Quality · 1K | \$0.03  |
| 1 张图片 · Quality · 2K | \$0.06  |
| 1 张图片 · Quality · 4K | \$0.28  |## 常见错误| 错误或现象                                                                                             | 原因                                                        | 处理方式                                                    |
| ------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | ------------------------------------------------------- |
| 400 `"aspect_ratio" must be one of: [21:9 2:1 16:9 3:2 7:5 4:3 5:4 1:1 4:5 3:4 5:7 2:3 9:16 1:2]` | 传了 `auto`，或这个模型不画的形状，例如 `9:21`。                           | 改用列表中的比例。编辑时想保持第一张图的形状，就不要传这个字段。                        |
| 400 `"quality" must be one of: [quality fast]`                                                    | 取值不在列表中，例如 `standard` 或 `pro`。                            | 传 `quality` 或 `fast`，或者不传。                              |
| 400 `"resolution" must be one of: [1K 2K 4K]`                                                     | 传了 `8K`，或 `2048x2048` 这类像素尺寸。                             | 传 `1K`、`2K` 或 `4K`，或者不传。                                |
| 400 `"output_format" must be one of: [jpeg png]`                                                  | 传了 `webp`，或把 `jpeg` 写成了 `jpg`。                            | 传 `jpeg` 或 `png`。                                       |
| 400 `field "n" is not supported by model flux-3.1-image`                                          | 想在一个任务里生成多张图。                                             | 去掉 `n`，每张图创建一个任务。                                       |
| 400 `field "seed" is not supported by model flux-3.1-image`                                       | 传了其他图片模型的字段（`seed`、`size`、`background`、`enhance_prompt`）。 | 去掉该字段。                                                  |
| 400 `"images" accepts at most 10 items`                                                           | 参考图超过 10 张。                                               | 最多传 10 个链接。                                             |
| 400 `"images[0]" must be a public HTTPS URL`                                                      | `http://` 链接、`data:` URI 或本地路径。                           | 把文件放到 HTTPS 上，或用 `POST /v1/files` 上传后使用 `data.url`。     |
| 传了参考图后任务 `failed`，错误码 `bad_request`                                                               | 链接打开的是网页、登录页或已过期的签名链接，或者主机拒绝了下载。                          | 直接链接到图片文件，或用 `POST /v1/files` 上传。不收费。                   |
| 账单比预期高                                                                                            | 没传 `quality`，任务按 Quality 价格计费。                            | 传 `"quality": "fast"`；在任务的 `usage.credits_charged` 上核对。 |
| 任务 `failed`，错误码 `content_policy_violation`                                                        | 提示词、参考图或生成的图片被审核拒绝。                                       | 修改提示词或图片。原样重试仍会失败；不收费。                                  |
| 任务 `failed`，错误码 `processing_timeout`                                                              | 图片没有在处理时限内完成。                                             | 重试即可；失败的任务已退款。                                          |
| 从未充值的账户收到 403 `forbidden`                                                                         | 免费额度只覆盖部分模型。                                              | 充值一次，或改用免费额度可用的模型。                                      |## 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` | 未扣费。使用指数退避重试。                                          |

Reference: https://docs.beatapi.io/api-reference/image-api/flux-3-1-image

## 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 Flux31ImageRequest.

- `model` (enum, required) — 要运行的模型。 **取值**：`flux-3.1-image` **取值有误时** - 缺失：`"model" is required` - 未知的模型 ID：`"model" flux-9 is not catalogued` - 把视频模型发到了这个接口：`"model" seedance-2.5 is served by POST /v1/videos/tasks, not this endpoint`
  - Allowed values: `flux-3.1-image`
- `prompt` (string, required) — 要画什么，或要在参考图片里改什么。用平常的话描述效果最好：主体、风格、光线、构图，以及必须出现在图里的文字。 **长度**：1–5000 个字符 - 长度按字符计算（一个汉字算一个字符）。 - 必须出现在图里的每个词都放进引号，按想要的拼写原样写出。 - 传了 `images` 时，请说明每张图的作用，例如“用第一张图里的产品，用第二张图做背景”。 **取值有误时** - 缺失：`"prompt" is required` - 为空或超过上限：`"prompt" has an unsupported length` - 不是字符串：`"prompt" must be a string`
- `aspect_ratio` (enum, optional, default: 1:1) — 图片形状，写作宽:高，从 `21:9`（宽）到 `1:2`（高）。 **可选值**：`21:9`, `2:1`, `16:9`, `3:2`, `7:5`, `4:3`, `5:4`, `1:1`, `4:5`, `3:4`, `5:7`, `2:3`, `9:16`, `1:2` **默认值**：`1:1` - 不传时，文生图出方图（`1:1`），编辑则沿用 `images` 中第一张图的形状。 - 没有 `auto`。编辑时想要与第一张图不同的形状，请写明比例。 **取值有误时** - 取值不在列表中（例如 `auto` 或 `9:21`）：`"aspect_ratio" must be one of: [21:9 2:1 16:9 3:2 7:5 4:3 5:4 1:1 4:5 3:4 5:7 2:3 9:16 1:2]`
  - Allowed values: `21:9`, `2:1`, `16:9`, `3:2`, `7:5`, `4:3`, `5:4`, `1:1`, `4:5`, `3:4`, `5:7`, `2:3`, `9:16`, `1:2`
- `images` (list of string, optional) — 要编辑或合成的参考图片。传了这个字段，请求就从文生图变成图片编辑。 **数量**：1–10 每一项都必须是公网 `https://` 链接。本地文件请先[上传](/quick-guide#upload-an-input-file)（`POST /v1/files`），再传入返回的 `data.url`。 - 每一项都必须是指向图片文件的公开 `https://` 链接，每边至少 256 像素。创建任务时 BeatAPI 只检查链接格式，不会下载图片，也不检查格式和大小（见素材限制下方的说明）。 - 指向网页、登录页、已过期的签名链接或禁止外链的主机时拿不到图片，任务会在创建后失败。 - 报错里的位置从 0 开始：`images[0]` 是第一个链接。 - 参考图不计费：编辑 10 张图与同样 `quality`、`resolution` 的文生图价格相同。 **取值有误时** - 超过上限：`"images" accepts at most 10 items` - 空数组：`"images" requires at least 1 item` - 不是 https:// 链接：`"images[0]" must be a public HTTPS URL` - 不是数组：`"images" must be an array` **示例** ```json "images": [ "https://cdn.beatapi.io/samples/smart-bottle.png", "https://cdn.beatapi.io/samples/neon-singer.png" ] ```
- `output_format` (enum, optional, default: jpeg) — 结果的文件类型：`jpeg`（默认）或 `png`。 **可选值**：`jpeg`, `png` **默认值**：`jpeg` - 如果模型返回的是另一种类型，BeatAPI 会在保存前转换，所以文件通常就是你要求的格式；转换失败时按原样保存。转成 JPEG 时透明区域会变成白色。 - `output.media[].mime_type` 始终标明实际保存的类型。 **取值有误时** - 取值不在列表中（例如 `webp` 或 `jpg`）：`"output_format" must be one of: [jpeg png]`
  - Allowed values: `jpeg`, `png`
- `quality` (enum, optional, default: quality) — 图片的渲染方式：`quality` 细节最多、文字最好，`fast` 出图更快、更便宜。两种模式在每个分辨率上各有单价。 **可选值**：`quality`, `fast` **默认值**：`quality` - 不传时使用 `quality`，任务按 Quality 价格计费。 - 两种模式接受的字段、参考图数量和分辨率完全相同，只有细节、速度和价格不同。见下文「quality 与 fast 怎么选」。 **说明**：不传 `quality` 会按较贵的 Quality 价格计费。想用便宜的模式，请明确传 `"quality": "fast"`。 **取值有误时** - 取值不在列表中：`"quality" must be one of: [quality fast]` **示例** ```json "quality": "fast" ```
  - Allowed values: `quality`, `fast`
- `resolution` (enum, optional, default: 1K) — 图片的尺寸档位：`1K`、`2K` 或 `4K`。档位越高越贵，价格还取决于 `quality`。 **可选值**：`1K`, `2K`, `4K` **默认值**：`1K` - 不传时使用 `1K`。 - 不接受 `2048x2048` 这类像素尺寸。具体像素随 `aspect_ratio` 而定；请以返回文件的实际尺寸为准，不要预设。 **取值有误时** - 取值不在列表中：`"resolution" must be one of: [1K 2K 4K]`
  - Allowed values: `1K`, `2K`, `4K`
- `callback_url` (string, optional) — 任务成功或失败时通知的地址：公网 HTTPS URL，协议、主机和端口必须与你某个已启用的 [Webhook 端点](/webhooks)相同，并由该端点的 `secret` 签名。 **长度**：≤ 2048 个字符 - 请先用 `POST /v1/webhooks` 注册端点。BeatAPI 会推送 `task.succeeded` 或 `task.failed`，事件体、请求头和重试规则与账户 Webhook 相同；订阅了该事件的账户端点也会收到，与该端点地址完全相同时只通知一次。 - 请在 10 秒内返回任意 `2xx`。投递失败会在约 1 分钟后、再约 5 分钟后重试，共 3 次；重试沿用同一个事件 `id`，请按它去重。处理事件前先校验 `x-beatapi-signature`。 - 签名端点被删除、停用或改到别的主机后，这条回调作废。 **取值有误时** - 值不是字符串：`"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) — 已接收任务或当前任务的状态。

## 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` 未扣费。使用指数退避重试。

- `map from string to any`

## Types

### QueuedTask

- `id` (string, required) — 用于轮询和支持排查的稳定 BeatAPI 任务 ID。
- `object` (enum, required) — 对象类型标识，始终为 `task`。
  - Allowed values: `task`
- `task_kind` (enum, required) — 公开任务类别，决定响应包含哪些能力字段。`data` 表示以任务方式运行的数据能力（`data:web.research`），通过 `POST /v1/capabilities/run` 轮询。
  - Allowed values: `workflow`, `effect`, `image`, `video`, `audio`, `data`
- `capability_id` (string, required) — 任务接收时选定的稳定 BeatAPI 工作流、特效、生成模型或数据能力 ID，例如 `web.research`。
- `capability_version` (integer, required) — 始终为 `1`。
- `status` (enum, required) — 任务当前的生命周期状态。在 `succeeded` 或 `failed` 时停止轮询；音乐视频也可能需要手动操作。
  - Allowed values: `queued`, `processing`, `storyboard_ready`, `requires_action`, `editing`, `composing`, `succeeded`, `failed`
- `stage` (enum, required) — 始终与 `status` 相同。为兼容保留，请读取 `status`。
  - Allowed values: `queued`, `processing`, `storyboard_ready`, `requires_action`, `editing`, `composing`, `succeeded`, `failed`
- `created_at` (integer, required) — BeatAPI 接收任务时的 Unix 时间戳。
- `updated_at` (integer, required) — 最近一次任务更新的 Unix 时间戳。
- `completed_at` (integer, required, nullable) — 任务结束时的 Unix 时间戳；处理中为 null。
- `output` (QueuedTaskOutput, required, nullable) — 任务成功前，output 为 null。
- `request_id` (string, required) — 请保留此关联 ID，用于日志记录和 BeatAPI 支持排查。
- `error_code` (string, required, nullable) — 机器可读的最终失败码；未记录任务失败时为 null。 `task_cancelled` 表示你在任务排队等待模型时取消了它。
- `error_message` (string, required, nullable) — 供用户阅读的最终失败详情；未记录任务失败时为 null。
- `workflow` (enum, optional) — 工作流任务包含此字段，标识选定的 BeatAPI 工作流。
  - Allowed values: `music-video`, `ecommerce-video`, `video-analysis`
- `effect_id` (string, optional) — 特效任务包含此字段，表示选定特效的稳定 ID。
- `effect_version` (integer, optional) — 特效任务包含此字段，表示处理时使用的不可变特效版本。
- `media_type` (enum, optional) — task_kind 为 image 或 video 时包含此字段。
  - Allowed values: `image`, `video`, `audio`
- `model` (string, optional) — 稳定的 BeatAPI 模型别名，独立于内部执行路由。
- `storyboard` (Storyboard, optional) — 音乐视频的分镜元数据，有数据时返回。
- `poll_after_seconds` (integer, optional) — 任务运行时返回：下次查询状态前应等待的秒数，图片为 5 秒，视频和特效为 8 秒，工作流和数据任务为 10 秒。请按此字段等待，不要使用固定间隔。任务结束后不再返回。
- `typical_seconds` (QueuedTaskTypicalSeconds, optional) — 任务运行且近期完成样本足够时返回：该模型近期在本网关上从接收到成功的实际耗时。超过 `p90` 仍无变化，表示任务耗时偏长；此后没有可用的预计完成时间。
- `queue` (QueuedTaskQueue, optional) — 仅在任务等待模型容量时出现（按 id 查询时返回，任务列表中没有）。到 `deadline` 仍在等待的任务以 `processing_unavailable` 失败并退款。可用 `POST /v1/tasks/{task_id}/cancel` 取消。
- `usage` (TaskUsage, optional) — 此任务的 USD 预留、结算、退款以及可选的计费时长。
- `error` (QueuedTaskError, optional) — 任务失败时出现：把最终失败合并成一个对象，值与平铺的 `error_code`、`error_message` 和 `retryable` 相同，平铺字段继续保留。
- `retryable` (boolean, optional) — 任务失败时返回，说明重新提交是否可能成功。因服务端问题或超时失败时为 true，失败任务不收费；因内容或输入错误被拒绝时为 false。错误码与 retryable 的对应规则与错误响应一致。

### QueuedTaskOutput

任务成功前，output 为 null。

- QueuedTaskOutput0
- QueuedTaskOutput1
- QueuedTaskOutput2

### Storyboard

- `shots` (list of StoryboardShot, required) — 按顺序排列的音乐视频分镜。分镜生成完成前，数组可能为空。

### QueuedTaskTypicalSeconds

任务运行且近期完成样本足够时返回：该模型近期在本网关上从接收到成功的实际耗时。超过 `p90` 仍无变化，表示任务耗时偏长；此后没有可用的预计完成时间。

- `p50` (integer, required) — 耗时中位数，单位为秒。
- `p90` (integer, required) — 耗时第 90 百分位数，单位为秒。
- `samples` (integer, required) — 统计所依据的已完成任务数量。
- `window` (string, required) — 统计窗口，例如 `7d`。

### QueuedTaskQueue

仅在任务等待模型容量时出现（按 id 查询时返回，任务列表中没有）。到 `deadline` 仍在等待的任务以 `processing_unavailable` 失败并退款。可用 `POST /v1/tasks/{task_id}/cancel` 取消。

- `position` (integer, required) — 在队列中的位置，1 表示下一个。
- `ahead` (integer, required) — 排在它前面的同型号任务数。
- `queued_at` (integer, required) — 任务入队的时间（Unix 秒）。
- `deadline` (integer, required) — 任务停止等待的时间（Unix 秒）。

### TaskUsage

- `credits_reserved` (double, required) — 为此任务预留的 USD 金额。为兼容保留原字段名；1 Credit 等于 $1 USD。
- `credits_charged` (double, required) — 实际扣取的 USD 金额。任务失败时为 `0`，因为预留金额已退回。
- `credits_settled` (double, required) — 任务成功后结算的 USD 金额。
- `credits_refunded` (double, required) — 任务失败后退回的 USD 金额。失败任务中，`credits_reserved` 为创建时预留的金额，`credits_charged` 和 `credits_settled` 为 `0`，`credits_refunded` 为退回金额。
- `billable_duration_seconds` (integer, optional) — 用于计算 USD 费用的计费时长，来自服务端检测或请求声明。

### QueuedTaskError

任务失败时出现：把最终失败合并成一个对象，值与平铺的 `error_code`、`error_message` 和 `retryable` 相同，平铺字段继续保留。

- `code` (string, required) — 机器可读的失败码，与 `error_code` 的值相同。
- `message` (string, required) — 说明原因的英文句子，与 `error_message` 的值相同。
- `retryable` (boolean, optional) — 重新提交是否可能成功，与 `retryable` 的值相同。`retryable` 不存在时它也不存在。

### QueuedTaskOutput0

- `media` (list of QueuedTaskOutputOneOf0MediaItems, required) — BeatAPI 托管的结果素材。
- `url` (string, required) — 主资产的 URL，需要单个文件时读取它（第一个视频，没有视频则取第一张图片）。与 `r2_url` 的值相同。
- `r2_url` (string, required, deprecated) — 已弃用——请读取 `url`。与 `url` 的值相同，仅为已在读取它的客户端保留。
- `tracks` (list of QueuedTaskOutputOneOf0TracksItems, optional) — 仅音乐任务。本次调用产出的每首歌曲或每条分轨各一项，与 `media` 中的文件并列。
- `data` (any, optional) — 任务返回的非文件结果。音乐任务：歌词、对齐歌词、增强后的风格、人设 ID 或 MIDI 音符。Midjourney：结果可接受的后续操作。Seedream 5.5（`layers: true`）：`layers`，与 `media` 一一对应、顺序相同，含 `index`、`z_index`、`background`、`name`、`description`、`size` 和 `bounding_box`。

### QueuedTaskOutput1

- `text` (string, required) — 已完成的视频分析文本。
- `usage` (QueuedTaskOutputOneOf1Usage, required) — 用于最终 USD 结算的实际 token 用量。
- `finish_reason` (string, required, nullable) — 模型停止生成的原因。

### QueuedTaskOutput2

数据任务的结果，即能力自身的结果对象，例如包含 `research_notes` 和 `sources` 的 `web.research`；使用视图时可能为 `items`。

- `object` (string, required) — 结果类型，例如 `web.research`。
- `request_id` (string, optional) — 生成该结果的任务 ID。
- `query` (string, optional) — 被研究的问题。
- `status` (enum, optional) — 研究只完成了一部分时为 `partial`，`partial_reasons` 说明原因。
  - Allowed values: `complete`, `partial`
- `research_notes` (string, optional) — 研究笔记。
- `sources` (list of map from string to any, optional) — 笔记所依据的来源。
- `partial_reasons` (list of string, optional) — `status` 为 `partial` 时存在。
- `x_search` (map from string to any, optional) — 本次运行搜索过 X 时，说明搜索了多少。

### StoryboardShot

- `id` (string, required) — BeatAPI 分镜 ID。获取媒体、编辑和合成时使用此 ID。
- `index` (integer, required) — 分镜在故事板中的顺序，从零开始。
- `status` (enum, required) — 该分镜当前的生命周期状态。
  - Allowed values: `queued`, `processing`, `storyboard_ready`, `requires_action`, `editing`, `composing`, `succeeded`, `failed`
- `created_at` (integer, required) — 分镜记录创建时的 Unix 时间戳。
- `updated_at` (integer, required) — 分镜记录最近一次变更的 Unix 时间戳。
- `duration_seconds` (integer, optional) — 计划或已生成的片段时长，单位为秒。
- `prompt` (string, optional) — 生成此分镜所用的创作指令。
- `lyric_text` (string, optional) — 与此分镜对齐的歌词片段，有数据时返回。
- `media` (StoryboardShotMedia, optional) — 仅在分镜媒体已获取并存储，或分镜编辑完成后返回。

### QueuedTaskOutputOneOf0MediaItems

- `type` (enum, required) — 结果素材类型。
  - Allowed values: `image`, `video`, `audio`
- `url` (string, required) — BeatAPI 托管的 HTTPS 结果 URL。
- `mime_type` (string, required) — 结果素材的 MIME 类型。

### QueuedTaskOutputOneOf0TracksItems

- `id` (string, required) — 后续操作作为 `audio_id` 传入的 ID。
- `title` (string, optional) — 歌曲标题。
- `name` (string, optional) — 分轨结果中的分轨名称。
- `tags` (string, optional) — 风格标签。
- `lyrics` (string, optional) — 歌曲的歌词。
- `duration` (double, optional) — 时长，单位为秒。
- `audio_url` (string, optional) — 歌曲或分轨文件。
- `image_url` (string, optional) — 封面图。

### QueuedTaskOutputOneOf1Usage

用于最终 USD 结算的实际 token 用量。

- `input_tokens` (integer, required) — 提示词和视频输入消耗的 token。
- `output_tokens` (integer, required) — 可见输出和模型推理消耗的 token。
- `total_tokens` (integer, required) — 实际输入与输出 token 总量。

### StoryboardShotMedia

仅在分镜媒体已获取并存储，或分镜编辑完成后返回。

- `type` (string, optional) — 已存储分镜的媒体类型。
- `url` (string, optional) — 已存储分镜的 BeatAPI HTTPS URL。
- `mime_type` (string, optional) — 已托管分镜媒体的 MIME 类型。

## Examples

### 文生图

**Request**

```json
{
  "model": "flux-3.1-image",
  "prompt": "A cinematic storefront campaign image at blue hour, warm light spilling from the windows onto wet pavement",
  "aspect_ratio": "3:2",
  "quality": "quality",
  "resolution": "1K"
}
```

**Response**

```json
{
  "data": {
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "object": "task",
    "task_kind": "image",
    "capability_id": "flux-3.1-image",
    "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": "flux-3.1-image",
    "poll_after_seconds": 5,
    "usage": {
      "credits_reserved": 0.03,
      "credits_charged": 0.03,
      "credits_settled": 0,
      "credits_refunded": 0
    }
  }
}
```

**SDK Code**

```python 文生图
import requests

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

payload = {
    "model": "flux-3.1-image",
    "prompt": "A cinematic storefront campaign image at blue hour, warm light spilling from the windows onto wet pavement",
    "aspect_ratio": "3:2",
    "quality": "quality",
    "resolution": "1K"
}
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":"flux-3.1-image","prompt":"A cinematic storefront campaign image at blue hour, warm light spilling from the windows onto wet pavement","aspect_ratio":"3:2","quality":"quality","resolution":"1K"}'
};

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\": \"flux-3.1-image\",\n  \"prompt\": \"A cinematic storefront campaign image at blue hour, warm light spilling from the windows onto wet pavement\",\n  \"aspect_ratio\": \"3:2\",\n  \"quality\": \"quality\",\n  \"resolution\": \"1K\"\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\": \"flux-3.1-image\",\n  \"prompt\": \"A cinematic storefront campaign image at blue hour, warm light spilling from the windows onto wet pavement\",\n  \"aspect_ratio\": \"3:2\",\n  \"quality\": \"quality\",\n  \"resolution\": \"1K\"\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\": \"flux-3.1-image\",\n  \"prompt\": \"A cinematic storefront campaign image at blue hour, warm light spilling from the windows onto wet pavement\",\n  \"aspect_ratio\": \"3:2\",\n  \"quality\": \"quality\",\n  \"resolution\": \"1K\"\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": "flux-3.1-image",
  "prompt": "A cinematic storefront campaign image at blue hour, warm light spilling from the windows onto wet pavement",
  "aspect_ratio": "3:2",
  "quality": "quality",
  "resolution": "1K"
}',
  '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\": \"flux-3.1-image\",\n  \"prompt\": \"A cinematic storefront campaign image at blue hour, warm light spilling from the windows onto wet pavement\",\n  \"aspect_ratio\": \"3:2\",\n  \"quality\": \"quality\",\n  \"resolution\": \"1K\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 文生图
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "flux-3.1-image",
  "prompt": "A cinematic storefront campaign image at blue hour, warm light spilling from the windows onto wet pavement",
  "aspect_ratio": "3:2",
  "quality": "quality",
  "resolution": "1K"
] 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()
```

### 2K 快速草稿

**Request**

```json
{
  "model": "flux-3.1-image",
  "prompt": "A cosy reading corner by a rainy window, a cat asleep on a knitted blanket, soft lamp light",
  "aspect_ratio": "16:9",
  "quality": "fast",
  "resolution": "2K"
}
```

**Response**

```json
{
  "data": {
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "object": "task",
    "task_kind": "image",
    "capability_id": "flux-3.1-image",
    "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": "flux-3.1-image",
    "poll_after_seconds": 5
  }
}
```

**SDK Code**

```python 2K 快速草稿
import requests

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

payload = {
    "model": "flux-3.1-image",
    "prompt": "A cosy reading corner by a rainy window, a cat asleep on a knitted blanket, soft lamp light",
    "aspect_ratio": "16:9",
    "quality": "fast",
    "resolution": "2K"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript 2K 快速草稿
const url = 'https://api.beatapi.io/v1/images/tasks';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"model":"flux-3.1-image","prompt":"A cosy reading corner by a rainy window, a cat asleep on a knitted blanket, soft lamp light","aspect_ratio":"16:9","quality":"fast","resolution":"2K"}'
};

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

```go 2K 快速草稿
package main

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

func main() {

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

	payload := strings.NewReader("{\n  \"model\": \"flux-3.1-image\",\n  \"prompt\": \"A cosy reading corner by a rainy window, a cat asleep on a knitted blanket, soft lamp light\",\n  \"aspect_ratio\": \"16:9\",\n  \"quality\": \"fast\",\n  \"resolution\": \"2K\"\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 2K 快速草稿
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\": \"flux-3.1-image\",\n  \"prompt\": \"A cosy reading corner by a rainy window, a cat asleep on a knitted blanket, soft lamp light\",\n  \"aspect_ratio\": \"16:9\",\n  \"quality\": \"fast\",\n  \"resolution\": \"2K\"\n}"

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

```java 2K 快速草稿
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\": \"flux-3.1-image\",\n  \"prompt\": \"A cosy reading corner by a rainy window, a cat asleep on a knitted blanket, soft lamp light\",\n  \"aspect_ratio\": \"16:9\",\n  \"quality\": \"fast\",\n  \"resolution\": \"2K\"\n}")
  .asString();
```

```php 2K 快速草稿
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.beatapi.io/v1/images/tasks', [
  'body' => '{
  "model": "flux-3.1-image",
  "prompt": "A cosy reading corner by a rainy window, a cat asleep on a knitted blanket, soft lamp light",
  "aspect_ratio": "16:9",
  "quality": "fast",
  "resolution": "2K"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp 2K 快速草稿
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\": \"flux-3.1-image\",\n  \"prompt\": \"A cosy reading corner by a rainy window, a cat asleep on a knitted blanket, soft lamp light\",\n  \"aspect_ratio\": \"16:9\",\n  \"quality\": \"fast\",\n  \"resolution\": \"2K\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 2K 快速草稿
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "flux-3.1-image",
  "prompt": "A cosy reading corner by a rainy window, a cat asleep on a knitted blanket, soft lamp light",
  "aspect_ratio": "16:9",
  "quality": "fast",
  "resolution": "2K"
] 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()
```

### 文字清晰的 4K 海报

**Request**

```json
{
  "model": "flux-3.1-image",
  "prompt": "A retro travel poster of a coastal city at sunset, bold flat colours, large title text \"SEASIDE\" at the top and a small line \"Ferries daily from Pier 3\" at the bottom",
  "aspect_ratio": "2:3",
  "quality": "quality",
  "resolution": "4K"
}
```

**Response**

```json
{
  "data": {
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "object": "task",
    "task_kind": "image",
    "capability_id": "flux-3.1-image",
    "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": "flux-3.1-image",
    "poll_after_seconds": 5
  }
}
```

**SDK Code**

```python 文字清晰的 4K 海报
import requests

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

payload = {
    "model": "flux-3.1-image",
    "prompt": "A retro travel poster of a coastal city at sunset, bold flat colours, large title text \"SEASIDE\" at the top and a small line \"Ferries daily from Pier 3\" at the bottom",
    "aspect_ratio": "2:3",
    "quality": "quality",
    "resolution": "4K"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript 文字清晰的 4K 海报
const url = 'https://api.beatapi.io/v1/images/tasks';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"model":"flux-3.1-image","prompt":"A retro travel poster of a coastal city at sunset, bold flat colours, large title text \"SEASIDE\" at the top and a small line \"Ferries daily from Pier 3\" at the bottom","aspect_ratio":"2:3","quality":"quality","resolution":"4K"}'
};

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

```go 文字清晰的 4K 海报
package main

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

func main() {

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

	payload := strings.NewReader("{\n  \"model\": \"flux-3.1-image\",\n  \"prompt\": \"A retro travel poster of a coastal city at sunset, bold flat colours, large title text \\\"SEASIDE\\\" at the top and a small line \\\"Ferries daily from Pier 3\\\" at the bottom\",\n  \"aspect_ratio\": \"2:3\",\n  \"quality\": \"quality\",\n  \"resolution\": \"4K\"\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 文字清晰的 4K 海报
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\": \"flux-3.1-image\",\n  \"prompt\": \"A retro travel poster of a coastal city at sunset, bold flat colours, large title text \\\"SEASIDE\\\" at the top and a small line \\\"Ferries daily from Pier 3\\\" at the bottom\",\n  \"aspect_ratio\": \"2:3\",\n  \"quality\": \"quality\",\n  \"resolution\": \"4K\"\n}"

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

```java 文字清晰的 4K 海报
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\": \"flux-3.1-image\",\n  \"prompt\": \"A retro travel poster of a coastal city at sunset, bold flat colours, large title text \\\"SEASIDE\\\" at the top and a small line \\\"Ferries daily from Pier 3\\\" at the bottom\",\n  \"aspect_ratio\": \"2:3\",\n  \"quality\": \"quality\",\n  \"resolution\": \"4K\"\n}")
  .asString();
```

```php 文字清晰的 4K 海报
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.beatapi.io/v1/images/tasks', [
  'body' => '{
  "model": "flux-3.1-image",
  "prompt": "A retro travel poster of a coastal city at sunset, bold flat colours, large title text \\"SEASIDE\\" at the top and a small line \\"Ferries daily from Pier 3\\" at the bottom",
  "aspect_ratio": "2:3",
  "quality": "quality",
  "resolution": "4K"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp 文字清晰的 4K 海报
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\": \"flux-3.1-image\",\n  \"prompt\": \"A retro travel poster of a coastal city at sunset, bold flat colours, large title text \\\"SEASIDE\\\" at the top and a small line \\\"Ferries daily from Pier 3\\\" at the bottom\",\n  \"aspect_ratio\": \"2:3\",\n  \"quality\": \"quality\",\n  \"resolution\": \"4K\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 文字清晰的 4K 海报
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "flux-3.1-image",
  "prompt": "A retro travel poster of a coastal city at sunset, bold flat colours, large title text \"SEASIDE\" at the top and a small line \"Ferries daily from Pier 3\" at the bottom",
  "aspect_ratio": "2:3",
  "quality": "quality",
  "resolution": "4K"
] 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": "flux-3.1-image",
  "prompt": "Keep the bottle exactly as it is. Replace the background with a sunlit kitchen counter and add a soft reflection under the bottle.",
  "images": [
    "https://cdn.beatapi.io/samples/smart-bottle.png"
  ],
  "resolution": "2K"
}
```

**Response**

```json
{
  "data": {
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "object": "task",
    "task_kind": "image",
    "capability_id": "flux-3.1-image",
    "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": "flux-3.1-image",
    "poll_after_seconds": 5
  }
}
```

**SDK Code**

```python 编辑一张图
import requests

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

payload = {
    "model": "flux-3.1-image",
    "prompt": "Keep the bottle exactly as it is. Replace the background with a sunlit kitchen counter and add a soft reflection under the bottle.",
    "images": ["https://cdn.beatapi.io/samples/smart-bottle.png"],
    "resolution": "2K"
}
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":"flux-3.1-image","prompt":"Keep the bottle exactly as it is. Replace the background with a sunlit kitchen counter and add a soft reflection under the bottle.","images":["https://cdn.beatapi.io/samples/smart-bottle.png"],"resolution":"2K"}'
};

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\": \"flux-3.1-image\",\n  \"prompt\": \"Keep the bottle exactly as it is. Replace the background with a sunlit kitchen counter and add a soft reflection under the bottle.\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\"\n  ],\n  \"resolution\": \"2K\"\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\": \"flux-3.1-image\",\n  \"prompt\": \"Keep the bottle exactly as it is. Replace the background with a sunlit kitchen counter and add a soft reflection under the bottle.\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\"\n  ],\n  \"resolution\": \"2K\"\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\": \"flux-3.1-image\",\n  \"prompt\": \"Keep the bottle exactly as it is. Replace the background with a sunlit kitchen counter and add a soft reflection under the bottle.\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\"\n  ],\n  \"resolution\": \"2K\"\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": "flux-3.1-image",
  "prompt": "Keep the bottle exactly as it is. Replace the background with a sunlit kitchen counter and add a soft reflection under the bottle.",
  "images": [
    "https://cdn.beatapi.io/samples/smart-bottle.png"
  ],
  "resolution": "2K"
}',
  '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\": \"flux-3.1-image\",\n  \"prompt\": \"Keep the bottle exactly as it is. Replace the background with a sunlit kitchen counter and add a soft reflection under the bottle.\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\"\n  ],\n  \"resolution\": \"2K\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 编辑一张图
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "flux-3.1-image",
  "prompt": "Keep the bottle exactly as it is. Replace the background with a sunlit kitchen counter and add a soft reflection under the bottle.",
  "images": ["https://cdn.beatapi.io/samples/smart-bottle.png"],
  "resolution": "2K"
] 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": "flux-3.1-image",
  "prompt": "Place the bottle from the first image on a neon-lit stage like the one in the second image. Keep the bottle label readable.",
  "aspect_ratio": "4:5",
  "images": [
    "https://cdn.beatapi.io/samples/smart-bottle.png",
    "https://cdn.beatapi.io/samples/neon-singer.png"
  ],
  "resolution": "2K"
}
```

**Response**

```json
{
  "data": {
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "object": "task",
    "task_kind": "image",
    "capability_id": "flux-3.1-image",
    "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": "flux-3.1-image",
    "poll_after_seconds": 5
  }
}
```

**SDK Code**

```python 合成多张图
import requests

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

payload = {
    "model": "flux-3.1-image",
    "prompt": "Place the bottle from the first image on a neon-lit stage like the one in the second image. Keep the bottle label readable.",
    "aspect_ratio": "4:5",
    "images": ["https://cdn.beatapi.io/samples/smart-bottle.png", "https://cdn.beatapi.io/samples/neon-singer.png"],
    "resolution": "2K"
}
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":"flux-3.1-image","prompt":"Place the bottle from the first image on a neon-lit stage like the one in the second image. Keep the bottle label readable.","aspect_ratio":"4:5","images":["https://cdn.beatapi.io/samples/smart-bottle.png","https://cdn.beatapi.io/samples/neon-singer.png"],"resolution":"2K"}'
};

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\": \"flux-3.1-image\",\n  \"prompt\": \"Place the bottle from the first image on a neon-lit stage like the one in the second image. Keep the bottle label readable.\",\n  \"aspect_ratio\": \"4:5\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\",\n    \"https://cdn.beatapi.io/samples/neon-singer.png\"\n  ],\n  \"resolution\": \"2K\"\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\": \"flux-3.1-image\",\n  \"prompt\": \"Place the bottle from the first image on a neon-lit stage like the one in the second image. Keep the bottle label readable.\",\n  \"aspect_ratio\": \"4:5\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\",\n    \"https://cdn.beatapi.io/samples/neon-singer.png\"\n  ],\n  \"resolution\": \"2K\"\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\": \"flux-3.1-image\",\n  \"prompt\": \"Place the bottle from the first image on a neon-lit stage like the one in the second image. Keep the bottle label readable.\",\n  \"aspect_ratio\": \"4:5\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\",\n    \"https://cdn.beatapi.io/samples/neon-singer.png\"\n  ],\n  \"resolution\": \"2K\"\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": "flux-3.1-image",
  "prompt": "Place the bottle from the first image on a neon-lit stage like the one in the second image. Keep the bottle label readable.",
  "aspect_ratio": "4:5",
  "images": [
    "https://cdn.beatapi.io/samples/smart-bottle.png",
    "https://cdn.beatapi.io/samples/neon-singer.png"
  ],
  "resolution": "2K"
}',
  '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\": \"flux-3.1-image\",\n  \"prompt\": \"Place the bottle from the first image on a neon-lit stage like the one in the second image. Keep the bottle label readable.\",\n  \"aspect_ratio\": \"4:5\",\n  \"images\": [\n    \"https://cdn.beatapi.io/samples/smart-bottle.png\",\n    \"https://cdn.beatapi.io/samples/neon-singer.png\"\n  ],\n  \"resolution\": \"2K\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 合成多张图
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "flux-3.1-image",
  "prompt": "Place the bottle from the first image on a neon-lit stage like the one in the second image. Keep the bottle label readable.",
  "aspect_ratio": "4:5",
  "images": ["https://cdn.beatapi.io/samples/smart-bottle.png", "https://cdn.beatapi.io/samples/neon-singer.png"],
  "resolution": "2K"
] 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()
```

### 超宽 PNG 横幅

**Request**

```json
{
  "model": "flux-3.1-image",
  "prompt": "A wide hero banner for an outdoor gear shop: a hiker on a ridge at sunrise, with open sky on the left for a headline",
  "aspect_ratio": "21:9",
  "output_format": "png",
  "resolution": "2K"
}
```

**Response**

```json
{
  "data": {
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "object": "task",
    "task_kind": "image",
    "capability_id": "flux-3.1-image",
    "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": "flux-3.1-image",
    "poll_after_seconds": 5
  }
}
```

**SDK Code**

```python 超宽 PNG 横幅
import requests

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

payload = {
    "model": "flux-3.1-image",
    "prompt": "A wide hero banner for an outdoor gear shop: a hiker on a ridge at sunrise, with open sky on the left for a headline",
    "aspect_ratio": "21:9",
    "output_format": "png",
    "resolution": "2K"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript 超宽 PNG 横幅
const url = 'https://api.beatapi.io/v1/images/tasks';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"model":"flux-3.1-image","prompt":"A wide hero banner for an outdoor gear shop: a hiker on a ridge at sunrise, with open sky on the left for a headline","aspect_ratio":"21:9","output_format":"png","resolution":"2K"}'
};

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

```go 超宽 PNG 横幅
package main

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

func main() {

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

	payload := strings.NewReader("{\n  \"model\": \"flux-3.1-image\",\n  \"prompt\": \"A wide hero banner for an outdoor gear shop: a hiker on a ridge at sunrise, with open sky on the left for a headline\",\n  \"aspect_ratio\": \"21:9\",\n  \"output_format\": \"png\",\n  \"resolution\": \"2K\"\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 超宽 PNG 横幅
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\": \"flux-3.1-image\",\n  \"prompt\": \"A wide hero banner for an outdoor gear shop: a hiker on a ridge at sunrise, with open sky on the left for a headline\",\n  \"aspect_ratio\": \"21:9\",\n  \"output_format\": \"png\",\n  \"resolution\": \"2K\"\n}"

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

```java 超宽 PNG 横幅
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\": \"flux-3.1-image\",\n  \"prompt\": \"A wide hero banner for an outdoor gear shop: a hiker on a ridge at sunrise, with open sky on the left for a headline\",\n  \"aspect_ratio\": \"21:9\",\n  \"output_format\": \"png\",\n  \"resolution\": \"2K\"\n}")
  .asString();
```

```php 超宽 PNG 横幅
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.beatapi.io/v1/images/tasks', [
  'body' => '{
  "model": "flux-3.1-image",
  "prompt": "A wide hero banner for an outdoor gear shop: a hiker on a ridge at sunrise, with open sky on the left for a headline",
  "aspect_ratio": "21:9",
  "output_format": "png",
  "resolution": "2K"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp 超宽 PNG 横幅
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\": \"flux-3.1-image\",\n  \"prompt\": \"A wide hero banner for an outdoor gear shop: a hiker on a ridge at sunrise, with open sky on the left for a headline\",\n  \"aspect_ratio\": \"21:9\",\n  \"output_format\": \"png\",\n  \"resolution\": \"2K\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 超宽 PNG 横幅
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "flux-3.1-image",
  "prompt": "A wide hero banner for an outdoor gear shop: a hiker on a ridge at sunrise, with open sky on the left for a headline",
  "aspect_ratio": "21:9",
  "output_format": "png",
  "resolution": "2K"
] 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()
```