> ## Documentation Index
> Fetch the complete documentation index at: https://dripart-willie-des-1087-router-migration-block.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Comfy Router로 Grok Imagine Image 사용하기

> Comfy Router를 통해 xai/grok-imagine-image를 호출합니다: 엔드포인트, 요청 형태, 그리고 Router가 반환하는 응답을 설명합니다.

Comfy Router가 xAI로부터 제공하는 `xai/grok-imagine-image`의 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 스니펫은 원시 HTTP를 통한 동일한 호출입니다.

**모델 ID:** `xai/grok-imagine-image`

**엔드포인트:** `POST https://api.comfy.org/v2/models/xai/grok-imagine-image`

<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",
              {
                  "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", {
        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 \
        -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">
    동일한 본문을 `POST https://api.comfy.org/v2/models/xai/grok-imagine-image/requests` 로 보냅니다. Router는 실행이 접수되는 즉시 `201` 과 `request_id` 를 응답하며, 결과는 준비가 되는 대로 이 프로세스나 다른 프로세스에서 수집할 수 있습니다. 상태, 취소, 수집 방법은 [Queued delivery](/ko/development/comfy-router/queue) 를 참고하세요.

    <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",
              {
                  "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", {
        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/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/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/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는 아웃바운드 요청에서 이 값을 `url`로 강제 변환합니다. Comfy Router 디스패치(`POST /v2/models/xai/{model}`)와 이 `/proxy/` 경로 모두에서 마찬가지인데, 어느 쪽이든 이미지 결과가 다시 호스팅된 URL로 제공되기 때문입니다. 이 필드는 거부되지 않고 허용된 뒤 무시됩니다. 보내든 생략하든 응답은 동일합니다.

  가능한 값: `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/openapi.json`에서 제공하는 스키마를 기반으로 생성되었으며, 이는 요청이 공급자에게 도달하기 전에 호출을 검증하는 데 사용하는 것과 동일한 문서입니다.

### 출력

<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 ticks 단위로 나타냅니다(10,000,000,000 ticks = 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가 공급자를 호출하기 전에 입력을 거부했음을 의미하고, `413`은 요청 본문이 Router가 허용하는 크기보다 컸음을 의미합니다. [결과 URL이 만료](/ko/development/comfy-router/reference#결과-에셋)될 수 있으므로 생성된 에셋은 즉시 다운로드하세요.

위의 필드 설명에 명시된 크기 제한은 해당 필드에 대한 공급자 자체의 한도이며, 공급자 사양에서 인용한 것입니다. Router는 전체 요청 본문에 별도의 상한을 적용하며, base64로 인코딩된 미디어도 여기에 포함됩니다. [요청 본문 크기](/ko/development/comfy-router/limitations)를 참고하세요.

<CardGroup cols={3}>
  <Card title="헤더" icon="list" href="/ko/development/comfy-router/headers">
    인증, 멱등성, 요청 ID, 오류 분류, 재시도 간격, 지출 한도.
  </Card>

  <Card title="Router API 사용" icon="code" href="/ko/development/comfy-router/api">
    모델 검색, 검증 오류, 재시도, 과금.
  </Card>

  <Card title="제한 사항" icon="triangle-exclamation" href="/ko/development/comfy-router/limitations">
    Router가 현재 지원하지 않는 기능과 대신 사용할 방법.
  </Card>
</CardGroup>
