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

# 将 Recraft V4.1 Flash V2 与 Comfy Router 配合使用

> 通过 Comfy Router 调用 recraft/recraftv4_1_flash_v2：端点、请求结构以及 Router 返回的响应。

由 Comfy Router 从 Recraft 提供的 `recraft/recraftv4_1_flash_v2` 的 API 参考。

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

## 快速开始

在[你的 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：** `recraft/recraftv4_1_flash_v2`

**端点：** `POST https://api.comfy.org/v2/models/recraft/recraftv4_1_flash_v2`

> [tab] 等待结果
>
> ```python Python theme={null}
> from comfy_sdk import Comfy
>
> # 从环境变量中读取 COMFY_API_KEY。
> # SDK 会自动创建幂等键，并在自动重试时复用它。
> with Comfy() as client:
>     result = client.models.run(
>         "recraft/recraftv4_1_flash_v2",
>         {
>             "n": 1,
>             "prompt": "A single red maple leaf on a plain white background.",
>         },
>     )
>
> print(result)
> ```
>
> ```typescript TypeScript theme={null}
> import { comfy } from "@comfyorg/sdk";
>
> // 从环境变量中读取 COMFY_API_KEY。
> // SDK 会自动创建幂等键，并在自动重试时复用它。
> const { data } = await comfy.models.run("recraft/recraftv4_1_flash_v2", {
>   n: 1,
>   prompt: "A single red maple leaf on a plain white background.",
> });
>
> console.log(data);
> ```
>
> ```bash cURL theme={null}
> curl https://api.comfy.org/v2/models/recraft/recraftv4_1_flash_v2 \
>   -H "X-API-Key: $COMFY_API_KEY" \
>   -H "Idempotency-Key: $(uuidgen)" \
>   -H "Content-Type: application/json" \
>   -d "{\"n\": 1, \"prompt\": \"A single red maple leaf on a plain white background.\"}"
> ```

> [tab] 入队并稍后获取
>
> 相同的请求体，发送至 `POST https://api.comfy.org/v2/models/recraft/recraftv4_1_flash_v2/requests`。运行一旦被接纳，Router 就会立即返回 `201` 和 `request_id`；结果就绪后即可收集，可由本进程或其他进程完成。[队列投递](https://docs.comfy.org/zh/development/comfy-router/queue.md)详细介绍了状态、取消与收集。
>
> ```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(
>             "recraft/recraftv4_1_flash_v2",
>             {
>                 "n": 1,
>                 "prompt": "A single red maple leaf on a plain white background.",
>             },
>         )
>         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("recraft/recraftv4_1_flash_v2", {
>   n: 1,
>   prompt: "A single red maple leaf on a plain white background.",
> });
> 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/recraft/recraftv4_1_flash_v2/requests \
>   -H "X-API-Key: $COMFY_API_KEY" \
>   -H "Idempotency-Key: $(uuidgen)" \
>   -H "Content-Type: application/json" \
>   -d "{\"n\": 1, \"prompt\": \"A single red maple leaf on a plain white background.\"}"
>
> # 2. 轮询直到状态为 COMPLETED，每次按响应中给出的 Retry-After 秒数等待。
> REQUEST_ID="<request_id from the 201 body>"
> curl -i https://api.comfy.org/v2/models/recraft/recraftv4_1_flash_v2/requests/$REQUEST_ID/status \
>   -H "X-API-Key: $COMFY_API_KEY"
>
> # 3. 收集。返回 200 和模型的原生输出；仍在运行时返回 202 和状态响应体。
> curl https://api.comfy.org/v2/models/recraft/recraftv4_1_flash_v2/requests/$REQUEST_ID \
>   -H "X-API-Key: $COMFY_API_KEY"
> ```

## Schema

### 输入

**controls** `object`

生成图像的控制参数

**controls.artistic\_level** `integer`

定义图像的艺术基调。在简单级别下，人物以静态、干净的方式直视相机；动态与古怪级别则会引入动感与创意。

范围：`0` 到 `5`

**controls.background\_color** `object`

RGB 颜色值

**controls.background\_color.rgb** `integer[]` *required*

**controls.colors** `object[]`

偏好的颜色数组

**controls.colors\[].rgb** `integer[]` *required*

**controls.no\_text** `boolean`

不嵌入文字版式

**model** `string`

用于生成的模型（例如 "recraftv3"）。此字段不受枚举约束：代理会原样转发调用方发送的内容。Comfy 内置的拼写（即 Comfy Router 以 `recraft/<model>` 形式寻址的集合）包括 recraftv2、recraftv3、recraftv4、recraftv4\_pro、recraftv4\_1、recraftv4\_1\_flash\_v2、recraftv4\_1\_utility、recraftv4\_1\_pro、recraftv4\_1\_utility\_pro、recraftv4\_styles、recraftv4\_styles\_pro、recraftv4\_1\_vector、recraftv4\_1\_utility\_vector、recraftv4\_1\_pro\_vector、recraftv4\_1\_utility\_pro\_vector、recraftv4\_styles\_vector 和 recraftv4\_styles\_pro\_vector。这里逐一列出它们而不是通过引用来命名，是因为声明这些取值的 RecraftGenerationModel 组件没有被任何地方以 `$ref` 引用，因此在 GET /openapi 提供的规范中会被裁剪掉，指向它的指针在提供的文档中会悬空。其中四个 `recraftv4_styles*` 拼写还额外要求 `style_id`，详见该字段。

**n** `integer`

要生成的图像数量。Recraft 接受 1-6。

范围：`1` 到 `6`

**prompt** `string` *required*

描述待生成图像的文本提示词

**response\_format** `string`

可能的值：`url`、`b64_json`

**size** `string`

生成图像的尺寸（例如 "1024x1024"）

**style** `string`

应用于生成图像的风格（例如 "digital\_illustration"）

**style\_id** `string`

应用于生成图像的风格 ID（例如 "123e4567-e89b-12d3-a456-426614174000"）。如果提供了 style\_id，则不应提供 style。四个 `recraftv4_styles*` 模型要求必填：Recraft 会拒绝没有 style\_id 或风格引用的这类调用。可通过 `POST /proxy/recraft/styles` 创建一个，该端点由同一个代理使用相同的凭据提供。此路由本身不会强制这一配对，请求体会原样转发给 Recraft，因此不带该字段的 `recraftv4_styles*` 调用会到达合作伙伴并返回 4xx。

根据 Router 在 `GET /v2/models/recraft/recraftv4_1_flash_v2/openapi.json` 提供的 schema 生成，这也是它在请求到达提供商之前用于校验调用的同一份文档。

### 输出

**created** `integer` *required*

生成创建时的 Unix 时间戳

**credits** `integer` *required*

本次生成使用的积分数量

**data** `object[]` *required*

生成图像信息的数组

**data\[].b64\_json** `string`

Base64 编码的图像数据（当请求设置 `response_format: b64_json` 时出现，替代 `url`）

**data\[].image\_id** `string`

生成图像的唯一标识符

**data\[].url** `string`

访问生成图像的 URL（当 `response_format` 为 `url`（默认值）时出现）

**style\_id** `string`

解析后的风格 id，在使用风格引用时由 Recraft 返回（尤其是必填输入模型 recraftv4\_styles\*）；可在后续请求中作为 `style_id` 复用。

## 示例

### 输入

```json theme={null}
{
  "n": 1,
  "prompt": "A single red maple leaf on a plain white background."
}
```

### 输出

```json theme={null}
{
  "created": 1767225600,
  "credits": 1,
  "data": [
    {
      "image_id": "3f7a1b28-5c0d-4e91-8a6f-1b2c3d4e5f60",
      "url": "https://example.invalid/recraft/recraftv3/generated.png"
    }
  ]
}
```

## 发布前须知

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

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

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

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

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

> [card] [使用 Router API](https://docs.comfy.org/zh/development/comfy-router/api.md)
>
> 模型发现、验证错误、重试与计费。

> [card] [限制](https://docs.comfy.org/zh/development/comfy-router/limitations.md)
>
> Router 目前不支持的功能，以及替代方案。


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