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

# Krea 2 Medium を Comfy Router で使用する

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

Krea の Comfy Router から提供される `krea/krea-2-medium` の 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:** `krea/krea-2-medium`

**エンドポイント:** `POST https://api.comfy.org/v2/models/krea/krea-2-medium`

<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(
              "krea/krea-2-medium",
              {
                  "aspect_ratio": "1:1",
                  "prompt": "a red circle",
                  "resolution": "1K",
              },
          )

      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("krea/krea-2-medium", {
        aspect_ratio: "1:1",
        prompt: "a red circle",
        resolution: "1K",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/krea/krea-2-medium \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"aspect_ratio\": \"1:1\", \"prompt\": \"a red circle\", \"resolution\": \"1K\"}"
      ```
    </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(
              "krea/krea-2-medium",
              {
                  "aspect_ratio": "1:1",
                  "prompt": "a red circle",
                  "resolution": "1K",
              },
          )
          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("krea/krea-2-medium", {
        aspect_ratio: "1:1",
        prompt: "a red circle",
        resolution: "1K",
      });
      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/krea/krea-2-medium/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"aspect_ratio\": \"1:1\", \"prompt\": \"a red circle\", \"resolution\": \"1K\"}"

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

## スキーマ

### 入力

<ParamField body="aspect_ratio" type="string" required>
  アスペクト比。次のいずれか: 1:1、4:3、3:2、16:9、2.35:1、4:5、2:3、9:16。

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

<ParamField body="creativity" type="string" default="&#x22;medium&#x22;">
  プロンプトの解釈の強さ: raw=0、low=10、medium=50、high=100。

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

<ParamField body="image_style_references" type="object[]">
  生成に使用するスタイル参照
</ParamField>

<ParamField body="image_style_references[].strength" type="number" required>
  範囲: `-2` から `2`

  形式: `double`
</ParamField>

<ParamField body="image_style_references[].url" type="string (uri)">
  形式: `uri`
</ParamField>

<ParamField body="moodboards" type="object[]">
  生成に使用するムードボード。現在は1つのムードボードに制限されています。
</ParamField>

<ParamField body="moodboards[].id" type="string (uuid)" required>
  形式: `uuid`
</ParamField>

<ParamField body="moodboards[].strength" type="number" default="0.35">
  範囲: `-0.5` から `1.5`

  形式: `double`
</ParamField>

<ParamField body="prompt" type="string" required />

<ParamField body="resolution" type="string" required>
  解像度スケール。次のいずれか: 1K。

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

<ParamField body="seed" type="number" />

<ParamField body="styles" type="object[]">
  生成に使用するスタイル(通常は LoRA)
</ParamField>

<ParamField body="styles[].id" type="string" required />

<ParamField body="styles[].strength" type="number" required>
  範囲: `-2` から `2`

  形式: `double`
</ParamField>

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

### 出力

<ResponseField name="completed_at" type="string (date-time)" required>
  形式: `date-time`
</ResponseField>

<ResponseField name="created_at" type="string (date-time)" required>
  形式: `date-time`
</ResponseField>

<ResponseField name="job_id" type="string (uuid)" required>
  形式: `uuid`
</ResponseField>

<ResponseField name="result" type="object" required>
  完了した生成結果。`KreaJob` とは異なり、ここでは null 許容ではありません。`result` に `urls` が含まれないターミナルジョブは Comfy Router のエラーとして返されるため、`200` には必ずこれが含まれます。
</ResponseField>

<ResponseField name="result.style_id" type="string">
  生成ではなく loraTraining ジョブによって設定されます。これらのモデルに対する `200` には `urls` が含まれます。
</ResponseField>

<ResponseField name="result.urls" type="string (uri)[]" required>
  生成済み画像をダウンロード可能なリンクとして示したもの。`urls` が空の `completed` ジョブは `success_without_output` となり、このドキュメントには決して到達しないため、少なくとも1つ含まれます。
</ResponseField>

<ResponseField name="status" type="string" required>
  このドキュメントでは常に `completed` です。`classifyKrea` が `succeeded` と返す唯一のステータスであり、Krea の用語は大文字小文字を区別せずに照合されます。

  指定可能な値: `completed`
</ResponseField>

## 例

### 入力

```json theme={null}
{
  "aspect_ratio": "1:1",
  "prompt": "a red circle",
  "resolution": "1K"
}
```

### 出力

```json theme={null}
{
  "completed_at": "2027-01-01T00:00:37Z",
  "created_at": "2027-01-01T00:00:00Z",
  "job_id": "7f1c2e84-5b90-4a37-8d61-2c0f9ab4e153",
  "result": {
    "urls": [
      "https://example.invalid/krea/krea-2/generated.png"
    ]
  },
  "status": "completed"
}
```

## 出荷前の確認

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>
