🟢OpenAI Image Models
TTAPI整合openai的优秀图片模型,让你能以更为优惠的价格且方便的方式集成到你的服务。
OpenAI Create image
POST
https://api.ttapi.io/v1/images/generations
根据文本以及图片提示创建图像,转自openai官方接口,支持模型 gpt-image-1
, dall-e-2
, dall-e-3
文档翻译自官方文档,如已对接官方文档可直接对接使用,所有入参出参结构与支持均一致,定价详见
Headers
Content-Type
application/json
TT-API-KEY
用于请求授权 TT-API 的API密钥
Body
prompt
string
是
图像的文本描述。gpt-image-1
的最大长度为 32000 个字符,dall-e-2
的最大长度为 1000 个字符,dall-e-3
的最大长度为 4000 个字符。
background
string
否
允许设置生成图像背景的透明度。
此参数仅适用于 gpt-image-1
。可选值 transparent
、opaque
或 auto
(默认)之一。使用 auto
时,模型将自动确定图像的最佳背景。
如果设置为透明,则输出格式需要支持透明度,因此应设置为 png 或 webp。
model
string
否
支持模型
gpt-image-1
dall-e-2
(默认)
dall-e-3
moderation
string
否
控制 gpt-image-1 生成的图片的内容审核级别。low
(用于限制较少的过滤)或 auto
(默认值)。
n
integer
否
生成图像数量,默认值为1
可选范围1-10
,dall-e-3
为固定值1
output_compression
integer
否
生成图像的压缩级别 (0-100%)。此参数仅支持输出格式为 webp 或 jpeg 的 gpt-image-1
,默认为 100
。
output_format
string
否
返回图像格式。此参数仅适用于 gpt-image-1
。可选值 png
(默认)、jpeg
、 webp
。
quality
string
否
图片质量,可选范围:
auto
(默认值)将自动为给定模型选择最佳质量。
gpt-image-1 支持high
、medium
、low
三种质量。
dall-e-3 支持 hd
和 standard
。
dall-e-2 仅支持 standard
。
response_format
string
否
返回数据格式
dall-e-3, dall-e-2 支持 url
或 b64_json
,url有效期为60分钟,请获取到数据后第一时间缓存。
gpt-image-1 仅支持 b64_json
size
string
否
图像尺寸
gpt-image-1 可选范围: 1024x1024 1536x1024 1024x1536 auto(默认)
dall-e-2 可选范围: 256x256 512x512 1024x1024 dall-e-3 可选范围: 1024x1024 1792x1024 1024x1792 注意:不同尺寸消耗ttapi quota不同
style
string
否
生成图像的风格。此参数仅支持 dall-e-3。 可选值:
vivid
(生动)
natural
(自然)
请求示例
import requests
endpoint = "https://api.ttapi.io/v1/images/generations"
headers = {
"TT-API-KEY": your_key
}
data = {
"prompt": "a cute cat",
"model":"gpt-image-1",
"size": "1024x1024",
}
response = requests.post(endpoint, headers=headers, json=data)
print(response.status_code)
print(response.json())
返回示例
{
"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."
}
],
"created": 1745818538
}
OpenAI Create image edit
POST
https://api.ttapi.io/v1/images/edits
根据给定的一个或多个源图像和提示,编辑或扩展图像。支持模型 gpt-image-1
, dall-e-2
文档翻译自官方文档,如已对接官方文档可直接对接使用,所有入参出参结构与支持均一致,定价详见
Headers
Content-Type
application/json
TT-API-KEY
用于请求授权 TT-API 的API密钥
Body
image
array[file]
是
要编辑的图片。必须是受支持的图片文件或图片数组。
gpt-image-1
,每张图片应为小于 25MB 的 png、webp 或 jpg 文件。
dall-e-2
,您只能提供一张图片,并且该图片应为小于 4MB 的方形 png 文件。
prompt
string
是
图像的文本描述。gpt-image-1
的最大长度为 32000 个字符,dall-e-2
的最大长度为 1000 个字符
mask
file
否
一张附加图片,其完全透明区域(例如,Alpha 值为零)指示应编辑图片的位置。如果提供了多张图片,则蒙版将应用于第一张图片。必须是有效的 PNG 文件,大小小于 4MB,且尺寸与图片相同。
model
string
否
支持模型
gpt-image-1
dall-e-2
(默认)
n
integer
否
生成图像数量,默认值为1
可选范围1-10
output_compression
integer
否
生成图像的压缩级别 (0-100%)。此参数仅支持输出格式为 webp 或 jpeg 的 gpt-image-1
,默认为 100
。
quality
string
否
图片质量,可选范围:
auto
(默认值)将自动为给定模型选择最佳质量。
gpt-image-1 支持high
、medium
、low
三种质量。
dall-e-2 仅支持 standard
。
response_format
string
否
返回数据格式
dall-e-2 支持 url
或 b64_json
,url有效期为60分钟,请获取到数据后第一时间缓存。
gpt-image-1 仅支持 b64_json
size
string
否
图像尺寸
gpt-image-1 可选范围: 1024x1024 1536x1024 1024x1536 auto(默认)
dall-e-2 可选范围: 256x256 512x512 1024x1024 注意:不同尺寸消耗ttapi quota不同
请求示例
import base64
from openai import OpenAI
client = OpenAI(
base_url="https://api.ttapi.io/v1",
api_key="your api key",
)
prompt = """
Generate a photorealistic image of a gift basket on a white background
labeled 'Relax & Unwind' with a ribbon and handwriting-like font,
containing all the items in the reference pictures.
"""
result = client.images.edit(
model="gpt-image-1",
image=[
open("body-lotion.png", "rb"),
open("bath-bomb.png", "rb"),
open("incense-kit.png", "rb"),
open("soap.png", "rb"),
],
prompt=prompt
)
image_base64 = result.data[0].b64_json
image_bytes = base64.b64decode(image_base64)
# Save the image to a file
with open("gift-basket.png", "wb") as f:
f.write(image_bytes)
返回示例
{
"created": 1713833628,
"data": [
{
"b64_json": "..."
}
],
"usage": {
"total_tokens": 100,
"input_tokens": 50,
"output_tokens": 50,
"input_tokens_details": {
"text_tokens": 10,
"image_tokens": 40
}
}
}
Dalle3 生成图像
POST
https://api.ttapi.io/openai/v1/images/generations
根据文本提示使用DALL·E 3模型创建图像。DALL·E 3模型相对于市场上的其他模型而言对文字理解能力最强,你可以使用任何语言作为你的描述文案,价格详见,此接口已不推荐使用
Headers
Content-Type
application/json
TT-API-KEY
用于请求授权 TT-API 的API密钥
Body
prompt
string
是
dall-e-3模型,描述词长度不能超过4000个字符
size
string
是
图像尺寸,可选范围:
1024x1024
1024x1792
1792x1024 注意:不同尺寸消耗ttapi quota不同
model
string
否
固定值:dall-e-3
n
integer
否
生成图像数量,固定值:1
quality
string
否
图片质量,可选范围: standard - 标准 hd - 增强细节
请求示例
import requests
endpoint = "https://api.ttapi.io/openai/v1/images/generations"
headers = {
"TT-API-KEY": your_key
}
data = {
"prompt": "a cute cat",
"size": "1024x1024",
}
response = requests.post(endpoint, headers=headers, json=data)
print(response.status_code)
print(response.json())
返回示例
{
"status": "SUCCESS",
"message": "success",
"data": {
"created": 1713577682,
"data": [
{
"revised_prompt": "A serene, domestic scene unfolding at dusk: a fluffy, long-haired tabby cat with piercing green eyes and distinctive black and white stripes curled up on a cozy, burgundy-colored velvet cushion. Around the cat is the warmth of a rustic country home, with wooden beams and a crackling fireplace. Light streams in through a large, arched window, painting the scene in the beautiful, ethereal light of golden hour.",
"url": "https://dalleprodaue.blob.core.windows.net/private/images/cbb4adae-b889-4adf-9b84-4cd6d72d74fc/generated_00.png?se=2024-04-21T01%3A48%3A14Z&sig=th9fuLXfJVtLUOWu%2BfkJk1aY8abDZTDe7aIWJ1QzLkY%3D&ske=2024-04-26T13%3A43%3A10Z&skoid=f4f58869-78fa-4857-8a87-4ce5ae4ba8c3&sks=b&skt=2024-04-19T13%3A43%3A10Z&sktid=33e01921-4d64-4f8c-a055-5bdaffd5e33d&skv=2020-10-02&sp=r&spr=https&sr=b&sv=2020-10-02"
}
]
}
}
GPT-4o 生成图像
POST
https://api.ttapi.io/openai/4o-image/generations
根据文本提示以及图片资源生成图片
Headers
Content-Type
application/json
TT-API-KEY
用于请求授权 TT-API 的API密钥
Body
prompt
string
是
生成图片文字提示,因为目前为逆向模型,建议文案提示存在关键字:“画一张xxx”, “生成一张”,"draw a xxx",具体语言不限制,openai本身就支持多语言模型,中文支持也非常友好。
referImages
array
否
垫图数组,示例:
[
"https://cdn.ttapi.io/demo/2025-03-30/5d17dd5207daeeac86bcecd2d6405a0.jpg",
"https://cdn.ttapi.io/demo/2025-03-30/5d17dd5207daeeac86bcecd2d6405a0.jpg"
]
请求示例
import requests
endpoint = "https://api.ttapi.io/openai/4o-image/generations"
headers = {
"TT-API-KEY": your_key
}
data = {
"prompt": "画一张美女模特该衣服平面照拍摄照片,要求高像素,高逼真度,完美还原衣服所有细节,全身照专业姿势,身材性感,穿着潮流,面带微笑,欧美女性皮肤白皙",
"referImages": [
"https://cdn.ttapi.io/demo/2025-03-30/5d17dd5207daeeac86bcecd2d6405a0.jpg"
],
"hookUrl": "https://webhook-test.com/b129b43b6619f977b3227387fc290f7d"
}
response = requests.post(endpoint, headers=headers, json=data)
print(response.status_code)
print(response.json())
返回示例
{
"status": "SUCCESS",
"message": "success",
"data": {
"jobId": "5ecc5080-b1d7-4b9f-8184-435e46ebb5cb"
}
}
GPT-4o生成结果查询
POST/GET
https://api.ttapi.io/openai/4o-image/fetch
获取GPT-4o生成任务结果,返回数据结构与hookUrl中返回一致
Headers
Content-Type
application/json
TT-API-KEY
用于请求授权 TT-API 的API密钥
Query / Body
jobId
string
是
生成接口返回的jobId
请求示例
import requests
endpoint = "https://api.ttapi.io/openai/4o-image/fetch"
headers = {
"TT-API-KEY": your_key
}
data = {
"jobId": "5ecc5080-b1d7-4b9f-8184-435e46ebb5cb"
}
response = requests.post(endpoint, headers=headers, json=data)
print(response.status_code)
print(response.json())
GPT-4o 异步响应JSON示例
{
"status": "ON_QUEUE",
"message": null,
"jobId": "0ccf0606-3f32-4090-85bd-1786e4593be5",
"data": {
"prompt": "画一张美女模特该衣服平面照拍摄照片,要求高像素,高逼真度,完美还原衣服所有细节,全身照专业姿势,身材性感,穿着潮流,面带微笑,欧美女性皮肤白皙",
"referImages": [
"https://cdn.ttapi.io/demo/2025-03-30/5d17dd5207daeeac86bcecd2d6405a0.jpg"
],
"imageUrl": null,
"quota": "2",
"finishTime": null,
"hookUrl": "https://webhook-test.com/b129b43b6619f977b3227387fc290f7d"
}
}
GPT-4o 使用案例
应用场景/实践案例:
制作海报(我的垫图可能不太恰当,随便官网首页截了个图,具体实际使用需要调试)
提示词:结合图片,生成一张GPT-4o宣传海报,要求海报简洁大气,存在TTAPI的logo,科技风格主题


文章插画
提示词:一张图详细解释马斯洛需求层次理论

模特试衣
提示词:画一张美女模特该衣服平面照拍摄照片,要求高像素,高逼真度,完美还原衣服所有细节,全身照专业姿势,身材性感,穿着潮流,面带微笑,欧美女性皮肤白皙


产品封面
小说插画
等等各种你能想到的复杂场景
总结:
OpenAI推出的这个4o图片模型在现在的AI市场里来说显然是一个王炸模型,个人觉得文生图不是他最强的所在,最强的关键点在于改图以及垫图生图
优点:
文本支持好。基于OpenAI llm大模型语言理解能力强,文字支持友好不像其他图片模型的鬼画符或者需要双引号+英文限制才会有概率的在图片中贴上你想要的文本
垫图识图。支持依据文案加识别就可以更改上传图片中的元素,或者依据上传图片生成你想要的场景图,这一点目前没有任何全品类的图片模型可以做到
不足:
人物刻画。目前尝试,人物的刻画能力与Midjourney对比来说会差一些,比如要求生成的任务客户到汗珠,皮肤纹理,发丝等等。
尺寸控制。目前由于官方还未给出api,整体图片的尺寸很难通过提示词进行精准的控制
细节把控。目前需要高精度的使用场景,很难做到细节的刻画与把控
Last updated
Was this helpful?