> ## Documentation Index
> Fetch the complete documentation index at: https://dripart-chore-mintlify-theme-mint.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Comfy Router で Grok Imagine Video 1.5 Preview を使う

> Comfy Router 経由で xai/grok-imagine-video-1.5-preview を呼び出します: エンドポイント、リクエストの形状、Router が返すレスポンスについて説明します。

`xai/grok-imagine-video-1.5-preview` の API リファレンス。Comfy Router が xAI から提供しています。

## クイックスタート

お使いの [Comfy ワークスペース](https://platform.comfy.org/profile/api-keys?onboarding=router)でキーを作成し、`COMFY_API_KEY` としてエクスポートします。Python、TypeScript、Swift のスニペットは Comfy SDK（`pip install comfy-sdk`、`npm install @comfyorg/sdk`、および [`ComfySwiftSDK`](https://github.com/Comfy-Org/comfy-swift-sdk) Swift パッケージ）を使用しています。cURL のスニペットは、同じ呼び出しを生の HTTP で実行するものです。

**モデル ID:** `xai/grok-imagine-video-1.5-preview`

**エンドポイント:** `POST https://api.comfy.org/v2/models/xai/grok-imagine-video-1.5-preview`

<Tabs>
  <Tab title="結果を待つ">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # 環境変数から COMFY_API_KEY を読み取ります。
      # SDK は自動的に冪等キーを作成し、自動リトライのために再利用します。
      with Comfy() as client:
          result = client.models.run(
              "xai/grok-imagine-video-1.5-preview",
              {
                  "duration": 4,
                  "prompt": "a single red maple leaf falling onto still water, slow motion",
              },
          )

      print(result)
      ```

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

      // 環境変数から COMFY_API_KEY を読み取ります。
      // SDK は自動的に冪等キーを作成し、自動リトライのために再利用します。
      const { data } = await comfy.models.run("xai/grok-imagine-video-1.5-preview", {
        duration: 4,
        prompt: "a single red maple leaf falling onto still water, slow motion",
      });

      console.log(data);
      ```

      ```swift Swift theme={null}
      import Foundation
      import ComfySwiftSDK

      // 環境変数から COMFY_API_KEY を読み取ります。
      // SDK は呼び出しごとに冪等キーを発行し、自動リトライのために再利用します。
      let client = ComfyCloudClient(apiKey: ProcessInfo.processInfo.environment["COMFY_API_KEY"]!)
      let result = try await client.models.run(
          "xai/grok-imagine-video-1.5-preview",
          input: [
              "duration": 4,
              "prompt": "a single red maple leaf falling onto still water, slow motion",
          ]
      )

      print(result.output)
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/xai/grok-imagine-video-1.5-preview \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"duration\": 4, \"prompt\": \"a single red maple leaf falling onto still water, slow motion\"}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="キューに送信して後で取得">
    同じボディを `POST https://api.comfy.org/v2/models/xai/grok-imagine-video-1.5-preview/requests` に送信します。Router は実行が受け付けられ次第 `201` と `request_id` を返し、結果は準備が整った時点で、このプロセスからでも別のプロセスからでも取得できます。ステータス、キャンセル、結果の取得の詳細は [キュー配信](/ja/development/comfy-router/queue) を参照してください。

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

      # 環境変数から COMFY_API_KEY を読み取ります。
      # submit() を呼び出すたびに独自の Idempotency-Key が発行され、自動リトライでも再利用されます。
      with Comfy() as client:
          handle = client.models.submit(
              "xai/grok-imagine-video-1.5-preview",
              {
                  "duration": 4,
                  "prompt": "a single red maple leaf falling onto still water, slow motion",
              },
          )
          print("request_id:", handle.request_id)  # モデル ID と合わせれば、別のプロセスに必要な情報はこれだけです

          # リクエストが完了するまでポーリングし、サーバーが指定する Retry-After の秒数だけ待機します。
          for update in handle.iter_events():
              print(update.status, update.queue_position)

          # プロバイダー自身のペイロードで、models.run() が返す値と同じです。
          # 失敗またはキャンセル済みのリクエストは、ここで型付きの Router エラーを送出します。
          result = handle.get()

      print(result)
      ```

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

      // 環境変数から COMFY_API_KEY を読み取ります。
      // submit() を呼び出すたびに独自の Idempotency-Key が発行され、自動リトライでも再利用されます。
      const handle = await comfy.models.submit("xai/grok-imagine-video-1.5-preview", {
        duration: 4,
        prompt: "a single red maple leaf falling onto still water, slow motion",
      });
      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);
      ```

      ```swift Swift theme={null}
      import Foundation
      import ComfySwiftSDK

      // 環境変数から COMFY_API_KEY を読み取ります。
      // submit() を呼び出すたびに独自の Idempotency-Key が発行され、自動リトライでも再利用されます。
      let client = ComfyCloudClient(apiKey: ProcessInfo.processInfo.environment["COMFY_API_KEY"]!)
      let handle = try await client.models.submit(
          "xai/grok-imagine-video-1.5-preview",
          input: [
              "duration": 4,
              "prompt": "a single red maple leaf falling onto still water, slow motion",
          ]
      )
      print("requestId:", handle.requestId)  // モデル ID と合わせれば、別のプロセスに必要な情報はこれだけです

      // リクエストが完了するまでポーリングし、サーバーが指定する Retry-After の秒数だけ待機します。
      for try await update in handle.events() {
          print(update.state.rawValue, update.queuePosition.map(String.init) ?? "unknown")
      }

      // プロバイダー自身のペイロードで、models.run() が返す値と同じです。
      // 失敗またはキャンセル済みのリクエストは、ここで型付きの Router エラーをスローします。
      let result = try await handle.result()

      print(result.output)
      ```

      ```bash cURL theme={null}
      # 1. 送信。Router は request_id、status_url、response_url、cancel_url とともに 201 を返します。
      curl https://api.comfy.org/v2/models/xai/grok-imagine-video-1.5-preview/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"duration\": 4, \"prompt\": \"a single red maple leaf falling onto still water, slow motion\"}"

      # 2. ステータスが COMPLETED になるまでポーリングし、各レスポンスが指定する Retry-After の秒数だけ待機します。
      REQUEST_ID="<request_id from the 201 body>"
      curl -i https://api.comfy.org/v2/models/xai/grok-imagine-video-1.5-preview/requests/$REQUEST_ID/status \
        -H "X-API-Key: $COMFY_API_KEY"

      # 3. 取得。モデルのネイティブ出力とともに 200、まだ実行中はステータスボディとともに 202 を返します。
      curl https://api.comfy.org/v2/models/xai/grok-imagine-video-1.5-preview/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## スキーマ

### 入力

<ParamField body="aspect_ratio" type="string" default="&#x22;16:9&#x22;">
  生成されるビデオのアスペクト比

  指定可能な値: `1:1`、`16:9`、`9:16`、`4:3`、`3:4`、`3:2`、`2:3`
</ParamField>

<ParamField body="duration" type="integer" default="8">
  ビデオの再生時間（秒）。範囲 \[1, 15]。デフォルトは 8。

  範囲: `1` から `15`
</ParamField>

<ParamField body="image" type="object">
  xAI エンドポイント用の入力画像オブジェクト
</ParamField>

<ParamField body="image.type" type="string">
  画像入力のタイプ

  指定可能な値: `image_url`
</ParamField>

<ParamField body="image.url" type="string" required>
  入力画像の URL（公開 URL または base64 エンコードされたデータ URI）
</ParamField>

<ParamField body="model" type="string">
  使用するモデル。対応: grok-imagine-video（デフォルト）、grok-imagine-video-1.5-preview、grok-imagine-video-1.5。非推奨の grok-imagine-video-beta ID は grok-imagine-video のエイリアスです。
</ParamField>

<ParamField body="output" type="object">
  生成されたビデオの任意の出力先
</ParamField>

<ParamField body="prompt" type="string" required>
  ビデオ生成用のプロンプト。最大 4,096 文字。
</ParamField>

<ParamField body="reference_images" type="object[]">
  ビデオ生成を誘導する 1 つ以上の参照画像（参照から動画モード）。image とは同時に指定できません。Router は application/json のみを転送し、このオブジェクトも XAIImageObject も file\_id を受け付けないため、このルートではファイルベースの画像入力はサポートされません。
</ParamField>

<ParamField body="reference_images[].url" type="string" required>
  参照画像の URL。HTTPS URL（公開）または base64 エンコードされたデータ URL（例: data:image/jpeg;base64,...）をサポートします。
</ParamField>

<ParamField body="resolution" type="string">
  出力ビデオの解像度
</ParamField>

<ParamField body="size" type="string">
  出力ビデオのサイズ
</ParamField>

<ParamField body="user" type="string">
  エンドユーザーを表す一意の識別子
</ParamField>

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

### 出力

<ResponseField name="block_reason" type="string">
  リクエストが入力モデレーションによってブロックされた場合、そのブロック理由が含まれます
</ResponseField>

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

<ResponseField name="status" type="string">
  遅延リクエストのステータス: 「pending」または「done」

  指定可能な値: `pending`、`done`
</ResponseField>

<ResponseField name="usage" type="object">
  ビデオ生成リクエストの使用情報
</ResponseField>

<ResponseField name="usage.cost_in_usd_ticks" type="integer">
  このリクエストのコストを USD ティックで表したもの。1 米セントは 100,000,000 ティックに等しく、1 米ドルは 10,000,000,000 ティックに等しくなります。
</ResponseField>

<ResponseField name="video" type="object">
  xAI によって生成されたビデオ
</ResponseField>

<ResponseField name="video.duration" type="integer">
  生成されたビデオの再生時間（秒）
</ResponseField>

<ResponseField name="video.respect_moderation" type="boolean">
  モデルによって生成されたビデオがモデレーションルールに準拠しているかどうか
</ResponseField>

<ResponseField name="video.url" type="string">
  生成されたビデオのダウンロード URL。Router はビデオを Comfy ストレージに再ホストしてこのフィールドを書き換えるため、通常は最大 24 時間有効な Comfy 署名付き URL になります。発行時に 24 時間の署名が付き、23 時間のメモから再生されるため、後でポーリングすると残り 1 時間しかない URL が返されることがあります。再ホストを実行できなかった場合、このフィールドには代わりに xAI 自身の短命な URL が保持されます。NULLABLE: `url` が空の成功は、生成が完了したことを意味しません。いずれの場合もリンクは失効するため、URL を保存するのではなくビデオをダウンロードしてください。
</ResponseField>

## 例

### 入力

```json theme={null}
{
  "duration": 4,
  "prompt": "a single red maple leaf falling onto still water, slow motion"
}
```

### 出力

```json theme={null}
{
  "model": "grok-imagine-video-1.5",
  "status": "done",
  "usage": {
    "cost_in_usd_ticks": 3500000000
  },
  "video": {
    "duration": 4,
    "respect_moderation": true,
    "url": "https://example.invalid/xai/grok-imagine-video/generated.mp4"
  }
}
```

## 出荷前の確認

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

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

上記のフィールド説明に記載されているサイズ制限は、プロバイダーの仕様から引用した、そのフィールドに対するプロバイダー自身の上限です。Router はリクエスト本文全体に対して別の上限を適用し、base64 エンコードされたメディアもこれにカウントされます。[リクエスト本文のサイズ](/ja/development/comfy-router/limitations) を参照してください。

このページは、Comfy Router 経由で呼び出す 1 つのパートナーモデルについて説明しています。同じ `comfy-sdk` / `@comfyorg/sdk` パッケージには、Comfy Cloud 上で ComfyUI のワークフローグラフ全体を実行するための 2 つ目のクライアントも含まれています: `Comfy(api_key=...)` / `new Comfy({ apiKey })`、および `client.workflows`、`client.assets`、`client.jobs`。[Comfy SDKs](/ja/development/api-development/sdks) を参照してください。

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

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

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