> ## 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 调用 Krea 3

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

`krea/krea-3` 的 API 参考文档，由 Comfy Router 从 Krea 提供。

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

## 快速开始

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

**端点：** `POST https://api.comfy.org/v2/models/krea/krea-3`

<Tabs defaultTabIndex={1}>
  <Tab title="等待结果">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # 从环境变量读取 COMFY_API_KEY。
      # SDK 会自动创建幂等键，并在自动重试时复用它。
      with Comfy() as client:
          result = client.models.run(
              "krea/krea-3",
              {
                  "image_urls": ["https://example.com/reference.png"],
                  "prompt": "Place the product on a clean studio background",
                  "resolution": "1k",
              },
          )

      print(result)
      ```

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

      // 从环境变量读取 COMFY_API_KEY。
      // SDK 会自动创建幂等键，并在自动重试时复用它。
      const { data } = await comfy.models.run("krea/krea-3", {
        image_urls: ["https://example.com/reference.png"],
        prompt: "Place the product on a clean studio background",
        resolution: "1k",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/krea/krea-3 \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"image_urls\": [\"https://example.com/reference.png\"], \"prompt\": \"Place the product on a clean studio background\", \"resolution\": \"1k\"}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="排队并稍后收集">
    相同的请求体，发送到 `POST https://api.comfy.org/v2/models/krea/krea-3/requests`。运行一经接纳，Router 就会返回 `201` 和一个 `request_id`，结果准备就绪后即可收集，可由当前进程或另一个进程收集。[队列投递](/zh/development/comfy-router/queue)会依次介绍状态、取消和收集。

    <CodeGroup>
      ```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(
                  "krea/krea-3",
                  {
                      "image_urls": ["https://example.com/reference.png"],
                      "prompt": "Place the product on a clean studio background",
                      "resolution": "1k",
                  },
              )
              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("krea/krea-3", {
        image_urls: ["https://example.com/reference.png"],
        prompt: "Place the product on a clean studio background",
        resolution: "1k",
      });
      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/krea/krea-3/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"image_urls\": [\"https://example.com/reference.png\"], \"prompt\": \"Place the product on a clean studio background\", \"resolution\": \"1k\"}"

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

      # 3. 收集。200 返回模型的原生输出，仍在运行时则返回 202 和状态响应体。
      curl https://api.comfy.org/v2/models/krea/krea-3/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## Schema

### 输入

<ParamField body="aspect_ratio" type="string">
  1:1、4:5、3:4、2:3、9:16、5:4、4:3、3:2、16:9 或 21:9。与 resolution 配合使用；省略则自动构图。
</ParamField>

<ParamField body="image_urls" type="string[]">
  输入图像 URL，最多 8 个。使用 POST /proxy/krea/assets 返回的 image\_url 值。文生图时省略。
</ParamField>

<ParamField body="model" type="string">
  berry（默认，质量）或 jam（速度）。
</ParamField>

<ParamField body="negative_prompt" type="string" />

<ParamField body="prompt" type="string" required>
  编辑指令。描述应更改什么以及应保持不变什么。
</ParamField>

<ParamField body="regional_edit" type="boolean">
  设为 true 表示执行局部编辑并保留图像其余部分。需要 model 为 berry，且 image\_urls 中至少有一个图像。
</ParamField>

<ParamField body="resolution" type="string" required>
  1k 或 2k。
</ParamField>

<ParamField body="seed" type="integer" />

<ParamField body="thinking_mode" type="string">
  fast（默认）、high 或 ultra。high 和 ultra 会更详细地规划复杂编辑，耗时也更长。ultra 需要 resolution 2k。
</ParamField>

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

### 输出

<ResponseField name="completed_at" type="string (date-time)" required>
  格式：`date-time`
</ResponseField>

<ResponseField name="created_at" type="string (date-time)" required>
  格式：`date-time`
</ResponseField>

<ResponseField name="job_id" type="string (uuid)" required>
  格式：`uuid`
</ResponseField>

<ResponseField name="result" type="object" required>
  已完成的生成结果。此处不可为空，与 `KreaJob` 上不同：终态任务的 `result` 若不携带 `urls`，会作为 Comfy Router 错误返回，因此 `200` 总是携带它。
</ResponseField>

<ResponseField name="result.style_id" type="string">
  由 loraTraining 任务设置，而非由生成设置；这些模型的 `200` 响应携带 `urls`。
</ResponseField>

<ResponseField name="result.urls" type="string (uri)[]" required>
  已生成的图像，以可下载链接的形式返回。至少一个，因为 `urls` 为空的 `completed` 任务属于 `success_without_output`，永远不会到达此文档。
</ResponseField>

<ResponseField name="status" type="string" required>
  此文档中始终为 `completed`：这是 Router 唯一报告为成功的状态，且匹配 Krea 的用词时不进行大小写折叠。

  可能的值：`completed`
</ResponseField>

## 示例

### 输入

```json theme={null}
{
  "image_urls": [
    "https://example.com/reference.png"
  ],
  "prompt": "Place the product on a clean studio background",
  "resolution": "1k"
}
```

### 输出

```json theme={null}
{
  "completed_at": "2027-01-01T00:00:37Z",
  "created_at": "2027-01-01T00:00:00Z",
  "job_id": "7f1c2e84-5b90-4a37-8d61-2c0f9ab4e153",
  "result": {
    "urls": [
      "https://example.invalid/krea/krea-2/generated.png"
    ]
  },
  "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)。

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

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

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


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