gpt-image-2

gpt-image-2

完整支援 OpenAI 相容的 GPT Image 2,涵蓋 images/generations、images/edits 以及使用 image_generation 工具的 responses。當一次性圖片輔助功能不足時使用——文字轉圖片、遮罩編輯、多圖批次、串流、partial_images 以及混合文字+圖片的 Responses 流程。會讀取 .env 並尊重程序環境變數;可搭配任何 OpenAI 相容的閘道使用。

2星標
0分支
更新於 2026/6/23
SKILL.md
readonlyread-only
name
gpt-image-2
description

完整支援 OpenAI 相容的 GPT Image 2,涵蓋 images/generations、images/edits 以及使用 image_generation 工具的 responses。當一次性圖片輔助功能不足時使用——文字轉圖片、遮罩編輯、多圖批次、串流、partial_images 以及混合文字+圖片的 Responses 流程。會讀取 .env 並尊重程序環境變數;可搭配任何 OpenAI 相容的閘道使用。

GPT Image 2

單一 Python 進入點,涵蓋所有 GPT Image 2 路由,並對模型的尺寸、長寬比及功能限制進行嚴格的執行前驗證。

工作流程

  1. 開啟 references/config.md 選擇環境變數與預設值。
  2. 開啟 references/api-surface.md 選擇 generationseditsresponses
  3. 除非使用者要求不同的 OpenAI 相容端點,否則優先使用 OPENAI_BASE_URL=https://api.openai.com/v1
  4. generationsedits 使用 gpt-image-2responses 使用具備文字能力的 Responses 模型,例如 gpt-5.4
  5. 使用三個子指令之一執行 scripts/gpt_image.py
  6. 當請求結構是主要風險時,先加上 --dry-run
  7. 當需要保留原始 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_idtool_choiceaction 以及可選的 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 範圍,或公開 Images 路由上 stream=true 搭配 n>1

資源