gpt-image-2
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGPT Image 2
GPT Image 2
A single Python entrypoint that covers every GPT Image 2 route, with strict pre-flight validation of the model's size, aspect, and feature constraints.
一个统一的Python入口点,覆盖GPT Image 2的所有路由,并对模型的尺寸、宽高比和功能约束进行严格的预校验。
Workflow
工作流程
- Open references/config.md to pick environment variables and defaults.
- Open references/api-surface.md to choose between ,
generations, andedits.responses - Prefer unless the user asks for a different OpenAI-compatible endpoint.
OPENAI_BASE_URL=https://api.openai.com/v1 - Use for
gpt-image-2andgenerations; use a text-capable Responses model such aseditsforgpt-5.4.responses - Run with one of the three subcommands.
scripts/gpt_image.py - Add first when the payload shape is the main risk.
--dry-run - Add when the raw JSON body or SSE event stream needs to be kept for debugging.
--save-response <path>
- 打开references/config.md选择环境变量和默认配置。
- 打开references/api-surface.md选择、
generations或edits模式。responses - 除非用户要求使用其他兼容OpenAI的端点,否则优先使用。
OPENAI_BASE_URL=https://api.openai.com/v1 - 和
generations模式使用edits;gpt-image-2模式使用支持文本功能的Responses模型,例如responses。gpt-5.4 - 运行并指定三个子命令之一。
scripts/gpt_image.py - 当请求负载格式是主要风险时,先添加参数。
--dry-run - 当需要保存原始JSON响应体或SSE事件流用于调试时,添加参数。
--save-response <path>
Commands
命令示例
Text-to-image through the public Images API:
powershell
python .\skills\gpt-image-2\scripts\gpt_image.py generations `
--prompt "A bold product hero image for a developer tool homepage" `
--output .\out\hero.png `
--size 1536x1024 `
--quality high `
--format pngMulti-image batch with a filename pattern:
powershell
python .\skills\gpt-image-2\scripts\gpt_image.py generations `
--prompt "A cinematic city skyline at night" `
--output .\out\skyline-{index}.webp `
--n 3 `
--format webp `
--compression 90Image edits with two inputs plus a mask:
powershell
python .\skills\gpt-image-2\scripts\gpt_image.py edits `
--prompt "Blend the two references into one clean marketing illustration" `
--image .\refs\subject.png `
--image .\refs\background.png `
--mask .\refs\mask.png `
--output .\out\edit-{index}.png `
--image-field-style brackets `
--n 2Responses API with streaming and partial previews:
powershell
python .\skills\gpt-image-2\scripts\gpt_image.py responses `
--input-text "Generate a poster for an AI developer summit" `
--model gpt-5.4 `
--output .\out\poster-{index}.png `
--stream `
--partial-images 2 `
--save-response .\out\poster-events.jsonResponses API edit with a local image plus a mask:
powershell
python .\skills\gpt-image-2\scripts\gpt_image.py responses `
--input-text "Turn this product shot into a clean studio ad" `
--model gpt-5.4 `
--input-image .\refs\product.png `
--mask .\refs\mask.png `
--output .\out\studio.png `
--action editInspect the built request without sending it:
powershell
python .\skills\gpt-image-2\scripts\gpt_image.py generations `
--prompt "A minimal cover image" `
--output .\out\cover.png `
--dry-run通过公开图像API实现文本转图像:
powershell
python .\skills\gpt-image-2\scripts\gpt_image.py generations `
--prompt "A bold product hero image for a developer tool homepage" `
--output .\out\hero.png `
--size 1536x1024 `
--quality high `
--format png带文件名模板的多图像批量生成:
powershell
python .\skills\gpt-image-2\scripts\gpt_image.py generations `
--prompt "A cinematic city skyline at night" `
--output .\out\skyline-{index}.webp `
--n 3 `
--format webp `
--compression 90双输入加蒙版的图像编辑:
powershell
python .\skills\gpt-image-2\scripts\gpt_image.py edits `
--prompt "Blend the two references into one clean marketing illustration" `
--image .\refs\subject.png `
--image .\refs\background.png `
--mask .\refs\mask.png `
--output .\out\edit-{index}.png `
--image-field-style brackets `
--n 2支持流式传输和局部预览的Responses API:
powershell
python .\skills\gpt-image-2\scripts\gpt_image.py responses `
--input-text "Generate a poster for an AI developer summit" `
--model gpt-5.4 `
--output .\out\poster-{index}.png `
--stream `
--partial-images 2 `
--save-response .\out\poster-events.json带本地图像和蒙版的Responses API编辑:
powershell
python .\skills\gpt-image-2\scripts\gpt_image.py responses `
--input-text "Turn this product shot into a clean studio ad" `
--model gpt-5.4 `
--input-image .\refs\product.png `
--mask .\refs\mask.png `
--output .\out\studio.png `
--action edit检查构建好的请求而不发送:
powershell
python .\skills\gpt-image-2\scripts\gpt_image.py generations `
--prompt "A minimal cover image" `
--output .\out\cover.png `
--dry-runRules
规则说明
- Use for public text-to-image calls.
generations - Use for multipart image edits and mask uploads.
edits - Use for advanced flows: streaming, mixed text + image input,
responses,previous_response_id,tool_choice, and optionalaction.tool_model - Process environment variables override ; CLI flags override both.
.env - Never print secrets.
- takes either a single path or a pattern such as
--outputfor multi-image or streaming flows.image-{index}.png - uses a top-level Responses model separate from the image model; default it to
responsesunless you need another text-capable model.gpt-5.4 - on Responses tool flows is passed through, but final behavior still depends on the hosted image tool.
quality - On OpenAI GPT image models, omit ; image data already comes back as base64.
response_format - Fail fast on unsupported combinations: transparent background, invalid size,
gpt-image-2outsidepartial_images, or0..3withstream=trueon public Images routes.n>1
- 公开文本转图像调用使用模式。
generations - 多部分图像编辑和蒙版上传使用模式。
edits - 高级流程使用模式:流式传输、文本+图像混合输入、
responses、previous_response_id、tool_choice以及可选的action。tool_model - 进程环境变量优先级高于文件;CLI参数优先级高于两者。
.env - 绝不打印敏感信息。
- 参数可接受单个路径或模板(如
--output),用于多图像或流式传输流程。image-{index}.png - 模式使用独立于图像模型的顶层Responses模型;默认使用
responses,除非需要其他支持文本功能的模型。gpt-5.4 - Responses工具流程中的参数会直接传递,但最终行为仍取决于托管的图像工具。
quality - 在OpenAI GPT图像模型上,省略;图像数据已以base64格式返回。
response_format - 遇到不支持的组合时立即终止:透明背景、无效尺寸、
gpt-image-2超出0..3范围,或公开图像路由中partial_images且stream=true的情况。n>1
Resources
资源链接
- Script: scripts/gpt_image.py
- Config reference: references/config.md
- API surface reference: references/api-surface.md
- 脚本:scripts/gpt_image.py
- 配置参考:references/config.md
- API接口参考:references/api-surface.md