# GPT Image 2 API 由 OpenAI 提供支援的 GPT Image 2 模型完整 API 參考文件。 ## 模型變體 此 API 支援四個模型變體: | 模型 | ID | 說明 | |-------|-----|-------------| | **GPT Image 2** | `gpt-image-2` | 文生圖 | | **GPT Image 2 Edit** | `gpt-image-2-edit` | 圖片編輯與多圖合成 | | **GPT Image 2 Client** | `gpt-image-2-client` | 預覽版文生圖,核心能力與 GPT Image 2 相同 | | **GPT Image 2 Edit Client** | `gpt-image-2-edit-client` | 預覽版圖片編輯與多圖合成,核心能力與 GPT Image 2 Edit 相同 | ## 快速比較 | 功能 | GPT Image 2 | GPT Image 2 Edit | GPT Image 2 Client | GPT Image 2 Edit Client | |---------|-------------|------------------|--------------------|-------------------------| | 輸入 | 文字提示詞 | 圖片 + 文字提示詞 | 文字提示詞 | 圖片 + 文字提示詞 | | 解析度選項 | `1k`, `2k`, `4k` | `1k`, `2k`, `4k` | `1k`, `2k`, `4k` | `1k`, `2k`, `4k` | | 品質選項 | `low`, `medium`, `high` | `low`, `medium`, `high` | `low`, `medium`, `high` | `low`, `medium`, `high` | | 長寬比 | 10 種 | 10 種 | 10 種 | 10 種 | | 圖片輸入 | 否 | 是(1-16 張) | 否 | 是(1-16 張) | | 多圖支援 | 否 | 是 | 否 | 是 | ### 支援的長寬比 `16:9`, `9:16`, `1:1`, `3:2`, `2:3`, `3:4`, `4:3`, `5:4`, `4:5`, `21:9` ## GPT Image 2(文生圖) ### 端點 ``` POST /api/v1/image/task ``` ### 驗證 ``` Authorization: Bearer YOUR_API_KEY ``` ### 請求參數 #### 必填 | 參數 | 類型 | 說明 | |-----------|------|-------------| | `model_name` | string | 必須為 `"gpt-image-2"` | | `prompt` | string | 圖像生成提示詞 | | `width` | number | 寬度比例值,例如 `16:9` 中傳 `16` | | `height` | number | 高度比例值,例如 `16:9` 中傳 `9` | | `resolution` | string | 輸出解析度:`"1k"`、`"2k"` 或 `"4k"` | | `quality` | string | 輸出品質:`"low"`、`"medium"` 或 `"high"` | **注意:** width:height 必須是以下比例之一:`16:9`、`9:16`、`1:1`、`3:2`、`2:3`、`3:4`、`4:3`、`5:4`、`4:5`、`21:9` ### 請求範例 ```javascript const response = await fetch('https://api.flaq.ai/api/v1/image/task', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ model_name: 'gpt-image-2', prompt: 'A minimalist product shot of a ceramic mug on marble, soft studio light', width: 1, height: 1, resolution: '1k', quality: 'medium' }) }); const { data } = await response.json(); const taskId = data.task_id; // Poll for results const pollResponse = await fetch( `https://api.flaq.ai/api/v1/image/${taskId}`, { headers: { Authorization: 'Bearer YOUR_API_KEY' } } ); const result = await pollResponse.json(); console.log(result.data.task_result.images[0].url); ``` ## GPT Image 2 Edit(圖片編輯) ### 端點 ``` POST /api/v1/image/task ``` ### 請求參數 #### 必填 | 參數 | 類型 | 說明 | |-----------|------|-------------| | `model_name` | string | 必須為 `"gpt-image-2-edit"` | | `prompt` | string | 要執行的編輯描述 | | `image_url_list` | string[] | 輸入圖片 URL 陣列(1-16 張) | #### 選填 | 參數 | 類型 | 預設值 | 說明 | |-----------|------|---------|-------------| | `width` | number | - | 寬度比例值,例如 `16:9` 中傳 `16` | | `height` | number | - | 高度比例值,例如 `16:9` 中傳 `9` | | `resolution` | string | `"1k"` | 輸出解析度:`"1k"`、`"2k"` 或 `"4k"` | | `quality` | string | `"medium"` | 輸出品質:`"low"`、`"medium"` 或 `"high"` | **注意:** 當提供 `width` 與 `height` 時,其比例必須是以下之一:`16:9`、`9:16`、`1:1`、`3:2`、`2:3`、`3:4`、`4:3`、`5:4`、`4:5`、`21:9` ### 單圖編輯範例 ```javascript { model_name: 'gpt-image-2-edit', prompt: 'Replace the background with a clean studio scene and brighten the product lighting', image_url_list: ['https://example.com/product-photo.jpg'], width: 16, height: 9, resolution: '1k', quality: 'medium' } ``` ### 多圖合成範例 ```javascript { model_name: 'gpt-image-2-edit', prompt: 'Blend these reference images into a polished campaign composition while keeping the main subject identity consistent', image_url_list: [ 'https://example.com/image1.jpg', 'https://example.com/image2.jpg', 'https://example.com/image3.jpg' ], width: 16, height: 9, resolution: '2k', quality: 'high' } ``` ## GPT Image 2 Client 與 GPT Image 2 使用相同參數和能力,只需將 `model_name` 設為 `gpt-image-2-client`。這是預覽體驗版,穩定性可能較低。 ### 請求範例 ```javascript const response = await fetch('https://api.flaq.ai/api/v1/image/task', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ model_name: 'gpt-image-2-client', prompt: 'A luxury skincare still life with soft reflections and elegant typography', width: 4, height: 5, resolution: '1k', quality: 'medium' }) }); const { data } = await response.json(); const taskId = data.task_id; ``` ## GPT Image 2 Edit Client 與 GPT Image 2 Edit 使用相同參數和能力,只需將 `model_name` 設為 `gpt-image-2-edit-client`。這是預覽體驗版,穩定性可能較低。 ### 請求範例 ```javascript const response = await fetch('https://api.flaq.ai/api/v1/image/task', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ model_name: 'gpt-image-2-edit-client', prompt: 'Turn this portrait into a clean editorial poster while preserving the face and pose', image_url_list: ['https://example.com/portrait.jpg'], width: 4, height: 5, resolution: '1k', quality: 'medium' }) }); const { data } = await response.json(); const taskId = data.task_id; ``` ## 回應格式 ### 初始回應 所有 GPT Image 2 變體都會返回一個可用於輪詢的 `task_id`: ```json { "code": 0, "data": { "task_id": "{task_id}", "task_status": "submitted", "response_url": "https://api.flaq.ai/api/v1/image/{task_id}" }, "message": "success" } ``` ### 輪詢回應 輪詢 `GET /api/v1/image/{task_id}` 以查看任務狀態: ```json { "code": 0, "data": { "task_id": "{task_id}", "task_status": "succeed", "task_status_msg": null, "response_url": "https://api.flaq.ai/api/v1/image/{task_id}", "task_result": { "credit": 0.0997, "images": [ { "url": "https://example.com/generated-image.jpeg" } ] } }, "message": "success" } ``` ### 狀態值 - `submitted`: 任務已接受 - `processing`: 圖像生成或編輯進行中 - `succeed`: 任務成功完成 - `failed`: 任務失敗 ## 處理時間 典型處理時間為 15-60 秒,取決於解析度、品質、提示詞複雜度,以及編輯請求中的圖片數量。 ## 最佳實踐 1. **明確描述構圖**:當提示詞清楚描述主體、構圖、光線與風格時,GPT Image 2 的表現最佳。 2. **依流程選擇品質**:迭代階段使用 `low` 或 `medium`,最終成品使用 `high`。 3. **依輸出場景設定比例**:在生成前就根據社群貼文、橫幅、商品頁或編輯版面決定長寬比。 4. **編輯時使用清晰來源圖**:清晰、光線良好的輸入圖有助於主體一致性與局部編輯品質。 5. **多圖請求只保留強參考**:對於編輯模型,只提供真正重要的參考圖,避免視覺指引互相衝突。