Skip to main content

OpenAI Async Image API

A single unified endpoint for both text-to-image generation and image editing. The operation type is auto-detected based on whether you provide an image field in the request body.

Supported Model

ModelDescription
gpt-image-2Latest OpenAI image model

How It Works

1

Create a task

Call POST /openai/images with your prompt. The endpoint auto-detects the operation:
  • No image field → text-to-image generation
  • With image field → image editing
  • With image + mask → inpainting (transparent mask areas are repainted)
Returns { "taskId": "..." }.
2

Poll for results

Call GET /openai/tasks?taskId=<taskId> until status is completed or failed.
3

Use the result

The task result field contains the generated image (base64 encoded by default for gpt-image-2).

Quick Examples

curl -X POST "https://api.mountsea.ai/openai/images" \
  -H "Authorization: Bearer your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A photorealistic cat wearing a space helmet, floating in orbit",
    "model": "gpt-image-2",
    "size": "1024x1024",
    "quality": "high"
  }'

Parameters

FieldTypeRequiredDescription
promptstringPrompt describing the desired image (for editing: describe the modification)
modelstringDefaults to gpt-image-2
sizeenumauto, 1024x1024 (default), 1024x1536, 1536x1024
nnumberGeneration count (currently only 1 supported)
qualityenumauto, low, medium, high, standard
backgroundenumtransparent, opaque, auto
output_formatenumpng / jpeg / webp
output_compressionnumberJPEG/WebP compression 0-100
moderationenumauto, low
response_formatenumurl or b64_json (gpt-image-2 always returns b64_json)
input_fidelityenumhigh or low — only for edit; controls how closely the output follows the input
imagestring / string[]URL or base64 data URL. Presence triggers editing mode. Single or multiple images
maskstringMask image (URL or base64). Transparent areas will be repainted. Edit-only

Task Status

StatusMeaning
pendingTask created, awaiting processing
readyReady for assignment
assignedAssigned to a worker
processingActively generating
completedDone — result contains the image
failedFailed — see errorMessage / errorCode
cancelledCancelled by user or system
timeoutExceeded processing timeout
Poll every 2-5 seconds. Tasks typically complete in 10-60 seconds depending on quality and size.

Available Endpoints

EndpointMethodDescription
/openai/imagesPOSTCreate image task (generate or edit)
/openai/tasksGETGet task status / result by taskId

Explore the API Documentation

Looking for the synchronous OpenAI-compatible API? See OpenAI Compat to use the official openai SDK.