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

# GPT-Image-2.6 · 图生图

> GPT-Image-2.6 Flare / Sunburst · POST /v1/images/edits

## 简介

GPT-Image-2.6 包含 **Flare** 和 **Sunburst** 两个模型，均支持基于参考图片和文本指令进行图像编辑。本页介绍 `POST /v1/images/edits` 端点，适用于修改颜色、替换背景、风格迁移、局部重绘以及融合多张参考图片等场景。

编辑请求需要提供参考图片，并在 `prompt` 中明确说明“修改什么”和“保留什么”。需要指定局部区域时，可以使用 **mask 蒙版**或 **markup 透明圈注层**，两者不能同时传入；还可基于静态参考图生成 GIF 动图。请求支持 JSON 图片引用和 multipart 文件上传，具体格式见下方示例。

Flare 适合快速尝试多个编辑方案，Sunburst 适合更重视细节、布局和编辑精度的任务。可使用 `quality` 调整渲染质量，使用独立的 `complexity` 控制规划量；局部修改可先尝试较低复杂度，并检查未指定区域是否保持符合预期。

### 模型选择

| 模型 ID | 适用场景 |
| - | - |
| `gpt-image-2.6-flare` | 快速迭代、交互式生成 |
| `gpt-image-2.6-sunburst` | 复杂布局、细节表现与精确编辑 |

两个模型共用本页的端点、参数和响应结构。示例默认使用 Flare；切换为 Sunburst 时只需替换请求中的 `model`，其他字段按实际需求设置。

## 认证

**Authorization** `string` *required*

Bearer \$GRAVITEX\_API\_KEY

**Content-Type** `string` *required*

application/json / multipart/form-data

## 请求参数

| 参数 | 类型 | 说明 |
| - | - | - |
| `model` | string | 必填，gpt-image-2.6-flare 或 gpt-image-2.6-sunburst |
| `prompt` | string | 必填，描述图片修改要求，最长 32,000 字符 |
| `quality` | string | auto / low / medium / high / xhigh / max；默认 auto |
| `complexity` | string | low / medium / high；默认 high。独立于 quality，控制渲染前的规划量 |
| `size` | string | auto 或 WxH，宽高为 16 的倍数；受模型尺寸和总像素预算约束 |
| `n` | integer | 1–10；默认 1 |
| `background` | string | auto / opaque / transparent；透明栅格输出使用 png 或 webp |
| `output_format` | string | png / jpeg / webp / gif |
| `output_compression` | integer | 0–100，仅 jpeg/webp；GIF 不支持自定义压缩 |
| `moderation` | string | auto / low；默认 auto |
| `safety_identifier` | string | 稳定的终端用户标识，建议哈希化，最长 128 字符；替代 user |
| `stream` | boolean | 默认 false；开启后返回 SSE 事件，不能按普通 JSON 响应解析。GIF 不支持 |
| `partial_images` | integer | 仅栅格流式输出，0–3，默认 0；表示期望的中间预览数，实际可能更少。GIF 不支持 |
| `images` / `image[]` | array / file | JSON 必填，至少一张参考图；使用 `images: [{"image_url": "HTTPS URL 或 base64 data URI"}]`。multipart 改用 image\[] 文件字段 |
| `markup` | object / file | 可选透明 PNG 圈注层，叠加在第一张参考图上；与 mask 互斥 |
| `mask` | object / file | 可选 PNG 蒙版，尺寸须与第一张参考图一致并包含 alpha 通道；完全透明区域表示需要编辑的位置。多图输入仅作用于第一张图；与 markup 互斥，GIF 不支持 |
| `frame_count` | integer | 仅 GIF，2–16，默认 9 |
| `frame_duration_ms` | integer | 仅 GIF，默认 200；指南建议 20–2000ms，按 10ms 取整 |

### images / markup / mask

JSON 使用 `images: [{"image_url": "https://..."}]`；也可传 base64 data URI。multipart 使用 `image[]` 上传文件。平台会将 JSON 编辑转为 multipart；不支持 OpenAI `file_id` 引用。此转换行为来自平台接入说明。

`markup` 是叠加在第一张参考图上的透明 PNG 圈注层，须含透明像素，尺寸匹配第一张图旋正后的尺寸。JSON 用 `markup: {"image_url": "https://..."}`，multipart 上传 markup 文件。与 mask 互斥。

`mask` 可用于标识编辑区域，与 markup 二选一；JSON 使用 image\_url，multipart 上传文件。

## 请求示例

示例从环境变量 `GRAVITEX_API_KEY` 读取平台令牌，请先在当前终端设置该变量。文件上传使用 curl 的 `-F` 自动生成 Content-Type 和 boundary，不要手动把 Content-Type 固定成 multipart/form-data。

> [!NOTE]
>
> JSON 示例使用 OpenAI 官方厨房照片；圈注示例使用与其尺寸匹配的官方透明圈注层，可直接复制请求体。multipart 示例先下载同一张官方图片到当前目录，再上传文件。平台不支持 file\_id，本次实测返回 HTTP 500（convert\_request\_failed），不能依赖其一定返回 400。

### JSON

```bash theme={null}
curl https://api.gravitex.ai/v1/images/edits \
  -H "Authorization: Bearer $GRAVITEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "gpt-image-2.6-flare",
  "prompt": "Change the vase to blue. Keep everything else unchanged.",
  "quality": "medium",
  "complexity": "low",
  "size": "1024x1024",
  "images": [
    {
      "image_url": "https://developers.openai.com/images/platform/guides/image-prompting/kitchen.webp"
    }
  ]
}'
```

### multipart/form-data

```bash theme={null}
curl --fail --location "https://developers.openai.com/images/platform/guides/image-prompting/kitchen.webp" -o kitchen.webp

curl https://api.gravitex.ai/v1/images/edits \
  -H "Authorization: Bearer $GRAVITEX_API_KEY" \
  -F "model=gpt-image-2.6-flare" \
  -F "prompt=Change the vase to blue. Keep everything else unchanged." \
  -F "image[]=@kitchen.webp" \
  -F "complexity=low"
```

### 圈注编辑

```bash theme={null}
curl https://api.gravitex.ai/v1/images/edits \
  -H "Authorization: Bearer $GRAVITEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "gpt-image-2.6-flare",
  "prompt": "Change the vase to blue. Keep everything else unchanged.",
  "quality": "medium",
  "complexity": "low",
  "size": "1024x1024",
  "images": [
    {
      "image_url": "https://developers.openai.com/images/platform/guides/image-prompting/kitchen.webp"
    }
  ],
  "markup": {
    "image_url": "https://developers.openai.com/images/platform/guides/image-prompting/markup-vase-overlay-gpt-image-2-6.png"
  }
}'
```

### GIF 动图

```bash theme={null}
curl https://api.gravitex.ai/v1/images/edits \
  -H "Authorization: Bearer $GRAVITEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "gpt-image-2.6-flare",
  "prompt": "Animate the kitchen curtains gently moving in a breeze. Keep the camera still and make a seamless loop.",
  "output_format": "gif",
  "frame_count": 9,
  "frame_duration_ms": 200,
  "size": "auto",
  "images": [
    {
      "image_url": "https://developers.openai.com/images/platform/guides/image-prompting/kitchen.webp"
    }
  ]
}'
```

`user` 为兼容旧请求保留，已废弃；新请求使用 safety\_identifier。非空 safety\_identifier 优先，未提供、null 或空字符串时才回退 user。

### 蒙版局部重绘

```bash theme={null}
curl https://api.gravitex.ai/v1/images/edits \
  -H "Authorization: Bearer $GRAVITEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "gpt-image-2.6-flare",
  "prompt": "Add a pink flamingo float in the masked pool area. Keep the rest of the room unchanged.",
  "images": [
    {
      "image_url": "https://cdn.openai.com/API/docs/images/sunlit_lounge.png"
    }
  ],
  "mask": {
    "image_url": "https://cdn.openai.com/API/docs/images/mask.png"
  },
  "quality": "medium"
}'
```

### 流式输出

```bash theme={null}
curl --no-buffer https://api.gravitex.ai/v1/images/edits \
  -H "Authorization: Bearer $GRAVITEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "gpt-image-2.6-flare",
  "prompt": "Change the vase to blue. Keep everything else unchanged.",
  "quality": "medium",
  "size": "1024x1024",
  "stream": true,
  "partial_images": 1,
  "images": [
    {
      "image_url": "https://developers.openai.com/images/platform/guides/image-prompting/kitchen.webp"
    }
  ]
}'
```

## 限制与注意事项

GIF 的 size 表示每帧尺寸，受帧数、n 和模型像素预算共同约束；优先使用 auto，超过预算时减少帧数或尺寸。

官方 Images API 的 JSON 编辑支持 **1–16 张**输入图片，PNG / JPEG / WebP，每张小于 **50MB**。mask 为带 alpha 通道的 PNG，须与第一张参考图尺寸一致；透明区域指定编辑位置，蒙版用于引导生成，不保证像素级硬裁剪。请勿把平台未主动校验理解为上游无限制。

本编辑端点不提供 SVG 输出；需要 SVG 请使用[文生图端点](https://docs.gravitex.ai/cn/api-reference/endpoint/gpt-image-2.6/generations.md)。

GIF 可用于本端点，需要相应预览权限。不可使用 mask、stream、partial\_images 或自定义 output\_compression。帧数、单帧尺寸和 n 共用请求像素预算，超限时减少这些值或使用 size=auto。

complexity 没有独立附加费，但可能影响延迟和输出结果。不要把低复杂度视为固定速度或固定单张价格保证。

## 响应示例

下面是非流式响应的结构示意，图片数据和 token 数仅为示例，并非实际生成结果。将 b64\_json 解码为对应格式的文件；不要将 Base64 字符串直接保存为图片。

```json theme={null}
{
  "created": 1794268800,
  "data": [
    {
      "b64_json": "<BASE64_IMAGE_DATA>"
    }
  ],
  "usage": {
    "input_tokens": 100,
    "output_tokens": 824,
    "total_tokens": 924
  }
}
```

若设置 `stream: true`，响应为 SSE 事件流；按事件读取中间预览和最终图片，不能对整个响应直接调用 JSON 解析。

## 响应与计费

本页示例为非流式调用时，图片通过 b64\_json 返回；不要传 response\_format=url 期待图片链接。输入图片和输出图片均有 token 用量；相同 token 单价不代表相同单张费用，需结合实际 usage。

返回 `data[].b64_json`，按所选格式解码保存；`usage` 为 token 用量。下表为 OpenAI 官方标准价，不是 GravitexAI 的报价；平台结算以控制台为准。

| 类型 | 美元 / 1M tokens |
| - | - |
| 文本输入 | \$5.00 |
| 缓存文本输入 | \$1.25 |
| 图片输入 | \$8.00 |
| 缓存图片输入 | \$2.00 |
| 图片输出 | \$30.00 |

## 官方参考

* [Image generation guide](https://developers.openai.com/api/docs/guides/image-generation)
* [API Reference](https://developers.openai.com/api/reference/resources/images/methods/edit)
* [Flare](https://developers.openai.com/api/docs/models/gpt-image-2.6-flare)
* [Sunburst](https://developers.openai.com/api/docs/models/gpt-image-2.6-sunburst)
* [Pricing](https://developers.openai.com/api/docs/pricing)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.