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

# 将 Aleph 2 与 Comfy Router 配合使用

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

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

<h2 id="quick-start">
  快速开始
</h2>

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

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

<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(
              "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";

      // 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("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="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(
              "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)  # 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("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); // 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/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. 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/runway/aleph2/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/runway/aleph2/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

<h2 id="schema">
  Schema
</h2>

### 输入

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