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

# 将 Uni 1 与 Comfy Router 配合使用

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

`luma_2/uni-1` 的 API 参考，由 Comfy Router 从 Luma 2 提供。

## 快速开始

在[你的 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_2/uni-1`

**端点：** `POST https://api.comfy.org/v2/models/luma_2/uni-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_2/uni-1",
              {
                  "prompt": "a red circle on a plain white background",
                  "type": "image",
              },
          )

      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_2/uni-1", {
        prompt: "a red circle on a plain white background",
        type: "image",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/luma_2/uni-1 \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"prompt\": \"a red circle on a plain white background\", \"type\": \"image\"}"
      ```
    </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_2/uni-1",
              {
                  "prompt": "a red circle on a plain white background",
                  "type": "image",
              },
          )
          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_2/uni-1", {
        prompt: "a red circle on a plain white background",
        type: "image",
      });
      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_2/uni-1/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"prompt\": \"a red circle on a plain white background\", \"type\": \"image\"}"

      # 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_2/uni-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_2/uni-1/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## Schema

### 输入

<ParamField body="aspect_ratio" type="string">
  输出宽高比。ray-3.2 视频模型支持其中的 9:16、3:4、1:1、4:3、16:9、21:9 子集。

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

<ParamField body="image_ref" type="object[]">
  用于风格/内容引导的参考图像。type 为 'image' 时最多 9 张，type 为 'image\_edit' 时最多 8 张。
</ParamField>

<ParamField body="image_ref[].data" type="string">
  Base64 编码的图像或视频数据
</ParamField>

<ParamField body="image_ref[].generation_id" type="string">
  先前已完成生成的 UUID，可用作来源复用。由 ray-3.2 video\_edit / video\_reframe 使用。
</ParamField>

<ParamField body="image_ref[].media_type" type="string">
  MIME 类型。与 data 一起使用时必填（对于视频来源还需与 url 一起使用，例如 video\_edit / video\_reframe 上的 video/mp4）。
</ParamField>

<ParamField body="image_ref[].url" type="string">
  可公开访问的图像或视频 URL
</ParamField>

<ParamField body="model" type="string">
  要使用的模型。uni-1 / uni-1-max 用于图像生成，ray-3.2 用于视频生成、编辑和重新取景。
</ParamField>

<ParamField body="output_format" type="string">
  输出图像格式

  可选值：`png`, `jpeg`
</ParamField>

<ParamField body="prompt" type="string" required>
  文本提示词
</ParamField>

<ParamField body="source" type="object">
  对图像或视频的引用。用于风格/内容引导、引导式生成、video-edit/video-reframe 来源以及引导关键帧。generation\_id、url 或 data 中必须且只能提供一个。
</ParamField>

<ParamField body="source.data" type="string">
  Base64 编码的图像或视频数据
</ParamField>

<ParamField body="source.generation_id" type="string">
  先前已完成生成的 UUID，可用作来源复用。由 ray-3.2 video\_edit / video\_reframe 使用。
</ParamField>

<ParamField body="source.media_type" type="string">
  MIME 类型。与 data 一起使用时必填（对于视频来源还需与 url 一起使用，例如 video\_edit / video\_reframe 上的 video/mp4）。
</ParamField>

<ParamField body="source.url" type="string">
  可公开访问的图像或视频 URL
</ParamField>

<ParamField body="style" type="string">
  风格预设

  可选值：`auto`, `manga`
</ParamField>

<ParamField body="type" type="string">
  要执行的生成类型。image/image\_edit 由 uni-1 / uni-1-max 模型生成；video/video\_edit/video\_reframe 由 ray-3.2 模型生成。

  可选值：`image`, `image_edit`, `video`, `video_edit`, `video_reframe`
</ParamField>

<ParamField body="video" type="object">
  ray-3.2 的视频输出设置。此处仅对影响验证和计费的字段建模；其他字段（编辑控制、end\_frame、loop、source\_position）会原样转发给 Luma。
</ParamField>

<ParamField body="video.duration" type="string">
  ray-3.2 video / video\_edit 的片段时长。默认为 5s。HDR 生成（type 为 video）限制为 5s。

  可选值：`5s`, `10s`
</ParamField>

<ParamField body="video.exr_export" type="boolean">
  在 MP4 之外额外导出 EXR 文件。需要 hdr 为 true。video\_reframe 不支持此项。
</ParamField>

<ParamField body="video.hdr" type="boolean">
  以 HDR 渲染。需要 720p/1080p。video\_reframe 不支持此项。
</ParamField>

<ParamField body="video.keyframes" type="object[]">
  引导帧图像。单个关键帧会使 type 为 "video" 的请求变为单关键帧延长，并始终按一个 5s 计费单元计费。
</ParamField>

<ParamField body="video.keyframes[].data" type="string">
  Base64 编码的图像或视频数据
</ParamField>

<ParamField body="video.keyframes[].generation_id" type="string">
  先前已完成生成的 UUID，可用作来源复用。由 ray-3.2 video\_edit / video\_reframe 使用。
</ParamField>

<ParamField body="video.keyframes[].media_type" type="string">
  MIME 类型。与 data 一起使用时必填（对于视频来源还需与 url 一起使用，例如 video\_edit / video\_reframe 上的 video/mp4）。
</ParamField>

<ParamField body="video.keyframes[].url" type="string">
  可公开访问的图像或视频 URL
</ParamField>

<ParamField body="video.loop" type="boolean">
  循环生成的片段。仅创建时可用（type 为 video）。
</ParamField>

<ParamField body="video.resolution" type="string">
  ray-3.2 视频的输出分辨率。默认为 720p。360p 是草稿档位。HDR 需要 720p 或 1080p。

  可选值：`360p`, `540p`, `720p`, `1080p`
</ParamField>

<ParamField body="video.start_frame" type="object">
  对图像或视频的引用。用于风格/内容引导、引导式生成、video-edit/video-reframe 来源以及引导关键帧。generation\_id、url 或 data 中必须且只能提供一个。
</ParamField>

<ParamField body="video.start_frame.data" type="string">
  Base64 编码的图像或视频数据
</ParamField>

<ParamField body="video.start_frame.generation_id" type="string">
  先前已完成生成的 UUID，可用作来源复用。由 ray-3.2 video\_edit / video\_reframe 使用。
</ParamField>

<ParamField body="video.start_frame.media_type" type="string">
  MIME 类型。与 data 一起使用时必填（对于视频来源还需与 url 一起使用，例如 video\_edit / video\_reframe 上的 video/mp4）。
</ParamField>

<ParamField body="video.start_frame.url" type="string">
  可公开访问的图像或视频 URL
</ParamField>

<ParamField body="web_search" type="boolean">
  启用 Google / 搜索引导
</ParamField>

根据 Router 在 `GET /v2/models/luma_2/uni-1/openapi.json` 提供的 schema 生成，该文档与它在请求到达提供商之前用于验证调用的文档相同。

### 输出

<ResponseField name="created_at" type="string">
  创建时间戳
</ResponseField>

<ResponseField name="failure_code" type="string">
  便于程序化处理的机器可读失败代码

  可能的值：`content_moderated`、`generation_failed`、`budget_exhausted`、`output_not_found`
</ResponseField>

<ResponseField name="failure_reason" type="string">
  人类可读的失败描述，仅在生成失败（FAILED）时填充。生成成功时为 `null`。
</ResponseField>

<ResponseField name="id" type="string">
  生成标识符
</ResponseField>

<ResponseField name="model" type="string">
  使用的模型
</ResponseField>

<ResponseField name="output" type="object[]">
  一条生成的输出条目
</ResponseField>

<ResponseField name="output[].type" type="string">
  媒体类型（例如 image）
</ResponseField>

<ResponseField name="output[].url" type="string">
  预签名 URL（1 小时过期）
</ResponseField>

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

  可能的值：`queued`、`processing`、`completed`、`failed`
</ResponseField>

<ResponseField name="type" type="string">
  要执行的生成类型。image/image\_edit 由 uni-1 / uni-1-max 模型生成；video/video\_edit/video\_reframe 由 ray-3.2 模型生成。

  可能的值：`image`、`image_edit`、`video`、`video_edit`、`video_reframe`
</ResponseField>

## 示例

### 输入

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

### 输出

```json theme={null}
{
  "created_at": "2027-01-01T00:00:00Z",
  "failure_code": null,
  "failure_reason": null,
  "id": "gen-luma-agents-3f2a7c1e8b40",
  "model": "uni-1",
  "output": [
    {
      "type": "image",
      "url": "https://example.invalid/luma_2/uni-1/generated.png"
    }
  ],
  "state": "completed",
  "type": "image"
}
```

## 发布前须知

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>
