curl --request POST \
--url https://api.ttapi.io/v1/images/generations \
--header 'Content-Type: application/json' \
--header 'TT-API-KEY: <api-key>' \
--data '
{
"prompt": "<string>",
"background": "auto",
"moderation": "auto",
"n": 123,
"output_compression": 100,
"output_format": "png",
"partial_images": 0,
"quality": "auto",
"size": "auto",
"stream": false,
"user": "<string>"
}
'import requests
url = "https://api.ttapi.io/v1/images/generations"
payload = {
"prompt": "<string>",
"background": "auto",
"moderation": "auto",
"n": 123,
"output_compression": 100,
"output_format": "png",
"partial_images": 0,
"quality": "auto",
"size": "auto",
"stream": False,
"user": "<string>"
}
headers = {
"TT-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'TT-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
prompt: '<string>',
background: 'auto',
moderation: 'auto',
n: 123,
output_compression: 100,
output_format: 'png',
partial_images: 0,
quality: 'auto',
size: 'auto',
stream: false,
user: '<string>'
})
};
fetch('https://api.ttapi.io/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.ttapi.io/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([
'prompt' => '<string>',
'background' => 'auto',
'moderation' => 'auto',
'n' => 123,
'output_compression' => 100,
'output_format' => 'png',
'partial_images' => 0,
'quality' => 'auto',
'size' => 'auto',
'stream' => false,
'user' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"TT-API-KEY: <api-key>"
],
]);
$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.ttapi.io/v1/images/generations"
payload := strings.NewReader("{\n \"prompt\": \"<string>\",\n \"background\": \"auto\",\n \"moderation\": \"auto\",\n \"n\": 123,\n \"output_compression\": 100,\n \"output_format\": \"png\",\n \"partial_images\": 0,\n \"quality\": \"auto\",\n \"size\": \"auto\",\n \"stream\": false,\n \"user\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("TT-API-KEY", "<api-key>")
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.ttapi.io/v1/images/generations")
.header("TT-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"<string>\",\n \"background\": \"auto\",\n \"moderation\": \"auto\",\n \"n\": 123,\n \"output_compression\": 100,\n \"output_format\": \"png\",\n \"partial_images\": 0,\n \"quality\": \"auto\",\n \"size\": \"auto\",\n \"stream\": false,\n \"user\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ttapi.io/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["TT-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"<string>\",\n \"background\": \"auto\",\n \"moderation\": \"auto\",\n \"n\": 123,\n \"output_compression\": 100,\n \"output_format\": \"png\",\n \"partial_images\": 0,\n \"quality\": \"auto\",\n \"size\": \"auto\",\n \"stream\": false,\n \"user\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"created": 1745818538,
"data": [
{
"url": "https://filesystem.site/cdn/20250428/5LsFMT0Def02RVVUkwJ4v7IslleMzo.webp",
"revised_prompt": "A cute fluffy cat with big, bright eyes, soft fur, and a playful expression. It has a light gray coat with hints of white on its paws and tail. The cat is sitting in a cozy setting, surrounded by soft cushions, with its tail wrapped around its paws. Its ears are perked up, and it's looking directly at the viewer, exuding a sense of curiosity and warmth."
}
],
"usage": {
"input_tokens": 9,
"input_tokens_details": {
"image_tokens": 0,
"text_tokens": 9
},
"output_tokens": 4160,
"total_tokens": 4169
}
}{
"status": "FAILED",
"message": "\"prompt\" cannot be empty.",
"data": {}
}{
"status": "FAILED",
"message": "Wrong TT-API-KEY or email is not activated."
}OpenAI Images Generations
curl --request POST \
--url https://api.ttapi.io/v1/images/generations \
--header 'Content-Type: application/json' \
--header 'TT-API-KEY: <api-key>' \
--data '
{
"prompt": "<string>",
"background": "auto",
"moderation": "auto",
"n": 123,
"output_compression": 100,
"output_format": "png",
"partial_images": 0,
"quality": "auto",
"size": "auto",
"stream": false,
"user": "<string>"
}
'import requests
url = "https://api.ttapi.io/v1/images/generations"
payload = {
"prompt": "<string>",
"background": "auto",
"moderation": "auto",
"n": 123,
"output_compression": 100,
"output_format": "png",
"partial_images": 0,
"quality": "auto",
"size": "auto",
"stream": False,
"user": "<string>"
}
headers = {
"TT-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'TT-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
prompt: '<string>',
background: 'auto',
moderation: 'auto',
n: 123,
output_compression: 100,
output_format: 'png',
partial_images: 0,
quality: 'auto',
size: 'auto',
stream: false,
user: '<string>'
})
};
fetch('https://api.ttapi.io/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.ttapi.io/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([
'prompt' => '<string>',
'background' => 'auto',
'moderation' => 'auto',
'n' => 123,
'output_compression' => 100,
'output_format' => 'png',
'partial_images' => 0,
'quality' => 'auto',
'size' => 'auto',
'stream' => false,
'user' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"TT-API-KEY: <api-key>"
],
]);
$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.ttapi.io/v1/images/generations"
payload := strings.NewReader("{\n \"prompt\": \"<string>\",\n \"background\": \"auto\",\n \"moderation\": \"auto\",\n \"n\": 123,\n \"output_compression\": 100,\n \"output_format\": \"png\",\n \"partial_images\": 0,\n \"quality\": \"auto\",\n \"size\": \"auto\",\n \"stream\": false,\n \"user\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("TT-API-KEY", "<api-key>")
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.ttapi.io/v1/images/generations")
.header("TT-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"<string>\",\n \"background\": \"auto\",\n \"moderation\": \"auto\",\n \"n\": 123,\n \"output_compression\": 100,\n \"output_format\": \"png\",\n \"partial_images\": 0,\n \"quality\": \"auto\",\n \"size\": \"auto\",\n \"stream\": false,\n \"user\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.ttapi.io/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["TT-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"<string>\",\n \"background\": \"auto\",\n \"moderation\": \"auto\",\n \"n\": 123,\n \"output_compression\": 100,\n \"output_format\": \"png\",\n \"partial_images\": 0,\n \"quality\": \"auto\",\n \"size\": \"auto\",\n \"stream\": false,\n \"user\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"created": 1745818538,
"data": [
{
"url": "https://filesystem.site/cdn/20250428/5LsFMT0Def02RVVUkwJ4v7IslleMzo.webp",
"revised_prompt": "A cute fluffy cat with big, bright eyes, soft fur, and a playful expression. It has a light gray coat with hints of white on its paws and tail. The cat is sitting in a cozy setting, surrounded by soft cushions, with its tail wrapped around its paws. Its ears are perked up, and it's looking directly at the viewer, exuding a sense of curiosity and warmth."
}
],
"usage": {
"input_tokens": 9,
"input_tokens_details": {
"image_tokens": 0,
"text_tokens": 9
},
"output_tokens": 4160,
"total_tokens": 4169
}
}{
"status": "FAILED",
"message": "\"prompt\" cannot be empty.",
"data": {}
}{
"status": "FAILED",
"message": "Wrong TT-API-KEY or email is not activated."
}POST /v1/images/generations 请求和响应结构保持一致,文档翻译自 官方文档,如已对接官方文档可直接使用,入参出参结构与支持保持一致。”。
支持模型包括 gpt-image-2.5-flare、gpt-image-2.5-sunburst、gpt-image-2、gpt-image-1.5、gpt-image-1、dall-e-2 和 dall-e-3。
请求体
图像的文本描述。gpt-image-2.5-flare、gpt-image-2.5-sunburst、gpt-image-2、gpt-image-1.5 和 gpt-image-1 最多支持 32000 个字符;dall-e-2 最多支持 1000 个字符;dall-e-3 最多支持 4000 个字符。
用于图像生成的模型。
gpt-image-2.5-flare, gpt-image-2.5-sunburst, gpt-image-2, gpt-image-1.5, gpt-image-1, dall-e-2, dall-e-3 设置生成图像背景的透明度。仅适用于 GPT Image 模型。可选值为 transparent、opaque 或 auto(默认)。当设置为 transparent 时,output_format 必须支持透明度,请使用 png 或 webp。
transparent, opaque, auto 控制 GPT Image 模型生成图像的内容审核级别。可选 low(限制更少的过滤)或 auto(默认)。
low, auto 要生成的图像数量,默认值为 1。可选范围 1-10;dall-e-3 固定为 1。
生成图像的压缩级别(0-100)。仅适用于 output_format 为 webp 或 jpeg 的 GPT Image 模型,默认值为 100。
生成图像的返回格式。仅适用于 GPT Image 模型。可选 png(默认)、jpeg 或 webp。
png, jpeg, webp 流式响应中要返回的部分图片数量,范围 0-3,默认值为 0。仅当 stream 为 true 时可用。
图像质量。auto(默认)会为给定模型自动选择最佳质量。
gpt-image-2.5-flare、gpt-image-2.5-sunburst 支持 low、medium、high、xhigh、max、auto;
其他 GPT Image 模型支持 high、medium、low;
dall-e-3 支持 hd 和 standard;
dall-e-2 仅支持 standard。
返回数据格式。仅 dall-e-2 与 dall-e-3 支持 url 或 b64_json;URL 有效期为 60 分钟。GPT Image 模型始终返回 b64_json。
url, b64_json 图像尺寸。
GPT Image 模型支持 1024x1024、1536x1024、1024x1536、auto(默认);
gpt-image-2、gpt-image-2.5-flare、gpt-image-2.5-sunburst 支持 WIDTHxHEIGHT 任意分辨率字符串,宽高需可被 16 整除,宽高比需在 1:3 到 3:1 之间。gpt-image-2.5-flare、gpt-image-2.5-sunburst 最长边不超过 3840,总像素需在 655,360 ~ 8,294,400 之间。
dall-e-2 支持 256x256、512x512、1024x1024;
dall-e-3 支持 1024x1024、1792x1024、1024x1792。
是否以流式方式返回生成进度。启用后可通过 partial_images 获取部分图片事件。
生成图像的风格。仅适用于 dall-e-3。
vivid(生动), natural(自然) 代表最终用户的唯一标识,可帮助 OpenAI 监测和检测滥用。