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

# 将 Krea 2 Medium Turbo 与 Comfy Router 搭配使用

> 通过 Comfy Router 调用 krea/krea-2-medium-turbo：端点、请求结构以及 Router 返回的响应。

`krea/krea-2-medium-turbo` 的 API 参考，该模型由 Comfy Router 提供，来源为 Krea。

## 快速开始

在[你的 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：** `krea/krea-2-medium-turbo`

**端点：** `POST https://api.comfy.org/v2/models/krea/krea-2-medium-turbo`

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

## Schema

### Input

<ParamField body="aspect_ratio" type="string" required>
  宽高比。可选值之一：1:1、4:3、3:2、16:9、2.35:1、4:5、2:3、9:16。

  Possible values: `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。

  Possible values: `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[]">
  用于生成的情绪板（moodboard）。目前限制为一个情绪板。
</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。

  Possible values: `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-turbo/openapi.json` 提供的 schema 生成，它与请求到达提供商之前用于校验调用的文档是同一份。

### Output

<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` 上不同，此处不可为空：`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`，永远不会出现在此文档中。
</ResponseField>

<ResponseField name="status" type="string" required>
  在此文档中始终为 `completed`：它是 `classifyKrea` 判定为 `succeeded` 的唯一状态，并且匹配 Krea 的词汇时不进行大小写折叠。

  Possible values: `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` 并在自动重试中复用它。手动重试时，请复用原始 key。Router 最长可保持连接 10 分钟。

请求失败时，Router 会发送 `X-Comfy-Error-Type` 响应头说明原因。`422` 表示 Router 在调用提供商之前就拒绝了输入。生成的资源请及时下载，因为[结果链接会过期](/zh/development/comfy-router/reference#结果资产)。

<CardGroup cols={3}>
  <Card title="请求头" icon="list" href="/zh/development/comfy-router/quickstart">
    身份验证、幂等性、请求 ID、错误分类、重试节奏、消费限额。
  </Card>

  <Card title="使用 Router API" icon="code" href="/zh/development/comfy-router/quickstart">
    模型发现、校验错误、重试与计费。
  </Card>

  <Card title="限制" icon="triangle-exclamation" href="/zh/development/comfy-router/limitations">
    Router 目前不支持的功能，以及替代方案。
  </Card>
</CardGroup>
