java/resources/images/methods/edit/index.md +0 −321 deleted
File Deleted View Diff
1## Create image edit
2
3`ImagesResponse images().edit(ImageEditParamsparams, RequestOptionsrequestOptions = RequestOptions.none())`
4
5**post** `/images/edits`
6
7Creates an edited or extended image given one or more source images and a prompt. This endpoint supports GPT Image models (`gpt-image-1.5`, `gpt-image-1`, `gpt-image-1-mini`, and `chatgpt-image-latest`) and `dall-e-2`.
8
9### Parameters
10
11- `ImageEditParams params`
12
13 - `Image image`
14
15 The image(s) to edit. Must be a supported image file or an array of images.
16
17 For the GPT image models (`gpt-image-1`, `gpt-image-1-mini`,
18 `gpt-image-1.5`, `gpt-image-2`, `gpt-image-2-2026-04-21`, and
19 `chatgpt-image-latest`), each image should be a `png`, `webp`, or
20 `jpg` file less than 50MB. You can provide up to 16 images.
21
22 For `dall-e-2`, you can only provide one image, and it should be a
23 square `png` file less than 4MB.
24
25 - `String`
26
27 - `List<String>`
28
29 - `String prompt`
30
31 A text description of the desired image(s). The maximum length is 1000 characters for `dall-e-2`, and 32000 characters for the GPT image models.
32
33 - `Optional<Background> background`
34
35 Allows to set transparency for the background of the generated image(s).
36 This parameter is only supported for GPT image models that support
37 transparent backgrounds. Must be one of `transparent`, `opaque`, or
38 `auto` (default value). When `auto` is used, the model will
39 automatically determine the best background for the image.
40
41 `gpt-image-2` and `gpt-image-2-2026-04-21` do not support
42 transparent backgrounds. Requests with `background` set to
43 `transparent` will return an error for these models; use `opaque` or
44 `auto` instead.
45
46 If `transparent`, the output format needs to support transparency,
47 so it should be set to either `png` (default value) or `webp`.
48
49 - `TRANSPARENT("transparent")`
50
51 - `OPAQUE("opaque")`
52
53 - `AUTO("auto")`
54
55 - `Optional<InputFidelity> inputFidelity`
56
57 Control how much effort the model will exert to match the style and features, especially facial features, of input images. This parameter is only supported for `gpt-image-1` and `gpt-image-1.5` and later models, unsupported for `gpt-image-1-mini`. Supports `high` and `low`. Defaults to `low`.
58
59 - `HIGH("high")`
60
61 - `LOW("low")`
62
63 - `Optional<String> mask`
64
65 An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where `image` should be edited. If there are multiple images provided, the mask will be applied on the first image. Must be a valid PNG file, less than 4MB, and have the same dimensions as `image`.
66
67 - `Optional<ImageModel> model`
68
69 The model to use for image generation. One of `dall-e-2` or a GPT image model (`gpt-image-1`, `gpt-image-1-mini`, `gpt-image-1.5`, `gpt-image-2`, `gpt-image-2-2026-04-21`, or `chatgpt-image-latest`). Defaults to `gpt-image-1.5`.
70
71 - `GPT_IMAGE_1("gpt-image-1")`
72
73 - `GPT_IMAGE_1_MINI("gpt-image-1-mini")`
74
75 - `GPT_IMAGE_2("gpt-image-2")`
76
77 - `GPT_IMAGE_2_2026_04_21("gpt-image-2-2026-04-21")`
78
79 - `GPT_IMAGE_1_5("gpt-image-1.5")`
80
81 - `CHATGPT_IMAGE_LATEST("chatgpt-image-latest")`
82
83 - `DALL_E_2("dall-e-2")`
84
85 - `DALL_E_3("dall-e-3")`
86
87 - `Optional<Long> n`
88
89 The number of images to generate. Must be between 1 and 10.
90
91 - `Optional<Long> outputCompression`
92
93 The compression level (0-100%) for the generated images. This parameter
94 is only supported for the GPT image models with the `webp` or `jpeg` output
95 formats, and defaults to 100.
96
97 - `Optional<OutputFormat> outputFormat`
98
99 The format in which the generated images are returned. This parameter is
100 only supported for the GPT image models. Must be one of `png`, `jpeg`, or `webp`.
101 The default value is `png`.
102
103 - `PNG("png")`
104
105 - `JPEG("jpeg")`
106
107 - `WEBP("webp")`
108
109 - `Optional<Long> partialImages`
110
111 The number of partial images to generate. This parameter is used for
112 streaming responses that return partial images. Value must be between 0 and 3.
113 When set to 0, the response will be a single image sent in one streaming event.
114
115 Note that the final image may be sent before the full number of partial images
116 are generated if the full image is generated more quickly.
117
118 - `Optional<Quality> quality`
119
120 The quality of the image that will be generated for GPT image models. Defaults to `auto`.
121
122 - `STANDARD("standard")`
123
124 - `LOW("low")`
125
126 - `MEDIUM("medium")`
127
128 - `HIGH("high")`
129
130 - `AUTO("auto")`
131
132 - `Optional<ResponseFormat> responseFormat`
133
134 The format in which the generated images are returned. Must be one of `url` or `b64_json`. URLs are only valid for 60 minutes after the image has been generated. This parameter is only supported for `dall-e-2` (default is `url` for `dall-e-2`), as GPT image models always return base64-encoded images.
135
136 - `URL("url")`
137
138 - `B64_JSON("b64_json")`
139
140 - `Optional<Size> size`
141
142 The size of the generated images. For `gpt-image-2` and `gpt-image-2-2026-04-21`, 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. For `dall-e-2`, use one of `256x256`, `512x512`, or `1024x1024`. For `dall-e-3`, use one of `1024x1024`, `1792x1024`, or `1024x1792`.
143
144 - `_256X256("256x256")`
145
146 - `_512X512("512x512")`
147
148 - `_1024X1024("1024x1024")`
149
150 - `_1536X1024("1536x1024")`
151
152 - `_1024X1536("1024x1536")`
153
154 - `AUTO("auto")`
155
156 - `Optional<String> user`
157
158 A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
159
160### Returns
161
162- `class ImagesResponse:`
163
164 The response from the image generation endpoint.
165
166 - `long created`
167
168 The Unix timestamp (in seconds) of when the image was created.
169
170 - `Optional<Background> background`
171
172 The background parameter used for the image generation. Either `transparent` or `opaque`.
173
174 - `TRANSPARENT("transparent")`
175
176 - `OPAQUE("opaque")`
177
178 - `Optional<List<Image>> data`
179
180 The list of generated images.
181
182 - `Optional<String> b64Json`
183
184 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`.
185
186 - `Optional<String> revisedPrompt`
187
188 For `dall-e-3` only, the revised prompt that was used to generate the image.
189
190 - `Optional<String> url`
191
192 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.
193
194 - `Optional<OutputFormat> outputFormat`
195
196 The output format of the image generation. Either `png`, `webp`, or `jpeg`.
197
198 - `PNG("png")`
199
200 - `WEBP("webp")`
201
202 - `JPEG("jpeg")`
203
204 - `Optional<Quality> quality`
205
206 The quality of the image generated. Either `low`, `medium`, or `high`.
207
208 - `LOW("low")`
209
210 - `MEDIUM("medium")`
211
212 - `HIGH("high")`
213
214 - `Optional<Size> size`
215
216 The size of the image generated. Either `1024x1024`, `1024x1536`, or `1536x1024`.
217
218 - `_1024X1024("1024x1024")`
219
220 - `_1024X1536("1024x1536")`
221
222 - `_1536X1024("1536x1024")`
223
224 - `Optional<Usage> usage`
225
226 For `gpt-image-1` only, the token usage information for the image generation.
227
228 - `long inputTokens`
229
230 The number of tokens (images and text) in the input prompt.
231
232 - `InputTokensDetails inputTokensDetails`
233
234 The input tokens detailed information for the image generation.
235
236 - `long imageTokens`
237
238 The number of image tokens in the input prompt.
239
240 - `long textTokens`
241
242 The number of text tokens in the input prompt.
243
244 - `long outputTokens`
245
246 The number of output tokens generated by the model.
247
248 - `long totalTokens`
249
250 The total number of tokens (images and text) used for the image generation.
251
252 - `Optional<OutputTokensDetails> outputTokensDetails`
253
254 The output token details for the image generation.
255
256 - `long imageTokens`
257
258 The number of image output tokens generated by the model.
259
260 - `long textTokens`
261
262 The number of text output tokens generated by the model.
263
264### Example
265
266```java
267package com.openai.example;
268
269import com.openai.client.OpenAIClient;
270import com.openai.client.okhttp.OpenAIOkHttpClient;
271import com.openai.models.images.ImageEditParams;
272import com.openai.models.images.ImagesResponse;
273import java.io.ByteArrayInputStream;
274import java.io.InputStream;
275
276public final class Main {
277 private Main() {}
278
279 public static void main(String[] args) {
280 OpenAIClient client = OpenAIOkHttpClient.fromEnv();
281
282 ImageEditParams params = ImageEditParams.builder()
283 .image(new ByteArrayInputStream("Example data".getBytes()))
284 .prompt("A cute baby sea otter wearing a beret")
285 .build();
286 ImagesResponse imagesResponse = client.images().edit(params);
287 }
288}
289```
290
291#### Response
292
293```json
294{
295 "created": 0,
296 "background": "transparent",
297 "data": [
298 {
299 "b64_json": "b64_json",
300 "revised_prompt": "revised_prompt",
301 "url": "https://example.com"
302 }
303 ],
304 "output_format": "png",
305 "quality": "low",
306 "size": "1024x1024",
307 "usage": {
308 "input_tokens": 0,
309 "input_tokens_details": {
310 "image_tokens": 0,
311 "text_tokens": 0
312 },
313 "output_tokens": 0,
314 "total_tokens": 0,
315 "output_tokens_details": {
316 "image_tokens": 0,
317 "text_tokens": 0
318 }
319 }
320}
321```