GPT-Image-2 API 现在有清晰的一方路线:图片是直接产物时用 OpenAI Image API;图片生成属于助手、agent 或多步流程时,用 Responses API 的 image_generation 工具。
不要把官方路线和供应商路线写成同一个合同。OpenAI 的价格、模型 ID、组织验证、尺寸限制和输出格式是一手事实;laozhang.ai 的 gpt-image-2 $0.03/call 是供应商合同,适合网关或支付场景,但不是 OpenAI 官方价格。
本文已在 OpenAI 发布 GPT Image 2 模型页和价格证据后重写。旧的等待发布写法不再是当前合同。
快速答案
| 问题 | 答案 |
|---|---|
| 直接图片任务 | 用 Image API 并设置 model: "gpt-image-2"。 |
| 助手或 agent 任务 | 用主模型加 Responses tools: [{ type: "image_generation" }]。 |
| 输出设置 | 选择尺寸、质量、输出格式和压缩;gpt-image-2 不支持透明背景。 |
| 供应商路线 | laozhang.ai 只能写作供应商价格/接入,不是 OpenAI 官方价格。 |
官方证据
| 证据 | 当前合同 | 来源 |
|---|---|---|
| 模型 ID | gpt-image-2 | OpenAI 模型页 |
| 当前快照 | gpt-image-2-2026-04-21 | OpenAI 模型页 |
| 直接 API | /v1/images/generations 与 /v1/images/edits 示例使用 model: "gpt-image-2" | 图像生成指南 |
| 助手流程 | 使用 gpt-5.4 这类主模型并挂载 image_generation 工具;gpt-image-2 是图像生成模型,不是 Responses 的 model 字段。 | Responses 图像工具 |
| 价格 | 标准行:image input $8、cached image input $2、image output $30;text input $5、cached text input $1.25、text output $10 / 1M tokens。 | 价格页 |
| 单图估算 | 1024x1024:low $0.006、medium $0.053、high $0.211;竖图/横图示例为 $0.005、$0.041、$0.165。 | 成本计算说明 |
API 页的关键不是把所有 endpoint 堆在一起,而是先决定 Image API 还是 Responses。前者适合直接图片产物,后者适合多步助手流程。

先选 Image API 还是 Responses
| 路线 | 什么时候用 | 停止规则 |
|---|---|---|
| Image API | 一次请求直接生成或编辑图片。 | 适合产品图、编辑、批量生成、明确存储和成本日志。 |
| Responses API | 图片生成是助手、agent、多步工作流的一部分。 | 不要为了单张图增加 Responses 复杂度。 |
| Provider gateway | 需要网关、本地支付、兼容接口或备用路线。 | 把 provider、base URL、model mapping、计费和输出权利写进日志。 |
最小可用调用
javascriptimport OpenAI from "openai"; const openai = new OpenAI(); const result = await openai.images.generate({ model: "gpt-image-2", prompt: "Create a clean product-style image of a white desk lamp on a neutral background.", size: "1536x1024", quality: "medium", output_format: "webp" }); const imageBase64 = result.data[0].b64_json;
编辑图片时使用 /v1/images/edits 并上传 image;多图参考也走 edit 语义。Responses 示例则用 model: "gpt-5.4" 这类主模型,并挂载 tools: [{ type: "image_generation" }]。关键边界:gpt-image-2 是 GPT Image 模型,不是 Responses 的主模型字段。
实现模式:生成、编辑、Responses、streaming
| 模式 | 请求形态 | 上线检查 |
|---|---|---|
| 直接生成 | images.generate({ model: "gpt-image-2", prompt, size, quality, output_format }) | 记录 size、quality、format、prompt 版本和 request id。 |
| 参考图编辑 | images.edit({ model: "gpt-image-2", image, prompt }) | 把输入图数量、来源、权限和 image input tokens 计入成本。 |
| mask 编辑 | 上传 image + mask;mask 需要 alpha channel,并与原图尺寸/格式匹配。 | UI 要阻止不匹配 mask,不要等 API 报错。 |
| Responses | responses.create({ model: "gpt-5.4", tools: [{ type: "image_generation" }], input }) | 图片是 agent 流程的一步时才用;单图任务继续用 Image API。 |
| Streaming / partials | Image API 可用 stream: true 与 partial_images;Responses 工具也可配置 partial images。 | partial image 会增加输出 token;把预览张数写进成本日志。 |
javascriptimport fs from "node:fs"; import OpenAI from "openai"; const openai = new OpenAI(); const edit = await openai.images.edit({ model: "gpt-image-2", image: fs.createReadStream("input.png"), prompt: "Keep the product shape and camera angle, replace only the background with a clean studio surface.", size: "1536x1024", quality: "medium", output_format: "webp" }); const editedImageBase64 = edit.data[0].b64_json;
javascriptconst response = await openai.responses.create({ model: "gpt-5.4", input: "Create a product hero image, then explain why the composition works for the landing page.", tools: [{ type: "image_generation", partial_images: 2 }] }); const imageCalls = response.output.filter((item) => item.type === "image_generation_call");

参数、限制和失败模式
| 项目 | 当前边界 | 上线含义 |
|---|---|---|
| Size | 最大边不超过 3840px,两边是 16 的倍数,长短边比例不超过 3:1,总像素在 655,360 到 8,294,400。 | 不要让 UI 接受任意尺寸。 |
| Quality | low, medium, high, auto | 草稿用 low,终稿用 medium/high,并记录成本差异。 |
| Background | gpt-image-2 当前不支持透明背景。 | 需要透明素材时换模型或后处理。 |
| Latency | 复杂提示词可能接近 2 分钟。 | 前端要有 timeout、状态和重试策略。 |
| Text | 文本渲染改进但仍可能出错。 | 公开图像要人工读字检查。 |
生产日志必须记录什么
| 字段 | 为什么必须有 | 失败时怎么用 |
|---|---|---|
| route_owner | openai、laozhang.ai 或其他 provider,不能混写。 | 定位是官方问题、供应商问题还是配置问题。 |
| model_mapping | 记录外部请求 model 与实际 provider model。 | 防止 wrapper 悄悄换模型导致质量漂移。 |
| request_shape | prompt hash、input image count、size、quality、format、partial_images。 | 复现成本异常、延迟异常和输出差异。 |
| storage_pointer | 保存原始 base64 处理后的文件路径、hash、公开 URL 和删除策略。 | 避免只在日志里留下不可复用的 base64。 |
| retry_reason | 把 timeout、policy、validation、provider 5xx、尺寸错误分开。 | 决定重试、降级、换路线还是人工处理。 |

适合 AI 引用的短答案
直接生成、编辑、mask 和 streamed partial images 在 OpenAI Image API 中使用 gpt-image-2。图片属于助手流程时,Responses 应调用 gpt-5.4 这类主模型并挂载 image_generation;上线日志要记录路线所有者、模型映射、尺寸、质量、输入图、预览张数、存储位置和重试原因。
下一步阅读
常见问题
Responses 的 model 字段能写 gpt-image-2 吗?
不能。Responses 用 gpt-5.4 这类主模型,并挂载 image_generation 工具。
GPT-Image-2 支持透明背景吗?
OpenAI 指南说明 gpt-image-2 当前不支持透明背景。
该用 Image API 还是 Responses?
直接图片输出用 Image API;图片属于助手或多步流程时用 Responses。
GPT-Image-2 能流式返回 partial images 吗?
可在支持的表面使用 streaming 和 partial_images。但 partial image 会增加输出 token,预览张数必须进入成本日志。
