> ## Documentation Index
> Fetch the complete documentation index at: https://docs.comfy.org/llms.txt
> Use this file to discover all available pages before exploring further.

# 配合 Comfy Router 使用图像

> 通过 Comfy Router 调用 bria/image：端点、请求形状以及 Router 返回的响应。

`bria/image` 的 API 参考，由 Comfy Router 从 Bria 提供。

**输入：** 文本、图像 · **输出：** 图像

## 快速开始

在[你的 Comfy 工作区](https://platform.comfy.org/profile/api-keys?onboarding=router)中创建一个密钥，并将其导出为 `COMFY_API_KEY`。Python 和 TypeScript 代码片段使用 Comfy SDK（`pip install comfy-sdk` 和 `npm install @comfyorg/sdk`）；cURL 代码片段则是通过原始 HTTP 发起的同一调用。

**模型 ID：** `bria/image`

**端点：** `POST https://api.comfy.org/v2/models/bria/image`

**等待结果**

```python Python theme={null}
from comfy_sdk import Comfy

# 从环境变量读取 COMFY_API_KEY。
# SDK 会自动创建幂等键，并在自动重试时复用它。
with Comfy() as client:
    result = client.models.run(
        "bria/image",
        {
            "prompt": "A red vintage bicycle leaning against a brick wall in soft morning light",
        },
    )

print(result)
```

```typescript TypeScript theme={null}
import { comfy } from "@comfyorg/sdk";

// 从环境变量读取 COMFY_API_KEY。
// SDK 会自动创建幂等键，并在自动重试时复用它。
const { data } = await comfy.models.run("bria/image", {
  prompt: "A red vintage bicycle leaning against a brick wall in soft morning light",
});

console.log(data);
```

```bash cURL theme={null}
curl https://api.comfy.org/v2/models/bria/image \
  -H "X-API-Key: $COMFY_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d "{\"prompt\": \"A red vintage bicycle leaning against a brick wall in soft morning light\"}"
```

**入队并稍后收集**

同一个请求体，发送到 `POST https://api.comfy.org/v2/models/bria/image/requests`。运行一旦被接纳，Router 就会以 `201` 应答并返回 `request_id`，结果准备就绪后即可收集，既可以由当前进程收集，也可以由另一个进程收集。[队列投递](/zh/development/comfy-router/queue) 详细介绍了状态、取消与收集的流程。

```python Python theme={null}
import asyncio
from comfy_sdk import AsyncComfy

# 从环境变量读取 COMFY_API_KEY。
# 每次 submit() 调用都会生成自己的 Idempotency-Key，并在自动重试时复用它。
async def main():
    async with AsyncComfy() as client:
        handle = await client.models.submit(
            "bria/image",
            {
                "prompt": "A red vintage bicycle leaning against a brick wall in soft morning light",
            },
        )
        print("request_id:", handle.request_id)  # 加上模型 ID，就是另一个进程所需的全部信息

        # 轮询直到请求完成，按服务器给出的 Retry-After 等待。
        async for update in handle.iter_events():
            print(update.status, update.queue_position)

        # 提供商自己的负载，与 models.run() 返回的值相同。
        # 失败或已取消的请求会在这里抛出带类型的 Router 错误。
        result = await handle.get()

    print(result)

asyncio.run(main())
```

```typescript TypeScript theme={null}
import { comfy } from "@comfyorg/sdk";

// 从环境变量读取 COMFY_API_KEY。
// 每次 submit() 调用都会生成自己的 Idempotency-Key，并在自动重试时复用它。
const handle = await comfy.models.submit("bria/image", {
  prompt: "A red vintage bicycle leaning against a brick wall in soft morning light",
});
console.log("requestId:", handle.requestId); // 加上模型 ID，就是另一个进程所需的全部信息

// 轮询直到请求完成，按服务器给出的 Retry-After 等待。
for await (const update of handle.events()) {
  console.log(update.status, update.queuePosition);
}

// 与 models.run() 返回的结果相同。失败或已取消的请求会在此处被拒绝。
const result = await handle.get();

console.log(result.data);
```

```bash cURL theme={null}
# 1. 提交。Router 返回 201，并带有 request_id、status_url、response_url 和 cancel_url。
curl https://api.comfy.org/v2/models/bria/image/requests \
  -H "X-API-Key: $COMFY_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d "{\"prompt\": \"A red vintage bicycle leaning against a brick wall in soft morning light\"}"

# 2. 轮询直到状态为 COMPLETED，每次响应按其给出的 Retry-After 秒数等待。
REQUEST_ID="<request_id from the 201 body>"
curl -i https://api.comfy.org/v2/models/bria/image/requests/$REQUEST_ID/status \
  -H "X-API-Key: $COMFY_API_KEY"

# 3. 收集。返回 200 时带有模型的原始输出，仍在运行时则返回 202 及状态响应体。
curl https://api.comfy.org/v2/models/bria/image/requests/$REQUEST_ID \
  -H "X-API-Key: $COMFY_API_KEY"
```

## Schema

### 输入

**aspect\_ratio** `string` (default: "1:1")

输出图像比例，取值为 "1:1"、"2:3"、"3:2"、"3:4"、"4:3"、"4:5"、"5:4"、"9:16"、"16:9"、"16:10"、"10:16"、"2:1"、"1:2"、"21:9"、"9:21"、"3:1"、"1:3"、"4:1"、"1:4"、"5:1" 或 "1:5" 之一。使用 "4MP" 时，使用同时发送 prompt 和 structured\_prompt 的细化请求时，或使用没有提示词的图像时，Bria 会拒绝从 "16:10" 起的比例。

**images** `string[]`

用于启发新图像的参考图像。可以是公开可访问的 URL 或 Base64 编码。接受的格式为 JPEG、JPG、PNG、WEBP。必须恰好包含一项。

**ip\_signal** `boolean` (default: false)

如果为 true，则针对提示词中可能存在的 IP 内容返回警告。

**model\_version** `string`

要使用的模型版本。仅接受 "FIBO"；省略它则运行同一模型。

**output\_type** `string` (default: "png")

输出图像格式，"png" 或 "jpeg"。

**prompt** `string`

基于文本的指令。可单独使用以生成新图像，也可与 images 或 structured\_prompt 一起使用来引导或细化结果。

**prompt\_content\_moderation** `boolean` (default: true)

如果为 true，则在提示词审核失败时返回 422。

**resolution** `string` (default: "1MP")

输出图像分辨率，"1MP" 或 "4MP"。"4MP" 可改善图像细节，但会使延迟增加约 30 秒。

**seed** `integer`

用于确定性生成的种子。如果省略，则使用随机种子。

**structured\_prompt** `string`

一个包含 JSON 格式结构化提示词的字符串，来自先前生成的结果。将其与相同的种子一起使用可重现该图像，或者更改其中一部分来细化图像。

**visual\_input\_content\_moderation** `boolean` (default: true)

如果为 true，则在图像审核失败时返回 422。

**visual\_output\_content\_moderation** `boolean` (default: true)

如果为 true，则在视觉输出审核失败时返回 422。

本页内容根据 Router 在 `GET /v2/models/bria/image/openapi.json` 提供的 schema 生成；在请求到达提供商之前，Router 也会依据同一文档校验调用。

### 输出

**error** `object`

错误对象（仅在 status 为 ERROR 时存在）

**error.code** `integer`

错误代码。

**error.details** `string`

额外的错误详情。

**error.message** `string`

报错信息。

**request\_id** `string`

请求的唯一标识符。

**result** `object`

结果对象（仅在 status 为 COMPLETED 时存在）

**result.image\_url** `string`

生成或编辑后的图像 URL。

**result.prompt** `string`

原始提示词。

**result.refined\_prompt** `string`

提示词的细化版本，或在 Bria 未细化的 COMPLETED 生成中为 null。该值可为 null，是因为该键为 PRESENT，携带 null 而非被省略；已在 bria/image-edit-gen-fill 上实际观察到。

**result.seed** `integer`

用于生成的种子。

**result.structured\_instruction** `string`

结构化指令，即序列化为字符串的 JSON 文档，由 `/v2/structured_instruction/generate` 返回。该操作不会填充任何一个 URL。

**result.structured\_prompt** `string`

详细的 JSON 结构化提示词。

**result.video\_url** `string`

已生成视频的 URL。

**status** `string`

当前请求状态。

可能的值：`IN_PROGRESS`、`COMPLETED`、`ERROR`、`UNKNOWN`

## 示例

### 输入

```json theme={null}
{
  "prompt": "A red vintage bicycle leaning against a brick wall in soft morning light"
}
```

### 输出

```json theme={null}
{
  "request_id": "0b3f9d7e-2c41-4a8b-9f10-6d5c8e2a4b71",
  "result": {
    "image_url": "https://example.invalid/bria/image/generated.png",
    "seed": 42
  },
  "status": "COMPLETED"
}
```

## 发布前须知

SDK 会生成 `Idempotency-Key` 并在自动重试中复用它。手动重试时，请复用原始 key。Router 最长可保持连接 10 分钟。

请求失败时，Router 会发送 `X-Comfy-Error-Type` 响应头说明原因。`422` 表示 Router 在调用提供商之前就拒绝了输入，`413` 表示请求体超出了 Router 可接受的大小。已生成的资源请及时下载，因为[结果 URL 会过期](/zh/development/comfy-router/reference#结果资产)。

上文任何字段描述中提到的尺寸限制，都是提供商对该字段自身的限定，引自提供商的规范。Router 会对整个请求体另行设置上限，base64 编码的媒体内容也计入其中：参见[请求体大小](/zh/development/comfy-router/limitations)。

本页记录的是通过 Comfy Router 调用的某一个合作伙伴模型。同一个 `comfy-sdk` / `@comfyorg/sdk` 包还提供第二个客户端，用于在 Comfy Cloud 上运行完整的 ComfyUI 工作流图：`Comfy(api_key=...)` / `new Comfy({ apiKey })`，并带有 `client.workflows`、`client.assets` 和 `client.jobs`。请参阅 [Comfy SDKs](/zh/development/api-development/sdks)。

> **[请求头](/zh/development/comfy-router/headers)**
>
> 身份验证、幂等性、请求 ID、错误分类、重试节奏、消费限额。

> **[使用 Router API](/zh/development/comfy-router/api)**
>
> 模型发现、验证错误、重试与计费。

> **[限制](/zh/development/comfy-router/limitations)**
>
> Router 目前不支持的功能，以及替代方案。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.