# GPT Image 改图 — JSON 引用

使用最新 GPT Image 模型，通过 URL 或 data URL 引用图片进行编辑。

- 原文: https://www.unifyllm.com/zh/docs/api-reference/gpt-image-edit-json/
- 语言: zh-CN
- 更新于: 2026-11-30

## 接口

```http
POST https://api.unifyllm.top/v1/images/edits
```

认证与请求头以本页调用示例为准。 Content-Type: application/json

## 当前模型与接口

模型广场核对日期：2026-11-30。当前示例使用 gpt-image-2.6-flare-c，同代可用型号包括 gpt-image-2.6-sunburst-c。请使用本站完整模型名，不要直接套用供应商内部别名。

- 统一请求 https://api.unifyllm.top；客户端不添加渠道前缀。

- 文生图用 generations，参考图编辑用 edits；Chat 适合已有聊天客户端。

- 旧的 gpt-image-2-c 与 gpt-image-2-4k-c 是否可用，以模型广场和 Key 权限为准。

## 尺寸、返回和参考图

- Images 返回 created、model、data[].url，不返回 b64_json 或上游原始 usage。一次请求返回一张图片。

- n=1、quality=high、response_format=url 固定；mask 等其他控制字段不保证生效。

- 尺寸请求不是原生画质保证。参考项目 2026-11-30 实测 1024x1024 输出 1254×1254、3840x2160 输出 3840×2160；本站具体路由仍以实际结果为准。

| 项目 | 规则 |
| --- | --- |
| size | auto 或宽x高；16 的倍数、最长边 3840、比例不超过 3:1 |
| 总像素 | 655,360–8,294,400 |
| 参考图 | 标准模型 JSON 或 multipart，最多 10 张 |
| 旧 4K 编辑别名 | gpt-image-2-4k-c 编辑必须上传 multipart 文件 |

## Chat 与流式响应

- Chat 从当前用户消息提取绘图说明和参考图；修改上次图片时应在当前消息中明确带上它。

- stream=false 的图片在 choices[0].message.content 的 Markdown 中。stream=true 在生成成功后输出内容块，最后 stop 和 [DONE]。

- 返回文字包含参数摘要和完成提示，由兼容层拼接；100% 不是实时进度。

- GPT 图片 Chat usage 为兼容层估算，不是供应商实际图片 Token 账单；缺失 Images usage 也不代表零费用。

## 保存图片与排查

- 返回的签名图片 URL 可直接下载，不携带 API Key；及时保存，不改写签名查询串。

- 不同渠道可能先保存文件或在首次完整下载时缓存。收到 URL 后优先完成下载，不依赖永久保留。

- 400 检查尺寸、参考图及模型；401 检查认证；413 缩小请求；429 遵循限流提示；超时或 5xx 保留请求 ID 排查。

- 不要对结果不明确的付费生成请求自动重试；图片下载失败时先重试原 URL。

## 参数

| 参数 | 位置 | 类型 | 必填 | 说明 | 可选值 | 示例 |
| --- | --- | --- | --- | --- | --- | --- |
| model | body | string | 是 | 示例使用当前模型 gpt-image-2.6-flare-c；同代还有 gpt-image-2.6-sunburst-c。旧别名是否可用请看模型广场及 Key 权限。 | gpt-image-2.6-flare-c, gpt-image-2.6-sunburst-c, gpt-image-2.5-flare-c, gpt-image-2.5-sunburst-c, gpt-image-2-c, gpt-image-2-4k-c | gpt-image-2.6-flare-c |
| prompt | body | string | 是 | 非空绘图或修改说明。 |  |  |
| image | body | string | 否 | 单张公网 URL 或完整 image data URL。与 images 互斥。 |  |  |
| images | body | array | 否 | 多张参考图的 URL/data URL 字符串数组，最多 10 张。image 和 images 必须提供其中之一。 |  |  |
| size | body | string | 否 | auto 或 WIDTHxHEIGHT。宽高为 16 的倍数，最长边 ≤3840，比例 ≤3:1，总像素 655,360–8,294,400。实际像素取决于上游，不保证等于请求值。 | auto, 1024x1024, 1536x1024, 1024x1536, 2048x1152, 3840x2160 | 1024x1024 |
| n / quality / response_format | body | fixed | 否 | 固定单张输出、high 和 URL；请求 b64_json 不会返回 Base64。其他生成控制字段不保证透传。 |  |  |

## 引用图片 URL

```json
{
  "model": "gpt-image-2.6-flare-c",
  "prompt": "Change the cup to green; preserve the background.",
  "image": "https://example.com/reference.jpg",
  "size": "1024x1024"
}
```

### cURL

```bash
curl --fail-with-body --max-time 300 'https://api.unifyllm.top/v1/images/edits' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "gpt-image-2.6-flare-c",
  "prompt": "Change the cup to green; preserve the background.",
  "image": "https://example.com/reference.jpg",
  "size": "1024x1024"
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1/images/edits", {
  method: "POST",
  headers: {
  "Authorization": "Bearer <YOUR_API_KEY>",
  "Content-Type": "application/json"
},
  body: JSON.stringify({
  "model": "gpt-image-2.6-flare-c",
  "prompt": "Change the cup to green; preserve the background.",
  "image": "https://example.com/reference.jpg",
  "size": "1024x1024"
}),
  signal: AbortSignal.timeout(300_000),
});
if (!response.ok) throw new Error(await response.text());
const data = await response.json();
console.log(data);
```

### Python

```python
import json
import requests

payload = json.loads("{\n  \"model\": \"gpt-image-2.6-flare-c\",\n  \"prompt\": \"Change the cup to green; preserve the background.\",\n  \"image\": \"https://example.com/reference.jpg\",\n  \"size\": \"1024x1024\"\n}")
response = requests.post(
    "https://api.unifyllm.top/v1/images/edits",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=payload,
    timeout=(10, 300),
)
response.raise_for_status()
print(response.json())
```

## 多张参考图

```json
{
  "model": "gpt-image-2.6-flare-c",
  "prompt": "Use the shape from the first image and the colors from the second.",
  "images": [
    "https://example.com/shape.jpg",
    "https://example.com/color.jpg"
  ],
  "size": "1536x1024"
}
```

### cURL

```bash
curl --fail-with-body --max-time 300 'https://api.unifyllm.top/v1/images/edits' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "gpt-image-2.6-flare-c",
  "prompt": "Use the shape from the first image and the colors from the second.",
  "images": [
    "https://example.com/shape.jpg",
    "https://example.com/color.jpg"
  ],
  "size": "1536x1024"
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1/images/edits", {
  method: "POST",
  headers: {
  "Authorization": "Bearer <YOUR_API_KEY>",
  "Content-Type": "application/json"
},
  body: JSON.stringify({
  "model": "gpt-image-2.6-flare-c",
  "prompt": "Use the shape from the first image and the colors from the second.",
  "images": [
    "https://example.com/shape.jpg",
    "https://example.com/color.jpg"
  ],
  "size": "1536x1024"
}),
  signal: AbortSignal.timeout(300_000),
});
if (!response.ok) throw new Error(await response.text());
const data = await response.json();
console.log(data);
```

### Python

```python
import json
import requests

payload = json.loads("{\n  \"model\": \"gpt-image-2.6-flare-c\",\n  \"prompt\": \"Use the shape from the first image and the colors from the second.\",\n  \"images\": [\n    \"https://example.com/shape.jpg\",\n    \"https://example.com/color.jpg\"\n  ],\n  \"size\": \"1536x1024\"\n}")
response = requests.post(
    "https://api.unifyllm.top/v1/images/edits",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=payload,
    timeout=(10, 300),
)
response.raise_for_status()
print(response.json())
```

## 响应示例

### 图片 URL — HTTP 200

```json
{
  "created": 1796000000,
  "model": "gpt-image-2.6-flare-c",
  "data": [
    {
      "url": "https://image.ezworkapi.top/oai-hc-img?u=EXAMPLE_IMAGE&sig=EXAMPLE_SIGNATURE"
    }
  ]
}
```

## 相关接口

- [GPT Image 2.6 改图 — 文件上传](https://www.unifyllm.com/zh/docs/api-reference/edit-image-form-data/)
- [GPT Image 2.6 文生图](https://www.unifyllm.com/zh/docs/api-reference/create-image/)
- [GPT Image 生图 — Chat 格式](https://www.unifyllm.com/zh/docs/api-reference/gpt-image-chat/)
