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
Submit Image Edit Request
Endpoint
Image Edit (no mask)
Inpainting (with mask)
Request Parameters
| Parameter | Type | Required | Description | Default | Constraints |
|---|---|---|---|---|---|
model | string | Yes | Model identifier | - | Must be "gpt-image-2-edit" |
payload.prompt | string | Yes | Text instruction describing the desired edit | - | - |
payload.image | string | Yes | Input image as base64-encoded string or publicly accessible URL | - | Must be a valid image |
payload.mask | string | No | Mask image for inpainting. White pixels are edited, black pixels are preserved. Must match the dimensions of image. | - | Same size as input image |
payload.size | string (enum) | No | Dimensions of the output image | "1024x1024" | "1024x1024", "1024x1536", "1536x1024" |
payload.quality | string (enum) | No | Image quality level — affects detail and cost | "medium" | "low", "medium", "high", "auto" |
payload.n | integer | No | Number of images to generate | 1 | Min: 1, Max: 10 |
Response
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 Type | Price |
|---|---|
| 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
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.| Quality | 1024x1024 | 1024x1536 | 1536x1024 |
|---|---|---|---|
| Low | $0.006 | $0.005 | $0.005 |
| Medium | $0.053 | $0.041 | $0.041 |
| High | $0.211 | $0.165 | $0.165 |
Check Request Status
Native OpenAI Format (Raw API)
Use the native OpenAI-compatible endpoint for direct integration with the OpenAI SDK or clients.Base URL
Edit Image (multipart)
Edit Image (JSON + base64)
Native Parameters
| Parameter | Type | Required | Description | Default | Notes |
|---|---|---|---|---|---|
model | string | Yes | Must be "gpt-image-2" | - | No other value accepted |
prompt | string | Yes | Text instruction for the edit | - | - |
image | file / string | Yes | Input image — binary file (multipart) or base64 data URI (JSON) | - | Up to 16 images via image[] |
mask | file / string | No | Inpainting mask — white pixels are edited, black pixels preserved | - | Same dimensions as input image |
size | string | No | WxH format | "1024x1024" | Both dimensions must be multiples of 16; max edge 3840px |
quality | string | No | low / medium / high / auto | "medium" | - |
n | integer | No | Number of images (1–10) | 1 | Each image billed separately |
output_format | string | No | png / jpeg | "png" | - |
output_compression | integer | No | Compression level 0–100 | null | Only valid for jpeg |