OpenAI GPT Image 影像生成

GPT Image 系列文生圖 (gpt-image-2 / 1.5 / 1), 相容 OpenAI SDK

POST /v1/images/generations

鉴权: {'type': 'bearer', 'prefix': 'sk-', 'description': 'API Key, 使用 `Authorization: Bearer sk-xxx` 鉴权'}

> **本端點僅文生圖 (t2i)**. 基於現有圖片做圖生圖 (i2i / image-to-image) 請用 [`/v1/images/edits`](./openai-gpt-image-edit) (multipart 協議). OpenAI GPT Image 系列影像生成 — `gpt-image-2` (最新) / `gpt-image-1.5` / `gpt-image-1`. ## 模型矩陣 | 模型 | 特點 | |---|---| | `gpt-image-2` | 最新, 支援複雜構圖與高解析度 (最大 3840px), 推理能力強 | | `gpt-image-1.5` | 平衡品質與速度 | | `gpt-image-1` | 經典版, 相容性最廣 | ## 支援的 size (按 model 分) | size | gpt-image-1 / 1.5 | gpt-image-2 | |---|---|---| | `auto` | ✅ (模型預設) | ✅ (模型預設) | | `1024x1024` | ✅ | ✅ | | `1024x1536` / `1536x1024` | ✅ | ✅ | | `2048x2048` / `2048x1152` | — | ✅ | | `3840x2160` / `2160x3840` (4K) | — | ✅ | | `1792x1024` / `1024x1792` (DALL-E 3 相容) | ⚠️ 部分 | — | | `256x256` / `512x512` (DALL-E 2 相容) | ⚠️ 部分 | — | ⚠️ **size 約束 (`gpt-image-2`)**: 寬高都必須是 16 的倍數, 最長邊 ≤ 3840px, 畫素總數 655,360 ~ 8,294,400, 寬高比 ≤ 3:1. ## quality 檔位 | quality | 說明 | |---|---| | `auto` (預設) | 模型自動選擇 | | `low` / `medium` / `high` | gpt-image-* 原生三檔 | | `standard` / `hd` | OpenAI SDK 相容 alias (從 DALL-E 3 平遷的客戶可直接用) | > 不同檔位對影像細節與生成 token 數有顯著影響. ## response 格式 `gpt-image-*` 始終返回 base64 內聯 (`data[].b64_json`), 不支援 `url` 形式. `response_format` 欄位保留是為 SDK 向後相容, 實際被上游忽略. 返回頂層包含 `created / data / background / output_format / quality / size / usage`. `usage.input_tokens_details` 提供文本與影像 token 細分. ## 用法提示 - 客戶端 SDK 調 `client.images.generate(model='gpt-image-2', prompt='...', size='1024x1024', quality='high')` 即可 - 相容 OpenAI Python SDK / Node SDK 標準用法 - 單張 base64 體積可達幾百 KB ~ 1 MB+, 客戶端需自行 decode 儲存 - 不支援 streaming (`stream` / `partial_images` 欄位會被忽略) - `style` (DALL-E 3 欄位) 在 `gpt-image-*` 不生效, 由模型自動選擇風格

请求体

modelstringrequired影像模型 ID, 如 `gpt-image-2` / `gpt-image-1.5` / `gpt-image-1`
promptstringrequired文本描述, 支援中英文; 描述越具體生成品質越高
ninteger生成圖片數量
sizestring影像尺寸 (寬×高). 可用範圍因 model 而異 — `gpt-image-2` 支援 4K + 自定義 (寬高 16 倍數, ≤3840px), `gpt-image-1` 系僅支援 1024² / 1024×1536 / 1536×1024 + 部分 DALL-E 相容尺寸
qualitystring品質檔位; 影響細節與推理 token 數. `low/medium/high` 是原生三檔; `standard/hd` 是 OpenAI SDK 相容 alias (DALL-E 風格); `auto` 由模型自動選擇
response_formatstring返回格式. `gpt-image-*` 始終返 `b64_json` (上游忽略此欄位); `url` 僅 DALL-E 系列生效
output_formatstring輸出影像編碼格式 (僅 `gpt-image-*` 支援)
output_compressioninteger壓縮等級 (0-100, 越高品質越低體積越小); 僅 `jpeg` / `webp` 生效
backgroundstring背景類型; `transparent` 需配合 `output_format=png` 或 `webp`
moderationstring內容稽核嚴格度; `auto` 預設, `low` 較寬鬆 (仍由上游稽核)
userstring客戶端可選傳入的終端使用者標識 (用於上游濫用檢測)

响应

调用示例

curl https://api.router.ai/v1/images/generations \
  -H "Authorization: Bearer sk-xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "雪夜中的东京街头, 霓虹灯倒影在湿润的柏油路上, 电影感",
    "size": "1024x1024",
    "quality": "high",
    "n": 1
  }'

API 文件