Skip to main content
Model ID
gpt-image-2-edit
Calling method: sync

gpt-image-2-edit API Usage Guide

Overview

gpt-image-2-edit uses OpenAI’s GPT Image 2 model to edit or transform an existing image based on a text prompt. It supports two modes:
  • Image Edit: Modify an image according to a prompt (e.g. change background, style transfer)
  • Inpainting: Edit a specific region of an image using a mask (white pixels are edited, black pixels are preserved)

Authentication

Authorization: Bearer YOUR_API_KEY

Submit Image Edit Request

Endpoint

POST /api/v1/ie/requestqueue/apikey/requests

Image Edit (no mask)

curl -X POST "https://console.gmicloud.ai/api/v1/ie/requestqueue/apikey/requests" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2-edit",
    "payload": {
      "prompt": "Replace the background with a snowy mountain scene",
      "image": "<base64-encoded-image-or-url>",
      "size": "1024x1024",
      "quality": "medium"
    }
  }'

Inpainting (with mask)

curl -X POST "https://console.gmicloud.ai/api/v1/ie/requestqueue/apikey/requests" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2-edit",
    "payload": {
      "prompt": "Paint a rainbow in the sky",
      "image": "<base64-encoded-image-or-url>",
      "mask": "<base64-encoded-mask-same-size-as-image>",
      "size": "1024x1024",
      "quality": "medium"
    }
  }'

Request Parameters

ParameterTypeRequiredDescriptionDefaultConstraints
modelstringYesModel identifier-Must be "gpt-image-2-edit"
payload.promptstringYesText instruction describing the desired edit--
payload.imagestringYesInput image as base64-encoded string or publicly accessible URL-Must be a valid image
payload.maskstringNoMask image for inpainting. White pixels are edited, black pixels are preserved. Must match the dimensions of image.-Same size as input image
payload.sizestring (enum)NoDimensions of the output image"1024x1024""1024x1024", "1024x1536", "1536x1024"
payload.qualitystring (enum)NoImage quality level — affects detail and cost"medium""low", "medium", "high", "auto"
payload.nintegerNoNumber of images to generate1Min: 1, Max: 10

Response

{
  "request_id": "cd5b59d5-1b3f-4fd5-9899-15ecea1f28ba",
  "model": "gpt-image-2-edit",
  "status": "success",
  "outcome": {
    "media_urls": [{"id": "0", "url": "https://storage.googleapis.com/..."}],
    "thumbnail_image_url": "https://storage.googleapis.com/..."
  }
}

Pricing

Billing is based on the actual token consumption reported by OpenAI for each request. Users are charged according to the real usage of input text tokens, cached input text tokens, input image tokens, cached input image tokens, and output image tokens. The final cost may vary depending on prompt length, whether input images are provided, image size, quality, number of generated images, and other request parameters.

Token Pricing

Prices below are charged per 1M tokens:
Token TypePrice
Text input tokens$5.00 / 1M tokens
Cached text input tokens$1.25 / 1M tokens
Image input tokens$8.00 / 1M tokens
Cached image input tokens$2.00 / 1M tokens
Image output tokens$30.00 / 1M tokens

Billing Formula

Total cost =
  (text_input_tokens × $5.00 / 1,000,000)
+ (cached_text_input_tokens × $1.25 / 1,000,000)
+ (image_input_tokens × $8.00 / 1,000,000)
+ (cached_image_input_tokens × $2.00 / 1,000,000)
+ (image_output_tokens × $30.00 / 1,000,000)

Estimated Price Reference (per image)

The following table is provided as a reference only for common quality and resolution combinations. These are estimated per-image prices and may differ from the final billed amount, which is always based on actual token usage.
Quality1024x10241024x15361536x1024
Low$0.006$0.005$0.005
Medium$0.053$0.041$0.041
High$0.211$0.165$0.165

Check Request Status

GET /api/v1/ie/requestqueue/apikey/requests/{request_id}

Native OpenAI Format (Raw API)

Use the native OpenAI-compatible endpoint for direct integration with the OpenAI SDK or clients.

Base URL

https://console.gmicloud.ai/api/v1/ie/requestqueue/apikey/requests/v1

Edit Image (multipart)

curl -X POST "https://console.gmicloud.ai/api/v1/ie/requestqueue/apikey/requests/v1/images/edits" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "model=gpt-image-2" \
  -F "prompt=Replace the background with mountains" \
  -F "image=@photo.jpg" \
  -F "size=1024x1024" \
  -F "quality=medium"

Edit Image (JSON + base64)

curl -X POST "https://console.gmicloud.ai/api/v1/ie/requestqueue/apikey/requests/v1/images/edits" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "Replace the background with mountains",
    "image": "data:image/jpeg;base64,...",
    "size": "1024x1024",
    "quality": "medium"
  }'

Native Parameters

ParameterTypeRequiredDescriptionDefaultNotes
modelstringYesMust be "gpt-image-2"-No other value accepted
promptstringYesText instruction for the edit--
imagefile / stringYesInput image — binary file (multipart) or base64 data URI (JSON)-Up to 16 images via image[]
maskfile / stringNoInpainting mask — white pixels are edited, black pixels preserved-Same dimensions as input image
sizestringNoWxH format"1024x1024"Both dimensions must be multiples of 16; max edge 3840px
qualitystringNolow / medium / high / auto"medium"-
nintegerNoNumber of images (1–10)1Each image billed separately
output_formatstringNopng / jpeg"png"-
output_compressionintegerNoCompression level 0–100nullOnly valid for jpeg

Native Response Format

{
  "created": 1780943967,
  "size": "1024x1024",
  "quality": "medium",
  "output_format": "png",
  "data": [
    { "b64_json": "<base64-encoded-image>" }
  ],
  "usage": {
    "input_tokens": 592,
    "input_tokens_details": { "text_tokens": 16, "image_tokens": 576 },
    "output_tokens": 256,
    "output_tokens_details": { "image_tokens": 256, "text_tokens": 0 },
    "total_tokens": 848
  }
}

OpenAI SDK Usage

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://console.gmicloud.ai/api/v1/ie/requestqueue/apikey/requests/v1"
)

with open("photo.jpg", "rb") as f:
    response = client.images.edit(
        model="gpt-image-2",
        image=f,
        prompt="Replace the background with mountains",
        size="1024x1024",
        quality="medium"
    )
print(response.data[0].b64_json)