> ## Documentation Index
> Fetch the complete documentation index at: https://dripart-chore-sync-comfy-api-v2-spec.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 通过 Comfy Router 使用 Recraft V4.1 Utility Pro Vector

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

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

## 快速开始

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

**模型 ID：** `recraft/recraftv4_1_utility_pro_vector`

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

<Tabs>
  <Tab title="Wait for the result">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # Reads COMFY_API_KEY from the environment.
      # The SDK automatically creates an idempotency key and reuses it for automatic retries.
      with Comfy() as client:
          result = client.models.run(
              "recraft/recraftv4_1_utility_pro_vector",
              {
                  "n": 1,
                  "prompt": "A single red maple leaf on a plain white background.",
              },
          )

      print(result)
      ```

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

      // Reads COMFY_API_KEY from the environment.
      // The SDK automatically creates an idempotency key and reuses it for automatic retries.
      const { data } = await comfy.models.run("recraft/recraftv4_1_utility_pro_vector", {
        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_utility_pro_vector \
        -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.\"}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Queue and collect later">
    将相同的请求体发送到 `POST https://api.comfy.org/v2/models/recraft/recraftv4-1-utility-pro-vector/requests`。运行被受理后，Router 会立即返回 `201` 和 `request_id`；结果就绪后，可以从本进程或其他进程收集。状态、取消与收集的细节见 [Queued delivery](/zh/development/comfy-router/queue)。

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

      # Reads COMFY_API_KEY from the environment.
      # Each submit() call mints its own Idempotency-Key and reuses it for automatic retries.
      with Comfy() as client:
          handle = client.models.submit(
              "recraft/recraftv4_1_utility_pro_vector",
              {
                  "n": 1,
                  "prompt": "A single red maple leaf on a plain white background.",
              },
          )
          print("request_id:", handle.request_id)  # with the model ID, all another process needs

          # Poll until the request completes, waiting the Retry-After the server names.
          for update in handle.iter_events():
              print(update.status, update.queue_position)

          # The provider's own payload, the same value models.run() returns.
          # A request that failed or was cancelled raises the typed Router error here.
          result = handle.get()

      print(result)
      ```

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

      // Reads COMFY_API_KEY from the environment.
      // Each submit() call mints its own Idempotency-Key and reuses it for automatic retries.
      const handle = await comfy.models.submit("recraft/recraftv4_1_utility_pro_vector", {
        n: 1,
        prompt: "A single red maple leaf on a plain white background.",
      });
      console.log("requestId:", handle.requestId); // with the model ID, all another process needs

      // Poll until the request completes, waiting the Retry-After the server names.
      for await (const update of handle.events()) {
        console.log(update.status, update.queuePosition);
      }

      // The same result models.run() returns. A request that failed or was cancelled rejects here.
      const result = await handle.get();

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

      ```bash cURL theme={null}
      # 1. Submit. Router answers 201 with request_id, status_url, response_url and cancel_url.
      curl https://api.comfy.org/v2/models/recraft/recraftv4_1_utility_pro_vector/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. Poll until status is COMPLETED, waiting the Retry-After seconds each response names.
      REQUEST_ID="<request_id from the 201 body>"
      curl -i https://api.comfy.org/v2/models/recraft/recraftv4_1_utility_pro_vector/requests/$REQUEST_ID/status \
        -H "X-API-Key: $COMFY_API_KEY"

      # 3. Collect. 200 with the model's native output, 202 with the status body while it is still running.
      curl https://api.comfy.org/v2/models/recraft/recraftv4_1_utility_pro_vector/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## Schema

### Input

<ParamField body="controls" type="object">
  生成图像的控制参数
</ParamField>

<ParamField body="controls.artistic_level" type="integer">
  定义图像的艺术基调。在简单级别下，人物以静态、简洁的风格直视相机。动态和古怪的级别则会引入动感与创意。

  范围：`0` 至 `5`
</ParamField>

<ParamField body="controls.background_color" type="object">
  RGB 颜色值
</ParamField>

<ParamField body="controls.background_color.rgb" type="integer[]" required />

<ParamField body="controls.colors" type="object[]">
  首选颜色的数组
</ParamField>

<ParamField body="controls.colors[].rgb" type="integer[]" required />

<ParamField body="controls.no_text" type="boolean">
  不嵌入文本排版
</ParamField>

<ParamField body="model" type="string">
  用于生成的模型（例如 "recraftv3"）。该字段不受枚举约束：代理会原样转发调用方发送的任何内容。Comfy 提供的拼写，也就是 Comfy Router 以 `recraft/<model>` 形式寻址的集合，包括 recraftv2、recraftv3、recraftv4、recraftv4\_pro、recraftv4\_1、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`，详见该字段。
</ParamField>

<ParamField body="n" type="integer">
  要生成的图像数量

  范围：`1` 至 `6`
</ParamField>

<ParamField body="prompt" type="string" required>
  描述要生成图像的文本提示词
</ParamField>

<ParamField body="size" type="string">
  已生成图像的尺寸（例如 "1024x1024"）
</ParamField>

<ParamField body="style" type="string">
  要应用于已生成图像的风格（例如 "digital\_illustration"）
</ParamField>

<ParamField body="style_id" type="string">
  要应用于已生成图像的风格 ID（例如 "123e4567-e89b-12d3-a456-426614174000"）。如果提供了 style\_id，则不应提供 style。四个 `recraftv4_styles*` 模型要求必填：Recraft 会拒绝没有 style\_id 或风格引用的请求。可使用 `POST /proxy/recraft/styles` 生成一个，同一代理以相同凭据提供该接口。此路由不会强制校验这种配对关系：请求体会原样转发给 Recraft，因此缺少该字段的 `recraftv4_styles*` 调用会到达合作伙伴并返回 4xx。
</ParamField>

由 Router 在 `GET /v2/models/recraft/recraftv4_1_utility_pro_vector/openapi.json` 提供的 schema 生成，该文档与请求到达提供商之前用于校验调用的文档相同。

### Output

<ResponseField name="created" type="integer" required>
  生成创建时的 Unix 时间戳
</ResponseField>

<ResponseField name="credits" type="integer" required>
  用于本次生成所消耗的积分数
</ResponseField>

<ResponseField name="data" type="object[]" required>
  已生成图像信息的数组
</ResponseField>

<ResponseField name="data[].image_id" type="string">
  已生成图像的唯一标识符
</ResponseField>

<ResponseField name="data[].url" type="string">
  用于访问已生成图像的 URL
</ResponseField>

## 示例

### 输入

```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 在调用提供商之前就拒绝了输入。生成的资源请及时下载，因为[结果链接会过期](/zh/development/comfy-router/reference#结果资产)。

<CardGroup cols={3}>
  <Card title="请求头" icon="list" href="/zh/development/comfy-router/quickstart">
    身份验证、幂等性、请求 ID、错误分类、重试节奏、消费限额。
  </Card>

  <Card title="使用 Router API" icon="code" href="/zh/development/comfy-router/quickstart">
    模型发现、校验错误、重试与计费。
  </Card>

  <Card title="限制" icon="triangle-exclamation" href="/zh/development/comfy-router/limitations">
    Router 目前不支持的功能，以及替代方案。
  </Card>
</CardGroup>
