ComfyPilotComfyPilot
文档 / 开发 / 通过 Comfy Router 使用 Krea 3

通过 Comfy Router 使用 Krea 3

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

开发 code 更新于 2026-10-31

查看官方原文

通过 Comfy Router 使用 Krea 3

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

krea/krea-3 的 API 参考,由 Comfy Router 从 Krea 提供。

输入: 文本、图像 · 输出: 图像

快速开始

在你的 Comfy 工作区中创建一个密钥,并将其导出为 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

[tab] 等待结果 ``python Python theme={null} from comfy_sdk import Comfy # 从环境变量中读取 COMFY_API_KEY。 # SDK 会自动创建幂等键,并在自动重试时复用它。 with Comfy() as client: result = client.models.run( "krea/krea-3", { "prompt": "A ceramic coffee mug 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", { prompt: "A ceramic coffee mug 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 "{\"prompt\": \"A ceramic coffee mug on a clean studio background\", \"resolution\": \"1k\"}" ``
[tab] 排队并稍后收集 相同的请求体,发送到 POST https://api.comfy.org/v2/models/krea/krea-3/requests。运行一经受理,Router 就会返回 201 和 request_id,结果准备就绪后即可收集,无论是由当前进程还是其他进程。排队投递 介绍了状态、取消和收集的流程。 ``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", { "prompt": "A ceramic coffee mug 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", { prompt: "A ceramic coffee mug 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 "{\"prompt\": \"A ceramic coffee mug on a clean studio background\", \"resolution\": \"1k\"}" # 2. 轮询直到 status 为 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" ``

Schema

输入

aspect\_ratio string

1:1、4:5、3:4、2:3、9:16、5:4、4:3、3:2、16:9 或 21:9。与 resolution 配合使用;省略则自动构图。

image\_urls string[]

输入图像 URL,最多 8 个。将图像上传到 POST /proxy/krea/assets(multipart 表单字段 file)后返回的 image\_url 始终会被接受。其他公共 https URL 是否会被接受取决于环境:在不接受的环境中,任何不是主机 app-uploads.krea.ai 上的 https URL 的链接都会被以 400 拒绝;在接受的环境中,任何公共 https 图像 URL 都会被接受,而格式错误或不是 https 的 URL 会被以 400 拒绝(端口为数字但超出范围的 URL 不会被此检查捕获,可能反而以 502 失败)。在这种情况下,对于格式正确的 https URL,调用方可以修复的引用会被以 400 拒绝并指明其主机:在抓取之前检查时,其主机无法解析或无法公开访问;它重定向的次数超过允许值、重定向到不是 https 的 URL,或重定向到无法公开访问的主机;它返回 408 或 429 以外的 4xx;它不是图像;它是无法读取格式的图像;它的图像尺寸头不在前 2 MiB 之内;或者未声明长度或使用分块编码的响应在其图像尺寸头之前就结束了。抓取它的任何其他失败都会使 POST /proxy/krea 以 502 错误失败(Comfy Router 以 500 internal\_error 应答):临时的 DNS、TLS 或连接失败,超时,源站返回 408、429、5xx 或其他非 200 状态,或者通过了该检查但在抓取连接时无法解析或无法公开访问的主机。在不接受其他 URL 的环境中,不是实时上传的 app-uploads.krea.ai 链接会以 5xx 错误失败;在接受的环境中,它会像任何其他不可达的引用一样被以 400 拒绝。当服务器尚未确定适用哪种情况时,任何主机不是 app-uploads.krea.ai 链接的 https URL(无论是否公共)都会以 503 错误失败,该错误可以安全重试。文生图时省略。

model string

berry(默认,质量优先)或 jam(速度优先)。

negative\_prompt string

prompt string required

要生成的内容。与 image\_urls 一起使用时,为编辑指令;描述应改变的内容以及应保持不变的内容。

regional\_edit boolean

设为 true 以执行局部编辑并保留图像的其他部分。需要 model 为 berry,且 image\_urls 中至少包含一个图像。

resolution string required

1k 或 2k。

seed integer

thinking\_mode string

fast(默认)、high 或 ultra。high 和 ultra 会更详细地规划复杂编辑,耗时也更长。ultra 需要 resolution 为 2k。

根据 Router 在 GET /v2/models/krea/krea-3/openapi.json 提供的 Schema 生成,这也是它在请求到达提供商之前校验调用所用的同一份文档。

输出

completed\_at string (date-time) required

格式:date-time

created\_at string (date-time) required

格式:date-time

job\_id string (uuid) required

格式:uuid

result object required

已完成的生成结果。与 KreaJob 上不同,此处不可为空:终端任务的 result 若不包含 urls,会作为 Comfy Router 错误返回,因此 200 响应中始终带有该字段。

result.style\_id string

由 loraTraining 任务而非生成过程设置;这些模型的 200 响应带有 urls。

result.urls string (uri)[] required

已生成的图像,以可下载链接的形式提供。至少一个,因为 completed 状态的任务若 urls 为空即为 success_without_output,永远不会出现在本文档中。

status string required

在本文档中始终为 completed:这是 Router 唯一报告为成功的状态,并且 Krea 的用词匹配不进行大小写折叠。

可能的值:completed

示例

输入

{
  "prompt": "A ceramic coffee mug on a clean studio background",
  "resolution": "1k"
}

输出

{
  "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 会过期。

上文任何字段描述中提到的尺寸限制,都是提供商对该字段自身的限定,引自提供商的规范。Router 会对整个请求体另行设置上限,base64 编码的媒体内容也计入其中:参见请求体大小。

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

[card] 请求头 身份验证、幂等性、请求 ID、错误分类、重试节奏、消费限额。
[card] 使用 Router API 模型发现、验证错误、重试与计费。
[card] 限制 Router 目前不支持的功能,以及替代方案。