图像生成 API(Nano Banana / GPT Image / GPT-5.5)
本站有四条出图链路,模型、请求路径和计费方式各不相同。本页是程序化调用的参考;只想在网页上出图,用 青墨工坊。
链路对照
| 链路 | 模型 | 端点 | 计费 | 令牌分组 |
|---|---|---|---|---|
| Nano Banana | nano-banana-pro、nano-banana-2(含 -2k / -4k 变体)、nano-banana-2-lite | /v1beta/models/{model}:generateContent(推荐)或 /v1/chat/completions | 按用量 | 0_Tools_Nano_Banana |
| GPT Image 2 / 2.5 | GPT Image 2、Flare、Sunburst(均含 -openai 版本,详见下表) | /v1/images/generations、/v1/images/edits、/v1/responses | 按张 | 0_Tools_GPT_IMAGE |
| GPT Image 2.6 | gpt-image-2.6-flare、gpt-image-2.6-sunburst(PNG / 动态 GIF) | /v1/images/generations | 按次 | 0_Tools_GPT_IMAGE |
| GPT-5.5 / 5.4 出图 | gpt-5.5、gpt-5.4 走 image_generation 工具 | /v1/responses | 按 token + tool 调用 | 1_vip_codex / 2_free_codex 等 |
通用约定
- 认证:
Authorization: Bearer sk-xxx,所有链路一致。 - Base URL:
https://e-flowcode.cc。唯一例外是 Cherry Studio 调gpt-image-2,见第 2 节。 - 令牌必须属于目标模型所在的分组,否则返回
model_not_found · No available channel for model X under group Y。
1. Nano Banana(两种协议)
nano-banana-pro ≈ gemini-3-pro-image-preview,nano-banana-2 ≈ gemini-3.1-flash-image-preview,nano-banana-2-lite ≈ gemini-3.1-flash-lite-image,都是 Google 的出图模型。nano-banana-2-lite 只支持 1K 输出,下文的 2K / 4K 档位和比例说明只适用于 Pro 与 2。本站支持两种调用协议:
| 方式 A:OpenAI chat completions | 方式 B:Gemini 原生 generateContent | |
|---|---|---|
| 端点 | /v1/chat/completions | /v1beta/models/{model}:generateContent |
| 图片返回位置 | 消息内容里的 data:image/jpeg;base64,... markdown 链接,需正则提取 | 结构化的 inlineData.data,直接解码 |
| 尺寸参数 | extra_body.google.image_config | generationConfig.imageConfig |
| 字段命名 | snake_case:aspect_ratio / image_size | camelCase:aspectRatio / imageSize |
| 适用 | 只认 OpenAI 协议的客户端(如 Cherry Studio) | 其余情况;image-web 也用这条 |
能用方式 B 就用方式 B。两种方式的字段大小写正好相反,不要混用。
尺寸档位(两种方式通用)
image_size / imageSize 取值,两个模型都支持:
| 值 | 1:1 时实际像素 |
|---|---|
1K | 1024×1024 |
2K | 2048×2048 |
4K | 4096×4096 |
非方图按"短边对齐档位 + 长边由比例推算"。例如 2K + 21:9 → 3168×1344。
aspect_ratio / aspectRatio 取值,两个模型都支持以下 10 档:
1:1 3:2 2:3 4:3 3:4 4:5 5:4 16:9 9:16 21:9nano-banana-2 额外支持 4 档极端比例(横竖窄长画面):
1:4 4:1 1:8 8:1nano-banana-pro 传这 4 个不会报错,但会回落到默认 16:9,出图不是你要的形状。
1A. 方式 A:chat completions + image_config
走的是 chat completions,不是 images 端点。
端点
POST /v1/chat/completions指定比例和分辨率
OpenAI 的 size: "1024x1024" 在这里会被忽略,模型固定输出默认尺寸。控制尺寸只能用 extra_body.google.image_config:
json
{
"model": "nano-banana-pro",
"messages": [{ "role": "user", "content": "a red apple on a wooden table, photo" }],
"extra_body": {
"google": {
"image_config": {
"aspect_ratio": "16:9",
"image_size": "2K"
}
}
}
}字段必须是 snake_case。写成 camelCase(aspectRatio / imageSize / imageConfig),上游直接拒绝:
extra_body.google.image_config.aspectRatio is not supported, use extra_body.google.image_config.aspect_ratio instead可选档位见上面的尺寸档位。
完整 curl 示例
bash
curl -X POST https://e-flowcode.cc/v1/chat/completions \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "nano-banana-pro",
"messages": [
{ "role": "user", "content": "a red apple on a wooden table, soft daylight, photo" }
],
"stream": false,
"extra_body": {
"google": {
"image_config": {
"aspect_ratio": "16:9",
"image_size": "2K"
}
}
}
}'返回的 choices[0].message.content 形如:
正则 data:image\/[^;]+;base64,([^)]+) 抓出 base64 解码即可。
图生图
参考图按 chat completions 标准格式塞 messages[*].content:
json
{
"model": "nano-banana-pro",
"messages": [{
"role": "user",
"content": [
{ "type": "text", "text": "把围巾改成蓝色,其他保持不变" },
{ "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,..." } }
]
}],
"extra_body": { "google": { "image_config": { "aspect_ratio": "1:1", "image_size": "1K" } } }
}1B. 方式 B:Gemini 原生 generateContent
端点
POST /v1beta/models/{model}:generateContent{model} 填别名 nano-banana-pro / nano-banana-2。裸 gemini-3-* 名在本站没有渠道,会返回 503 model_not_found。鉴权头同样是 Authorization: Bearer sk-xxx,带不带 x-goog-api-key 都行。
请求体
尺寸放在 generationConfig.imageConfig,字段用 camelCase:aspectRatio / imageSize,档位见尺寸档位。responseModalities 必须包含 "IMAGE",否则只回文字不出图。
json
{
"contents": [{ "parts": [{ "text": "a red apple on a wooden table, photo" }] }],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"],
"imageConfig": { "aspectRatio": "16:9", "imageSize": "2K" }
}
}完整 curl 示例
bash
curl -X POST https://e-flowcode.cc/v1beta/models/nano-banana-pro:generateContent \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"contents": [{ "parts": [{ "text": "a red apple on a wooden table, soft daylight, photo" }] }],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"],
"imageConfig": { "aspectRatio": "16:9", "imageSize": "2K" }
}
}'图在 candidates[0].content.parts[] 的 inlineData 里,直接 base64 解码:
json
{ "candidates": [{ "content": { "parts": [
{ "inlineData": { "mimeType": "image/jpeg", "data": "/9j/4AAQ..." } }
] } }] }图生图 / 多图融合
参考图作为 inlineData 放进 parts,排在指令 text 之前。多张参考图就放多个 inlineData,模型会一起参考,多图融合也是这么传:
json
{
"contents": [{ "parts": [
{ "inlineData": { "mimeType": "image/jpeg", "data": "<图A base64>" } },
{ "inlineData": { "mimeType": "image/jpeg", "data": "<图B base64>" } },
{ "text": "把第二张图的柠檬放到第一张图的杯子旁边" }
] }],
"generationConfig": { "responseModalities": ["TEXT", "IMAGE"], "imageConfig": { "imageSize": "1K" } }
}1C. 计费(方式 A / B 通用)
分组 0_Tools_Nano_Banana,按用量计费,各模型当前价格以 模型广场 为准。
| 模型 ID | 说明 |
|---|---|
nano-banana-pro | 通用旗舰 |
nano-banana-2 | 默认 1K |
nano-banana-2-2k | 强制 2K 出片 |
nano-banana-2-4k | 强制 4K 出片 |
nano-banana-2-lite | 低延迟、高吞吐,仅 1K;适合贴纸、局部修改和交互式创作 |
nano-banana-2 默认按 1K 出片。需要稳定的 2K / 4K 输出时,直接调 nano-banana-2-2k / nano-banana-2-4k 这两个独立模型 ID,即使你已经传了 image_config.image_size。
2. GPT Image 2 / 2.5(Images 与 Responses)
三款官方模型,每款有一个常规标识和一个本站 -openai 路由标识,共六个:
| 模型标识 | 本站分辨率 |
|---|---|
gpt-image-2 | 仅 1K |
gpt-image-2-openai | 1K / 2K / 4K |
gpt-image-2.5-flare | 仅 1K |
gpt-image-2.5-flare-openai | 1K / 2K / 4K |
gpt-image-2.5-sunburst | 仅 1K |
gpt-image-2.5-sunburst-openai | 1K / 2K / 4K |
分组 0_Tools_GPT_IMAGE,按张计费,价格见 模型广场。-openai 是本站的路由后缀,分辨率限制属于本站规则,不是 OpenAI 官方的模型命名。
- GPT Image 2:高质量图像生成与编辑,支持灵活的图片尺寸和高保真参考图。官方介绍
- GPT Image 2.5 Flare:快速、高质量的日常图像生成,适合看重速度的创作和迭代。官方介绍
- GPT Image 2.5 Sunburst:OpenAI 能力最强的图像生成与编辑模型,侧重编辑精度,适合精细创作和修改。官方介绍
三款都接受文本和图像输入、输出图像。更多参数和示例见 官方图像生成指南。
端点与分辨率选择
六个标识都支持 Image Generation(POST /v1/images/generations)和 Responses(POST /v1/responses)两种接入方式;图生图用 Images 的 POST /v1/images/edits。
直接调 API 时,要 2K / 4K 必须显式选同款的 -openai 标识,例如 gpt-image-2.5-flare-openai;不带后缀的只出 1K。工坊在高分辨率请求中会自动切到同款 -openai 版本,具体以上线配置和页面提示为准。
关于 Responses:官方指南里,Images 请求把图像模型直接填在顶层 model;Responses 则用支持生图工具的主模型,在 tools: [{ type: "image_generation", model: "gpt-image-2.5-sunburst" }] 里指定图像模型。本站通过 0_Tools_GPT_IMAGE 提供的是图像模型的 Responses 兼容入口,顶层 model 直接填本站图像模型标识。这两种写法不要混用。
下面的 Images 示例可以把 model 换成表中任一标识,注意对应的分辨率限制。
文生图
bash
curl -X POST https://e-flowcode.cc/v1/images/generations \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "a samurai standing in cherry blossoms, anime",
"n": 1,
"size": "1024x1024",
"response_format": "b64_json"
}'size 可选值(OpenAI 官方约束):1024x1024 / 1536x1024 / 1024x1536 / 2048x2048 / 2048x1152 / 3840x2160 / 2160x3840 / auto。自定义尺寸时边长 ≤ 3840 且为 16 的倍数。本站不带 -openai 的标识仍只出 1K。
返回:
json
{ "created": 1777..., "data": [{ "b64_json": "/9j/..." }] }流式文生图与中间预览
使用 gpt-image-2-openai 时,可以设 stream: true,并用 partial_images 指定中间预览图数量(1~3):
bash
curl -N -X POST https://e-flowcode.cc/v1/images/generations \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2-openai",
"prompt": "a samurai standing in cherry blossoms, anime",
"n": 1,
"size": "3840x2160",
"quality": "high",
"output_format": "png",
"response_format": "b64_json",
"stream": true,
"partial_images": 2
}'响应类型为 text/event-stream。按 data: 行解析,主要事件如下:
type | 关键字段 | 说明 |
|---|---|---|
image_generation.partial_image | partial_image_index、partial_image_b64 | 中间预览图,可直接按 base64 显示 |
image_generation.completed | b64_json、size | 最终图片和实际输出尺寸 |
[DONE] | — | 流结束 |
示例:
text
data: {"type":"image_generation.partial_image","partial_image_index":0,"partial_image_b64":"..."}
data: {"type":"image_generation.completed","b64_json":"...","size":"3840x2160"}
data: [DONE]中间预览只用来展示进度,保存图片以 image_generation.completed 里的 b64_json 为准。不需要预览时省略 stream 和 partial_images,响应就是普通 JSON。
图生图(含 mask)
/v1/images/edits 走 multipart:
bash
curl -X POST https://e-flowcode.cc/v1/images/edits \
-H "Authorization: Bearer sk-xxx" \
-F "model=gpt-image-2" \
-F "prompt=replace the sky with sunset" \
-F "image=@./input.png" \
-F "mask=@./mask.png" \
-F "size=1024x1024" \
-F "response_format=b64_json"多张参考图用 image[][email protected] -F image[][email protected] 的 image[] 字段名。
gpt-image-2-openai 的流式图生图示例:
bash
curl -N -X POST https://e-flowcode.cc/v1/images/edits \
-H "Authorization: Bearer sk-xxx" \
-F "model=gpt-image-2-openai" \
-F "prompt=replace the sky with sunset" \
-F "image=@./input.png" \
-F "mask=@./mask.png" \
-F "size=2048x2048" \
-F "quality=high" \
-F "output_format=png" \
-F "response_format=b64_json" \
-F "stream=true" \
-F "partial_images=2"事件格式与流式文生图相同,最终图片同样以 image_generation.completed 为准。多张参考图继续用多个 image[] 字段。
Cherry Studio 调 gpt-image-2 必须改地址
Cherry Studio 内置的 OpenAI 适配器对 image endpoint 的处理与本站不兼容。调 gpt-image-2 时 Base URL 必须填 https://e-flowcode.cc/cherry,否则请求异常、拿不到图。其他模型仍用 https://e-flowcode.cc。
3. GPT Image 2.6(PNG 与动态 GIF)
gpt-image-2.6-flare 与 gpt-image-2.6-sunburst 走同一个 Images 端点,请求结构相同,替换 model 即可。除静态 PNG 外,可通过 output_format: "gif" 生成动态 GIF。
| 模型标识 | 已验证调用 |
|---|---|
gpt-image-2.6-flare | 文生 PNG、文生 GIF |
gpt-image-2.6-sunburst | 文生 PNG、文生 GIF |
- 分组
0_Tools_GPT_IMAGE,按次计费,PNG 和 GIF 同价;价格见 模型广场。 - 2.6 没有
-openai版本,请使用上表的完整 ID,不要写image2.6等简称。 - 本节依据 2026-11-05 的实测,范围为
POST /v1/images/generations、quality: "low"、n: 1。图片编辑、多张输出、其他质量档位、流式输出及 Responses 路径未验证。
实测原则
模型在 /v1/models 中可见、HTTP 200、文件尺寸和帧数符合请求是三件不同的事。请以返回文件的实际宽高、帧数为准,不要只看请求参数或状态码。
3A. 静态 PNG
bash
curl --fail-with-body --max-time 600 \
https://e-flowcode.cc/v1/images/generations \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2.6-flare",
"prompt": "A cute orange tabby cat wearing an orange scarf, raising one front paw in greeting. Warm storybook illustration, plain cream background, no text.",
"n": 1,
"size": "1536x1024",
"quality": "low",
"output_format": "png"
}' \
-o response-png.jsonresponse-png.json 是 JSON 响应,不是图片;按下文 3C 解码或下载。
PNG 尺寸实测(不是平台承诺的上限或成功率保证):
请求 size | Flare 实际输出 | Sunburst 实际输出 |
|---|---|---|
1536x1024 | 1536×1024 | 1536×1024 |
2048x2048 | 2048×2048 | 2048×2048 |
3840x2160 | 3840×3413,比例不符 | 3840×2160 |
需要固定画幅时,先读取返回文件的真实宽高再进入后续流程;Flare 的 4K 横图目前会出现比例偏差。
3B. 动态 GIF
同一端点设置 output_format: "gif",并在提示词里写清动作和循环方式:
bash
curl --fail-with-body --max-time 600 \
https://e-flowcode.cc/v1/images/generations \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2.6-sunburst",
"prompt": "Create an animated GIF of a cute orange tabby cat wearing an orange scarf. The cat gently waves one front paw, blinks, and returns to its starting pose in a seamless loop. Fixed camera, plain cream background, no text.",
"n": 1,
"size": "512x512",
"quality": "low",
"output_format": "gif",
"frame_count": 9,
"frame_duration_ms": 200
}' \
-o response-gif.json| GIF 专用参数 | 含义 | 实测表现 |
|---|---|---|
frame_count | 请求帧数 | 请求 9,实际 8~9 帧;16 帧请求出现过失败,有效上限未确认 |
frame_duration_ms | 每帧时长(毫秒) | 请求 200,实测均为 180 |
size | 每帧宽高 | 请求 512x512,实际约 413~414 × 401~414 |
这两个字段只用于 GIF,不要传给 PNG 请求。
多轮实测(512x512、9 帧、200 ms)结果:
| 模型 | 实际尺寸 | 帧数 | 每帧时长 | 循环 |
|---|---|---|---|---|
| Flare | 414×412 / 414×414 / 413×412 | 9 | 180 ms | 无限循环 |
| Sunburst | 414×401 / 414×413 | 8 | 180 ms | 无限循环 |
两款都返回真实多帧动画(各帧像素不同),但尺寸、帧数、时长不会精确执行。另外,1024x1024 的 GIF 请求两款都返回过 upstream_text_reply,Flare 的 16 帧请求出现过连接提前结束;32 / 64 帧、500 ms/帧等配置尚未验证。本站不承诺 GIF 的精确参数或稳定成功率。
3C. 处理响应
成功响应的结果在 data[0],可能是 b64_json,也可能是 url。实测 PNG 和 GIF 都会返回 URL,不要按格式推断:
json
{
"created": 1793886300,
"output_format": "png",
"usage": { "input_tokens": 0, "output_tokens": 0, "total_tokens": 0 },
"data": [{
"url": "https://.../result.png",
"revised_prompt": "..."
}]
}- 有
b64_json就 Base64 解码保存;有url就下载(下载不需要带 API Key)。URL 有效期未验证,建议拿到后立即保存。 - 不要依赖
width/height/model等字段一定存在。 usage可能全为 0,不代表免费,费用以站点账单为准。- 没有
data[0]或两个字段都没有时,不要把文字响应存成.png/.gif。
3D. Python 示例(标准库)
支持两款模型与 PNG / GIF,兼容 b64_json 和 url,校验文件头,不覆盖已有文件,不自动重试。
必须设置 User-Agent
Python urllib 默认的 Python-urllib/3.x 请求头会被站点防护拦截,返回 HTTP 403、正文为 error code: 1010。下面的脚本已显式设置 User-Agent。
保存为 generate_image.py:
python
import argparse
import base64
import json
import os
import sys
from pathlib import Path
from urllib.error import HTTPError, URLError
from urllib.parse import urlparse
from urllib.request import Request, urlopen
ENDPOINT = "https://e-flowcode.cc/v1/images/generations"
MODELS = ("gpt-image-2.6-flare", "gpt-image-2.6-sunburst")
USER_AGENT = "generate-image/1.0" # 默认的 Python-urllib UA 会被拦截(403 / 1010)
def save_result(response, output_path, expected_format):
results = response.get("data")
if not isinstance(results, list) or not results:
raise ValueError("响应中没有图片结果 data[0]")
item = results[0]
if item.get("b64_json"):
content = base64.b64decode(item["b64_json"], validate=True)
elif item.get("url"):
image_url = item["url"]
if urlparse(image_url).scheme != "https":
raise ValueError("图片 URL 不是 HTTPS,请检查响应")
# 下载图片不携带 API Key。
with urlopen(Request(image_url, headers={"User-Agent": USER_AGENT}), timeout=120) as download:
content = download.read()
else:
raise ValueError("图片结果缺少 b64_json 和 url")
actual_format = None
if content.startswith(b"\x89PNG\r\n\x1a\n"):
actual_format = "png"
elif content.startswith((b"GIF87a", b"GIF89a")):
actual_format = "gif"
if actual_format != expected_format:
raise ValueError(f"返回文件格式不符:请求 {expected_format},识别为 {actual_format}")
# 不覆盖已有文件。
with output_path.open("xb") as file:
file.write(content)
print(f"已保存:{output_path.resolve()}({len(content)} 字节)")
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--model", choices=MODELS, default=MODELS[0])
parser.add_argument("--format", choices=("png", "gif"), default="png")
parser.add_argument("--prompt", required=True)
parser.add_argument("--size", help="宽x高;默认 PNG 1536x1024,GIF 512x512")
parser.add_argument("--frames", type=int, default=9)
parser.add_argument("--frame-duration-ms", type=int, default=200)
parser.add_argument("--out", required=True, help="输出文件路径;父目录需已存在")
args = parser.parse_args()
api_key = os.environ.get("EFLOW_API_KEY")
if not api_key:
raise ValueError("请先设置 EFLOW_API_KEY 环境变量")
output = Path(args.out)
if output.exists():
raise FileExistsError(f"输出文件已存在:{output}")
if not output.parent.is_dir():
raise ValueError("输出文件的父目录不存在")
if args.format == "gif" and (args.frames <= 0 or args.frame_duration_ms <= 0):
raise ValueError("帧数和帧时长需为正数")
body = {
"model": args.model,
"prompt": args.prompt,
"n": 1,
"size": args.size or ("512x512" if args.format == "gif" else "1536x1024"),
"quality": "low",
"output_format": args.format,
}
if args.format == "gif":
body.update(frame_count=args.frames, frame_duration_ms=args.frame_duration_ms)
request = Request(
ENDPOINT,
data=json.dumps(body, ensure_ascii=False).encode("utf-8"),
headers={
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json; charset=utf-8",
"User-Agent": USER_AGENT,
},
method="POST",
)
with urlopen(request, timeout=600) as response:
result = json.loads(response.read().decode("utf-8"))
save_result(result, output, args.format)
if __name__ == "__main__":
try:
main()
except HTTPError as error:
detail = error.read().decode("utf-8", errors="replace")
print(f"HTTP {error.code}: {detail}", file=sys.stderr)
sys.exit(1)
except (URLError, OSError, ValueError, KeyError, TypeError) as error:
print(f"调用或保存失败:{error}", file=sys.stderr)
sys.exit(1)运行(每条命令发起一次生成请求):
bash
export EFLOW_API_KEY="sk-xxx" # PowerShell:$env:EFLOW_API_KEY = "sk-xxx"
python generate_image.py --model gpt-image-2.6-flare --format png --prompt "A cute orange cat wearing an orange scarf, warm storybook illustration." --out cat.png
python generate_image.py --model gpt-image-2.6-sunburst --format gif --frames 9 --frame-duration-ms 200 --prompt "An animated GIF of an orange cat waving one paw and blinking, fixed camera, seamless loop." --out cat.gif文件头检查只确认格式。需要精确尺寸、帧数或时长时,用 Pillow 等工具读取实际文件再验收。
3E. 错误与排查
| 现象 / 错误码 | 含义 | 处理 |
|---|---|---|
HTTP 403,正文 error code: 1010 | 请求的 User-Agent 被站点防护拦截(常见于 Python urllib 默认 UA) | 显式设置自定义 User-Agent |
HTTP 400,upstream_text_reply | 上游只回了文字(如"无法完成生成"),没有图像 | 按生成失败处理,记录时间与请求 ID;它不直接说明尺寸或帧数超限 |
HTTP 500,do_request_failed | 渠道到上游的请求失败 | 稍后重试;持续出现请联系管理员 |
| SSL EOF / 连接提前结束 | 响应没有完整接收,可能发生在客户端、网关或上游任一层 | 检查网络和长连接;实测偶发,单次重试即恢复 |
| HTTP 200,但尺寸或帧数不符 | 已出图,但参数未被精确执行 | 读取实际文件,按业务标准决定是否接受 |
生成耗时实测 PNG 约 20~30 秒、GIF 约 40 秒,示例超时设为 600 秒。超时或断连不代表上游没有执行,重新提交可能产生新的计费请求;业务如需重试,请限制次数。
4. GPT-5.5 / 5.4 出图(/v1/responses + image_generation 工具)
GPT-5 系列出图不走 /v1/images/generations,而是 /v1/responses 下的 image_generation 工具调用。下面的请求骨架里,stream、prompt 前缀和 tool_choice 三处都不能省,原因见后文。
端点与最小请求骨架
POST /v1/responsesjson
{
"model": "gpt-5.5",
"input": "Use the following text as the complete prompt. Do not rewrite it:\na samurai standing in cherry blossoms, anime",
"tools": [
{
"type": "image_generation",
"action": "generate",
"size": "1024x1024",
"output_format": "png",
"quality": "auto",
"partial_images": 3
}
],
"tool_choice": "required",
"stream": true
}参数约束
stream: true
GPT-5.5 出图通常要 30–120 秒,high 档 + 4K 可能超过 3 分钟。站点前置 nginx 的 proxy_read_timeout 实测约 120 秒,不开 stream 的长任务会被切断。开 stream 后上游约每 30 秒推一次 keepalive 事件维持连接,客户端按事件累积出最终图。
只有确定任务很短时才考虑不开 stream。
Prompt 加"不改写"前缀
GPT-5.5 默认会先翻译、优化或做安全改写,再把 prompt 交给 image_generation 工具,出来的图可能跟你写的不是一回事。把下面这行前缀一字不改地放在 input 最前面:
Use the following text as the complete prompt. Do not rewrite it:
<你的真实 prompt>后端日志里的 revised_prompt 字段是改写后的版本,可以用来排查。
tool_choice: "required"
不写或写成 "auto" 时,模型有一定概率不调工具,直接回一段文字(比如"我建议你用以下 prompt 调用工具…")。"required" 强制走工具。
size 会被服务端归一化
/v1/responses 下的 size 会经过一层归一化校验:
- 边长按 16 的倍数向下取整
- 单边 ≤ 3840
- 宽高比 ≤ 3:1(含 1:3)
- 像素总数在 [655 360, 8 294 400] 之间(约 0.65 MP 到 8.29 MP)
例如传 5000x500,会先按比例缩到 ≤3840,再按 3:1 截断,再对齐 16 的倍数,收敛成合法值。建议直接传按"档位 × 比例"算好的合法值,常用的有:
| 档位 | 1:1 | 3:2 | 2:3 | 16:9 | 9:16 |
|---|---|---|---|---|---|
| 1K | 1024×1024 | 1216×832 | 832×1216 | 1376×768 | 768×1376 |
| 2K | 2048×2048 | 2496×1664 | 1664×2496 | 2752×1536 | 1536×2752 |
| 4K | 3840×3840 (落到 max) | — | — | 3840×2160 | 2160×3840 |
size: "auto" 也合法,由模型自己选。
output_format、output_compression 与 quality
output_format | output_compression |
|---|---|
png | 不能传,传了上游返回 400 |
jpeg / webp | 可选,0–100 整数,越低体积越小 |
quality 只接受 low / medium / high / auto。其他值(包括空字符串)就不要传,让上游用默认值。
流式响应事件
stream: true 返回 text/event-stream,需要处理这几类事件:
event 类型(data.type 字段) | 含义 |
|---|---|
keepalive | 心跳,丢弃 |
response.image_generation_call.partial_image | 中间预览图(最多 3 张,从粗到细)。data.partial_image_b64 是完整 base64 图,可直接显示 |
response.output_item.done(item.type == "image_generation_call") | 最终图。item.result 是完整 b64,item.size / item.quality / item.output_format 是上游实际生效的参数 |
response.completed | 任务结束 |
response.failed / error | 失败,response.error.message 是原因 |
服务端可能接受了你传的 size,实际却出了降级后的小图。以 output_item.done.item.size 为准,跟请求不一致就是被降级了,常见原因是渠道对该模型设了上限倍率。
n > 1 的处理
image_generation 工具一次调用只返回 1 张图。要 4 张就并发发 4 次请求,自己合并结果,image-web 前端就是这么做的。
计费
按 token + tool 调用计费,不是按张固定价,高质量、高分辨率的图消耗的输出 token 更多。价格见 模型广场。
选哪个
| 你想要 | 选 |
|---|---|
| 写实 / 摄影 / 自然光 / 多 ratio 灵活 | nano-banana-pro |
| 极端窄长 banner(1:8 / 8:1)或批量出图 | nano-banana-2(含 -2k/-4k) |
| 低延迟交互、贴纸、局部修改(1K 足够) | nano-banana-2-lite |
| 老 OpenAI 客户端最少改动 | gpt-image-2 |
| GPT Image 2 / 2.5 的 2K / 4K | 对应的 -openai 标识 |
| 优先生成速度 | gpt-image-2.5-flare,高分辨率用 gpt-image-2.5-flare-openai |
| 优先编辑精度 | gpt-image-2.5-sunburst,高分辨率用 gpt-image-2.5-sunburst-openai |
| 动态 GIF(短循环动画) | gpt-image-2.6-flare / gpt-image-2.6-sunburst,output_format: "gif" |
| 跟 GPT 文本对话连贯地边聊边出图、需要 partial 进度 | gpt-5.5 走 responses |
| Cherry / Cline / Cursor 这类现成客户端接图像模型 | gpt-image-2(Cherry 要走 /cherry) |
排障速查
| 现象 | 原因 |
|---|---|
| nano-banana 出图永远是 1408×768,无视 image_size | 没用 extra_body.google.image_config,或字段名写成了 camelCase |
| nano-banana-pro 传 4:1 / 1:8 后图不对 | Pro 不支持这 4 档极端比例,换 nano-banana-2 |
| Images 流式请求一直没有最终图 | 不能把最后一张 partial 当完成结果,要继续读到 image_generation.completed 或 [DONE] |
| gpt-5.5 出图 ~120 秒后断连 | 没开 stream: true,被 nginx 切了 |
| gpt-5.5 出图风格跟 prompt 完全不一致 | 没加"不改写"前缀,被模型重写了 |
| gpt-5.5 偶尔不返回图、只回一段文字 | tool_choice 不是 "required" |
model_not_found · No available channel for X under group Y | 当前 token 所在分组没有目标模型,去控制台换分组或确认模型名 |
Cherry Studio 调 gpt-image-2 没图 | Base URL 没改成 https://e-flowcode.cc/cherry |
Python 脚本调用返回 403、正文 error code: 1010 | 用了 urllib 默认 User-Agent,被站点防护拦截;显式设置 User-Agent |
| GPT Image 2.6 的 GIF 尺寸 / 帧数 / 时长和请求不一致 | 上游没有精确执行参数,属已知现象,见 3B;其他 2.6 报错见 3E |
跑通示例
本页 curl 示例换上对应分组的 Key 即可直接运行:Nano Banana 用 0_Tools_Nano_Banana,GPT Image 2 / 2.5 / 2.6 用 0_Tools_GPT_IMAGE,GPT-5.5 用 1_vip_codex 或 2_free_codex,且要带齐第 4 节的参数。网页端 image-web 是开源实现,调用代码在 apps/image-web/lib/ef.mjs,可作参考。
