> ## Documentation Index
> Fetch the complete documentation index at: https://dripart-chore-sync-comfy-api-v2-spec.mintlify.site/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)中创建密钥，并将其导出为 `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>
  <Tab title="Wait for the result">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # Reads COMFY_API_KEY from the environment.
      # The SDK automatically creates an idempotency key and reuses it for automatic retries.
      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";

      // Reads COMFY_API_KEY from the environment.
      // The SDK automatically creates an idempotency key and reuses it for automatic retries.
      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="Queue and collect later">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # Reads COMFY_API_KEY from the environment.
      # Each submit() call mints its own Idempotency-Key and reuses it for automatic retries.
      with Comfy() as client:
          handle = 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)  # with the model ID, all another process needs

          # Poll until the request completes, waiting the Retry-After the server names.
          for update in handle.iter_events():
              print(update.status, update.queue_position)

          # The provider's own payload, the same value models.run() returns.
          # A request that failed or was cancelled raises the typed Router error here.
          result = handle.get()

      print(result)
      ```

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

      // Reads COMFY_API_KEY from the environment.
      // Each submit() call mints its own Idempotency-Key and reuses it for automatic retries.
      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); // with the model ID, all another process needs

      // Poll until the request completes, waiting the Retry-After the server names.
      for await (const update of handle.events()) {
        console.log(update.status, update.queuePosition);
      }

      // The same result models.run() returns. A request that failed or was cancelled rejects here.
      const result = await handle.get();

      console.log(result.data);
      ```

      ```bash cURL theme={null}
      # 1. Submit. Router answers 201 with request_id, status_url, response_url and 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. Poll until status is COMPLETED, waiting the Retry-After seconds each response names.
      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. Collect. 200 with the model's native output, 202 with the status body while it is still running.
      curl https://api.comfy.org/v2/models/luma/photon-1/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## 架构

### 输入

<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 在调用提供商之前就拒绝了输入。生成的资源请及时下载，因为[结果链接会过期](/zh/development/comfy-router/reference#结果资产)。

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

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

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