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-image | Image-to-image / editing | Output formats | Highlights |
|---|---|---|---|---|
gemini-2.5-flash-imagegemini-2.5-flash-image-previewgemini-3.1-flash-image-previewgemini-3-pro-image-preview | Supported | Supported (pass images in contents.parts) | inlineData | Native Gemini multimodal generation that can return text and images together |
gpt-image-2 | Supported | Supported (incl. masked inpainting) | png / jpeg / webp | Strong instruction following, accurate text rendering, flexible sizes, high-fidelity image input |
doubao-seedream-5-0-pro-260628 | Supported | Supported (single / multiple images) | png / jpeg | Interactive editing (free-form marks, coordinate targeting), strong performance across varied scenes |
qwen-image-3.0-pro | Supported | Supported (1–3 reference images) | png | Multi-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.
| Item | Value |
|---|---|
| Model IDs | gemini-2.5-flash-imagegemini-2.5-flash-image-previewgemini-3.1-flash-image-previewgemini-3-pro-image-preview |
| Endpoint | POST /v1beta/models/{model}:generateContent |
| Header | Authorization: Bearer sk-*** (do not send x-goog-api-key) |
| Return mode | candidates[].content.parts[].inlineData |
Request parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
contents | array<object> | Required | Native Gemini content array. User input normally uses role: "user". |
contents[].parts[].text | string | Required | Generation or editing instruction describing the final desired image. |
contents[].parts[].inlineData | object | Optional | Image-to-image input containing the image mimeType and Base64 data. It can share the same parts array with text. |
generationConfig.responseModalities | array<string> | Optional | Response modalities. Use ["TEXT", "IMAGE"] for image generation, or keep only "IMAGE" when no text is needed. |
generationConfig.imageConfig.aspectRatio | string | Optional | Output aspect ratio such as 1:1, 16:9 or 9:16. Available values depend on the model. |
generationConfig.imageConfig.imageSize | string | Optional | Output 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.
| Item | Value |
|---|---|
| model_id | gpt-image-2 |
| Text-to-image endpoint | POST /v1/images/generations |
| Image-to-image endpoint | POST /v1/images/edits |
| Return mode | Base64 (data[].b64_json) |
gpt-image-2 text-to-image
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Required | Fixed at gpt-image-2. |
prompt | string | Required | Text description of the image; up to 32,000 characters for the GPT Image series. |
n | integer | Optional | Number of images to generate, 1 ~ 10, default 1. |
size | string | Optional | Output 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. |
quality | string | Optional | auto (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_format | string | Optional | png (default) / jpeg / webp. Transparent output requires png or webp; jpeg is always opaque. For latency-sensitive opaque images, prefer jpeg. |
output_compression | integer | Optional | Compression level 0 ~ 100, default 100. Only effective for jpeg and webp. |
background | string | Optional | transparent / opaque / auto (default). To preserve an alpha channel, use background: "transparent" together with output_format: "png" or "webp". |
moderation | string | Optional | Content moderation strength: auto (default, standard filtering) or low (loose filtering). |
user | string | Optional | End-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
Generates an edited image from one or more source images plus a prompt. The request body is multipart/form-data, not JSON.
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Required | Fixed at gpt-image-2. |
image | file / file[] | Required | The 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. |
prompt | string | Required | The edit instruction. Describe "what the final whole image should look like", not just the area to be erased. |
mask | file | Optional | Mask 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. |
n | integer | Optional | Number of images to generate, 1 ~ 10, default 1. |
size | string | Optional | Same as text-to-image; default auto (follows the input image). |
quality | string | Optional | Same as text-to-image. |
output_format | string | Optional | Same as text-to-image. |
output_compression | integer | Optional | Same as text-to-image; only effective for jpeg / webp. |
background | string | Optional | Same as text-to-image. Transparent edits are supported when background is transparent and output_format is png or webp. |
user | string | Optional | End-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"anderror.code = "moderation_blocked", possibly witherror.moderation_details(containingmoderation_stage:input/output/unknown, and coarse-grainedcategorieslabels). 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.
| Item | Value |
|---|---|
| model_id | doubao-seedream-5-0-pro-260628 |
| Endpoint | POST /api/v3/images/generations |
| Return mode | url (default, valid for 24 hours) or b64_json |
Capability matrix
| Capability | Seedream 5.0 pro |
|---|---|
| Text-to-image | Supported |
| Single / multi image-to-image | Supported |
| Interactive editing | Supported (unique to this series) |
| Text to image set | Not supported yet |
| Single / multi image to image set | Not supported yet |
| Streaming | Not supported yet |
| Web search | Not supported yet |
| Resolution presets | 1K / 2K (default 2K) |
| Output formats | png, jpeg |
| Prompt optimization modes | Standard mode standard, fast mode fast |
Request parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Required | doubao-seedream-5-0-pro-260628 |
prompt | string | Required | Generation or edit instruction. For interactive editing, <point> / <bbox> coordinate tags can be embedded. |
image | string / array | Optional | Reference 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. |
size | string | Optional | Two 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_format | string | Optional | url (returns a download link) or b64_json (returns Base64). |
output_format | string | Optional | png or jpeg. |
watermark | boolean | Optional | When true, adds the vendor-supplied "AI-generated" watermark at the bottom-right corner of the image; false adds none. |
optimize_prompt_options | object | Optional | Prompt optimization mode, e.g. {"mode": "fast"}. fast generates images faster and suits latency-sensitive workloads. |
Width × height pixels for each resolution preset
| Aspect ratio | 1K | 2K |
|---|---|---|
| 1:1 | 1024 × 1024 | 2048 × 2048 |
| 4:3 | 1152 × 864 | 2368 × 1776 |
| 3:4 | 864 × 1152 | 1776 × 2368 |
| 16:9 | 1424 × 800 | 2816 × 1584 |
| 9:16 | 800 × 1424 | 1584 × 2816 |
| 3:2 | 1248 × 832 | 2496 × 1664 |
| 2:3 | 832 × 1248 | 1664 × 2496 |
| 21:9 | 1568 × 672 | 3136 × 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 editing① Arbitrary 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.
| Item | Value |
|---|---|
| model_id | qwen-image-3.0-pro |
| Invocation mode | Synchronous response (not an async task) |
| Output formats | PNG |
| Resolution range | Total pixels 512×512 ~ 2048×2048; when size is not specified, the model recommends one automatically based on the prompt |
Request parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Required | qwen-image-3.0-pro |
input.messages | array<object> | Required | Single turn only: the array contains exactly one object with role and content. |
input.messages[].role | string | Required | Fixed at user. |
input.messages[].content | array<object> | Required | Text-to-image: exactly one {"text": "..."}. Image-to-image: 1 ~ 3 {"image": "..."} plus 1 {"text": "..."}. |
…content[].image | string | Optional | Reference image, a public URL (HTTP / HTTPS) or Base64 (data:{MIME};base64,{data}). With multiple images, the array order defines the image order. |
…content[].text | string | Required | Positive prompt describing the desired image. Only one text is allowed; omitting it or passing multiple raises an error. |
parameters.prompt_extend | boolean | Optional | Smart prompt rewriting, default true (recommended). Noticeably improves results when the prompt is short. |
parameters.n | integer | Optional | Number of output images, 1 ~ 6, default 1. |
parameters.size | string | Optional | Output 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_prompt | string | Optional | Negative prompt, describing content you do not want to appear. |
parameters.seed | integer | Optional | Random seed, [0, 2147483647]. Fixing it makes generation results relatively stable. |
parameters.watermark | boolean | Optional | Whether 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."
}
| Field | Description |
|---|---|
output.choices[].finish_reason | stop when generation ends naturally. |
output.choices[].message.content[].image | URL of the generated image, in PNG format; the link is valid for 24 hours. |
usage.width / usage.height | The actual width and height (pixels) of the generated image. |
usage.image_count | Number of images generated in this call. |
request_id | Unique request identifier; provide it when troubleshooting issues. |
code / message | Returned 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;
messagescan 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"forgpt-image-2, the1Ktier forseedream, andoptimize_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.