ComfyPilotComfyPilot
文档 / 开发 / 将 Photon Flash 1 与 Comfy Router 配合使用

将 Photon Flash 1 与 Comfy Router 配合使用

通过 Comfy Router 调用 luma/photon-flash-1:端点、请求结构以及 Router 返回的响应。

开发 code 更新于 2026-11-09

查看官方原文

将 Photon Flash 1 与 Comfy Router 配合使用

通过 Comfy Router 调用 luma/photon-flash-1:端点、请求结构以及 Router 返回的响应。

luma/photon-flash-1 的 API 参考,由 Comfy Router 从 Luma 提供。

输入: 文本 · 输出: 图像

快速开始

在你的 Comfy 工作区中创建密钥,并将其导出为 COMFY_API_KEY。Python 和 TypeScript 代码片段使用 Comfy SDK(pip install comfy-sdk 和 npm install @comfyorg/sdk);cURL 代码片段是通过原始 HTTP 进行的同一调用。

模型 ID: luma/photon-flash-1

端点: POST https://api.comfy.org/v2/models/luma/photon-flash-1

[tab] 等待结果 ``python Python theme={null} from comfy_sdk import Comfy # 从环境变量中读取 COMFY_API_KEY。 # SDK 会自动创建幂等键,并在自动重试时复用它。 with Comfy() as client: result = client.models.run( "luma/photon-flash-1", { "aspect_ratio": "1:1", "prompt": "a red circle 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("luma/photon-flash-1", { aspect_ratio: "1:1", prompt: "a red circle on a plain white background", }); console.log(data); ` `bash cURL theme={null} curl https://api.comfy.org/v2/models/luma/photon-flash-1 \ -H "X-API-Key: $COMFY_API_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d "{\"aspect_ratio\": \"1:1\", \"prompt\": \"a red circle on a plain white background\"}" ``
[tab] 排队后稍后收集 相同的请求体,发送到 POST https://api.comfy.org/v2/models/luma/photon-flash-1/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( "luma/photon-flash-1", { "aspect_ratio": "1:1", "prompt": "a red circle 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) # 提供商自身的 payload,与 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("luma/photon-flash-1", { aspect_ratio: "1:1", prompt: "a red circle 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/luma/photon-flash-1/requests \ -H "X-API-Key: $COMFY_API_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d "{\"aspect_ratio\": \"1:1\", \"prompt\": \"a red circle 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/luma/photon-flash-1/requests/$REQUEST_ID/status \ -H "X-API-Key: $COMFY_API_KEY" # 3. 收集结果。返回 200 及模型的原始输出;若仍在运行,则返回 202 及状态主体。 curl https://api.comfy.org/v2/models/luma/photon-flash-1/requests/$REQUEST_ID \ -H "X-API-Key: $COMFY_API_KEY" ``

Schema

输入

aspect\_ratio string (default: "16:9")

生成内容的宽高比

可能的值:1:1、16:9、9:16、4:3、3:4、21:9、9:21

callback\_url string (uri)

生成内容的回调 URL

格式:uri

character\_ref object

character\_ref.identity0 object

图像身份对象

character\_ref.identity0.images string (uri)[]

图像身份的 URL 列表

generation\_type string (default: "image")

可能的值:image

image\_ref object[]

图像参考对象

image\_ref\[].url string (uri)

图像参考的 URL

格式:uri

image\_ref\[].weight number

图像参考的权重

model string

用于生成内容的图像模型。在 Comfy Router 路由 POST /v2/models/luma/{model} 上,该字段由路径提供,不得发送;在 v1 的 POST /proxy/luma/generations/image 路由上,该字段被限制为 LumaImageModel 枚举(photon-1、photon-flash-1),Rewrite 通过在模型缺失或未知时拒绝请求来强制执行该约束。

modify\_image\_ref object

修改图像参考对象

modify\_image\_ref.url string (uri)

图像参考的 URL

格式:uri

modify\_image\_ref.weight number

修改图像参考的权重

prompt string

生成内容的提示词

style\_ref object[]

图像参考对象

style\_ref\[].url string (uri)

图像参考的 URL

格式:uri

style\_ref\[].weight number

图像参考的权重

根据 Router 在 GET /v2/models/luma/photon-flash-1/openapi.json 提供的 schema 生成,该文档也是它在请求到达提供商之前用于验证调用的同一份文档。

输出

assets object

图像生成的资产。image 是结果;video 和 progress_video 属于 Dream Machine 的 VIDEO 操作,该操作共用这条状态路由,Luma 将它们作为显式的 null 发送到这里。

assets.image string (uri)

生成图像的 URL,也是 luma/photon-* 生成所填充的叶子字段。在生成达到 completed 之前为 null。

格式:uri

assets.progress\_video string (uri)

在图像生成中始终为 null;它是 VIDEO 生成运行期间 Luma 发布的进行中预览。

格式:uri

assets.video string (uri)

图像生成时始终为 null。只有 Dream Machine 的视频生成会填充该字段,而目前没有任何操作会发起视频生成;该字段只出现在通过状态路由回读的旧视频生成记录中。

格式:uri

created\_at string (date-time)

生成创建时的日期和时间

格式:date-time

failure\_reason string

生成所处状态的原因

generation\_type string

生成的类型,在此操作中始终为 image

可能的值:image

id string (uuid)

生成的 ID

格式:uuid

model string

用于生成的模型

request object

图像生成请求,在终端文档中回显。Luma 会序列化其请求模型的每个字段,为调用方未设置的每个字段写入显式的 null,因此请根据字段的值而不是键来判断字段是否存在。

request.aspect\_ratio string (default: "16:9")

生成的宽高比

可能的值:1:1、16:9、9:16、4:3、3:4、21:9、9:21

request.callback\_url string (uri)

生成的回调 URL

格式:uri

request.character\_ref object

request.character\_ref.identity0 object

图像身份在终端文档中回显时的形态。形状与 LumaImageIdentity 相同,其成员可为 null,原因与 LumaImageRefEcho 所述相同。

request.character\_ref.identity0.images string (uri)[]

图像身份的 URL

request.generation\_type string

设置时始终为 image,与操作保持一致。调用方未发送时则为 null,这正是整个回显对象存在的原因。

request.image\_ref object[]

图像引用在终端文档中回显时的形态。形状与 LumaImageRef 相同,每个成员均可为 null,因为 Luma 对未设置的项会回显为显式的 null,而不是将其省略。

request.image\_ref\[].url string (uri)

图像引用的 URL

格式:uri

request.image\_ref\[].weight number

图像引用的权重

request.model string (default: "photon-1")

用于生成的图像模型

可能的值:photon-1、photon-flash-1

request.modify\_image\_ref object

修改图像引用在终端文档中回显时的形态。形状与 LumaModifyImageRef 相同,其成员可为 null,原因与 LumaImageRefEcho 所述相同。

request.modify\_image\_ref.url string (uri)

图像引用的 URL

格式:uri

request.modify\_image\_ref.weight number

修改图像引用的权重

request.prompt string

生成的提示词

request.style\_ref object[]

图像引用在终端文档中回显时的形态。形状与 LumaImageRef 相同,每个成员均可为 null,因为 Luma 对未设置的项会回显为显式的 null,而不是将其省略。

request.style\_ref\[].url string (uri)

图像引用的 URL

格式:uri

request.style\_ref\[].weight number

图像引用的权重

state string

生成的状态

可能的值:queued、dreaming、completed、failed

示例

输入

{
  "aspect_ratio": "1:1",
  "prompt": "a red circle on a plain white background"
}

输出

{
  "assets": {
    "image": "https://example.invalid/luma/photon-flash-1/generated.png",
    "progress_video": null,
    "video": null
  },
  "created_at": "2027-01-01T00:00:00Z",
  "failure_reason": null,
  "generation_type": "image",
  "id": "a1c73f26-08d5-4e69-b7a2-3c4d5e6f7a80",
  "model": "photon-flash-1",
  "request": {
    "aspect_ratio": "1:1",
    "callback_url": null,
    "character_ref": null,
    "generation_type": "image",
    "image_ref": null,
    "model": "photon-flash-1",
    "modify_image_ref": null,
    "prompt": "a red circle on a plain white background",
    "style_ref": null
  },
  "state": "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 目前不支持的功能,以及替代方案。