> ## 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 で Grok Imagine Video を使用する

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

`xai/grok-imagine-video` の API リファレンスです。xAI 提供のモデルを 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:** `xai/grok-imagine-video`

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

<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(
              "xai/grok-imagine-video",
              {
                  "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";

      // 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("xai/grok-imagine-video", {
        duration: 4,
        prompt: "a single red maple leaf falling onto still water, slow motion",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/xai/grok-imagine-video \
        -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="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(
              "xai/grok-imagine-video",
              {
                  "duration": 4,
                  "prompt": "a single red maple leaf falling onto still water, slow motion",
              },
          )
          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("xai/grok-imagine-video", {
        duration: 4,
        prompt: "a single red maple leaf falling onto still water, slow motion",
      });
      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/xai/grok-imagine-video/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. 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/xai/grok-imagine-video/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/xai/grok-imagine-video/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/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 USD セントは 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",
  "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 が入力を拒否したことを意味します。生成されたアセットは [結果 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>
