resources/images/methods/edit/index.md +0 −369 deleted
File Deleted View Diff
1## Create image edit
2
3**post** `/images/edits`
4
5Creates an edited or extended image given one or more source images and a prompt. This endpoint supports GPT Image models and `dall-e-2`.
6
7### Body Parameters
8
9- `images: array of object { file_id, image_url }`
10
11 Input image references to edit.
12 For GPT image models, you can provide up to 16 images.
13
14 - `file_id: optional string`
15
16 The File API ID of an uploaded image to use as input.
17
18 - `image_url: optional string`
19
20 A fully qualified URL or base64-encoded data URL.
21
22- `prompt: string`
23
24 A text description of the desired image edit.
25
26- `background: optional "transparent" or "opaque" or "auto" or null`
27
28 Set the background of the generated image output. `gpt-image-2.5-sunburst` and `gpt-image-2.5-flare`, including their `2026-09-08` snapshots, support `opaque` and `transparent` backgrounds. Transparent backgrounds are available for supported GPT Image models. For `gpt-image-2` and `gpt-image-2-2026-04-21`, this support is in preview. When using `transparent`, set the output format to `png` or `webp`.
29
30 - `"transparent"`
31
32 - `"opaque"`
33
34 - `"auto"`
35
36- `input_fidelity: optional "high" or "low" or null`
37
38 Controls fidelity to the original input image(s).
39
40 - `"high"`
41
42 - `"low"`
43
44- `mask: optional object { file_id, image_url }`
45
46 Reference an input image by either URL or uploaded file ID.
47 Provide exactly one of `image_url` or `file_id`.
48
49 - `file_id: optional string`
50
51 The File API ID of an uploaded image to use as input.
52
53 - `image_url: optional string`
54
55 A fully qualified URL or base64-encoded data URL.
56
57- `model: optional string or "gpt-image-1.5" or "gpt-image-2" or "gpt-image-2-2026-04-21" or 7 more or null`
58
59 The GPT image model to use for image editing, including `gpt-image-2`, its dated snapshot `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, and `gpt-image-2.5-flare-2026-09-08`.
60
61 - `string`
62
63 - `"gpt-image-1.5" or "gpt-image-2" or "gpt-image-2-2026-04-21" or 7 more`
64
65 The GPT image model to use for image editing, including `gpt-image-2`, its dated snapshot `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, and `gpt-image-2.5-flare-2026-09-08`.
66
67 - `"gpt-image-1.5"`
68
69 - `"gpt-image-2"`
70
71 - `"gpt-image-2-2026-04-21"`
72
73 - `"gpt-image-2.5-sunburst"`
74
75 - `"gpt-image-2.5-sunburst-2026-09-08"`
76
77 - `"gpt-image-2.5-flare"`
78
79 - `"gpt-image-2.5-flare-2026-09-08"`
80
81 - `"gpt-image-1"`
82
83 - `"gpt-image-1-mini"`
84
85 - `"chatgpt-image-latest"`
86
87- `moderation: optional "low" or "auto" or null`
88
89 Moderation level for GPT image models.
90
91 - `"low"`
92
93 - `"auto"`
94
95- `n: optional number or null`
96
97 The number of edited images to generate.
98
99- `output_compression: optional number or null`
100
101 Compression level for `jpeg` or `webp` output.
102
103- `output_format: optional "png" or "jpeg" or "webp" or null`
104
105 Output image format. Supported for GPT image models.
106
107 - `"png"`
108
109 - `"jpeg"`
110
111 - `"webp"`
112
113- `partial_images: optional number or null`
114
115 The number of partial images to generate. This parameter is used for
116 streaming responses that return partial images. Value must be between 0 and 3.
117 When set to 0, the response will be a single image sent in one streaming event.
118
119 Note that the final image may be sent before the full number of partial images
120 are generated if the full image is generated more quickly.
121
122- `quality: optional "low" or "medium" or "high" or 3 more or null`
123
124 Output quality for GPT image models. The GPT image models support `low`, `medium`,
125 and `high`. `gpt-image-2.5-sunburst` and `gpt-image-2.5-flare`, including their
126 `2026-09-08` snapshots, also support `xhigh` and `max`. Defaults to `auto`.
127
128 - `"low"`
129
130 - `"medium"`
131
132 - `"high"`
133
134 - `"xhigh"`
135
136 - `"max"`
137
138 - `"auto"`
139
140- `size: optional string or "auto" or "1024x1024" or "1536x1024" or "1024x1536" or null`
141
142 The size of the generated images. For `gpt-image-2`, `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, and `gpt-image-2.5-flare-2026-09-08`, arbitrary resolutions are supported as `WIDTHxHEIGHT` strings, for example `1536x864`. Width and height must both be divisible by 16 and the requested aspect ratio must be between 1:3 and 3:1. Resolutions above `2560x1440` are experimental, and the maximum supported resolution is `3840x2160`. The requested size must also satisfy the model's current pixel and edge limits. The standard sizes `1024x1024`, `1536x1024`, and `1024x1536` are supported by the GPT image models; `auto` is supported for models that allow automatic sizing.
143
144 - `string`
145
146 - `"auto" or "1024x1024" or "1536x1024" or "1024x1536"`
147
148 The size of the generated images. For `gpt-image-2`, `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, and `gpt-image-2.5-flare-2026-09-08`, arbitrary resolutions are supported as `WIDTHxHEIGHT` strings, for example `1536x864`. Width and height must both be divisible by 16 and the requested aspect ratio must be between 1:3 and 3:1. Resolutions above `2560x1440` are experimental, and the maximum supported resolution is `3840x2160`. The requested size must also satisfy the model's current pixel and edge limits. The standard sizes `1024x1024`, `1536x1024`, and `1024x1536` are supported by the GPT image models; `auto` is supported for models that allow automatic sizing.
149
150 - `"auto"`
151
152 - `"1024x1024"`
153
154 - `"1536x1024"`
155
156 - `"1024x1536"`
157
158- `stream: optional boolean or null`
159
160 Stream partial image results as events.
161
162- `user: optional string`
163
164 A unique identifier representing your end-user, which can help OpenAI
165 monitor and detect abuse.
166
167### Returns
168
169- `ImagesResponse object { created, background, data, 4 more }`
170
171 The response from the image generation endpoint.
172
173 - `created: number`
174
175 The Unix timestamp (in seconds) of when the image was created.
176
177 - `background: optional "transparent" or "opaque"`
178
179 The background parameter used for the image generation. Either `transparent` or `opaque`.
180
181 - `"transparent"`
182
183 - `"opaque"`
184
185 - `data: optional array of Image`
186
187 The list of generated images.
188
189 - `b64_json: optional string`
190
191 The base64-encoded JSON of the generated image. Returned by default for the GPT image models, and only present if `response_format` is set to `b64_json` for `dall-e-2` and `dall-e-3`.
192
193 - `revised_prompt: optional string`
194
195 For `dall-e-3` only, the revised prompt that was used to generate the image.
196
197 - `url: optional string`
198
199 When using `dall-e-2` or `dall-e-3`, the URL of the generated image if `response_format` is set to `url` (default value). Unsupported for the GPT image models.
200
201 - `output_format: optional "png" or "webp" or "jpeg"`
202
203 The output format of the image generation. Either `png`, `webp`, or `jpeg`.
204
205 - `"png"`
206
207 - `"webp"`
208
209 - `"jpeg"`
210
211 - `quality: optional "low" or "medium" or "high" or 2 more`
212
213 The quality of the image generated. One of `low`, `medium`, `high`, `xhigh`, or `max`.
214
215 - `"low"`
216
217 - `"medium"`
218
219 - `"high"`
220
221 - `"xhigh"`
222
223 - `"max"`
224
225 - `size: optional string or "1024x1024" or "1024x1536" or "1536x1024"`
226
227 The image dimensions as a `WIDTHxHEIGHT` string, for example `1536x864`.
228
229 - `string`
230
231 - `"1024x1024" or "1024x1536" or "1536x1024"`
232
233 The image dimensions as a `WIDTHxHEIGHT` string, for example `1536x864`.
234
235 - `"1024x1024"`
236
237 - `"1024x1536"`
238
239 - `"1536x1024"`
240
241 - `usage: optional object { input_tokens, input_tokens_details, output_tokens, 2 more }`
242
243 For `gpt-image-1` only, the token usage information for the image generation.
244
245 - `input_tokens: number`
246
247 The number of tokens (images and text) in the input prompt.
248
249 - `input_tokens_details: object { image_tokens, text_tokens }`
250
251 The input tokens detailed information for the image generation.
252
253 - `image_tokens: number`
254
255 The number of image tokens in the input prompt.
256
257 - `text_tokens: number`
258
259 The number of text tokens in the input prompt.
260
261 - `output_tokens: number`
262
263 The number of output tokens generated by the model.
264
265 - `total_tokens: number`
266
267 The total number of tokens (images and text) used for the image generation.
268
269 - `output_tokens_details: optional object { image_tokens, text_tokens }`
270
271 The output token details for the image generation.
272
273 - `image_tokens: number`
274
275 The number of image output tokens generated by the model.
276
277 - `text_tokens: number`
278
279 The number of text output tokens generated by the model.
280
281### Example
282
283```http
284curl https://api.openai.com/v1/images/edits \
285 -H 'Content-Type: application/json' \
286 -H "Authorization: Bearer $OPENAI_API_KEY" \
287 -d '{
288 "images": [
289 {
290 "image_url": "https://example.com/source-image.png"
291 }
292 ],
293 "prompt": "Add a watercolor effect to this image",
294 "model": "gpt-image-1.5",
295 "quality": "high",
296 "size": "1024x1024"
297 }'
298```
299
300#### Response
301
302```json
303{
304 "created": 0,
305 "background": "transparent",
306 "data": [
307 {
308 "b64_json": "b64_json",
309 "revised_prompt": "revised_prompt",
310 "url": "https://example.com"
311 }
312 ],
313 "output_format": "png",
314 "quality": "low",
315 "size": "1024x1024",
316 "usage": {
317 "input_tokens": 0,
318 "input_tokens_details": {
319 "image_tokens": 0,
320 "text_tokens": 0
321 },
322 "output_tokens": 0,
323 "total_tokens": 0,
324 "output_tokens_details": {
325 "image_tokens": 0,
326 "text_tokens": 0
327 }
328 }
329}
330```
331
332### Edit image
333
334```http
335curl -s -D >(grep -i x-request-id >&2) \
336 -o >(jq -r '.data[0].b64_json' | base64 --decode > gift-basket.png) \
337 -X POST "https://api.openai.com/v1/images/edits" \
338 -H "Authorization: Bearer $OPENAI_API_KEY" \
339 -F "model=gpt-image-1.5" \
340 -F "image[]=@body-lotion.png" \
341 -F "image[]=@bath-bomb.png" \
342 -F "image[]=@incense-kit.png" \
343 -F "image[]=@soap.png" \
344 -F 'prompt=Create a lovely gift basket with these four items in it'
345```
346
347### Streaming
348
349```http
350curl -s -N -X POST "https://api.openai.com/v1/images/edits" \
351 -H "Authorization: Bearer $OPENAI_API_KEY" \
352 -F "model=gpt-image-1.5" \
353 -F "image[]=@body-lotion.png" \
354 -F "image[]=@bath-bomb.png" \
355 -F "image[]=@incense-kit.png" \
356 -F "image[]=@soap.png" \
357 -F 'prompt=Create a lovely gift basket with these four items in it' \
358 -F "stream=true"
359```
360
361#### Response
362
363```json
364event: image_edit.partial_image
365data: {"type":"image_edit.partial_image","b64_json":"...","partial_image_index":0}
366
367event: image_edit.completed
368data: {"type":"image_edit.completed","b64_json":"...","usage":{"total_tokens":100,"input_tokens":50,"output_tokens":50,"input_tokens_details":{"text_tokens":10,"image_tokens":40}}}
369```