将 Photon 1 与 Comfy Router 配合使用
通过 Comfy Router 调用 luma/photon-1:端点、请求形状以及 Router 返回的响应。
将 Photon 1 与 Comfy Router 配合使用
通过 Comfy Router 调用 luma/photon-1:端点、请求形状以及 Router 返回的响应。
luma/photon-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-1
端点: POST https://api.comfy.org/v2/models/luma/photon-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-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-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-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-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-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) # 提供商自己的载荷,与 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-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() 返回的结果相同。失败或已取消的请求会在此处 reject。 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-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-1/requests/$REQUEST_ID/status \ -H "X-API-Key: $COMFY_API_KEY" # 3. 收集结果。返回 200 时带有该模型的原生输出,仍在运行时则返回 202 和状态响应体。 curl https://api.comfy.org/v2/models/luma/photon-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-1/openapi.json 提供的 schema 生成,这也是 Router 在请求到达提供商之前用于校验调用的同一份文档。
输出
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-1/generated.png",
"progress_video": null,
"video": null
},
"created_at": "2027-01-01T00:00:00Z",
"failure_reason": null,
"generation_type": "image",
"id": "5e8b06d7-91c4-4a2f-8b3d-6f7a8b9c0d1e",
"model": "photon-1",
"request": {
"aspect_ratio": "1:1",
"callback_url": null,
"character_ref": null,
"generation_type": "image",
"image_ref": null,
"model": "photon-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 目前不支持的功能,以及替代方案。