> ## Documentation Index
> Fetch the complete documentation index at: https://comfyuiwiki.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 将 Photon 1 与 Comfy Router 配合使用

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

`luma/photon-1` 的 API 参考文档，由 Comfy Router 从 Luma 提供。

## 快速开始

在[你的 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：** `luma/photon-1`

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

<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(
              "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\"}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="排队并稍后收集">
    同一个请求体，发送到 `POST https://api.comfy.org/v2/models/luma/photon-1/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(
                  "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"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## Schema

### 输入

<ParamField body="aspect_ratio" type="string" default="&#x22;16:9&#x22;">
  生成结果的宽高比

  可选值：`1:1`、`16:9`、`9:16`、`4:3`、`3:4`、`21:9`、`9:21`
</ParamField>

<ParamField body="callback_url" type="string (uri)">
  生成的回调 URL

  格式：`uri`
</ParamField>

<ParamField body="character_ref" type="object" />

<ParamField body="character_ref.identity0" type="object">
  图像身份对象
</ParamField>

<ParamField body="character_ref.identity0.images" type="string (uri)[]">
  图像身份的 URL 列表
</ParamField>

<ParamField body="generation_type" type="string" default="&#x22;image&#x22;">
  可选值：`image`
</ParamField>

<ParamField body="image_ref" type="object[]">
  图像参考对象
</ParamField>

<ParamField body="image_ref[].url" type="string (uri)">
  图像参考的 URL

  格式：`uri`
</ParamField>

<ParamField body="image_ref[].weight" type="number">
  图像参考的权重
</ParamField>

<ParamField body="model" type="string">
  用于生成的图像模型。在 Comfy Router 路由 `POST /v2/models/luma/{model}` 上，该字段由路径提供，禁止发送；在 v1 的 `POST /proxy/luma/generations/image` 路由上，它被限制为 LumaImageModel 枚举（`photon-1`、`photon-flash-1`），Rewrite 通过拒绝省略或未知的模型来强制执行这一约束。
</ParamField>

<ParamField body="modify_image_ref" type="object">
  修改图像参考对象
</ParamField>

<ParamField body="modify_image_ref.url" type="string (uri)">
  图像参考的 URL

  格式：`uri`
</ParamField>

<ParamField body="modify_image_ref.weight" type="number">
  修改图像参考的权重
</ParamField>

<ParamField body="prompt" type="string">
  生成的提示词
</ParamField>

<ParamField body="style_ref" type="object[]">
  图像参考对象
</ParamField>

<ParamField body="style_ref[].url" type="string (uri)">
  图像参考的 URL

  格式：`uri`
</ParamField>

<ParamField body="style_ref[].weight" type="number">
  图像参考的权重
</ParamField>

本文档由 Router 在 `GET /v2/models/luma/photon-1/openapi.json` 提供的 schema 生成，这也是 Router 在请求到达提供商之前用于校验调用的同一份文档。

### 输出

<ResponseField name="assets" type="object">
  图像生成的资产。`image` 是结果；`video` 和 `progress_video` 属于 Dream Machine 的 VIDEO 操作，该操作共用这条状态路由，Luma 会把它们作为显式 null 发送到这里。
</ResponseField>

<ResponseField name="assets.image" type="string (uri)">
  生成图像的 URL：这是 `luma/photon-*` 生成所填充的叶子字段。在生成达到 `completed` 之前为 null。

  格式：`uri`
</ResponseField>

<ResponseField name="assets.progress_video" type="string (uri)">
  在图像生成中始终为 null；它是 VIDEO 生成运行期间 Luma 发布的进行中预览。

  格式：`uri`
</ResponseField>

<ResponseField name="assets.video" type="string (uri)">
  在图像生成中始终为 null；由 `luma/ray-*` 视频模型填充。

  格式：`uri`
</ResponseField>

<ResponseField name="created_at" type="string (date-time)">
  生成创建时的日期和时间

  格式：`date-time`
</ResponseField>

<ResponseField name="failure_reason" type="string">
  生成状态的原因
</ResponseField>

<ResponseField name="generation_type" type="string">
  生成类型：在此操作中始终为 `image`

  可选值：`image`
</ResponseField>

<ResponseField name="id" type="string (uuid)">
  生成的 ID

  格式：`uuid`
</ResponseField>

<ResponseField name="model" type="string">
  用于生成的模型
</ResponseField>

<ResponseField name="request" type="object">
  图像生成请求，会在终端文档中原样回传。Luma 会序列化其请求模型的每个字段，对调用方未设置的字段写入显式 `null`，因此请根据字段的值而不是键是否存在来判断它是否被设置。
</ResponseField>

<ResponseField name="request.aspect_ratio" type="string" default="&#x22;16:9&#x22;">
  生成的比例

  可选值：`1:1`、`16:9`、`9:16`、`4:3`、`3:4`、`21:9`、`9:21`
</ResponseField>

<ResponseField name="request.callback_url" type="string (uri)">
  生成的回调 URL

  格式：`uri`
</ResponseField>

<ResponseField name="request.character_ref" type="object" />

<ResponseField name="request.character_ref.identity0" type="object">
  在终端文档中回传时的图像身份。与 `LumaImageIdentity` 形状相同，其成员可为 null，原因与 `LumaImageRefEcho` 所述相同。
</ResponseField>

<ResponseField name="request.character_ref.identity0.images" type="string (uri)[]">
  该图像身份的 URL
</ResponseField>

<ResponseField name="request.generation_type" type="string">
  设置时始终为 `image`，与操作相呼应。当调用方未发送该字段时为 null，原因正是这个整体回传对象存在的原因。
</ResponseField>

<ResponseField name="request.image_ref" type="object[]">
  在终端文档中回传时的图像引用。与 `LumaImageRef` 形状相同，每个成员均可为 null，因为对于未设置的字段，Luma 会回传显式 `null` 而不是将其省略。
</ResponseField>

<ResponseField name="request.image_ref[].url" type="string (uri)">
  图像引用的 URL

  格式：`uri`
</ResponseField>

<ResponseField name="request.image_ref[].weight" type="number">
  图像引用的权重
</ResponseField>

<ResponseField name="request.model" type="string" default="&#x22;photon-1&#x22;">
  用于生成的图像模型

  可选值：`photon-1`、`photon-flash-1`
</ResponseField>

<ResponseField name="request.modify_image_ref" type="object">
  在终端文档中回传时的修改图像引用。与 `LumaModifyImageRef` 形状相同，其成员可为 null，原因与 `LumaImageRefEcho` 所述相同。
</ResponseField>

<ResponseField name="request.modify_image_ref.url" type="string (uri)">
  图像引用的 URL

  格式：`uri`
</ResponseField>

<ResponseField name="request.modify_image_ref.weight" type="number">
  修改图像引用的权重
</ResponseField>

<ResponseField name="request.prompt" type="string">
  生成的提示词
</ResponseField>

<ResponseField name="request.style_ref" type="object[]">
  在终端文档中回传时的图像引用。与 `LumaImageRef` 形状相同，每个成员均可为 null，因为对于未设置的字段，Luma 会回传显式 `null` 而不是将其省略。
</ResponseField>

<ResponseField name="request.style_ref[].url" type="string (uri)">
  图像引用的 URL

  格式：`uri`
</ResponseField>

<ResponseField name="request.style_ref[].weight" type="number">
  图像引用的权重
</ResponseField>

<ResponseField name="state" type="string">
  生成的状态

  可选值：`queued`、`dreaming`、`completed`、`failed`
</ResponseField>

## 示例

### 输入

```json theme={null}
{
  "aspect_ratio": "1:1",
  "prompt": "a red circle on a plain white background"
}
```

### 输出

```json theme={null}
{
  "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 会过期](/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>
