GPT Image 2 / 2.5 / 2.6 圖像生成 API
¶ 1. 取得 API Key
開啟 AI 聚合應用程式列表,進入可用的應用程式並複製 API Key。

¶ 2. 傳送第一個請求
curl https://api.yxai-tech.top/openai/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Minimal editorial product illustration: one plain white ceramic coffee mug centered on a solid cobalt blue tabletop, pale cream background, soft shadow, clean geometric shapes, no text, no logo, portrait composition",
"size": "1024x1536"
}'
成功回應的圖片位於 data[].url。下面是 2026 年 9 月 8 日透過 AI 聚合實際請求得到的 1024×1536 結果(任務 d56455e2-e7f7-4bcd-b935-475b0a1e0948,追蹤 eb938601-8192-407f-b539-1e0554b697ec):

¶ 3. 常用參數
| 欄位 | 說明 |
|---|---|
model |
gpt-image-2(預設推薦)、gpt-image-2.5-flare(更快)或 gpt-image-2.5-sunburst(更高保真度與控制);三者均可選擇對應的 :official 變體,gpt-image-2 還支援 :reverse |
prompt |
圖片描述,最長 32,000 個字元 |
size |
auto 或 WIDTHxHEIGHT;寬高須為 16 的倍數,長邊不超過 3840,總像素為 655,360–8,294,400,寬高比不超過 3:1 |
n |
1–10;response_format=b64_json 時僅支援 1 |
quality |
GPT Image 模型支援 auto、low、medium、high;2.5 / 2.6 Flare / Sunburst(含 :official)額外支援 xhigh、max。官方通道按實際 Token 用量計費 |
response_format |
url 或 b64_json |
callback_url |
可選;長時間任務完成後向該位址傳送結果 |
常用尺寸:
| 比例 | 1K | 2K | 4K |
|---|---|---|---|
| 1:1 | 1024x1024 |
2048x2048 |
2880x2880 |
| 4:3 | 1536x1024 |
2048x1536 |
3264x2448 |
| 3:4 | 1024x1536 |
1536x2048 |
2448x3264 |
| 16:9 | 1792x1024 |
2048x1152 |
3840x2160 |
| 9:16 | 1024x1792 |
1152x2048 |
2160x3840 |
size: "auto" 會根據提示詞中的比例、像素和版面配置意圖選擇畫幅;需要精確像素時直接填寫尺寸。
¶ 模型與計費方式
| 模型 | 適用情境與計費方式 |
|---|---|
gpt-image-2 |
預設逆向通道,按成功圖片張數固定計費 |
gpt-image-2:reverse |
明確選擇逆向通道,按成功圖片張數固定計費 |
gpt-image-2:official |
官方 API 通道,穩定性更高,按實際 Token 用量計費 |
gpt-image-2.5-flare |
側重生成速度,按成功圖片張數固定計費 |
gpt-image-2.6-flare |
側重生成速度,按成功圖片張數固定計費 |
gpt-image-2.5-flare:reverse |
明確逆向別名,與 gpt-image-2.5-flare 等價,按成功圖片張數固定計費 |
gpt-image-2.6-flare:reverse |
明確逆向別名,與 gpt-image-2.6-flare 等價,按成功圖片張數固定計費 |
gpt-image-2.5-flare:official |
官方 API 通道,穩定性更高且側重生成速度,按實際 Token 用量計費 |
gpt-image-2.6-flare:official |
官方 API 通道,穩定性更高且側重生成速度,按實際 Token 用量計費 |
gpt-image-2.5-sunburst |
側重高保真度與精細控制,按成功圖片張數固定計費 |
gpt-image-2.6-sunburst |
側重高保真度與精細控制,按成功圖片張數固定計費 |
gpt-image-2.5-sunburst:reverse |
明確逆向別名,與 gpt-image-2.5-sunburst 等價,按成功圖片張數固定計費 |
gpt-image-2.6-sunburst:reverse |
明確逆向別名,與 gpt-image-2.6-sunburst 等價,按成功圖片張數固定計費 |
gpt-image-2.5-sunburst:official |
官方 API 通道,穩定性更高且側重高保真度與精細控制,按實際 Token 用量計費 |
gpt-image-2.6-sunburst:official |
官方 API 通道,穩定性更高且側重高保真度與精細控制,按實際 Token 用量計費 |
官方 API 通道的頁面價格是請求前估算,最終以回應中的實際 Token 用量和使用紀錄為準。
¶ 4. 多張生成
curl https://api.yxai-tech.top/openai/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A small fox reading under a glowing mushroom, watercolor illustration",
"size": "1536x1024",
"n": 2
}'
gpt-image-2、gpt-image-2.5-flare、gpt-image-2.5-sunburst 及其 :reverse 別名按成功張數計費;gpt-image-2:official、gpt-image-2.5-flare:official 和 gpt-image-2.5-sunburst:official 根據回應中的文字輸入和圖片輸出實際 Token 結算。頁面價格是請求前估算,最終以使用紀錄為準。
¶ 5. 非同步回呼
請求本文加入 callback_url 後,介面會先回傳 {"task_id": "..."},完成時向該 URL POST 最終結果;同步請求仍回傳 created 和 data:
{
"model": "gpt-image-2",
"prompt": "A product poster with clear typography",
"size": "1024x1024",
"callback_url": "https://example.com/webhooks/images"
}
回呼接收方應使用 task_id 去重,並驗證請求來源與資料格式。
¶ 6. 疑難排解
| 狀態 | 檢查 |
|---|---|
| 400 | model、prompt、尺寸格式、n 與 response_format 組合 |
| 401 | API Key 是否完整,Header 是否為 Authorization: Bearer ... |
| 429 | 請求過於頻繁,稍後重試 |
| 504 | 同步生成逾時;改用 callback_url |
錯誤回應會包含 error.code、error.message 和 trace_id。回報問題時提供 trace_id,不要提供 API Key。
完整欄位和即時列舉值以 OpenAI Images Generations API 頁面為準。影像編輯請查看 GPT Image 2 / 2.5 / 2.6 影像編輯。
¶ GPT Image 2.6
GPT Image 2.6 沿用 2.5 的生成、編輯、非同步任務和計費介面:
| 模型 | 計費 |
|---|---|
gpt-image-2.6-flare / gpt-image-2.6-flare:reverse |
0.22 Credits/張 |
gpt-image-2.6-sunburst / gpt-image-2.6-sunburst:reverse |
0.22 Credits/張 |
gpt-image-2.6-flare:official |
與 2.5 official 相同,按實際 Token 用量計費 |
gpt-image-2.6-sunburst:official |
與 2.5 official 相同,按實際 Token 用量計費 |
品質可選 auto、low、medium、high、xhigh、max;尺寸使用 auto 或符合上述限制的 WIDTHxHEIGHT。本介面支援 png、jpeg、webp;GPT Image 2.6 還支援原生 gif 動圖,暫不支援 SVG。編輯支援 JSON 圖片 URL 和 multipart 檔案上傳。:reverse 是同名普通版的明確別名。請使用完整型號,不要傳入 gpt-image-2.6。
¶ GPT Image 2.6 GIF 動圖
GPT Image 2.6 Flare、Sunburst 的普通版、:reverse、:official 均可使用 output_format: "gif"。動畫影格、循環資訊和播放時長會保留;frame_count 表示影格數,frame_duration_ms 表示每影格毫秒數,影格數必須為 2–16 的整數,每影格時長必須為 20–655350 毫秒的整數,且僅用於 GIF;編碼按最接近的 10ms 取整。未指定時預設為 9 個影格、每影格 200 毫秒;GIF 的 size 省略或為 auto 時使用 512x512 預設值。
建議先使用 size: "512x512"、frame_count: 9、frame_duration_ms: 200。GIF 有獨立的尺寸和影格數限制,不能直接套用靜態 4K 規格;部分模型會調整實際輸出尺寸。n 表示回傳的 GIF 檔案數量,不是動畫影格數。普通版和 :reverse 仍按成功檔案數量計費,官方版按實際 Token 用量計費。
{
"model": "gpt-image-2.6-flare",
"prompt": "A small red ball moves left and right on a white background, seamless looping animation, no text.",
"output_format": "gif",
"size": "512x512",
"quality": "medium",
"frame_count": 9,
"frame_duration_ms": 200,
"n": 1,
"async": true
}
¶ GPT Image 2.6 4K 靜態圖
Flare、Sunburst 及其 :reverse、:official 變體都可使用前述 4K 像素預設值,例如 3840x2160 和 2160x3840。生成和編輯均透過 size 傳入具體像素;4K 不是有效的 size 值,4096x4096 也超出目前像素上限。上述 4K 規格適用於靜態 PNG/JPEG/WebP,GIF 請使用其專用參數。
¶ GPT Image 2.6 構圖複雜度
complexity 可選 low、medium、high,省略時使用模型預設值 high。它控制規劃複雜度,與 quality 渲染品質獨立;不會額外按次收費,官方版仍按實際 Token 結算。其他型號不支援此參數。
GIF 不支援遮罩、標註圖、自訂壓縮、提示詞重寫或部分影像串流輸出;不相容的組合會在生成前拒絕。尺寸、影格數和數量共同受模型像素預算限制;普通 Flare 的 1024x1024、2 個影格已驗證可用,不能把這個結論擴展到所有 1K 組合或 4K GIF。

