关于 gpt-image-2
通过单个 Python 脚本处理 GPT Image 2 的图像生成与编辑请求,并在发送前校验参数限制,也支持 Responses API 的进阶流程。
主要功能
- 01统一的 Python 入口
- 02生成、编辑和 Responses 路由
- 03请求限制的预检校验
- 04试运行与响应保存
- 05批量输出和流式选项
适用场景
- 01根据文字提示生成图像
- 02使用参考图和蒙版编辑图像
- 03在 API 调用前检查请求内容
- 04保存流式输出和响应数据
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ gargantuax/ openskills --skill gpt-image-2安装后在 Claude Code 中输入/gpt-image-2确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
README.mdagents/openai.yamlreferences/api-surface.mdconfig.mdscripts/gpt_image.pytests/test_gpt_image.py详细介绍
GPT Image 2
一个 Python 入口,涵盖 GPT Image 2 的所有路由,并对模型的尺寸、宽高比和功能限制进行严格的预先验证。
工作流
- 打开 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>。
命令
通过公共 Images API 将文本转换为图像:
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
使用文件名模式批量处理多张图像:
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
使用两个输入和一个蒙版编辑图像:
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:
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 编辑:
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
检查构建的请求,但不发送:
python .\skills\gpt-image-2\scripts\gpt_image.py generations `
--prompt "A minimal cover image" `
--output .\out\cover.png `
--dry-run
规则
- 公共文本转图像请求使用
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组合应快速失败:透明背景、无效尺寸、超出0..3范围的partial_images,或在公共 Images 路由中stream=true且n>1。
资源
- 脚本:scripts/gpt_image.py
- 配置参考:references/config.md
- API 端点参考:references/api-surface.md
评论
支持 Markdown