gpt-image-2

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GPT 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

工作流程

  1. Open references/config.md to pick environment variables and defaults.
  2. Open references/api-surface.md to choose between
    generations
    ,
    edits
    , and
    responses
    .
  3. Prefer
    OPENAI_BASE_URL=https://api.openai.com/v1
    unless the user asks for a different OpenAI-compatible endpoint.
  4. Use
    gpt-image-2
    for
    generations
    and
    edits
    ; use a text-capable Responses model such as
    gpt-5.4
    for
    responses
    .
  5. Run
    scripts/gpt_image.py
    with one of the three subcommands.
  6. Add
    --dry-run
    first when the payload shape is the main risk.
  7. Add
    --save-response <path>
    when the raw JSON body or SSE event stream needs to be kept for debugging.
  1. 打开references/config.md选择环境变量和默认配置。
  2. 打开references/api-surface.md选择
    generations
    edits
    responses
    模式。
  3. 除非用户要求使用其他兼容OpenAI的端点,否则优先使用
    OPENAI_BASE_URL=https://api.openai.com/v1
  4. generations
    edits
    模式使用
    gpt-image-2
    responses
    模式使用支持文本功能的Responses模型,例如
    gpt-5.4
  5. 运行
    scripts/gpt_image.py
    并指定三个子命令之一。
  6. 当请求负载格式是主要风险时,先添加
    --dry-run
    参数。
  7. 当需要保存原始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 png
Multi-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 90
Image 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 2
Responses 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.json
Responses 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 edit
Inspect 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-run

Rules

规则说明

  • Use
    generations
    for public text-to-image calls.
  • Use
    edits
    for multipart image edits and mask uploads.
  • Use
    responses
    for advanced flows: streaming, mixed text + image input,
    previous_response_id
    ,
    tool_choice
    ,
    action
    , and optional
    tool_model
    .
  • Process environment variables override
    .env
    ; CLI flags override both.
  • Never print secrets.
  • --output
    takes either a single path or a pattern such as
    image-{index}.png
    for multi-image or streaming flows.
  • responses
    uses a top-level Responses model separate from the image model; default it to
    gpt-5.4
    unless you need another text-capable model.
  • quality
    on Responses tool flows is passed through, but final behavior still depends on the hosted image tool.
  • On OpenAI GPT image models, omit
    response_format
    ; image data already comes back as base64.
  • Fail fast on unsupported
    gpt-image-2
    combinations: transparent background, invalid size,
    partial_images
    outside
    0..3
    , or
    stream=true
    with
    n>1
    on public Images routes.
  • 公开文本转图像调用使用
    generations
    模式。
  • 多部分图像编辑和蒙版上传使用
    edits
    模式。
  • 高级流程使用
    responses
    模式:流式传输、文本+图像混合输入、
    previous_response_id
    tool_choice
    action
    以及可选的
    tool_model
  • 进程环境变量优先级高于
    .env
    文件;CLI参数优先级高于两者。
  • 绝不打印敏感信息。
  • --output
    参数可接受单个路径或模板(如
    image-{index}.png
    ),用于多图像或流式传输流程。
  • responses
    模式使用独立于图像模型的顶层Responses模型;默认使用
    gpt-5.4
    ,除非需要其他支持文本功能的模型。
  • Responses工具流程中的
    quality
    参数会直接传递,但最终行为仍取决于托管的图像工具。
  • 在OpenAI GPT图像模型上,省略
    response_format
    ;图像数据已以base64格式返回。
  • 遇到不支持的
    gpt-image-2
    组合时立即终止:透明背景、无效尺寸、
    partial_images
    超出0..3范围,或公开图像路由中
    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