Skip to content

Generate images

Two synchronous endpoints: POST /v1/images/generations for text to image and POST /v1/images/edits for image to image. The response arrives when generation completes; large images can take up to a couple of minutes, so keep client timeouts generous.

Text to image

curl https://api.tokport.io/v1/images/generations \
  -H "Authorization: Bearer $TOKPORT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-image-2","prompt":"a neon koi swimming through clouds, cinematic lighting","size":"1024x1024","n":1}'

Request fields

Shown for gpt-image-2; sizes and extras differ per model, see each model's schema.

FieldTypeDescription
model*stringModel id. Always "gpt-image-2".
prompt*stringWhat to generate. Be concrete about subject, style, lighting and composition.
sizestring (enum)Output size as "WIDTHxHEIGHT" pixels.1024x10241536x10241024x1536autodefault: 1024x1024
nintegerNumber of images to generate in one request. Each image is billed.default: 1range: 1–4
response_formatstring (enum)Return hosted URLs (expire after a while) or inline base64 PNG data.urlb64_jsondefault: url
qualitystring (enum)Rendering quality tier. Higher tiers take longer.lowmediumhighautodefault: auto
backgroundstring (enum)Transparent backgrounds need output_format png or webp.autoopaquetransparentdefault: auto
output_formatstring (enum)Encoding of the returned image.pngjpegwebpdefault: png

Image to image (edits)

Send the reference as a public URL or a data: URL in image and describe the change in prompt. JSON bodies are accepted; multipart form uploads also work for OpenAI-style clients.

curl https://api.tokport.io/v1/images/edits \
  -H "Authorization: Bearer $TOKPORT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-image-2","image":"https://example.com/reference.png","prompt":"put the product on a marble pedestal with soft studio lighting","size":"1024x1024","n":1}'
FieldTypeDescription
model*stringModel id. Always "gpt-image-2".
image*string (url | data:)Reference image as a public URL or a data: URL (PNG, JPEG or WebP, up to 8 MB).
prompt*stringHow the reference image should change. The model keeps what you do not mention.
sizestring (enum)Output size as "WIDTHxHEIGHT" pixels.1024x10241536x10241024x1536autodefault: 1024x1024
nintegerNumber of images to generate in one request. Each image is billed.default: 1range: 1–4
response_formatstring (enum)Return hosted URLs (expire after a while) or inline base64 PNG data.urlb64_jsondefault: url

Response

json — response
{
  "created": 1726400000,
  "data": [
    {
      "url": "https://cdn.example.com/generated/abc.png",
      "revised_prompt": "a neon koi swimming through clouds, cinematic lighting"
    }
  ]
}

Synchronous. `data[]` holds one entry per generated image with `url` (or `b64_json` when requested). The `X-Oneapi-Request-Id` response header identifies the request in your usage log.

Image models

Sizes & ratios

The size parameter takes an explicit pixel string like "1024x1536". Standard sizes per aspect ratio are in the size reference; allowed values per model are listed in its schema.