curl --fail-with-body --silent --show-error --max-time 600 \
--request POST \
--url https://code.heihuzi.ai/v1/images/generations \
--header "Authorization: Bearer $HEIHUZI_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-image-2.6-flare",
"prompt": "A simple blue ceramic cup on a white background.",
"n": 1,
"size": "1024x1024",
"quality": "low",
"output_format": "png"
}' \
--output generation.json
{
"created": 1794058821,
"background": "opaque",
"data": [
{
"b64_json": "<此处省略真实图片的 base64>",
"generation_id": "c9317a1c-3b59-4611-86c2-fe59407d7581"
}
],
"output_format": "png",
"quality": "low",
"safety_identifier": null,
"size": "1024x1024",
"usage": {
"input_tokens": 16,
"input_tokens_details": {
"image_tokens": 0,
"text_tokens": 16
},
"output_tokens": 824,
"output_tokens_details": {
"image_tokens": 824,
"text_tokens": 0
},
"total_tokens": 840
}
}
GPT Image 2.6
GPT Image 2.6 图像生成
生成图片和 GIF 动图的完整实测示例、参数和响应。
POST
/
v1
/
images
/
generations
curl --fail-with-body --silent --show-error --max-time 600 \
--request POST \
--url https://code.heihuzi.ai/v1/images/generations \
--header "Authorization: Bearer $HEIHUZI_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-image-2.6-flare",
"prompt": "A simple blue ceramic cup on a white background.",
"n": 1,
"size": "1024x1024",
"quality": "low",
"output_format": "png"
}' \
--output generation.json
{
"created": 1794058821,
"background": "opaque",
"data": [
{
"b64_json": "<此处省略真实图片的 base64>",
"generation_id": "c9317a1c-3b59-4611-86c2-fe59407d7581"
}
],
"output_format": "png",
"quality": "low",
"safety_identifier": null,
"size": "1024x1024",
"usage": {
"input_tokens": 16,
"input_tokens_details": {
"image_tokens": 0,
"text_tokens": 16
},
"output_tokens": 824,
"output_tokens_details": {
"image_tokens": 824,
"text_tokens": 0
},
"total_tokens": 840
}
}
本页适用于 GPT Image 2.6。使用 2.5 请查看 GPT Image 2.5 API。
通过
请求会把完整响应保存到
跨行叠加参数会形成新的组合,请先在自己的业务里验证再使用。
再把响应里的 base64 解码保存为
本次实测返回 400 的情况:
POST https://code.heihuzi.ai/v1/images/generations 生成图片或 GIF 动图。验证日期:2026-11-07。请使用具有 GPT Image 2.6 权限的 API Key,并设置环境变量 HEIHUZI_API_KEY。
curl --fail-with-body --silent --show-error --max-time 600 \
--request POST \
--url https://code.heihuzi.ai/v1/images/generations \
--header "Authorization: Bearer $HEIHUZI_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-image-2.6-flare",
"prompt": "A simple blue ceramic cup on a white background.",
"n": 1,
"size": "1024x1024",
"quality": "low",
"output_format": "png"
}' \
--output generation.json
generation.json,其中 data[].b64_json 是图片的 base64。
请求参数
参数名、取值和返回结构与 OpenAI 官方POST /v1/images/generations 一致。下面每个取值都在正式环境实际调用过,具体组合见已验证的参数组合。
填写
gpt-image-2.6-flare 或 gpt-image-2.6-sunburst。官方要求明确填写型号;本站省略时使用 gpt-image-2.5-flare,不是 2.6。背景。已验证
transparent、opaque、auto。transparent 配 png 得到透明背景的 PNG;GIF 填 auto 时实际返回 opaque。实际背景以响应里的 background 为准。GIF 的帧数,只能与
output_format: "gif" 一起用。已验证 2、4、9、12、16,生成的帧数与请求一致;不填时为 9 帧。填 17 或在非 GIF 请求里带这个字段,返回 400。GIF 每帧显示的时长,单位毫秒,只用于 GIF。已验证
20、100、200、500、2000,生成的每帧时长与请求一致;不填时为 200。填 105 实际为 100 毫秒(按 10 毫秒取整);填 10 返回 400。已验证
1024x1024、1536x1024、1024x1536、2048x2048、2880x2880、3840x2160、自定义的 1536x864 和 auto。宽高都要是 16 的倍数,1000x1000 返回 400。auto 的返回尺寸不固定,本次出现过 1312x1199、1536x1024,需要固定尺寸时请明确填写。GIF 的 size 指每一帧的尺寸:不填和填 512x512 都输出 512×512;填 1024x1024 返回 400。设置
true 后返回 SSE(text/event-stream),两款型号都验证过;省略时返回 JSON。见下方流式返回。已验证的参数组合
以下每行都在正式环境实际调用,返回 200 并核对了图片文件。| 模型 | 尺寸 | 质量 | 格式 | 其他 | 实际结果 |
|---|---|---|---|---|---|
| Flare | 1024x1024 | low | png | n: 1 | 1024×1024 PNG |
| Flare | 1024x1024 | low | png | n: 2 | 两张 1024×1024 PNG |
| Flare | 1024x1024 | low | png | n: 10 | 十张 1024×1024 PNG |
| Sunburst | 1536x1024 | low | webp | n: 2 | 两张 1536×1024 WebP |
| Flare | 2048x2048 | medium | jpeg | 2048×2048 JPEG | |
| Sunburst | 2048x2048 | medium | jpeg | output_compression: 50、safety_identifier | 2048×2048 JPEG,safety_identifier 原样返回 |
| Flare | 2880x2880 | high | webp | 2880×2880 WebP | |
| Sunburst | 2880x2880 | high | png | 2880×2880 PNG | |
| Flare | 1024x1024 | max | png | 1024×1024 PNG | |
| Sunburst | 1024x1024 | max | png | 1024×1024 PNG | |
| Flare | 1024x1536 | xhigh | webp | output_compression: 0 | 1024×1536 WebP |
| Sunburst | 1024x1536 | low | png | background: "transparent" | 透明背景的 1024×1536 PNG |
| Flare | 1536x864 | low | png | background: "opaque"、moderation: "low"、user | 1536×864 PNG,user 作为 safety_identifier 返回 |
| Flare | 3840x2160 | low | jpeg | 3840×2160 JPEG | |
| Flare | auto | auto | 省略 | complexity: "low"、safety_identifier | 1312×1199 PNG,质量 low |
| Sunburst | auto | auto | 省略 | stream: true、partial_images: 3 | 1 张预览和 1536×1024 PNG 完成图,质量 low |
| Flare | 1024x1024 | low | png | complexity 分别为 low、medium、high | 均为 1024×1024 PNG |
| Flare | 省略 | low | gif | frame_count: 4、frame_duration_ms: 100 | 512×512 GIF,4 帧,每帧 100 毫秒 |
| Flare | 512x512 | low | gif | frame_count: 2、frame_duration_ms: 20、moderation: "auto" | 512×512 GIF,2 帧,每帧 20 毫秒 |
| Sunburst | 省略 | low | gif | frame_count: 9、frame_duration_ms: 200 | 512×512 GIF,9 帧,每帧 200 毫秒 |
| Sunburst | 省略 | low | gif | 不填帧数和帧时长,background: "auto"、moderation: "low" | 512×512 GIF,9 帧,每帧 200 毫秒 |
| Flare | 省略 | low | gif | frame_count: 12、frame_duration_ms: 500 | 512×512 GIF,12 帧,每帧 500 毫秒 |
| Flare | 省略 | low | gif | frame_count: 16、frame_duration_ms: 200 | 512×512 GIF,16 帧,每帧 200 毫秒 |
| Flare | 省略 | low | gif | frame_count: 16、frame_duration_ms: 2000 | 512×512 GIF,16 帧,每帧 2000 毫秒 |
生成 GIF 动图
下面的完整示例生成一张 9 帧、每帧 200 毫秒的 GIF,响应保存到rabbit.json。
curl --fail-with-body --silent --show-error --max-time 600 \
--request POST \
--url https://code.heihuzi.ai/v1/images/generations \
--header "Authorization: Bearer $HEIHUZI_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-image-2.6-sunburst",
"prompt": "A small rabbit waving, simple flat illustration.",
"quality": "low",
"output_format": "gif",
"frame_count": 9,
"frame_duration_ms": 200
}' \
--output rabbit.json
rabbit.gif:
python3 -c 'import base64, json; d = json.load(open("rabbit.json")); open("rabbit.gif", "wb").write(base64.b64decode(d["data"][0]["b64_json"]))'
- GIF 输出 512×512,响应里的
output_format为gif、size为512x512。 - 费用按实际输出用量计算,不随帧数平稳增加。本次 4、9、12、16 帧的输出用量分别是 555、1172、1038、1668,12 帧比 9 帧还少。
流式返回
curl --fail-with-body --silent --show-error --no-buffer --max-time 600 \
--request POST \
--url https://code.heihuzi.ai/v1/images/generations \
--header "Authorization: Bearer $HEIHUZI_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-image-2.6-flare",
"prompt": "A simple blue ceramic cup on a white background.",
"n": 1,
"size": "1024x1024",
"quality": "low",
"output_format": "png",
"stream": true
}' \
--output stream.txt
stream.txt 里是 SSE 事件。这个示例没有填 partial_images,只收到一个 image_generation.completed 事件,它的 b64_json 是最终图片,usage 是本次用量。填了 partial_images 时,完成事件之前会先收到 image_generation.partial_image 预览事件(带 partial_image_index),张数可能少于请求值。请以完成事件作为成功依据。
错误返回
参数不合法时返回 HTTP 400,结构与官方相同:error 里有 message、type、param、code。下面是填 frame_count: 17 的真实返回:
{
"error": {
"code": "invalid_value",
"message": "Invalid 'frame_count' for GIF output. Received 17. Use an integer from 2 to 16, or omit 'frame_count' to use 9.",
"param": "frame_count",
"type": "image_generation_user_error"
}
}
frame_count 超过 16、frame_duration_ms 小于 20、GIF 加 stream: true、非 GIF 请求带 frame_count、尺寸不是 16 的倍数、n 超过 10、GIF 填 size: "1024x1024"。这些请求没有扣费。
真实响应节选
下面是页首示例的一次真实响应,图片 base64 已省略。{
"created": 1794058821,
"background": "opaque",
"data": [
{
"b64_json": "<此处省略真实图片的 base64>",
"generation_id": "c9317a1c-3b59-4611-86c2-fe59407d7581"
}
],
"output_format": "png",
"quality": "low",
"safety_identifier": null,
"size": "1024x1024",
"usage": {
"input_tokens": 16,
"input_tokens_details": {
"image_tokens": 0,
"text_tokens": 16
},
"output_tokens": 824,
"output_tokens_details": {
"image_tokens": 824,
"text_tokens": 0
},
"total_tokens": 840
}
}
data[].b64_json 解码后是图片文件,usage 是本次用量。同样是 1024×1024 低画质,2.6 的输出用量是 824,2.5 是 196,单张费用约为 2.5 的 4 倍。低画质想省钱可以用 GPT Image 2.5。