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

# 将 GPT Image 2.5 Flare 与 Comfy Router 搭配使用

> 通过 Comfy Router 调用 openai/gpt-image-2.5-flare：端点、请求结构以及 Router 返回的响应。

`openai/gpt-image-2.5-flare` 的 API 参考，由 Comfy Router 从 OpenAI 提供。

## 快速开始

在[你的 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：** `openai/gpt-image-2.5-flare`

**端点：** `POST https://api.comfy.org/v2/models/openai/gpt-image-2.5-flare`

<Tabs>
  <Tab title="等待结果">
    <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(
              "openai/gpt-image-2.5-flare",
              {
                  "image": ["https://storage.googleapis.com/comfy-cloud-assets/0199b3f4-1d2e-7a3b-8c4d-5e6f70819234.png"],
                  "prompt": "give the rocketship rainbow coloring",
                  "quality": "low",
                  "size": "1024x1024",
              },
          )

      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("openai/gpt-image-2.5-flare", {
        image: ["https://storage.googleapis.com/comfy-cloud-assets/0199b3f4-1d2e-7a3b-8c4d-5e6f70819234.png"],
        prompt: "give the rocketship rainbow coloring",
        quality: "low",
        size: "1024x1024",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/openai/gpt-image-2.5-flare \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"image\": [\"https://storage.googleapis.com/comfy-cloud-assets/0199b3f4-1d2e-7a3b-8c4d-5e6f70819234.png\"], \"prompt\": \"give the rocketship rainbow coloring\", \"quality\": \"low\", \"size\": \"1024x1024\"}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="排队并稍后收集">
    将相同的请求体发送到 `POST https://api.comfy.org/v2/models/openai/gpt-image-2.5-flare/requests`。运行一经受理，Router 就会立即返回 `201` 和 `request_id`；结果就绪后即可收集，无论是从本进程还是其他进程。[队列化交付](/zh/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(
              "openai/gpt-image-2.5-flare",
              {
                  "image": ["https://storage.googleapis.com/comfy-cloud-assets/0199b3f4-1d2e-7a3b-8c4d-5e6f70819234.png"],
                  "prompt": "give the rocketship rainbow coloring",
                  "quality": "low",
                  "size": "1024x1024",
              },
          )
          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("openai/gpt-image-2.5-flare", {
        image: ["https://storage.googleapis.com/comfy-cloud-assets/0199b3f4-1d2e-7a3b-8c4d-5e6f70819234.png"],
        prompt: "give the rocketship rainbow coloring",
        quality: "low",
        size: "1024x1024",
      });
      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/openai/gpt-image-2.5-flare/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"image\": [\"https://storage.googleapis.com/comfy-cloud-assets/0199b3f4-1d2e-7a3b-8c4d-5e6f70819234.png\"], \"prompt\": \"give the rocketship rainbow coloring\", \"quality\": \"low\", \"size\": \"1024x1024\"}"

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

## Schema

### 输入

<ParamField body="background" type="string">
  背景透明度

  可选值：`transparent`、`opaque`
</ParamField>

<ParamField body="image" type="string | string[]">
  要编辑的来源图像。存在此字段即表示选择编辑操作：若要执行文生图，请完全省略该字段。
  可接受一张图像或一个图像数组；gpt-image-1 及更高版本最多接受 16 张，Router 会在派发之前依据此 schema 强制执行该限制。
</ParamField>

<ParamField body="mask" type="string">
  一张图像，形式可以是 Router 代调用方抓取的 https URL，也可以是内联携带字节的 `data:image/<format>;base64,<payload>` URI。可接受的图像类型为 png、webp 和 jpeg，并且该集合在解析时即强制执行，而不是交由提供商处理：svg、gif、avif 或 tiff 会在此处被拒绝，并指出你发送的图像，而不会变成距根因两跳之外的合作伙伴错误。
  优先使用 URL 形式。base64 载荷大约会膨胀 4/3，而整个请求体上限为 10 MiB，因此内联形式的上限约为 7.5 MB 的来源图像；使用 URL 则完全不受此限制。
  该 URL 必须无需你的凭据即可解析。Router 在服务器端抓取它，并且不会随请求发送任何调用方凭据，因此受 Comfy 签名的资产 URL（签名位于查询字符串中的那种）才是受支持的形式。诸如 `/api/assets/{id}/content` 这类需要认证的端点会向 Router 返回 401 而不是图像；请自行请求该 URL，并传入它重定向到的已签名 URL。该抓取仅限于 Comfy 自有的资产存储桶，而不会访问开放互联网，无论是你发送的 URL 还是每一跳重定向都如此，因此第三方 URL 或会发生重定向的 URL 都会被拒绝。
  下面的示例仅展示格式：真实的值还会携带签名查询参数，此处有意省略它们，因为已发布的示例会永远留存在规范中，而真实的签名既是泄露的凭据，也是一个会失效的链接。
  每张图像上限为 25 MiB，单个请求的图像总量上限为 64 MiB。
</ParamField>

<ParamField body="model" type="string">
  要运行的 gpt-image 模型。Router 会把所寻址的模型 id 拼接进去，因此寻址 /v2/models/openai/gpt-image-2 的调用方无需发送此字段。
</ParamField>

<ParamField body="moderation" type="string">
  内容审核设置

  可选值：`low`、`auto`
</ParamField>

<ParamField body="n" type="integer">
  要生成的图像数量（1-10）。

  范围：`1` 到 `10`
</ParamField>

<ParamField body="output_compression" type="integer">
  JPEG 或 WebP 的压缩级别（0-100）

  范围：`0` 到 `100`
</ParamField>

<ParamField body="output_format" type="string">
  输出图像的格式

  可选值：`png`、`webp`、`jpeg`
</ParamField>

<ParamField body="prompt" type="string" required>
  要生成的图像的文本描述，或要对 `image` 所做编辑的文本描述。
</ParamField>

<ParamField body="quality" type="string">
  生成或编辑后图像的质量

  可选值：`low`、`medium`、`high`、`standard`、`hd`
</ParamField>

<ParamField body="size" type="string">
  图像的尺寸（例如 1024x1024、1536x1024、auto）
</ParamField>

<ParamField body="user" type="string">
  用于最终用户监控的唯一标识符
</ParamField>

根据 Router 在 `GET /v2/models/openai/gpt-image-2.5-flare/openapi.json` 提供的 schema 生成，该文档与请求到达提供商之前用于校验调用的文档相同。

### 输出

<ResponseField name="data" type="object[]" />

<ResponseField name="data[].b64_json" type="string">
  Base64 编码的图像数据
</ResponseField>

<ResponseField name="data[].revised_prompt" type="string">
  修订后的提示词
</ResponseField>

<ResponseField name="data[].url" type="string">
  图像的 URL
</ResponseField>

<ResponseField name="usage" type="object" />

<ResponseField name="usage.input_tokens" type="integer" />

<ResponseField name="usage.input_tokens_details" type="object" />

<ResponseField name="usage.input_tokens_details.image_tokens" type="integer" />

<ResponseField name="usage.input_tokens_details.text_tokens" type="integer" />

<ResponseField name="usage.output_tokens" type="integer" />

<ResponseField name="usage.output_tokens_details" type="object" />

<ResponseField name="usage.output_tokens_details.image_tokens" type="integer" />

<ResponseField name="usage.output_tokens_details.text_tokens" type="integer" />

<ResponseField name="usage.total_tokens" type="integer" />

<ResponseField name="background" type="string">
  生成图像的背景是不透明还是透明。仅在 fal 提供的分支上填充，该分支会报告 `opaque`。
</ResponseField>

<ResponseField name="created" type="integer">
  生成完成时的 Unix 时间戳（以秒为单位）。声明为 `int64`，因为当前时代的纪元值已接近 2^31，未做格式限定的 `integer` 会在许多 SDK 生成器中生成 32 位字段。

  格式：`int64`
</ResponseField>

<ResponseField name="output_format" type="string">
  `data[].b64_json` 中字节的编码（例如 `png`）。在 fal 提供的分支上填充；在 OpenAI 提供的分支上缺失，此时调用方请求的 `output_format` 是权威的。
</ResponseField>

<ResponseField name="quality" type="string">
  生成实际运行的质量档位。当 fal 提供的分支能够解析出该值时填充；否则缺失。
</ResponseField>

<ResponseField name="size" type="string">
  生成实际运行的像素尺寸，格式为 `<width>x<height>`。当 fal 提供的分支能够解析出该值时填充；否则缺失。
</ResponseField>

## 示例

### 输入

```json theme={null}
{
  "image": [
    "https://storage.googleapis.com/comfy-cloud-assets/0199b3f4-1d2e-7a3b-8c4d-5e6f70819234.png"
  ],
  "prompt": "give the rocketship rainbow coloring",
  "quality": "low",
  "size": "1024x1024"
}
```

### 输出

```json theme={null}
{
  "created": 1767225600,
  "data": [
    {
      "b64_json": "PGJhc2U2ND4="
    }
  ],
  "usage": {
    "input_tokens": 12,
    "output_tokens": 1056,
    "total_tokens": 1068
  }
}
```

## 发布前须知

SDK 会生成 `Idempotency-Key` 并在自动重试中复用它。手动重试时，请复用原始 key。Router 最长可保持连接 10 分钟。

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

上文任何字段描述中提到的尺寸限制，都是提供商对该字段自身的限定，引自提供商的规范。Router 会对整个请求体另行设置上限，base64 编码的媒体内容也计入其中：参见[请求体大小](/zh/development/comfy-router/limitations)。

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

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

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