TTAPI 中文文档
  • TTAPI 中文文档
  • API能力
    • 🔥Midjourney API
    • Flux API
    • Recraft API
    • 📖LLM API
    • 🔀Midjourney Hold Account
    • 🟢OpenAI Image Models
    • 🔵Luma
    • 🎵Suno
    • 🔗账户体系
    • ⭕状态码详解
  • 企业服务
    • Midjourney离线服务
  • 问答专区
    • Midjourney
      • 常见问题解答
      • 账户托管
      • 科学使用你的Midjourney账户
    • Luma
    • 使用相关
    • 其他杂项
  • 升级日志
Powered by GitBook
On this page
  • OpenAI Create image
  • OpenAI Create image edit
  • Dalle3 生成图像
  • GPT-4o 生成图像
  • GPT-4o生成结果查询
  • GPT-4o 异步响应JSON示例
  • GPT-4o 使用案例
  • 应用场景/实践案例:
  • 总结:

Was this helpful?

  1. API能力

OpenAI Image Models

TTAPI整合openai的优秀图片模型,让你能以更为优惠的价格且方便的方式集成到你的服务。

PreviousMidjourney Hold AccountNextLuma

Last updated 18 days ago

Was this helpful?

OpenAI Create image

POST https://api.ttapi.io/v1/images/generations

根据文本以及图片提示创建图像,转自openai官方接口,支持模型 gpt-image-1, dall-e-2, dall-e-3

文档翻译自,如已对接官方文档可直接对接使用,所有入参出参结构与支持均一致,

Headers

Name
Value

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())
const axios = require('axios');

let config = {
  method: 'post',
  url: 'https://api.ttapi.io/openai/v1/images/generations',
  headers: { 
    'TT-API-KEY': 'your_key'
  },
  data : {
    "prompt": "a cute cat",
    "model": "gpt-image-1",
    "size": "1024x1024 "
  }
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.status));
})
.catch(function (error) {
  console.log(error);
});

返回示例

{
    "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
}
{
    "created": 1745818890,
    "data": [
        {
            "b64_json": "iVBORw0KGgoAAAANSUhE..."
        }
    ],
    "usage": {
        "input_tokens": 9,
        "input_tokens_details": {
            "image_tokens": 0,
            "text_tokens": 9
        },
        "output_tokens": 4160,
        "total_tokens": 4169
    }
}

OpenAI Create image edit

POST https://api.ttapi.io/v1/images/edits

根据给定的一个或多个源图像和提示,编辑或扩展图像。支持模型 gpt-image-1, dall-e-2

Headers

Name
Value

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)
import fs from "fs";
import OpenAI, { toFile } from "openai";


const client = new OpenAI({
  apiKey: "your api key", 
  baseURL: "https://api.ttapi.io/v1"
});

const imageFiles = [
    "bath-bomb.png",
    "body-lotion.png",
    "incense-kit.png",
    "soap.png",
];

const images = await Promise.all(
    imageFiles.map(async (file) =>
        await toFile(fs.createReadStream(file), null, {
            type: "image/png",
        })
    ),
);

const rsp = await client.images.edit({
    model: "gpt-image-1",
    image: images,
    prompt: "Create a lovely gift basket with these four items in it",
});

// Save the image to a file
const image_base64 = rsp.data[0].b64_json;
const image_bytes = Buffer.from(image_base64, "base64");
fs.writeFileSync("basket.png", 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

Headers

Name
Value

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 - 增强细节

注意:dalle3接口的任务结果是同步返回的并不需要异步回调或者再次去查询该任务结果,接口响应时间一般在3-15s中间,时效同步根据OpenAI官方。

请求示例

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())
const axios = require('axios');

let config = {
  method: 'post',
  url: 'https://api.ttapi.io/openai/v1/images/generations',
  headers: { 
    'TT-API-KEY': 'your_key'
  },
  data : {
    "prompt": "a cute cat",
    "size": "1024x1024 "
  }
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.status));
})
.catch(function (error) {
  console.log(error);
});

返回示例

Dalle3 返回图片存在有效期限制,使用请自行转存图片

{
    "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"
            }
        ]
    }
}
{
    "status": "FAILED",
    "message": "For the dall-e-3 model, \"size\" must be one of 1024x1024, 1792x1024, or 1024x1792.",
    "data": null
}

GPT-4o 生成图像

POST https://api.ttapi.io/openai/4o-image/generations

根据文本提示以及图片资源生成图片

注意:由于openai目前暂未以api形式提供该接口,所以该接口目前为逆向接口。稳定性可能存在波动,目前整体定价较为便宜,后续官方正式上线后,可能会同步调整接口字段以及定价。

Headers

Name
Value

Content-Type

application/json

TT-API-KEY

用于请求授权 TT-API 的API密钥

Body

参数
类型
是否必须
描述

prompt

string

是

生成图片文字提示,因为目前为逆向模型,建议文案提示存在关键字:“画一张xxx”, “生成一张”,"draw a xxx",具体语言不限制,openai本身就支持多语言模型,中文支持也非常友好。

referImages

array

否

垫图数组,示例:

hookUrl

string

否

请求示例

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())
const axios = require('axios');

let config = {
  method: 'post',
  url: 'https://api.ttapi.io/openai/v1/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"
  }
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.status));
})
.catch(function (error) {
  console.log(error);
});

返回示例

{
    "status": "SUCCESS",
    "message": "success",
    "data": {
        "jobId": "5ecc5080-b1d7-4b9f-8184-435e46ebb5cb"
    }
}
{
    "status": "FAILED",
    "message": "",
    "data": null
}

GPT-4o生成结果查询

POST/GET https://api.ttapi.io/openai/4o-image/fetch

Headers

Name
Value

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"
    }
}
{
  "status": "SUCCESS",
  "message": "success",
  "jobId": "5ecc5080-b1d7-4b9f-8184-435e46ebb5cb",
  "data": {
    "prompt": "画一张美女模特该衣服平面照拍摄照片,要求高像素,高逼真度,完美还原衣服所有细节,全身照专业姿势,身材性感,穿着潮流,面带微笑,欧美女性皮肤白皙",
    "referImages": [
      "https://cdn.ttapi.io/demo/2025-03-30/5d17dd5207daeeac86bcecd2d6405a0.jpg"
    ],
    "imageUrl": "https://cdnc.ttapi.io/2025-03-31/cd3f3ce5-06be-4b3a-9aed-014045ca1804.png",
    "quota": "2",
    "finishTime": "2025-03-31 04:25:33",
    "hookUrl": "https://webhook-test.com/b129b43b6619f977b3227387fc290f7d"
  }
}
{
  "status": "FAILED",
  "message": "job failed",
  "jobId": "b45fcf32-71a5-4df2-82c7-2e6300e32e29",
  "data": {
    "prompt": "画一张模特采光棚真实试衣场景,要求高像素,高逼真度,全身照专业姿势,中国模特美女,身材比例协调,面带微笑,皮肤白皙",
    "referImages": [
      "https://cdn.ttapi.io/demo/2025-03-30/5d17dd5207daeeac86bcecd2d6405a0.jpg"
    ],
    "imageUrl": null,
    "quota": "0",
    "finishTime": "2025-03-31 04:10:21",
    "hookUrl": "https://webhook-test.com/b129b43b6619f977b3227387fc290f7d"
  }
}

GPT-4o 使用案例

应用场景/实践案例:

  • 制作海报(我的垫图可能不太恰当,随便官网首页截了个图,具体实际使用需要调试)

提示词:结合图片,生成一张GPT-4o宣传海报,要求海报简洁大气,存在TTAPI的logo,科技风格主题

  • 文章插画

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

  • 模特试衣

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

  • 产品封面

  • 小说插画

  • 等等各种你能想到的复杂场景

总结:

OpenAI推出的这个4o图片模型在现在的AI市场里来说显然是一个王炸模型,个人觉得文生图不是他最强的所在,最强的关键点在于改图以及垫图生图

优点:

  • 文本支持好。基于OpenAI llm大模型语言理解能力强,文字支持友好不像其他图片模型的鬼画符或者需要双引号+英文限制才会有概率的在图片中贴上你想要的文本

  • 垫图识图。支持依据文案加识别就可以更改上传图片中的元素,或者依据上传图片生成你想要的场景图,这一点目前没有任何全品类的图片模型可以做到

不足:

  • 人物刻画。目前尝试,人物的刻画能力与Midjourney对比来说会差一些,比如要求生成的任务客户到汗珠,皮肤纹理,发丝等等。

  • 尺寸控制。目前由于官方还未给出api,整体图片的尺寸很难通过提示词进行精准的控制

  • 细节把控。目前需要高精度的使用场景,很难做到细节的刻画与把控

文档翻译自,如已对接官方文档可直接对接使用,所有入参出参结构与支持均一致,

根据文本提示使用DALL·E 3模型创建图像。DALL·E 3模型相对于市场上的其他模型而言对文字理解能力最强,你可以使用任何语言作为你的描述文案,,此接口已不推荐使用

回调地址,任务完成或失败将通过请地址进行通知。如果未设置,则需要请求进行查询。

获取GPT-4o生成任务结果,返回数据结构与中返回一致

🟢
 [
      "https://cdn.ttapi.io/demo/2025-03-30/5d17dd5207daeeac86bcecd2d6405a0.jpg",
      "https://cdn.ttapi.io/demo/2025-03-30/5d17dd5207daeeac86bcecd2d6405a0.jpg"
]
hookUrl
fetch 接口
官方文档
官方文档
定价详见
定价详见
价格详见
结合图片,生成一张GPT-4o宣传海报,要求海报简洁大气,存在TTAPI的logo,科技风格主题
一张图详细解释马斯洛需求层次理论