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

# 将 Aleph 2 与 Comfy Router 配合使用

> 通过 Comfy Router 调用 runway/aleph2：端点、请求结构以及 Router 返回的响应。

`runway/aleph2` 的 API 参考，由 Comfy Router 从 Runway 提供。

## 快速开始

在[你的 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：** `runway/aleph2`

**端点：** `POST https://api.comfy.org/v2/models/runway/aleph2`

<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(
              "runway/aleph2",
              {
                  "promptText": "recolor the scene in cool blue tones",
                  "videoUri": "https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4",
              },
          )

      print(result)
      ```

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

      // 从环境变量中读取 COMFY_API_KEY。
      // SDK 会自动创建幂等键，并在自动重试时复用它。
      const { data } = await comfy.models.run("runway/aleph2", {
        promptText: "recolor the scene in cool blue tones",
        videoUri: "https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/runway/aleph2 \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"promptText\": \"recolor the scene in cool blue tones\", \"videoUri\": \"https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4\"}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="加入队列，稍后收集">
    同一个请求体，发送到 `POST https://api.comfy.org/v2/models/runway/aleph2/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(
                  "runway/aleph2",
                  {
                      "promptText": "recolor the scene in cool blue tones",
                      "videoUri": "https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4",
                  },
              )
              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("runway/aleph2", {
        promptText: "recolor the scene in cool blue tones",
        videoUri: "https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4",
      });
      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/runway/aleph2/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"promptText\": \"recolor the scene in cool blue tones\", \"videoUri\": \"https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4\"}"

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

      # 3. 收集。仍在运行时返回 202 及状态响应体；完成后返回 200 及模型的原生输出。
      curl https://api.comfy.org/v2/models/runway/aleph2/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## Schema

### 输入

<ParamField body="contentModeration" type="object">
  影响内容审核系统行为的设置。
</ParamField>

<ParamField body="contentModeration.publicFigureThreshold" type="string">
  当设置为 `low` 时，内容审核系统对于阻止生成包含可识别公众人物的内容会不那么严格。

  可能的值：`auto`、`low`
</ParamField>

<ParamField body="keyframes" type="object[]">
  放置在输入视频中特定时间点的定时引导图像。最多 5 个关键帧。
</ParamField>

<ParamField body="model" type="string">
  用于生成的模型。在 Comfy Router 路由 `POST /v2/models/runway/{model}` 上，该字段由路径提供，禁止发送；在 v1 的 `POST /proxy/runway/video_to_video` 路由上，该字段为必填，且限定为 RunwayVideoToVideoModelEnum（`aleph2`）。
</ParamField>

<ParamField body="promptImage" type="object[]">
  一个最多包含 5 个图像关键帧的列表，用于在视频中的特定时间点引导编辑。
</ParamField>

<ParamField body="promptImage[].position" type="`first`, `last` | object" required>
  该图像在输出视频中应用的位置。
</ParamField>

<ParamField body="promptImage[].uri" type="string" required>
  包含编码图像的 HTTPS URL、Runway 或 data URI。
</ParamField>

<ParamField body="promptText" type="string" required>
  一个非空字符串，最多 1000 个字符，描述输出中应出现的内容。
</ParamField>

<ParamField body="seed" type="integer">
  用于生成的随机种子。

  范围：`0` 到 `4294967295`

  格式：`int64`
</ParamField>

<ParamField body="videoUri" type="string" required>
  要编辑的输入视频（HTTPS URL、Runway 上传 URI 或 data URI）。时长必须不超过 30 秒。
</ParamField>

由 Router 在 `GET /v2/models/runway/aleph2/openapi.json` 提供的 schema 生成，该文档与请求到达提供商之前用于校验调用的文档相同。

### 输出

<ResponseField name="createdAt" type="string (date-time)" required>
  任务创建时间戳

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

<ResponseField name="id" type="string" required>
  任务 ID
</ResponseField>

<ResponseField name="output" type="string[]">
  已完成生成的资源 URL。对于 `runway/gen4_turbo` 和 `runway/aleph2`，每个元素都是一个视频 URL。任务成功终止后提供；该列表就是结果本身。
</ResponseField>

<ResponseField name="progress" type="number">
  介于 0 和 1 之间的浮点值，表示任务的进度。仅在状态为 RUNNING 时可用。

  范围：`0` 到 `1`

  格式：`float`
</ResponseField>

<ResponseField name="status" type="string" required>
  Runway 任务可能的状态。

  可能的值：`SUCCEEDED`、`RUNNING`、`FAILED`、`PENDING`、`CANCELLED`、`THROTTLED`
</ResponseField>

## 示例

### 输入

```json theme={null}
{
  "promptText": "recolor the scene in cool blue tones",
  "videoUri": "https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4"
}
```

### 输出

```json theme={null}
{
  "createdAt": "2027-01-01T00:00:00Z",
  "id": "5f7c1b28-9a03-4e61-8d2f-1b2c3d4e5f60",
  "output": [
    "https://example.invalid/runway/gen4_turbo/generated.mp4"
  ],
  "status": "SUCCEEDED"
}
```

## 发布前须知

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>
