> ## 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.

# 搭配 Comfy Router 使用 Ray 3.2

> 通过 Comfy Router 调用 luma_2/ray-3.2：endpoint、请求结构以及 Router 返回的响应。

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

**输入：** 文本、图像、视频 · **输出：** 视频

## 快速开始

在[你的 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_2/ray-3.2`

**端点：** `POST https://api.comfy.org/v2/models/luma_2/ray-3.2`

**等待结果**

```python Python theme={null}
from comfy_sdk import Comfy

# 从环境变量中读取 COMFY_API_KEY。
# SDK 会自动创建幂等键，并在自动重试时复用它。
with Comfy() as client:
    result = client.models.run(
        "luma_2/ray-3.2",
        {
            "prompt": "a paper boat drifting across a plain white background",
            "type": "video",
            "video": {
                "duration": "5s",
                "resolution": "360p",
            },
        },
    )

print(result)
```

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

// 从环境变量中读取 COMFY_API_KEY。
// SDK 会自动创建幂等键，并在自动重试时复用它。
const { data } = await comfy.models.run("luma_2/ray-3.2", {
  prompt: "a paper boat drifting across a plain white background",
  type: "video",
  video: {
    duration: "5s",
    resolution: "360p",
  },
});

console.log(data);
```

```bash cURL theme={null}
curl https://api.comfy.org/v2/models/luma_2/ray-3.2 \
  -H "X-API-Key: $COMFY_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d "{\"prompt\": \"a paper boat drifting across a plain white background\", \"type\": \"video\", \"video\": {\"duration\":\"5s\",\"resolution\":\"360p\"}}"
```

**排队并稍后收集**

同一个请求体，发送到 `POST https://api.comfy.org/v2/models/luma_2/ray-3.2/requests`。只要运行被接纳，Router 就会立即返回 `201` 和 `request_id`，结果就绪后即可从当前进程或其他进程中收集。[队列投递](https://docs.comfy.org/zh/development/comfy-router/queue.md)介绍了状态、取消和收集的流程。

```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_2/ray-3.2",
            {
                "prompt": "a paper boat drifting across a plain white background",
                "type": "video",
                "video": {
                    "duration": "5s",
                    "resolution": "360p",
                },
            },
        )
        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_2/ray-3.2", {
  prompt: "a paper boat drifting across a plain white background",
  type: "video",
  video: {
    duration: "5s",
    resolution: "360p",
  },
});
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_2/ray-3.2/requests \
  -H "X-API-Key: $COMFY_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d "{\"prompt\": \"a paper boat drifting across a plain white background\", \"type\": \"video\", \"video\": {\"duration\":\"5s\",\"resolution\":\"360p\"}}"

# 2. 轮询直到 status 为 COMPLETED，并按每个响应给出的 Retry-After 秒数等待。
REQUEST_ID="<request_id from the 201 body>"
curl -i https://api.comfy.org/v2/models/luma_2/ray-3.2/requests/$REQUEST_ID/status \
  -H "X-API-Key: $COMFY_API_KEY"

# 3. 收集。请求完成时返回 200 和模型的原始输出；仍在运行时返回 202 和状态正文。
curl https://api.comfy.org/v2/models/luma_2/ray-3.2/requests/$REQUEST_ID \
  -H "X-API-Key: $COMFY_API_KEY"
```

## Schema

### 输入

**aspect\_ratio** `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`

**image\_ref** `object[]`

用于风格/内容引导的参考图像。type 为 'image' 时最多 9 张，type 为 'image\_edit' 时最多 8 张。

**image\_ref\[].data** `string`

Base64 编码的图像或视频数据

**image\_ref\[].generation\_id** `string`

先前已完成生成的 UUID，用于复用为来源。供 ray-3.2 video\_edit / video\_reframe 使用。

**image\_ref\[].media\_type** `string`

MIME 类型。与 data 一起使用时为必填（对于视频来源还需与 url 一起使用，例如 video\_edit / video\_reframe 上的 video/mp4）。

**image\_ref\[].url** `string`

可公开访问的图像或视频 URL

**model** `string`

要使用的模型。uni-1 / uni-1-max 用于图像生成，ray-3.2 用于视频生成、编辑和重新取景。

**output\_format** `string`

输出图像格式

可能的值：`png`、`jpeg`

**prompt** `string` *required*

文本提示词

**source** `object`

对图像或视频的引用。用于风格/内容引导、引导式生成、video-edit/video-reframe 来源以及引导关键帧。请提供 generation\_id、url 或 data 中的恰好一个。

**source.data** `string`

Base64 编码的图像或视频数据

**source.generation\_id** `string`

先前已完成生成的 UUID，用于复用为来源。供 ray-3.2 video\_edit / video\_reframe 使用。

**source.media\_type** `string`

MIME 类型。与 data 一起使用时为必填（对于视频来源还需与 url 一起使用，例如 video\_edit / video\_reframe 上的 video/mp4）。

**source.url** `string`

可公开访问的图像或视频 URL

**style** `string`

风格预设

可能的值：`auto`、`manga`

**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`

**video** `object`

ray-3.2 的视频输出设置。此处仅建模影响验证和计费的字段；其他字段（编辑控制项、source\_position）将原样转发给 Luma。

**video.duration** `string`

ray-3.2 video / video\_edit 的片段时长。默认为 5s。HDR 生成（type 为 video）仅限 5s。

可能的值：`5s`、`10s`

**video.end\_frame** `object`

对图像或视频的引用。用于风格/内容引导、引导式生成、video-edit/video-reframe 来源以及引导关键帧。请提供 generation\_id、url 或 data 中的恰好一个。

**video.end\_frame.data** `string`

Base64 编码的图像或视频数据

**video.end\_frame.generation\_id** `string`

先前已完成生成的 UUID，用于复用为来源。供 ray-3.2 video\_edit / video\_reframe 使用。

**video.end\_frame.media\_type** `string`

MIME 类型。与 data 一起使用时为必填（对于视频来源还需与 url 一起使用，例如 video\_edit / video\_reframe 上的 video/mp4）。

**video.end\_frame.url** `string`

可公开访问的图像或视频 URL

**video.exr\_export** `boolean`

暂不可用：在 Luma 提供 EXR 交付之前，带 `exr_export=true` 的请求会以 400 拒绝。将来会在 MP4 之外同时导出 EXR 文件（需要 hdr 为 true）。video\_reframe 下会被拒绝。

**video.hdr** `boolean`

以 HDR 渲染。需要 720p/1080p。video\_reframe 下会被拒绝。

**video.keyframe\_indexes** `integer[]`

`keyframes` 对应的输出帧位置，长度相同；5s 时为 0–120，10s 时为 0–240。原样转发。

**video.keyframes** `object[]`

引导帧图像（1–64），与 start\_frame/end\_frame 互斥。按请求的时长计费；keyframes 请求绝不会是单关键帧延长。

**video.keyframes\[].data** `string`

Base64 编码的图像或视频数据

**video.keyframes\[].generation\_id** `string`

先前已完成生成的 UUID，用于复用为来源。供 ray-3.2 video\_edit / video\_reframe 使用。

**video.keyframes\[].media\_type** `string`

MIME 类型。与 data 一起使用时为必填（对于视频来源还需与 url 一起使用，例如 video\_edit / video\_reframe 上的 video/mp4）。

**video.keyframes\[].url** `string`

可公开访问的图像或视频 URL

**video.loop** `boolean`

循环播放生成的片段。仅创建时可用（type 为 video）。

**video.resolution** `string`

ray-3.2 视频的输出分辨率。默认为 720p。360p 为草稿档位。HDR 需要 720p 或 1080p。

可能的值：`360p`、`540p`、`720p`、`1080p`

**video.start\_frame** `object`

对图像或视频的引用。用于风格/内容引导、引导式生成、video-edit/video-reframe 来源以及引导关键帧。请提供 generation\_id、url 或 data 中的恰好一个。

**video.start\_frame.data** `string`

Base64 编码的图像或视频数据

**video.start\_frame.generation\_id** `string`

先前已完成生成的 UUID，用于复用为来源。供 ray-3.2 video\_edit / video\_reframe 使用。

**video.start\_frame.media\_type** `string`

MIME 类型。与 data 搭配时为必填（对于视频来源，还需搭配 url，例如在 video\_edit / video\_reframe 上使用 video/mp4）。

**video.start\_frame.url** `string`

可公开访问的图像或视频 URL

**web\_search** `boolean`

启用网络搜索依据

根据 Router 在 `GET /v2/models/luma_2/ray-3.2/openapi.json` 提供的 schema 生成，该文档也是它在请求到达提供商之前用于校验调用的同一份文档。

### 输出

**created\_at** `string`

创建时间戳

**failure\_code** `string`

供程序化处理的机器可读失败代码

可能的值：`content_moderated`、`generation_failed`、`budget_exhausted`、`output_not_found`

**failure\_reason** `string`

人类可读的失败描述，仅在生成状态为 FAILED 时填充。生成成功时为 `null`。

**id** `string`

生成标识符

**model** `string`

使用的模型

**output** `object[]`

一条生成的输出条目

**output\[].type** `string`

媒体类型（例如 image）

**output\[].url** `string`

预签名 URL（1 小时过期）

**state** `string`

生成的当前状态

可能的值：`queued`、`processing`、`completed`、`failed`

**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`

## 示例

### 输入

```json theme={null}
{
  "prompt": "a paper boat drifting across a plain white background",
  "type": "video",
  "video": {
    "duration": "5s",
    "resolution": "360p"
  }
}
```

### 输出

```json theme={null}
{
  "created_at": "2027-01-01T00:00:00Z",
  "failure_code": null,
  "failure_reason": null,
  "id": "gen-luma-agents-ray32-9c1f3a0e7d52",
  "model": "ray-3.2",
  "output": [
    {
      "type": "video",
      "url": "https://example.invalid/luma_2/ray-3.2/generated.mp4"
    }
  ],
  "state": "completed",
  "type": "video"
}
```

## 发布前须知

SDK 会生成 `Idempotency-Key` 并在自动重试中复用它。手动重试时，请复用原始 key。Router 最长可保持连接 10 分钟。

请求失败时，Router 会发送 `X-Comfy-Error-Type` 响应头说明原因。`422` 表示 Router 在调用提供商之前就拒绝了输入，`413` 表示请求体超出了 Router 可接受的大小。已生成的资源请及时下载，因为[结果 URL 会过期](https://docs.comfy.org/zh/development/comfy-router/reference.md#结果资产)。

上文任何字段描述中提到的尺寸限制，都是提供商对该字段自身的限定，引自提供商的规范。Router 会对整个请求体另行设置上限，base64 编码的媒体内容也计入其中：参见[请求体大小](https://docs.comfy.org/zh/development/comfy-router/limitations.md)。

本页记录的是通过 Comfy Router 调用的某一个合作伙伴模型。同一个 `comfy-sdk` / `@comfyorg/sdk` 包还提供第二个客户端，用于在 Comfy Cloud 上运行完整的 ComfyUI 工作流图：`Comfy(api_key=...)` / `new Comfy({ apiKey })`，并带有 `client.workflows`、`client.assets` 和 `client.jobs`。请参阅 [Comfy SDKs](https://docs.comfy.org/zh/development/api-development/sdks.md)。

> **[请求头](https://docs.comfy.org/zh/development/comfy-router/headers.md)**
>
> 身份验证、幂等性、请求 ID、错误分类、重试节奏、消费限额。

> **[使用 Router API](https://docs.comfy.org/zh/development/comfy-router/api.md)**
>
> 模型发现、验证错误、重试与计费。

> **[限制](https://docs.comfy.org/zh/development/comfy-router/limitations.md)**
>
> Router 目前不支持的功能，以及替代方案。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.