GPT-Image-2.6 圖像生成
curl --request POST \
--url https://api.toapis.com/v1/images/generations \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"prompt": "<string>",
"quality": "<string>",
"size": "<string>",
"resolution": "<string>",
"n": 123,
"background": "<string>",
"output_format": "<string>",
"frame_count": 123,
"frame_duration_ms": 123,
"reference_images": [
"<string>"
]
}
'import requests
url = "https://api.toapis.com/v1/images/generations"
payload = {
"model": "<string>",
"prompt": "<string>",
"quality": "<string>",
"size": "<string>",
"resolution": "<string>",
"n": 123,
"background": "<string>",
"output_format": "<string>",
"frame_count": 123,
"frame_duration_ms": 123,
"reference_images": ["<string>"]
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
prompt: '<string>',
quality: '<string>',
size: '<string>',
resolution: '<string>',
n: 123,
background: '<string>',
output_format: '<string>',
frame_count: 123,
frame_duration_ms: 123,
reference_images: ['<string>']
})
};
fetch('https://api.toapis.com/v1/images/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.toapis.com/v1/images/generations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'prompt' => '<string>',
'quality' => '<string>',
'size' => '<string>',
'resolution' => '<string>',
'n' => 123,
'background' => '<string>',
'output_format' => '<string>',
'frame_count' => 123,
'frame_duration_ms' => 123,
'reference_images' => [
'<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.toapis.com/v1/images/generations"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"quality\": \"<string>\",\n \"size\": \"<string>\",\n \"resolution\": \"<string>\",\n \"n\": 123,\n \"background\": \"<string>\",\n \"output_format\": \"<string>\",\n \"frame_count\": 123,\n \"frame_duration_ms\": 123,\n \"reference_images\": [\n \"<string>\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.toapis.com/v1/images/generations")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"quality\": \"<string>\",\n \"size\": \"<string>\",\n \"resolution\": \"<string>\",\n \"n\": 123,\n \"background\": \"<string>\",\n \"output_format\": \"<string>\",\n \"frame_count\": 123,\n \"frame_duration_ms\": 123,\n \"reference_images\": [\n \"<string>\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.toapis.com/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"quality\": \"<string>\",\n \"size\": \"<string>\",\n \"resolution\": \"<string>\",\n \"n\": 123,\n \"background\": \"<string>\",\n \"output_format\": \"<string>\",\n \"frame_count\": 123,\n \"frame_duration_ms\": 123,\n \"reference_images\": [\n \"<string>\"\n ]\n}"
response = http.request(request)
puts response.read_bodyGPT-Image-2.6
GPT-Image-2.6 圖像生成
gpt-image-2.6-flare 和 gpt-image-2.6-sunburst 普通版接入指南, 包含非同步任務, 三檔品質, 參考圖, GIF 和 SVG 輸出, 按解析度計價
POST
/
v1
/
images
/
generations
GPT-Image-2.6 圖像生成
curl --request POST \
--url https://api.toapis.com/v1/images/generations \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"prompt": "<string>",
"quality": "<string>",
"size": "<string>",
"resolution": "<string>",
"n": 123,
"background": "<string>",
"output_format": "<string>",
"frame_count": 123,
"frame_duration_ms": 123,
"reference_images": [
"<string>"
]
}
'import requests
url = "https://api.toapis.com/v1/images/generations"
payload = {
"model": "<string>",
"prompt": "<string>",
"quality": "<string>",
"size": "<string>",
"resolution": "<string>",
"n": 123,
"background": "<string>",
"output_format": "<string>",
"frame_count": 123,
"frame_duration_ms": 123,
"reference_images": ["<string>"]
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
prompt: '<string>',
quality: '<string>',
size: '<string>',
resolution: '<string>',
n: 123,
background: '<string>',
output_format: '<string>',
frame_count: 123,
frame_duration_ms: 123,
reference_images: ['<string>']
})
};
fetch('https://api.toapis.com/v1/images/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.toapis.com/v1/images/generations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'prompt' => '<string>',
'quality' => '<string>',
'size' => '<string>',
'resolution' => '<string>',
'n' => 123,
'background' => '<string>',
'output_format' => '<string>',
'frame_count' => 123,
'frame_duration_ms' => 123,
'reference_images' => [
'<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.toapis.com/v1/images/generations"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"quality\": \"<string>\",\n \"size\": \"<string>\",\n \"resolution\": \"<string>\",\n \"n\": 123,\n \"background\": \"<string>\",\n \"output_format\": \"<string>\",\n \"frame_count\": 123,\n \"frame_duration_ms\": 123,\n \"reference_images\": [\n \"<string>\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.toapis.com/v1/images/generations")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"quality\": \"<string>\",\n \"size\": \"<string>\",\n \"resolution\": \"<string>\",\n \"n\": 123,\n \"background\": \"<string>\",\n \"output_format\": \"<string>\",\n \"frame_count\": 123,\n \"frame_duration_ms\": 123,\n \"reference_images\": [\n \"<string>\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.toapis.com/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"quality\": \"<string>\",\n \"size\": \"<string>\",\n \"resolution\": \"<string>\",\n \"n\": 123,\n \"background\": \"<string>\",\n \"output_format\": \"<string>\",\n \"frame_count\": 123,\n \"frame_duration_ms\": 123,\n \"reference_images\": [\n \"<string>\"\n ]\n}"
response = http.request(request)
puts response.read_body普通版透過
API Key 可在 控制台 建立.
提交回應範例:
保存回傳的
任務可能經過
任務按任務 ID 正常查詢, 從
把
POST /v1/images/generations 建立圖片任務, 回傳任務 ID. 任務完成後透過查詢接口取得圖片 URL. 兩個模型使用相同的請求格式:
| 模型 | 請求中的 model |
|---|---|
| Flare | gpt-image-2.6-flare |
| Sunburst | gpt-image-2.6-sunburst |
gpt-image-2.6 是系列名稱. 呼叫時請填寫表中的完整模型名.
中國大陸用戶請注意: 請使用
https://api.toapis.cn 作為 API 端點 (Base URL), 將本文範例中的 https://api.toapis.com 替換為 https://api.toapis.cn.快速開始
將自己的 ToAPIs API Key 設為環境變數TOAPIS_API_KEY, 提交任務:
curl --fail-with-body --request POST \
--url https://api.toapis.com/v1/images/generations \
--header "Authorization: Bearer $TOAPIS_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-image-2.6-flare",
"prompt": "兒童繪本風格, 一位獸醫用聽診器為小水獺檢查心跳",
"quality": "high",
"size": "1:1",
"resolution": "1K",
"n": 1
}'
{
"id": "tsk_img_example",
"object": "generation.task",
"model": "gpt-image-2.6-flare",
"status": "pending",
"progress": 0,
"created_at": 1788951900,
"metadata": {}
}
id, 將下方的 TASK_ID 替換為該值後查詢:
curl --fail-with-body \
--url https://api.toapis.com/v1/images/generations/TASK_ID \
--header "Authorization: Bearer $TOAPIS_API_KEY"
pending, queued, in_progress, 最終進入 completed 或 failed. completed 時從 result.data 讀取圖片 URL, failed 時讀取 error. 建議每隔數秒查詢一次. 完整欄位見 圖片任務狀態接口.
提交成功僅表示任務已建立. 請等待 completed 後再下載圖片, 期間持續輪詢同一個任務 ID.
請求參數
string
必填
使用
Bearer YOUR_TOAPIS_API_KEY 鑑權.string
必填
gpt-image-2.6-flare 或 gpt-image-2.6-sunburst.string
必填
圖像描述. 使用參考圖時, 請說明要保留的主體和要修改的內容.
string
預設值:"high"
三檔品質:
low, medium, high. Playground 預設 high. 不傳時使用上游預設值.string
預設值:"1:1"
畫面比例, 例如
1:1, 3:2, 2:3, 4:3, 3:4, 5:4, 4:5, 16:9, 9:16, 21:9.建議將 size 設為畫面比例並明確傳入 resolution, 服務會按兩者計算輸出像素尺寸.也可以傳 auto 讓上游自行決定尺寸, 但最終比例和像素尺寸不作保證.string
預設值:"1K"
解析度檔位. 支援
1K, 2K, 4K, 小寫同樣有效. 普通版按該欄位計價.integer
預設值:1
每次請求傳
1, 生成一張圖.string
可選背景設定. 傳
"transparent" 生成透明背景圖片, 普通生成不傳該欄位.文生圖和攜帶 reference_images 的請求皆可使用.string
輸出格式:
png, jpeg, webp, gif, svg. 不傳時使用上游預設格式. GIF 和 SVG 的附加參數與限制見下文對應章節.integer
預設值:9
僅 GIF 生效. 幀數, 取值
2 到 64. 文生 GIF 按該值生成; 圖生 GIF 固定輸出 9 幀.integer
預設值:200
僅 GIF 生效. 單幀時長, 毫秒, 取值
20 到 2000, 步長 10.string[]
可選參考圖 URL 列表, 最多 10 張. 圖片必須可被服務端存取, 僅支援 URL, 不接受本地檔案和 base64. 本地圖片請先透過 上傳圖片接口 取得 URL.同樣支援
image_urls 欄位, 兩者選其一.與 "output_format": "gif" 組合時即為圖生 GIF.透明背景
在生成請求中加入"background": "transparent" 即可獲得透明背景圖片, 普通生成不傳該欄位.
curl --fail-with-body --request POST \
--url https://api.toapis.com/v1/images/generations \
--header "Authorization: Bearer $TOAPIS_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-image-2.6-flare",
"prompt": "透明背景上的紅色圓形貼紙",
"quality": "high",
"size": "1:1",
"resolution": "1K",
"background": "transparent",
"n": 1
}'
result.data 讀取圖片 URL.
GIF 輸出
將output_format 設為 gif 生成動圖. frame_count 控制幀數 (2 到 64, 預設 9), frame_duration_ms 控制單幀時長 (20 到 2000 毫秒, 步長 10, 預設 200).
curl --fail-with-body --request POST \
--url https://api.toapis.com/v1/images/generations \
--header "Authorization: Bearer $TOAPIS_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-image-2.6-flare",
"prompt": "扁平插畫風格, 一架紙飛機在藍天中循環飛行",
"output_format": "gif",
"frame_count": 8,
"frame_duration_ms": 200,
"size": "1:1",
"n": 1
}'
圖生 GIF
加入reference_images 即可讓已有圖片動起來. 圖生 GIF 固定輸出 9 幀, frame_count 在該模式下不生效, frame_duration_ms 仍然有效.
curl --fail-with-body --request POST \
--url https://api.toapis.com/v1/images/generations \
--header "Authorization: Bearer $TOAPIS_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-image-2.6-flare",
"prompt": "讓畫面中的場景輕輕動起來",
"reference_images": ["https://example.com/scene.png"],
"output_format": "gif",
"frame_duration_ms": 200,
"n": 1
}'
SVG 輸出
將output_format 設為 svg 生成向量圖, 無需其他附加欄位.
curl --fail-with-body --request POST \
--url https://api.toapis.com/v1/images/generations \
--header "Authorization: Bearer $TOAPIS_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-image-2.6-flare",
"prompt": "極簡風格的雪山標誌, 扁平向量風",
"output_format": "svg",
"n": 1
}'
比例與解析度對照
| size | 1K | 2K | 4K |
|---|---|---|---|
1:1 | 1024x1024 | 2048x2048 | 2880x2880 |
3:2 | 1536x1024 | 2048x1360 | 3520x2336 |
2:3 | 1024x1536 | 1360x2048 | 2336x3520 |
16:9 | 1536x864 | 2048x1152 | 3840x2160 |
9:16 | 864x1536 | 1152x2048 | 2160x3840 |
4K 是解析度檔位, 實際寬高由比例決定. 例如正方形 4K 輸出為 2880x2880.
參考圖生成
沿用同一個生成接口並加入reference_images, 最多 10 張. 下面範例使用 Sunburst, 同樣回傳非同步任務:
curl --fail-with-body --request POST \
--url https://api.toapis.com/v1/images/generations \
--header "Authorization: Bearer $TOAPIS_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-image-2.6-sunburst",
"prompt": "保留參考圖中的小水獺和獸醫, 為小水獺加一條黃色圍巾",
"reference_images": ["https://example.com/otter.png"],
"quality": "high",
"size": "1:1",
"resolution": "2K",
"n": 1
}'
https://example.com/otter.png 換成自己的參考圖 URL, 再用回傳的任務 ID 查詢結果.
計費
普通版按生成的每張圖片計費, 價格檔位由resolution 決定. GIF 和 SVG 輸出按相同的單圖價格計費. 參考圖輸入暫不額外收費. 帳號專屬定價或折扣可能不同, 最新價格以 模型定價頁 和帳戶配置為準.
相關模型
GPT-Image-2.6 Official 版走官接渠道, 提供六檔品質, 自訂像素尺寸, 標注引導編輯和按 token 計費. 使用該渠道請傳帶-official 後綴的模型名.