> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anyfast.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# GPT Image 2.5

> 使用 gpt-image-2.5-sunburst 和 gpt-image-2.5-flare 生成与编辑图片。

通过图片生成或编辑端点使用 GPT Image 2.5 模型。

| 模型 ID                    | 推荐场景                |
| ------------------------ | ------------------- |
| `gpt-image-2.5-flare`    | 快速、高质量生成和日常编辑的默认选择  |
| `gpt-image-2.5-sunburst` | 需要更高保真度和控制力的精细创作与编辑 |

<Info>
  GPT Image 2.5 始终通过 `data[].b64_json` 返回 Base64 图片数据。请勿传入仅适用于 DALL·E 的 `response_format` 参数。
</Info>

<Tabs sync={false}>
  <Tab title="图片生成">
    ## 生成图片

    `POST /v1/images/generations`

    <div className="kling-api-example-panel">
      ```bash cURL theme={null}
      curl --request POST \
        --url https://www.anyfast.ai/v1/images/generations \
        --header 'Authorization: Bearer YOUR_API_KEY' \
        --header 'Content-Type: application/json' \
        --data '{
          "model": "gpt-image-2.5-flare",
          "prompt": "一张简洁的杂志风产品照片，半透明绿色玻璃瓶放在浅色石材上，柔和晨光",
          "size": "1536x1024",
          "quality": "high",
          "background": "opaque",
          "output_format": "jpeg",
          "output_compression": 85,
          "moderation": "auto",
          "n": 1
        }'
      ```
    </div>

    ## 请求头

    <ParamField header="Authorization" type="string" required>Bearer 鉴权，格式为 `Bearer YOUR_API_KEY`。</ParamField>
    <ParamField header="Content-Type" type="string" default="application/json" required>数据交换格式。</ParamField>

    ## 请求体

    <ParamField body="model" type="string" required>
      模型 ID：`gpt-image-2.5-sunburst` 或 `gpt-image-2.5-flare`。
    </ParamField>

    <ParamField body="prompt" type="string" required>
      描述目标图片的文本提示词。长度为 `1`–`32,000` 个字符。
    </ParamField>

    <ParamField body="n" type="integer" default={1}>
      生成图片数量，支持 `1`–`10`。
    </ParamField>

    <ParamField body="size" type="string" default="auto">
      使用 `auto` 或自定义 `宽x高`。宽和高必须为 16 的倍数，宽高比在 1:3 到 3:1 之间，任一边不超过 3,840 像素，总像素数在 655,360 到 8,294,400 之间。
    </ParamField>

    <ParamField body="quality" type="string" default="auto">
      渲染质量：`low`、`medium`、`high`、`xhigh`、`max` 或 `auto`。
    </ParamField>

    <ParamField body="background" type="string" default="auto">
      背景模式：`auto`、`opaque` 或 `transparent`。透明背景必须使用 PNG 或 WebP 输出。
    </ParamField>

    <ParamField body="output_format" type="string" default="png">
      输出格式：`png`、`jpeg` 或 `webp`。
    </ParamField>

    <ParamField body="output_compression" type="integer" default={100}>
      JPEG 或 WebP 压缩等级，范围为 `0`–`100`。PNG 输出会忽略此参数。
    </ParamField>

    <ParamField body="moderation" type="string" default="auto">
      内容审核严格程度：`auto` 或 `low`。
    </ParamField>

    ## 生成响应

    <div className="kling-api-example-panel">
      ```json 200 theme={null}
      {
        "created": 1788926400,
        "background": "opaque",
        "data": [
          {
            "b64_json": "iVBORw0KGgoAAA..."
          }
        ],
        "output_format": "jpeg",
        "quality": "high",
        "size": "1536x1024"
      }
      ```
    </div>

    <ResponseField name="created" type="integer">创建时间，Unix 秒级时间戳。</ResponseField>
    <ResponseField name="background" type="string">最终背景模式：`opaque` 或 `transparent`。</ResponseField>
    <ResponseField name="data" type="object[]">生成图片结果。</ResponseField>
    <ResponseField name="data[].b64_json" type="string">Base64 编码的图片数据。</ResponseField>
    <ResponseField name="output_format" type="string">返回图片格式：`png`、`jpeg` 或 `webp`。</ResponseField>
    <ResponseField name="quality" type="string">结果使用的质量等级。</ResponseField>
    <ResponseField name="size" type="string">最终输出尺寸，格式为 `宽x高`。</ResponseField>
  </Tab>

  <Tab title="图片编辑">
    ## 编辑图片

    `POST /v1/images/edits`

    <div className="kling-api-example-panel">
      ```bash cURL theme={null}
      curl --request POST \
        --url https://www.anyfast.ai/v1/images/edits \
        --header 'Authorization: Bearer YOUR_API_KEY' \
        --form 'model=gpt-image-2.5-sunburst' \
        --form 'image[]=@/path/to/product.png' \
        --form 'mask=@/path/to/mask.png' \
        --form 'prompt=保持产品主体不变，将背景替换为暖色摄影棚渐变' \
        --form 'size=1536x1024' \
        --form 'quality=xhigh' \
        --form 'background=opaque' \
        --form 'output_format=png' \
        --form 'n=1'
      ```
    </div>

    ## 请求头

    <ParamField header="Authorization" type="string" required>Bearer 鉴权，格式为 `Bearer YOUR_API_KEY`。</ParamField>
    <ParamField header="Content-Type" type="string" default="multipart/form-data" required>使用 multipart 表单上传时由客户端自动设置。</ParamField>

    ## 请求体

    <ParamField body="model" type="string" required>
      模型 ID：`gpt-image-2.5-sunburst` 或 `gpt-image-2.5-flare`。
    </ParamField>

    <ParamField body="image" type="file">
      一张源图片文件。上传多张图片时改用 `image[]`。每张源图片必须小于 50 MB。
    </ParamField>

    <ParamField body="image[]" type="file[]">
      最多 16 张源图片文件。不要同时传入 `image` 和 `image[]`。
    </ParamField>

    <ParamField body="mask" type="file">
      可选编辑蒙版。蒙版用于引导编辑，不保证形成像素级精确边界。蒙版必须包含 Alpha 通道，与第一张源图片的格式和尺寸一致，且小于 50 MB。上传多张源图片时，蒙版作用于第一张图片。
    </ParamField>

    <ParamField body="prompt" type="string" required>
      描述编辑目标的文本指令。长度为 `1`–`32,000` 个字符。
    </ParamField>

    <ParamField body="n" type="integer" default={1}>
      返回编辑图片数量，支持 `1`–`10`。
    </ParamField>

    <ParamField body="size" type="string" default="auto">
      使用 `auto` 或符合图片生成端点相同限制的自定义 `宽x高`。
    </ParamField>

    <ParamField body="quality" type="string" default="auto">
      渲染质量：`low`、`medium`、`high`、`xhigh`、`max` 或 `auto`。
    </ParamField>

    <ParamField body="background" type="string" default="auto">
      背景模式：`auto`、`opaque` 或 `transparent`。透明背景必须使用 PNG 或 WebP 输出。
    </ParamField>

    <ParamField body="output_format" type="string" default="png">
      输出格式：`png`、`jpeg` 或 `webp`。
    </ParamField>

    <ParamField body="output_compression" type="integer" default={100}>
      JPEG 或 WebP 压缩等级，范围为 `0`–`100`。PNG 输出会忽略此参数。
    </ParamField>

    <ParamField body="moderation" type="string" default="auto">
      内容审核严格程度：`auto` 或 `low`。
    </ParamField>

    ## 编辑响应

    <div className="kling-api-example-panel">
      ```json 200 theme={null}
      {
        "created": 1788926460,
        "background": "opaque",
        "data": [
          {
            "b64_json": "iVBORw0KGgoAAA..."
          }
        ],
        "output_format": "png",
        "quality": "xhigh",
        "size": "1536x1024"
      }
      ```
    </div>

    <ResponseField name="created" type="integer">创建时间，Unix 秒级时间戳。</ResponseField>
    <ResponseField name="background" type="string">最终背景模式：`opaque` 或 `transparent`。</ResponseField>
    <ResponseField name="data" type="object[]">编辑图片结果。</ResponseField>
    <ResponseField name="data[].b64_json" type="string">Base64 编码的编辑后图片数据。</ResponseField>
    <ResponseField name="output_format" type="string">返回图片格式：`png`、`jpeg` 或 `webp`。</ResponseField>
    <ResponseField name="quality" type="string">结果使用的质量等级。</ResponseField>
    <ResponseField name="size" type="string">最终输出尺寸，格式为 `宽x高`。</ResponseField>
  </Tab>
</Tabs>

## 校验规则

* `background="transparent"` 必须搭配 `output_format="png"` 或 `output_format="webp"`。
* 自定义宽和高必须能被 16 整除，宽高比在 `1:3` 到 `3:1` 之间，任一边不超过 3,840 像素，总像素数在 655,360 到 8,294,400 之间。
* 高于 `2560x1440` 的分辨率属于实验能力。
* `output_compression` 仅适用于 JPEG 和 WebP 输出。
* GPT Image 2.5 返回 Base64 图片数据，不支持通过 `response_format` 获取 URL。

上游接口定义请参阅 [OpenAI 创建图片 API](https://developers.openai.com/api/reference/resources/images/methods/generate) 和 [创建图片编辑 API](https://developers.openai.com/api/reference/resources/images/methods/edit)。

<script src="/public/feedback.js" />
