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

# Comfy Router で Ray 2 を使用する

> Comfy Router を通じて luma/ray-2 を呼び出す: エンドポイント、リクエストの形状、Router が返すレスポンス。

`luma/ray-2` の API リファレンス。Luma から Comfy Router によって提供されます。

## クイックスタート

[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/ray-2`

**エンドポイント:** `POST https://api.comfy.org/v2/models/luma/ray-2`

<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/ray-2",
              {
                  "aspect_ratio": "16:9",
                  "duration": "5s",
                  "prompt": "a single red maple leaf resting on a plain white background",
                  "resolution": "540p",
              },
          )

      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/ray-2", {
        aspect_ratio: "16:9",
        duration: "5s",
        prompt: "a single red maple leaf resting on a plain white background",
        resolution: "540p",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/luma/ray-2 \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"aspect_ratio\": \"16:9\", \"duration\": \"5s\", \"prompt\": \"a single red maple leaf resting on a plain white background\", \"resolution\": \"540p\"}"
      ```
    </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/ray-2",
              {
                  "aspect_ratio": "16:9",
                  "duration": "5s",
                  "prompt": "a single red maple leaf resting on a plain white background",
                  "resolution": "540p",
              },
          )
          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/ray-2", {
        aspect_ratio: "16:9",
        duration: "5s",
        prompt: "a single red maple leaf resting on a plain white background",
        resolution: "540p",
      });
      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/ray-2/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"aspect_ratio\": \"16:9\", \"duration\": \"5s\", \"prompt\": \"a single red maple leaf resting on a plain white background\", \"resolution\": \"540p\"}"

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

## スキーマ

### 入力

<ParamField body="aspect_ratio" type="string" required 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)">
  生成の callback URL。生成が dreaming、完了、または失敗したときに、Generation オブジェクトを含む POST リクエストが callback URL に送信されます

  フォーマット: `uri`
</ParamField>

<ParamField body="duration" type="`5s`, `9s` | string" required />

<ParamField body="generation_type" type="string" default="&#x22;video&#x22;">
  指定可能な値: `video`
</ParamField>

<ParamField body="keyframes" type="object">
  生成のキーフレーム
</ParamField>

<ParamField body="keyframes.frame0" type="object">
  キーフレームは、Generation 参照、Image、または Video のいずれかです
</ParamField>

<ParamField body="keyframes.frame1" type="object">
  キーフレームは、Generation 参照、Image、または Video のいずれかです
</ParamField>

<ParamField body="loop" type="boolean">
  ビデオをループするかどうか
</ParamField>

<ParamField body="model" type="string">
  生成に使用するビデオモデル。Comfy Router のルート `POST /v2/models/luma/{model}` では、このフィールドはパスから供給されるため、送信してはいけません。v1 の `POST /proxy/luma/generations` ルートでは必須であり、LumaVideoModel enum（`ray-2`、`ray-flash-2`）に制限されます。
</ParamField>

<ParamField body="prompt" type="string" required>
  生成のプロンプト
</ParamField>

<ParamField body="resolution" type="`540p`, `720p`, `1080p`, `4k` | string" required />

Router が `GET /v2/models/luma/ray-2/openapi.json` で提供するスキーマから生成されており、これはリクエストがプロバイダーに到達する前に Router が呼び出しを検証する際に使用するドキュメントと同じものです。

### 出力

<ResponseField name="assets" type="object">
  生成のアセット
</ResponseField>

<ResponseField name="assets.image" type="string (uri)">
  画像の URL

  フォーマット: `uri`
</ResponseField>

<ResponseField name="assets.progress_video" type="string (uri)">
  進行状況ビデオの URL

  フォーマット: `uri`
</ResponseField>

<ResponseField name="assets.video" type="string (uri)">
  ビデオの URL

  フォーマット: `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">
  指定可能な値: `video`、`image`
</ResponseField>

<ResponseField name="id" type="string (uuid)">
  生成の ID

  フォーマット: `uuid`
</ResponseField>

<ResponseField name="model" type="string">
  生成に使用されたモデル
</ResponseField>

<ResponseField name="request" type="object">
  生成のリクエスト
</ResponseField>

<ResponseField name="state" type="string">
  生成の状態

  指定可能な値: `queued`、`dreaming`、`completed`、`failed`
</ResponseField>

## 例

### 入力

```json theme={null}
{
  "aspect_ratio": "16:9",
  "duration": "5s",
  "prompt": "a single red maple leaf resting on a plain white background",
  "resolution": "540p"
}
```

### 出力

```json theme={null}
{
  "assets": {
    "video": "https://example.invalid/luma/ray-2/generated.mp4"
  },
  "created_at": "2027-01-01T00:00:00Z",
  "generation_type": "video",
  "id": "3f2a7c1e-8b40-4d59-9f6a-1c2d3e4f5a60",
  "model": "ray-2",
  "state": "completed"
}
```

## 出荷前の確認

SDK は `Idempotency-Key` を生成し、自動リトライで再利用します。手動リトライでは元のキーを再利用してください。Router は最大 10 分間接続を保持できます。

リクエストが失敗すると、Router は理由を示す `X-Comfy-Error-Type` レスポンスヘッダーを送信します。`422` は、プロバイダーを呼び出す前に Router が入力を拒否したことを意味します。生成されたアセットは [結果 URL の有効期限](/ja/development/comfy-router/reference#結果アセット) があるため、早めにダウンロードしてください。

<CardGroup cols={3}>
  <Card title="ヘッダー" icon="list" href="/ja/development/comfy-router/quickstart">
    認証、冪等性、リクエスト ID、エラー分類、リトライ間隔、支出上限。
  </Card>

  <Card title="Router API の利用" icon="code" href="/ja/development/comfy-router/quickstart">
    モデルの検出、バリデーションエラー、リトライ、課金。
  </Card>

  <Card title="制限事項" icon="triangle-exclamation" href="/ja/development/comfy-router/limitations">
    Router が現在対応していないことと、代替手段。
  </Card>
</CardGroup>
