OpenAI Image Models

TTAPI integrates OpenAI's excellent image model, allowing you to integrate it into your services in a more affordable and convenient way.

OpenAI Create Images

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


Create images based on text and image prompts, official documentation (opens in a new tab), supporting models gpt-image-1, dall-e-2, dall-e-3. And for price

Headers

NameTypeDescription
TT-API-KEY*StringYour API Key in TT API used for request authorization

Request Body

NameTypeRequiredDescription
promptStringtrueA text description of the desired image(s). The maximum length is 32000 characters for gpt-image-1, 1000 characters for dall-e-2 and 4000 characters for dall-e-3.
others...falseMore refer to... (opens in a new tab)

Example Request

import base64
from openai import OpenAI
client = OpenAI(
    base_url="https://api.ttapi.io/v1",
    api_key="your api key",
)
 
img = client.images.generate(
    model="gpt-image-1",
    prompt="A cute baby sea otter",
    n=1,
    size="1024x1024"
)
 
image_bytes = base64.b64decode(img.data[0].b64_json)
with open("output.png", "wb") as f:
f.write(image_bytes)

OpenAI Create Images edit

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


Creates an edited or extended image given one or more source images and a prompt. This endpoint only supports gpt-image-1 and dall-e-2. And for price

Headers

NameTypeDescription
TT-API-KEY*StringYour API Key in TT API used for request authorization

Request Body

NameTypeRequiredDescription
imageString or ArraytrueThe image(s) to edit. Must be a supported image file or an array of images. For gpt-image-1, each image should be a png, webp, or jpg file less than 25MB. For dall-e-2, you can only provide one image, and it should be a square png file less than 4MB.
promptStringtrueA text description of the desired image(s). The maximum length is 32000 characters for gpt-image-1, 1000 characters for dall-e-2 and 4000 characters for dall-e-3.
others...falseMore refer to... (opens in a new tab)

Example Request

import base64
from openai import OpenAI
client = OpenAI(
    base_url="https://api.ttapi.io/v1",
    api_key="your api key",
)
 
img = 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)

DALLE 3 Generate Image

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


Headers

NameTypeDescription
TT-API-KEY*StringYour API Key in TT API used for request authorization

Request Body

NameTypeRequiredDescription
promptStringtruePrompt use to generate image
sizeStringtrueImage Size:
1024x1024
1024x1792
1792x1024
modelStringfalsedall-e-3
nIntfalsegenerate images number only can ues 1 in dall-e-3
qualityStringfalsePicture quality, optional range:
standard, hd

Example Request

import requests
endpoint = "https://api.ttapi.io/openai/v1/images/generations"
headers = {
    "TT-API-KEY": your_key
}
data = {
    "prompt": "a cat",
    "size": "1024x1024"
}
response = requests.post(endpoint, headers=headers, json=data)
print(response.status_code)
print(response.json())

Example Response

There are expiration restrictions on the images returned by Dalle3. Please transfer the images yourself when using them.

{
    "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"
            }
        ]
    }
}

ChaGPT-4o Generate Image (async)

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


Generate images based on text prompts and image resources. Using the OpenAI ChatGPT-4o Model

Headers

NameTypeDescription
TT-API-KEY*StringYour API Key in TT API used for request authorization

Request Body

NameTypeRequiredDescription
promptStringtruePrompt use to generate image
referImagesarrayfalseBase the image then generate
exp: [ "https://cdn.ttapi.io/demo/2025-03-30/5d17dd5207daeeac86bcecd2d6405a0.jpg", "https://cdn.ttapi.io/demo/2025-03-30/5d17dd5207daeeac86bcecd2d6405a0.jpg"]
hookUrlStringfalseSend a request to the address for task completion or failed notification. If not set you need to request fetch endpoint to get response

Example Request

import requests
endpoint = "https://api.ttapi.io/openai/4o-image/generations"
headers = {
    "TT-API-KEY": your_key
}
data = {
    "prompt": "Draw a flat photo of a beautiful model wearing the clothes. It requires high pixels, high fidelity, perfect restoration of all the details of the clothes, full-body photo with professional pose, sexy figure, fashionable clothes, smiling, and fair skin.",
    "referImages": [
        "https://cdn.ttapi.io/demo/2025-03-30/5d17dd5207daeeac86bcecd2d6405a0.jpg"
    ],
}
response = requests.post(endpoint, headers=headers, json=data)
print(response.status_code)
print(response.json())

Example Response

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

Fetch ChatGPT-4o Image Result

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


Get the generate task result query, the returned json data is same with the return in hookUrl

Headers

NameTypeDescription
TT-API-KEY*StringYour API Key in TT API used for request authorization

Request Body / Query param

NameTypeRequiredDescription
jobIdStringtrue5ecc5080-b1d7-4b9f-8184-435e46ebb5cb

Example Request

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())

ChatGPT-4o Image Async callback & Fetch json

{
      "status": "SUCCESS",
      "message": "success",
      "jobId": "5ecc5080-b1d7-4b9f-8184-435e46ebb5cb",
      "data": {
          "prompt": "Draw a flat photo of a beautiful model wearing the clothes. It requires high pixels, high fidelity, perfect restoration of all the details of the clothes, full-body photo with professional pose, sexy figure, fashionable clothes, smiling, and fair skin.",
          "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"
      }
}