GPT Image Generation

The code examples in this guide follow the OpenAI Images official specification. The endpoints and parameters are 100% compatible with OpenAI's official specification. You can call them directly using official OpenAI SDKs (e.g., Python / Node.js openai libraries) or native parameters, or take advantage of built-in platform extensions (such as passing web image URLs directly or multi-image reference arrays) for rapid integration without changing existing business logic.

Official references: Images API (Generate), Images API (Edit).


1. Endpoints

  • Text-to-Image (Generations): POST https://www.tokenpad.ai/v1/images/generations
  • Image Edits & Inpainting (Edits): POST https://www.tokenpad.ai/v1/images/edits
  • Authentication: Authorization: Bearer sk-your_token
  • Request Format: application/json (recommended, supports direct image URLs) or multipart/form-data (official binary file upload)

Model IDFeatures & StrengthsRecommended Scenarios
gpt-image-2.5-flareFlagship Workhorse (Recommended). Fastest speed, lowest cost, exceptional detail and superior prompt adherenceDefault choice for production, high-frequency generation, and real-time interactive apps
gpt-image-2.5-sunburstUltimate High-Fidelity Model. Maximum compute capacity, exquisite micro-textures and complex scene renderingHigh-end commercial visuals, billboard printing, and hyper-realistic digital arts
gpt-image-2Previous-generation base model with solid backward compatibilityLegacy workflows and compatibility with existing business pipelines

3. Resolution & Size Guide (Size & Aspect Ratio)

The endpoints support official preset aspect ratios and custom dimensions. You can directly pass the dimensions below without calculating pixel multiples:

CompositionAspect Ratio1K Standard (Default)2K High-Definition4K Ultra-HD (Peak Quality)Typical Use Cases
Square1:11024x10242048x20482880x2880Avatars, e-commerce products, square art
Widescreen / Video16:91280x7202048x11523840x2160Desktop wallpapers, video thumbnails, presentations
Mobile / Poster9:16720x12801152x20482160x3840Mobile wallpapers, TikTok/Shorts covers, vertical posters
Standard Landscape4:31024x7682048x15363264x2448Tablets, traditional landscape displays
Standard Portrait3:4768x10241536x20482448x3264Social media cards, lookbooks, product details
Photo Landscape3:21536x10242048x13603504x2336DSLR photography, editorial layouts
Photo Portrait2:31024x15361360x20482336x3504Portrait photography, book covers
Cinematic Ultrawide21:91344x5762016x8643840x1648Cinema scope banners, ultrawide wallpapers
AdaptiveautoAutomatically inferred by the model based on the prompt-General purpose creation

[!TIP] Custom Resolution Rules: You can pass any arbitrary WIDTHxHEIGHT string (e.g. 1536x864), provided it complies with:

  1. Multiples of 16: Both width and height must be strictly divisible by 16;
  2. Aspect Ratio Limits: The aspect ratio must be between 1:3 and 3:1 (0.33 <= W/H <= 3.0);
  3. Total Pixel Bounds: Total pixels must be between 655,360 and 8,294,400 (max single dimension ≤ 3840). Note that dimensions exceeding 2560x1440 require higher compute time.

4. Core Request Parameters

ParameterTypeRequiredDefaultDescription & Value Guidance
modelstringYes-Model identifier. Recommended: gpt-image-2.5-flare, gpt-image-2.5-sunburst (or gpt-image-2)
promptstringYes-Textual description of desired visuals, artistic style, lighting, and composition (up to ~32,000 characters)
sizestringNoautoTarget resolution. Pass preset dimensions from the table above (e.g., 1024x1024, 3840x2160) or custom dimensions
qualitystringNoautoRendering Quality Tier:
• auto: Intelligent adaptive selection (default);
• low: Lightweight and ultra-fast, ideal for rapid prototyping;
• medium: Balanced daily interaction;
• high: Production recommended, rich natural textures;
• xhigh / max: Exclusive to GPT-Image-2.5, supreme photorealism and microscopic details for commercial printing.
backgroundstringNoautoBackground Transparency:
• auto: Inferred by the model (default);
• transparent: Generates transparent background (isolated subject), must be paired with output_format="png" or "webp";
• opaque: Enforces opaque background scene.
output_formatstringNopngEncoding Format: png (lossless, transparency supported), webp (high compression, transparency supported), jpeg (lossy, no transparency)
output_compressionintegerNo100Compression Quality: 0 to 100 (effective only for webp or jpeg). Lower values produce smaller files
moderationstringNoautoContent Moderation: auto (standard safety filter) or low (relaxed filter to prevent false rejections in creative/anatomical domains)
nintegerNo1Number of image variations to generate (1 to 10)
response_formatstringNourlReturn Payload Format: url (gateway hosted URL) or b64_json (Base64 encoded string). The gateway handles upstream adaptation automatically
imagefile / string / arrayNo-For /v1/images/edits only: Base/reference image(s). Supports single or multiple images (up to 16):
• Single image: Pass a single image URL string or one multipart file;
• Multiple images: Pass an array of image URLs (e.g. ["https://...", "https://..."]) or multiple multipart -F "image=@file1" -F "image=@file2";
• Compatibility: Also accepts images or image_urls arrays.
maskfile / stringNo-For /v1/images/edits only: Inpainting mask. Must be a PNG with an alpha channel where transparent areas (alpha=0) indicate edit regions

5. Text-to-Image Practical Scenarios (Generations)

A. Quick Start Basic Generation

curl -X POST https://www.tokenpad.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2.5-flare",
    "prompt": "A minimalist astronaut standing on the red surface of Mars, breathtaking cosmic galaxy background",
    "size": "1024x1024",
    "quality": "high",
    "n": 1
  }'

B. 4K Ultra-HD Wallpaper (16:9 + Peak max Quality)

curl -X POST https://www.tokenpad.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2.5-sunburst",
    "prompt": "Futuristic cyberpunk megacity on a rainy night, reflections of vibrant neon lights on wet asphalt, ultra-detailed 8k texture",
    "size": "3840x2160",
    "quality": "max",
    "output_format": "png",
    "n": 1
  }'

C. Isolated Subject with Transparent Background

curl -X POST https://www.tokenpad.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2.5-flare",
    "prompt": "A translucent frosted glass folder icon, minimalist clean UI glyph, transparent background, isolated without shadows",
    "size": "1024x1024",
    "background": "transparent",
    "output_format": "png"
  }'

6. Image Editing & Inpainting (Edits)

Supports both modern JSON image URL transmission and standard Form-Data multipart upload.

A. Single / Multiple Images JSON Editing (Up to 16 Images)

Pass a single URL string for one image, or an array of URLs for multi-image blending and style transfer:

curl -X POST https://www.tokenpad.ai/v1/images/edits \
  -H "Authorization: Bearer sk-your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2.5-flare",
    "image": [
      "https://example.com/assets/character.png",
      "https://example.com/assets/cyberpunk_style.png"
    ],
    "prompt": "Keep the character facial features identical, blend into the cyberpunk style and outfit of the second image",
    "size": "1024x1024",
    "quality": "high",
    "n": 1
  }'

B. Masked Inpainting

Specify an inpainting mask with mask. The transparent alpha pixels (Alpha=0) will be repainted:

curl -X POST https://www.tokenpad.ai/v1/images/edits \
  -H "Authorization: Bearer sk-your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2.5-flare",
    "image": "https://example.com/assets/my_avatar.png",
    "mask": "https://example.com/assets/mask_face.png",
    "prompt": "Add cool futuristic aviator reflective sunglasses to the masked face area with natural lighting",
    "size": "1024x1024",
    "quality": "high",
    "n": 1
  }'

C. Standard Form-Data Binary File Upload

Pass one -F "image=@file.png" or multiple files -F "image=@file1.png" -F "image=@file2.png":

curl -X POST https://www.tokenpad.ai/v1/images/edits \
  -H "Authorization: Bearer sk-your_token_here" \
  -F "model=gpt-image-2.5-flare" \
  -F "image=@/path/to/my_avatar.png" \
  -F "mask=@/path/to/mask_face.png" \
  -F "prompt=Add cool futuristic sunglasses to the masked face area" \
  -F "size=1024x1024" \
  -F "quality=high" \
  -F "n=1"

7. Response Examples (200 OK)

Standard URL Output (Default):

{
  "created": 1719441600,
  "data": [
    {
      "url": "https://example.com/output/img_astronaut_gptimage25.png"
    }
  ]
}

Base64 Output (When response_format: "b64_json" is requested):

{
  "created": 1719441600,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAABAAAAAQACAIAAAD..."
    }
  ]
}

5. Common Error Codes & Troubleshooting

HTTP codes, error body format, and troubleshooting are maintained in one dedicated page (not duplicated under each example).

👉 Gateway Error Codes & Troubleshooting

Quick reference:

CodeMeaning
400Invalid parameters / content moderation or copyright block
402Insufficient account balance (not 429)
429RPS/RPM limits or in-flight task cap (low balance)
403Token / IP / model permission (balance → 402; content filter → 400)
200 + status: failedAsync video/long-task business failure on poll

HTTP status matches call log status_code for traceability by log_id.

Maintenance: update the error-codes article only; this appendix links to it.

Raw Markdown (.md) · llms.txt