AI Model APIs

Images

AI image generation and editing use vendor-native protocols. Google Gemini, OpenAI GPT Image, Volcano Engine Seedream and Alibaba Cloud Model Studio Qwen Image each use their own endpoint, request body and parameters.

Model overview

Model (model)Text-to-imageImage-to-image / editingOutput formatsHighlights
gemini-2.5-flash-image
gemini-2.5-flash-image-preview
gemini-3.1-flash-image-preview
gemini-3-pro-image-preview
SupportedSupported (pass images in contents.parts)inlineDataNative Gemini multimodal generation that can return text and images together
gpt-image-2SupportedSupported (incl. masked inpainting)png / jpeg / webpStrong instruction following, accurate text rendering, flexible sizes, high-fidelity image input
doubao-seedream-5-0-pro-260628SupportedSupported (single / multiple images)png / jpegInteractive editing (free-form marks, coordinate targeting), strong performance across varied scenes
qwen-image-3.0-proSupportedSupported (1–3 reference images)pngMulti-reference editing, smart prompt rewriting, 1–6 images per call

Parameter sets are separated by vendor protocolThe four image APIs use native Gemini, OpenAI, Volcano Engine and Alibaba Cloud Model Studio request structures. Their endpoints, authentication headers, parameter names and value ranges are not interchangeable. Follow the matching section below.

Limits follow upstream documentationThe size, dimension, count and duration limits on this page come from each upstream vendor's documentation and may change as they update it. For the current values, refer to each vendor's official documentation.


Native Gemini image generation

Google Gemini image models use the native generateContent API. Put the model ID in the URL, content in contents[].parts[], and generation options in generationConfig.

ItemValue
Model IDsgemini-2.5-flash-image
gemini-2.5-flash-image-preview
gemini-3.1-flash-image-preview
gemini-3-pro-image-preview
EndpointPOST /v1beta/models/{model}:generateContent
HeaderAuthorization: Bearer sk-*** (do not send x-goog-api-key)
Return modecandidates[].content.parts[].inlineData
POST https://api.tokgate.io/v1beta/models/{model}:generateContent

Request parameters

ParameterTypeRequiredDescription
contentsarray<object>RequiredNative Gemini content array. User input normally uses role: "user".
contents[].parts[].textstringRequiredGeneration or editing instruction describing the final desired image.
contents[].parts[].inlineDataobjectOptionalImage-to-image input containing the image mimeType and Base64 data. It can share the same parts array with text.
generationConfig.responseModalitiesarray<string>OptionalResponse modalities. Use ["TEXT", "IMAGE"] for image generation, or keep only "IMAGE" when no text is needed.
generationConfig.imageConfig.aspectRatiostringOptionalOutput aspect ratio such as 1:1, 16:9 or 9:16. Available values depend on the model.
generationConfig.imageConfig.imageSizestringOptionalOutput size tier such as 1K or 2K. Supported values depend on the model.

Request example

curl -X POST "https://api.tokgate.io/v1beta/models/gemini-3.1-flash-image-preview:generateContent" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-***" \
  -d '{
    "contents": [{
      "role": "user",
      "parts": [{"text": "Create a minimalist product photo: a white ceramic aroma diffuser on a light wood table, natural morning side light, 1:1 composition"}]
    }],
    "generationConfig": {
      "responseModalities": ["TEXT", "IMAGE"],
      "imageConfig": {"aspectRatio": "1:1", "imageSize": "2K"}
    }
  }'
curl -X POST "https://api.tokgate.io/v1beta/models/gemini-2.5-flash-image:generateContent" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-***" \
  -d '{
    "contents": [{
      "role": "user",
      "parts": [
        {"text": "Keep the product shape and logo, and replace the background with a wooden table by the sea at dawn with natural side light"},
        {"inlineData": {"mimeType": "image/png", "data": "BASE64_IMAGE_DATA"}}
      ]
    }],
    "generationConfig": {"responseModalities": ["TEXT", "IMAGE"]}
  }'

Image response

{
  "candidates": [{
    "content": {
      "role": "model",
      "parts": [{
        "inlineData": {
          "mimeType": "image/png",
          "data": "iVBORw0KGgoAAAANSUhEUgAA..."
        }
      }]
    }
  }]
}

Iterate over candidates[].content.parts[], find parts containing inlineData, then decode the Base64 data according to mimeType.


gpt-image-2

OpenAI's image generation model. Supports text-to-image and image editing, with flexible sizes and high-fidelity image input.

ItemValue
model_idgpt-image-2
Text-to-image endpointPOST /v1/images/generations
Image-to-image endpointPOST /v1/images/edits
Return modeBase64 (data[].b64_json)

gpt-image-2 text-to-image

POST https://api.tokgate.io/v1/images/generations
ParameterTypeRequiredDescription
modelstringRequiredFixed at gpt-image-2.
promptstringRequiredText description of the image; up to 32,000 characters for the GPT Image series.
nintegerOptionalNumber of images to generate, 1 ~ 10, default 1.
sizestringOptionalOutput size, default auto. Common presets: 1024x1024, 1536x1024, 1024x1536, 2048x2048, 2048x1152, 3840x2160, 2160x3840. You can also customize widthxheight within the constraints: long edge ≤ 3840px, both width and height in multiples of 16px, long/short edge ratio ≤ 3:1, and total pixels between 655,360 and 8,294,400. Square images generate the fastest.
qualitystringOptionalauto (default) / low / medium / high. low suits drafts, thumbnails and fast iteration; medium / high are for finals. Output with total pixels over 2560x1440 (about 3.68 MP, commonly called 2K) is still experimental.
output_formatstringOptionalpng (default) / jpeg / webp. Transparent output requires png or webp; jpeg is always opaque. For latency-sensitive opaque images, prefer jpeg.
output_compressionintegerOptionalCompression level 0 ~ 100, default 100. Only effective for jpeg and webp.
backgroundstringOptionaltransparent / opaque / auto (default). To preserve an alpha channel, use background: "transparent" together with output_format: "png" or "webp".
moderationstringOptionalContent moderation strength: auto (default, standard filtering) or low (loose filtering).
userstringOptionalEnd-user identifier, useful for abuse investigation.

Transparent background outputSet both background: "transparent" and output_format: "png" or "webp". The parameter enables the alpha channel; describing the subject as isolated with no background in the prompt helps produce cleaner edges.

curl -X POST https://api.tokgate.io/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-***" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "A friendly corgi pilot mascot wearing aviator goggles, full body, isolated, clean edges, no shadow, no text",
    "n": 1,
    "size": "1536x1024",
    "quality": "high",
    "output_format": "png",
    "background": "transparent"
  }'
import base64
from openai import OpenAI

client = OpenAI(
    api_key="sk-***",
    base_url="https://api.tokgate.io/v1",
)

resp = client.images.generate(
    model="gpt-image-2",
    prompt="A friendly corgi pilot mascot wearing aviator goggles, full body, isolated, clean edges, no shadow, no text",
    size="1536x1024",
    quality="high",
    output_format="png",
    background="transparent",
)

with open("corgi-transparent.png", "wb") as f:
    f.write(base64.b64decode(resp.data[0].b64_json))

Response

{
  "created": 1779348818,
  "data": [
    { "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..." }
  ],
  "usage": {
    "total_tokens": 1620,
    "input_tokens": 52,
    "output_tokens": 1568,
    "input_tokens_details": { "text_tokens": 52, "image_tokens": 0 }
  }
}

gpt-image-2 image-to-image

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

Generates an edited image from one or more source images plus a prompt. The request body is multipart/form-data, not JSON.

ParameterTypeRequiredDescription
modelstringRequiredFixed at gpt-image-2.
imagefile / file[]RequiredThe source image(s) to edit. PNG, WEBP and JPG are supported. Multiple images are allowed (pass the same field repeatedly); with multiple images, elements from different images are combined into one output.
promptstringRequiredThe edit instruction. Describe "what the final whole image should look like", not just the area to be erased.
maskfileOptionalMask PNG; fully transparent (alpha=0) areas mark the positions to repaint. It must be in the same format and size as the image to edit, under 50 MB, and carry an alpha channel. When multiple images are passed, the mask only applies to the first image.
nintegerOptionalNumber of images to generate, 1 ~ 10, default 1.
sizestringOptionalSame as text-to-image; default auto (follows the input image).
qualitystringOptionalSame as text-to-image.
output_formatstringOptionalSame as text-to-image.
output_compressionintegerOptionalSame as text-to-image; only effective for jpeg / webp.
backgroundstringOptionalSame as text-to-image. Transparent edits are supported when background is transparent and output_format is png or webp.
userstringOptionalEnd-user identifier.

The mask is guidance, not pixel-level croppingGPT Image mask editing works through prompt understanding; it is not guaranteed to strictly follow the mask shape and may alter areas outside the mask. To preserve content that must not change, explicitly write "keep ×× unchanged" in the prompt. gpt-image-2 does not support the input_fidelity parameter — the model always processes all input images at the highest fidelity, which neither needs nor allows configuration; this also means editing requests with reference images may consume more input image tokens.

curl -X POST https://api.tokgate.io/v1/images/edits \
  -H "Authorization: Bearer sk-***" \
  -F "model=gpt-image-2" \
  -F "image=@product.png" \
  -F "mask=@product-mask.png" \
  -F "prompt=Keep the product itself, the logo and all packaging text completely unchanged; replace the background with a wooden tabletop by the seaside in the early morning, natural side light, shallow depth of field" \
  -F "size=1024x1024" \
  -F "output_format=png"
import base64
from openai import OpenAI

client = OpenAI(
    api_key="sk-***",
    base_url="https://api.tokgate.io/v1",
)

resp = client.images.edit(
    model="gpt-image-2",
    image=[open("product.png", "rb")],
    mask=open("product-mask.png", "rb"),
    prompt="Keep the product itself, the logo and all packaging text completely unchanged; replace the background with a wooden tabletop by the seaside in the early morning",
    size="1024x1024",
)

with open("product-edited.png", "wb") as f:
    f.write(base64.b64decode(resp.data[0].b64_json))

The response structure is identical to text-to-image; usage.input_tokens_details.image_tokens counts the token consumption of input images.

Usage limits and content moderation

  • Latency: complex prompts can take up to about 2 minutes to process.
  • Text rendering: greatly improved, but precise text layout and clarity can still be unstable.
  • Consistency: the visual consistency of recurring characters or brand elements across multiple generations cannot be fully guaranteed.
  • Composition control: in structured or layout-sensitive compositions, the precise placement of elements can still deviate.
  • Content moderation: all prompts and generated images are filtered against the content policy. When moderation is hit, the response returns error.type = "image_generation_user_error" and error.code = "moderation_blocked", possibly with error.moderation_details (containing moderation_stage: input / output / unknown, and coarse-grained categories labels). Do not automatically retry such user-correctable errors; modify the prompt or input image first.

seedream-5-0

Volcano Engine Ark Doubao Seedream 5.0 pro. Supports text-to-image and single- / multi-image-to-image, and introduces interactive editing: precisely specify edit locations with hand-drawn marks or coordinate tags.

ItemValue
model_iddoubao-seedream-5-0-pro-260628
EndpointPOST /api/v3/images/generations
Return modeurl (default, valid for 24 hours) or b64_json

Capability matrix

CapabilitySeedream 5.0 pro
Text-to-imageSupported
Single / multi image-to-imageSupported
Interactive editingSupported (unique to this series)
Text to image setNot supported yet
Single / multi image to image setNot supported yet
StreamingNot supported yet
Web searchNot supported yet
Resolution presets1K / 2K (default 2K)
Output formatspng, jpeg
Prompt optimization modesStandard mode standard, fast mode fast

Request parameters

ParameterTypeRequiredDescription
modelstringRequireddoubao-seedream-5-0-pro-260628
promptstringRequiredGeneration or edit instruction. For interactive editing, <point> / <bbox> coordinate tags can be embedded.
imagestring / arrayOptionalReference image(s). Passing this switches to image-to-image / editing mode. Accepts public URLs or Base64 (data:image/png;base64,<data>, MIME must be lowercase). Pass an array for multiple images.
sizestringOptionalTwo notations; do not mix them: ① resolution preset 1K / 2K (recommended, default 2K); ② exact pixels widthxheight, which must satisfy total pixels 921600 ~ 4624220 and aspect ratio within [1/16, 16].
response_formatstringOptionalurl (returns a download link) or b64_json (returns Base64).
output_formatstringOptionalpng or jpeg.
watermarkbooleanOptionalWhen true, adds the vendor-supplied "AI-generated" watermark at the bottom-right corner of the image; false adds none.
optimize_prompt_optionsobjectOptionalPrompt optimization mode, e.g. {"mode": "fast"}. fast generates images faster and suits latency-sensitive workloads.

Width × height pixels for each resolution preset

Aspect ratio1K2K
1:11024 × 10242048 × 2048
4:31152 × 8642368 × 1776
3:4864 × 11521776 × 2368
16:91424 × 8002816 × 1584
9:16800 × 14241584 × 2816
3:21248 × 8322496 × 1664
2:3832 × 12481664 × 2496
21:91568 × 6723136 × 1344

Request example

curl -X POST https://api.tokgate.io/api/v3/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-***" \
  -d '{
    "model": "doubao-seedream-5-0-pro-260628",
    "prompt": "A Mid-Autumn Festival gift-box key visual in guochao illustration style, deep cyan background with gold-foil patterns, a box of mooncakes at the center, soft light and shadow, neatly arranged negative space",
    "size": "2K",
    "output_format": "png",
    "watermark": false
  }'
curl -X POST https://api.tokgate.io/api/v3/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-***" \
  -d '{
    "model": "doubao-seedream-5-0-pro-260628",
    "prompt": "Edit the image based on the hand-drawn sketch: add a stack of magazines in the marked area at the lower-left, add a cup of coffee with a saucer in the marked area on the right, remove all sketch lines, keep the composition unchanged, and blend the new objects naturally into the original scene",
    "image": "https://your-cdn.example.com/sketch.png",
    "size": "2K",
    "output_format": "png",
    "watermark": false
  }'
{
  "model": "doubao-seedream-5-0-pro-260628",
  "image": ["https://your-cdn.example.com/a.png", "https://your-cdn.example.com/b.png"],
  "prompt": "Move the subject in image 1 179 283 796 986 to the position 118 331 933 871 in image 2",
  "size": "2K"
}

Two ways to locate edits in interactive editingArbitrary marks + natural language: draw color blocks or circles on the original image, then specify the location with a description such as "add a TV set inside the blue box"; ② precise coordinate targeting: give coordinates in the prompt using <point> or <bbox> tags.

Usage limits

  • Reference image formats: jpeg, png, webp, bmp, tiff, gif, heic, heif.
  • Reference image dimensions: aspect ratio [1/16, 16]; both width and height must be greater than 14 px and no more than 6000 px (total pixels ≤ 36,000,000).
  • Reference image size: no more than 30 MB each; up to 10 images.
  • Quantity constraint: number of input reference images + number of final generated images ≤ 15.
  • Output validity: image links returned with response_format: "url" are kept for only 24 hours; download and store them promptly.

qwen-image-3.0-pro

Qwen image generation and editing 3.0. Supports both text-to-image (T2I) and image-to-image / editing (I2I), performing precise edits based on 1 ~ 3 reference images combined with edit instructions. The request body structure differs from the previous two models: the prompt and reference images go into input.messages, and the remaining control parameters go into parameters.

ItemValue
model_idqwen-image-3.0-pro
Invocation modeSynchronous response (not an async task)
Output formatsPNG
Resolution rangeTotal pixels 512×512 ~ 2048×2048; when size is not specified, the model recommends one automatically based on the prompt
POST https://api.tokgate.io/api/v1/services/aigc/multimodal-generation/generation

Request parameters

ParameterTypeRequiredDescription
modelstringRequiredqwen-image-3.0-pro
input.messagesarray<object>RequiredSingle turn only: the array contains exactly one object with role and content.
input.messages[].rolestringRequiredFixed at user.
input.messages[].contentarray<object>RequiredText-to-image: exactly one {"text": "..."}. Image-to-image: 1 ~ 3 {"image": "..."} plus 1 {"text": "..."}.
…content[].imagestringOptionalReference image, a public URL (HTTP / HTTPS) or Base64 (data:{MIME};base64,{data}). With multiple images, the array order defines the image order.
…content[].textstringRequiredPositive prompt describing the desired image. Only one text is allowed; omitting it or passing multiple raises an error.
parameters.prompt_extendbooleanOptionalSmart prompt rewriting, default true (recommended). Noticeably improves results when the prompt is short.
parameters.nintegerOptionalNumber of output images, 1 ~ 6, default 1.
parameters.sizestringOptionalOutput resolution, formatted as width*height (an asterisk, not x), e.g. 1024*1024. Pixel range 512*512 ~ 2048*2048. If omitted, the model recommends one automatically.
parameters.negative_promptstringOptionalNegative prompt, describing content you do not want to appear.
parameters.seedintegerOptionalRandom seed, [0, 2147483647]. Fixing it makes generation results relatively stable.
parameters.watermarkbooleanOptionalWhether to add a watermark, default false.

Request example

curl -X POST https://api.tokgate.io/api/v1/services/aigc/multimodal-generation/generation \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-***" \
  -d '{
    "model": "qwen-image-3.0-pro",
    "input": {
      "messages": [
        {
          "role": "user",
          "content": [
            { "text": "Vertical outdoor portrait photography: a newsstand on a European street corner backlit in the afternoon, vines and small orange flowers hanging from the eaves, a sunlit street on the right side of the frame, warm film texture, fine grain, shallow depth of field" }
          ]
        }
      ]
    },
    "parameters": {
      "prompt_extend": true,
      "n": 1,
      "size": "1024*1536"
    }
  }'
curl -X POST https://api.tokgate.io/api/v1/services/aigc/multimodal-generation/generation \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-***" \
  -d '{
    "model": "qwen-image-3.0-pro",
    "input": {
      "messages": [
        {
          "role": "user",
          "content": [
            { "image": "https://your-cdn.example.com/portrait.png" },
            { "text": "Keep the person's facial features and long black hair from the input image; change the outfit to a champagne silk shirt under a dark gray blazer; change the scene to a modern, minimalist high-end café, afternoon side light, background naturally blurred" }
          ]
        }
      ]
    },
    "parameters": {
      "prompt_extend": true,
      "negative_prompt": "deformed fingers, text watermark, low resolution",
      "seed": 42
    }
  }'

Response structure

{
  "output": {
    "choices": [
      {
        "finish_reason": "stop",
        "message": {
          "role": "assistant",
          "content": [
            { "image": "https://.../result.png?Expires=..." }
          ]
        }
      }
    ]
  },
  "usage": {
    "width": 1024,
    "height": 1536,
    "image_count": 1
  },
  "request_id": "571ae02f-5c9d-436c-83c2-f221e6df0xxx"
}
{
  "request_id": "31f808fd-8eef-9004-xxxxx",
  "code": "InvalidApiKey",
  "message": "Invalid API-key provided."
}
FieldDescription
output.choices[].finish_reasonstop when generation ends naturally.
output.choices[].message.content[].imageURL of the generated image, in PNG format; the link is valid for 24 hours.
usage.width / usage.heightThe actual width and height (pixels) of the generated image.
usage.image_countNumber of images generated in this call.
request_idUnique request identifier; provide it when troubleshooting issues.
code / messageReturned only on failure, indicating the error cause.

Usage limits

  • Input image formats: JPG, JPEG, PNG, BMP, TIFF, WEBP, GIF.
  • Input image resolution: both width and height are recommended to be between 384 and 2048 pixels.
  • Input image size: no more than 10 MB each.
  • Reference image count: 1 ~ 3 for image-to-image scenarios; multiple images correspond by array order.
  • Turns: only single-turn is currently supported; messages can contain only one object.
  • Output validity: task data and image URLs are kept for only 24 hours and are automatically cleared after that.
  • This model is in an invitation-only beta upstream. If it returns "model unavailable", apply for access via the contact page.

General recommendations

  • Store outputs promptly: URLs returned by Seedream and Qwen Image are retained for only 24 hours; Gemini and GPT Image return Base64. Decode or download every result and move it to your own storage promptly.
  • Set client timeouts properly: image generation is a synchronous API but takes noticeably longer than chat, and high-quality tiers are slower; do not set the client timeout to just a few seconds.
  • Write prompts as "the final picture": especially for editing, describe what the whole image should look like after completion, and explicitly state the parts that must remain unchanged.
  • Start with low-cost tiers: quality: "low" for gpt-image-2, the 1K tier for seedream, and optimize_prompt_options.mode: "fast" are all suitable for the prompt-tuning stage; switch to high-quality tiers after finalizing.
  • Mind the MIME when passing Base64 images: the format is data:image/png;base64,<data>; the MIME type must be lowercase and match the real format.