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普通版通过
提交响应示例:
保存返回的
任务可能经过
任务按任务 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.com 替换为 https://api.toapis.cn. API Key 可在 控制台 创建.
快速开始
将自己的 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 后缀的模型名.