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

# Comfy Router 빠른 시작

> 아무것도 없는 상태에서 Python과 TypeScript로 Comfy Router를 사용해 약 5분 만에 생성된 이미지를 얻는 방법.

<div className="router-quickstart-marker" />

Comfy Router를 사용하면 하나의 Comfy API 키로 `https://api.comfy.org`를 통해 파트너 모델을 호출할 수 있습니다. 모델의 입력을 `POST /v2/models/{provider}/{model}`로 보내고 완료된 결과를 기다리면 됩니다. 이 예시에서는 `bfl/flux-2-pro`로 이미지를 생성합니다.

<Steps>
  <Step title="API 키 생성">
    [Comfy 워크스페이스](https://platform.comfy.org/profile/api-keys)에서 키를 생성하세요. Bash 호환 터미널에서 다음을 설정합니다:

    ```bash theme={null}
    export COMFY_API_KEY="comfyui-..."
    ```

    API 키는 서버나 로컬 환경에 보관하세요. 이 예시는 터미널 또는 서버용이며, 브라우저 JavaScript용이 아닙니다.
  </Step>

  <Step title="이 요청에 사용할 키 저장">
    이 이미지에 대해 이 값을 한 번 생성하세요. 같은 요청을 다시 시도할 때는 이 값을 재사용하세요.

    ```bash theme={null}
    export COMFY_REQUEST_KEY="$(uuidgen)"
    ```

    `uuidgen`을 사용할 수 없다면 다른 UUID 생성기를 사용하세요. 새로운 이미지를 시작할 때는 새 키를 사용하세요.
  </Step>

  <Step title="이미지 생성">
    언어를 선택하고 예시를 실행하세요. 이미지 생성에는 몇 분이 걸릴 수 있습니다.

    <CodeGroup>
      ```bash cURL theme={null}
      curl --max-time 660 \
        https://api.comfy.org/v2/models/bfl/flux-2-pro \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $COMFY_REQUEST_KEY" \
        -H "Content-Type: application/json" \
        -d '{"prompt": "a red teapot on a windowsill, morning light"}'
      ```

      ```python Python theme={null}
      # Python 3.10+
      # Install: python -m pip install "comfy-sdk>=0.1.9"
      # Save as quickstart.py, then run: python quickstart.py

      import os

      from comfy_sdk import Comfy

      # Comfy reads COMFY_API_KEY from the environment.
      with Comfy() as client:
          result = client.models.run(
              "bfl/flux-2-pro",
              {"prompt": "a red teapot on a windowsill, morning light"},
              idempotency_key=os.environ["COMFY_REQUEST_KEY"],
              timeout=660.0,
          )

      print("image:", result["result"]["sample"])
      ```

      ```typescript TypeScript theme={null}
      // Node.js 22+
      // Install: npm install @comfyorg/sdk@^0.1.9 --save-dev tsx
      // Save as quickstart.mts, then run: npx tsx quickstart.mts

      import { comfy } from "@comfyorg/sdk";

      // Comfy reads COMFY_API_KEY from the environment.
      type FluxResult = { result: { sample: string } };
      const idempotencyKey = process.env.COMFY_REQUEST_KEY;
      if (!idempotencyKey) throw new Error("Set COMFY_REQUEST_KEY first.");

      const { data } = await comfy.models.run<FluxResult>(
        "bfl/flux-2-pro",
        { prompt: "a red teapot on a windowsill, morning light" },
        { idempotencyKey, timeoutMs: 660_000 },
      );

      console.log("image:", data.result.sample);
      ```
    </CodeGroup>

    두 SDK 모두 환경 변수에서 `COMFY_API_KEY`를 읽습니다.
  </Step>

  <Step title="결과 읽고 저장하기">
    이 모델의 경우 이미지 URL은 응답 본문의 `result.sample`에 있습니다. 축약된 응답은 다음과 같으며, 아래 URL은 예시일 뿐입니다:

    ```json theme={null}
    {
      "status": "Ready",
      "result": { "sample": "https://example.com/generated-image.jpeg" }
    }
    ```

    반환된 URL을 열거나 다운로드하세요:

    ```bash theme={null}
    curl --fail --location "PASTE_IMAGE_URL_HERE" --output teapot.jpg
    ```

    지체 없이 다운로드하세요. Router는 BFL 에셋을 Comfy 스토리지에 다시 호스팅할 수 있지만, URL은 만료되며 재생(replay)해도 갱신되지 않습니다. 재호스팅이 실패하면 수명이 더 짧은 공급자 URL이 남을 수 있습니다. [결과 에셋](/ko/development/comfy-router/reference#결과-에셋)을 참고하세요.
  </Step>
</Steps>

## 대기 대신 큐 사용하기

`run`은 이미지가 준비될 때까지 연결을 유지합니다. `request_id`를 즉시 받고 이 프로세스 또는 다른 프로세스에서 나중에 결과를 수집하려면 대신 `submit`을 호출하거나(`comfy-sdk` 및 `@comfyorg/sdk` 0.3.0 이상), 동일한 본문을 HTTP로 `POST /v2/models/{provider}/{model}/requests`에 보내세요. 모든 모델 페이지에는 동기식 스니펫 옆에 **Queue and collect later** 탭이 있으며, [큐 전송](/ko/development/comfy-router/queue)에서 상태, 취소, 수집 방법을 설명합니다. 큐 전송은 워크스페이스 단위로 출시되고 있습니다.

## 모델 선택

[Comfy Router를 통해 사용할 수 있는 모델을 찾아보고](/ko/development/comfy-router/models), 각 모델의 입력을 확인한 다음, 이 예시의 모델 ID를 바꾸세요.
