Skip to main content
GPT Image 2 is OpenAI’s next-generation image generation model, available through Anyfast API. Built on an autoregressive + reasoning hybrid architecture, it delivers native 2K resolution, near-perfect text rendering (~99% character-level accuracy across 12+ languages), and superior multi-object scene composition.

Key capabilities

  • Text-to-Image — Generate images from natural language descriptions
  • Image editing — Edit an existing image with a text prompt via /v1/images/edits
  • Flexible resolution — Any custom size up to 4K (3840px), edges must be multiples of 16
  • Near-perfect text rendering — ~99% character-level accuracy across 12+ languages
  • Multi-object composition — Complex scenes without occlusion or misplacement issues
  • Multi-style — Photorealism, illustration, anime, vector, 3D, data visualization
Both /v1/images/generations and /v1/images/edits support n=1–10 (default 1). Requires selecting the Direct group in the console.

Output specifications

PropertyValue
SizesFlexible resolution (e.g. 1024x1024, 2048x2048, 3840x2160)
Size constraintsEdges: multiples of 16, aspect ratio ≤ 3:1, total pixels 655,360–8,294,400
Qualitylow, medium, high
Output formatspng, jpeg
Input formats (edits)png, jpeg

Quick example

curl https://www.anyfast.ai/v1/images/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "A futuristic city skyline at sunset with flying cars",
    "size": "2048x2048",
    "quality": "high"
  }'

Parameters

ParameterTypeRequiredDescription
modelstringYesMust be gpt-image-2
promptstringYesText description of the desired image
nintegerNoNumber of images to generate. Supports 1–10. Default: 1. Requires selecting the Direct group.
sizestringNo{width}x{height} format. Edges must be multiples of 16, aspect ratio ≤ 3:1, total pixels 655,360–8,294,400, max edge 3,840px. Default: 1024x1024
qualitystringNolow, medium, high. Default: medium
output_formatstringNopng, jpeg, webp. Default: png
moderationstringNoauto or low. Default: auto
output_compressionintegerNoCompression level for jpeg (0–100).

Image editing

Edit an existing image with a text prompt via POST /v1/images/edits. Use multipart/form-data and pass images as file uploads. Supports up to 16 input images per request (image[]).

Input image formats

Supported formats: PNG, JPEG. Images must be provided as multipart/form-data file uploads. Two model IDs are available:
  • gpt-image-2 — official model
  • gpt-image-2-c — cost-effective variant (supports response_format)
Note: When using gpt-image-2-c, a higher quality setting may affect the stability of multi-image output (n > 1). For more consistent results when generating multiple images, use a lower quality setting.
curl https://www.anyfast.ai/v1/images/edits \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "image=@/path/to/source.jpeg" \
  -F model="gpt-image-2" \
  -F prompt="Change the background to a sunset over the ocean" \
  -F n=1 \
  -F size="1024x1024"

Edit parameters

ParameterTypeRequiredDescription
imagefileYesSingle source image (PNG or JPEG, multipart upload)
image[]file arrayYes*Multiple source images — up to 16 images (PNG or JPEG). Use instead of image for multi-image input
maskfileNoMask image with an alpha channel. Same format and size as source (< 50MB). Applied to the first image when multiple images are provided. Requires selecting the Direct group.
modelstringYesgpt-image-2 or gpt-image-2-c
promptstringYesEdit instruction text
nintegerNoNumber of images to return. Supports 1–10. Default: 1. Requires selecting the Direct group.
sizestringNo{width}x{height}. Default: 1024x1024
output_formatstringNopng, jpeg. Default: png
output_compressionintegerNoCompression level for jpeg (0–100)
response_formatstringNourl. Only supported by gpt-image-2-c. Default: url
Use either image (single file) or image[] (array) — not both.

Mask editing

Provide a mask image with an alpha channel to control which areas of the source image to edit. Pixels with white (opaque) alpha are preserved; pixels with black (transparent) alpha are edited. Requirements:
  • The mask must contain an Alpha channel
  • Must be the same image format and same dimensions as the source image
  • File size limit: < 50MB
Both mask editing and the n parameter require selecting the Direct group in the console.
cURL
curl https://www.anyfast.ai/v1/images/edits \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F image=@/path/to/source.jpeg \
  -F mask=@/path/to/mask.png \
  -F model="gpt-image-2" \
  -F prompt="Replace the background with a futuristic cityscape" \
  -F n=1 \
  -F size="2048x2048"
If your mask is a black-and-white image without an alpha channel, convert it first:
Python
from PIL import Image
import numpy as np

img = Image.open("bw_mask.png").convert("L")
alpha = np.array(img)
rgba = np.zeros((*alpha.shape, 4), dtype=np.uint8)
rgba[alpha > 0] = [255, 255, 255, 255]
Image.fromarray(rgba).save("mask.png")

Generate API Reference

Interactive playground for POST /v1/images/generations.

Edit API Reference

Interactive playground for POST /v1/images/edits.