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

# Grok Imagine Image Pro を Comfy Router で使用する

> Comfy Router 経由で xai/grok-imagine-image-pro を呼び出す: エンドポイント、リクエストの形状、Router が返すレスポンス。

xAI から Comfy Router によって提供される `xai/grok-imagine-image-pro` の API リファレンスです。

## クイックスタート

[Comfy ワークスペース](https://platform.comfy.org/profile/api-keys)でキーを作成し、`COMFY_API_KEY` としてエクスポートします。Python と TypeScript のスニペットは Comfy SDK（`pip install comfy-sdk`、`npm install @comfyorg/sdk`）を使用しています。cURL のスニペットは同じ呼び出しを raw HTTP で行うものです。

**モデル ID:** `xai/grok-imagine-image-pro`

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

<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-image-pro",
              {
                  "n": 1,
                  "prompt": "A single red maple leaf on a plain white background.",
              },
          )

      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-image-pro", {
        n: 1,
        prompt: "A single red maple leaf on a plain white background.",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/xai/grok-imagine-image-pro \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"n\": 1, \"prompt\": \"A single red maple leaf on a plain white background.\"}"
      ```
    </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-image-pro",
              {
                  "n": 1,
                  "prompt": "A single red maple leaf on a plain white background.",
              },
          )
          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-image-pro", {
        n: 1,
        prompt: "A single red maple leaf on a plain white background.",
      });
      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-image-pro/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"n\": 1, \"prompt\": \"A single red maple leaf on a plain white background.\"}"

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

## スキーマ

### 入力

<ParamField body="aspect_ratio" type="string" default="&#x22;auto&#x22;">
  生成される画像のアスペクト比。デフォルトは auto で、プロンプトに最適な比率が自動的に選択されます。

  指定可能な値: `1:1`, `3:4`, `4:3`, `9:16`, `16:9`, `2:3`, `3:2`, `9:19.5`, `19.5:9`, `9:20`, `20:9`, `1:2`, `2:1`, `auto`
</ParamField>

<ParamField body="model" type="string" default="&#x22;grok-imagine-image&#x22;">
  使用するモデル。対応: grok-imagine-image（デフォルト）、grok-imagine-image-pro、grok-imagine-image-quality、grok-imagine-image-2.0。非推奨の -beta ID は GA モデルへのエイリアスです。
</ParamField>

<ParamField body="n" type="integer" default="1">
  生成する画像の数

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

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

<ParamField body="quality" type="string">
  出力画像の品質。grok-imagine-image-2.0 では価格ティアを選択します（low/medium、デフォルトは medium）。その他のモデルでは現在無視されます。

  指定可能な値: `low`, `medium`, `high`
</ParamField>

<ParamField body="resolution" type="string" default="&#x22;1k&#x22;">
  生成される画像の解像度。デフォルトは 1k。

  指定可能な値: `1k`, `2k`
</ParamField>

<ParamField body="response_format" type="string" default="&#x22;url&#x22;">
  画像を返す際のレスポンス形式。url または b64\_json を指定できます。Comfy Router（`POST /v2/models/xai/{model}`）は、いずれの場合も画像結果を再ホストされた URL として提供するため、送信リクエストではこれを `url` に強制変換します。この `/proxy/` ルートでは記述どおりに扱われます。

  指定可能な値: `url`, `b64_json`
</ParamField>

<ParamField body="size" type="string">
  画像のサイズ（未対応）
</ParamField>

<ParamField body="style" type="string">
  画像のスタイル（未対応）
</ParamField>

<ParamField body="user" type="string">
  エンドユーザーを表す一意の識別子。xAI が不正利用の監視と検出を行うのに役立ちます
</ParamField>

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

### 出力

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

<ResponseField name="data" type="object[]">
  生成された画像オブジェクトのリスト
</ResponseField>

<ResponseField name="data[].b64_json" type="string">
  生成された画像を jpeg エンコーディングで表した base64 エンコード文字列（response\_format が b64\_json の場合）
</ResponseField>

<ResponseField name="data[].mime_type" type="string">
  生成された画像の MIME タイプ（例: image/png、image/jpeg、image/webp）。
</ResponseField>

<ResponseField name="data[].url" type="string">
  生成された画像への URL（response\_format が url の場合）
</ResponseField>

<ResponseField name="usage" type="object">
  画像生成リクエストの使用量情報
</ResponseField>

<ResponseField name="usage.cost_in_usd_ticks" type="integer">
  このリクエストの正確なコスト（USD ティック単位、10,000,000,000 ティック = 1 USD）
</ResponseField>

## 例

### 入力

```json theme={null}
{
  "n": 1,
  "prompt": "A single red maple leaf on a plain white background."
}
```

### 出力

```json theme={null}
{
  "data": [
    {
      "mime_type": "image/jpeg",
      "url": "https://example.invalid/xai/grok-imagine-image/generated.jpg"
    },
    {
      "mime_type": "image/jpeg",
      "url": "https://example.invalid/xai/grok-imagine-image/generated-2.jpg"
    }
  ],
  "usage": {
    "cost_in_usd_ticks": 200000000
  }
}
```

## 出荷前の確認

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>
