gpt-image-2.5-flare
图像生成、参考图编辑与质量参数
能力概览
接口
https://www.yunqiai.chat/v1/images/generationshttps://www.yunqiai.chat/v1/images/edits?api-version=2025-04-01-preview使用 Authorization: Bearer YOUR_API_KEY。文生图发送 JSON;参考图编辑发送 multipart/form-data,保留完整查询参数,由客户端生成 boundary。
请求参数
| 字段 | 类型 | 说明 |
|---|---|---|
| model | string,必填 | gpt-image-2.5-flare |
| prompt | string,必填 | 生成或编辑指令。多图编辑时按上传顺序说明各图的作用。 |
| size | string | auto 或 WIDTHxHEIGHT,例如 1024x1024、1536x1024、1024x1536、1536x864。 |
| quality | string | auto、low、medium、high、xhigh、max;auto 由服务选择档位。 |
| n | integer | 图片数量,默认 1;返回时遍历完整 data[],不要只保存第一张。 |
| image / image[] | file / file[],编辑必填 | 单图使用 image;多图重复 image[]。输入 PNG、JPEG、WebP。 |
| mask | file,编辑可选 | 带 Alpha 通道的 PNG,尺寸与第一张参考图相同;透明区域表示需要修改的区域。 |
| output_format | string | png(默认)、jpeg。此模型不使用 webp 输出。 |
| output_compression | integer | 0–100,仅 JPEG 输出使用。需要固定文件大小时由客户端另行编码。 |
| background | string | auto(默认)、opaque、transparent;透明输出使用 PNG。 |
| moderation | string | auto(默认)、low;仍须符合内容政策。 |
| response_format | 不发送 | 返回图片直接读取 data[].b64_json。 |
| input_fidelity | 不发送 | 这两个型号不使用此参数。 |
尺寸与输出
宽高使用小写 x 分隔,不传额外 resolution。指定尺寸时,宽和高均需按 16 对齐,长短边比例不超过 3:1。auto 允许服务决定尺寸;下游排版应读取实际图片宽高。
quality 控制生成档位,size 控制输出像素;二者不是同一参数。用量读取 usage,结算以控制台账单为准,不用文件体积推算费用。
参考图与蒙版
图片通过独立的 multipart 文件字段上传,不把 Base64 拼进 prompt。多图使用重复的 image[],第一张对应提示词中的“图 1”。有蒙版时只作用于第一张参考图,编辑结果不保证其他区域逐像素不变。
curl --fail-with-body --max-time 300 'https://www.yunqiai.chat/v1/images/edits?api-version=2025-04-01-preview' \
-H "Authorization: Bearer $YUNQIAI_API_KEY" \
-F 'model=gpt-image-2.5-flare' \
-F 'prompt=保留左侧蓝色方块和文字 YQ-A1,仅将右侧红圆改为绿圆' \
-F 'image=@reference.png;type=image/png' \
-F 'size=1024x1024' -F 'quality=low' -F 'n=1' \
-o result.json多图请求将 image 字段替换为 -F 'image[]=@reference.png' -F 'image[]=@product.png'。局部编辑另外添加 -F 'mask=@mask.png;type=image/png'。
文生图示例
curl --fail-with-body --max-time 300 https://www.yunqiai.chat/v1/images/generations \
-H "Authorization: Bearer $YUNQIAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-image-2.5-flare","prompt":"蓝色陶瓷杯,杯身印有黄色方块,旁边纸卡写着 YUNQI,白色背景产品摄影","size":"1024x1024","quality":"low","n":1}' \
-o result.json命令适用于 Bash / WSL。PowerShell 使用 curl.exe、$env:YUNQIAI_API_KEY 和反引号换行。跨平台 Python 示例见 Agent 文档第 12A 节。
保存图片
import base64, json
from pathlib import Path
from PIL import Image
import io
result = json.loads(Path("result.json").read_text(encoding="utf-8"))
if result.get("error") or not result.get("data"):
raise RuntimeError("请求失败或没有图片,请检查 result.json")
for index, item in enumerate(result["data"]):
raw = base64.b64decode(item["b64_json"], validate=True)
image = Image.open(io.BytesIO(raw))
image.load()
path = Path(f"result-{index}.{image.format.lower()}")
path.write_bytes(raw)
print(path, image.size, result.get("quality"), result.get("usage"))响应说明
从 data[].b64_json 解码图片,结合返回的 size、quality、output_format 和 usage 处理结果。检查 HTTP 状态、error 对象、图片数量及解码结果;不要仅凭 HTTP 200 判定生成成功。
usage.output_tokens_details.image_tokens 为图像输出用量。固定档位需显式发送 quality;auto 不保证每次选择相同档位。
超时处理
同步请求可设置 300 秒读取等待。超时且未收到完整响应时,生成结果未知,不自动重复提交。此接口不使用 MJ 的任务查询路径。