java/resources/images/methods/edit/index.md +0 −305 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 - `Optional<Long> n`
72
73 The number of images to generate. Must be between 1 and 10.
74
75 - `Optional<Long> outputCompression`
76
77 The compression level (0-100%) for the generated images. This parameter
78 is only supported for the GPT image models with the `webp` or `jpeg` output
79 formats, and defaults to 100.
80
81 - `Optional<OutputFormat> outputFormat`
82
83 The format in which the generated images are returned. This parameter is
84 only supported for the GPT image models. Must be one of `png`, `jpeg`, or `webp`.
85 The default value is `png`.
86
87 - `PNG("png")`
88
89 - `JPEG("jpeg")`
90
91 - `WEBP("webp")`
92
93 - `Optional<Long> partialImages`
94
95 The number of partial images to generate. This parameter is used for
96 streaming responses that return partial images. Value must be between 0 and 3.
97 When set to 0, the response will be a single image sent in one streaming event.
98
99 Note that the final image may be sent before the full number of partial images
100 are generated if the full image is generated more quickly.
101
102 - `Optional<Quality> quality`
103
104 The quality of the image that will be generated for GPT image models. Defaults to `auto`.
105
106 - `STANDARD("standard")`
107
108 - `LOW("low")`
109
110 - `MEDIUM("medium")`
111
112 - `HIGH("high")`
113
114 - `AUTO("auto")`
115
116 - `Optional<ResponseFormat> responseFormat`
117
118 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.
119
120 - `URL("url")`
121
122 - `B64_JSON("b64_json")`
123
124 - `Optional<Size> size`
125
126 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`.
127
128 - `_256X256("256x256")`
129
130 - `_512X512("512x512")`
131
132 - `_1024X1024("1024x1024")`
133
134 - `_1536X1024("1536x1024")`
135
136 - `_1024X1536("1024x1536")`
137
138 - `AUTO("auto")`
139
140 - `Optional<String> user`
141
142 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).
143
144### Returns
145
146- `class ImagesResponse:`
147
148 The response from the image generation endpoint.
149
150 - `long created`
151
152 The Unix timestamp (in seconds) of when the image was created.
153
154 - `Optional<Background> background`
155
156 The background parameter used for the image generation. Either `transparent` or `opaque`.
157
158 - `TRANSPARENT("transparent")`
159
160 - `OPAQUE("opaque")`
161
162 - `Optional<List<Image>> data`
163
164 The list of generated images.
165
166 - `Optional<String> b64Json`
167
168 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`.
169
170 - `Optional<String> revisedPrompt`
171
172 For `dall-e-3` only, the revised prompt that was used to generate the image.
173
174 - `Optional<String> url`
175
176 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.
177
178 - `Optional<OutputFormat> outputFormat`
179
180 The output format of the image generation. Either `png`, `webp`, or `jpeg`.
181
182 - `PNG("png")`
183
184 - `WEBP("webp")`
185
186 - `JPEG("jpeg")`
187
188 - `Optional<Quality> quality`
189
190 The quality of the image generated. Either `low`, `medium`, or `high`.
191
192 - `LOW("low")`
193
194 - `MEDIUM("medium")`
195
196 - `HIGH("high")`
197
198 - `Optional<Size> size`
199
200 The size of the image generated. Either `1024x1024`, `1024x1536`, or `1536x1024`.
201
202 - `_1024X1024("1024x1024")`
203
204 - `_1024X1536("1024x1536")`
205
206 - `_1536X1024("1536x1024")`
207
208 - `Optional<Usage> usage`
209
210 For `gpt-image-1` only, the token usage information for the image generation.
211
212 - `long inputTokens`
213
214 The number of tokens (images and text) in the input prompt.
215
216 - `InputTokensDetails inputTokensDetails`
217
218 The input tokens detailed information for the image generation.
219
220 - `long imageTokens`
221
222 The number of image tokens in the input prompt.
223
224 - `long textTokens`
225
226 The number of text tokens in the input prompt.
227
228 - `long outputTokens`
229
230 The number of output tokens generated by the model.
231
232 - `long totalTokens`
233
234 The total number of tokens (images and text) used for the image generation.
235
236 - `Optional<OutputTokensDetails> outputTokensDetails`
237
238 The output token details for the image generation.
239
240 - `long imageTokens`
241
242 The number of image output tokens generated by the model.
243
244 - `long textTokens`
245
246 The number of text output tokens generated by the model.
247
248### Example
249
250```java
251package com.openai.example;
252
253import com.openai.client.OpenAIClient;
254import com.openai.client.okhttp.OpenAIOkHttpClient;
255import com.openai.models.images.ImageEditParams;
256import com.openai.models.images.ImagesResponse;
257import java.io.ByteArrayInputStream;
258import java.io.InputStream;
259
260public final class Main {
261 private Main() {}
262
263 public static void main(String[] args) {
264 OpenAIClient client = OpenAIOkHttpClient.fromEnv();
265
266 ImageEditParams params = ImageEditParams.builder()
267 .image(new ByteArrayInputStream("Example data".getBytes()))
268 .prompt("A cute baby sea otter wearing a beret")
269 .build();
270 ImagesResponse imagesResponse = client.images().edit(params);
271 }
272}
273```
274
275#### Response
276
277```json
278{
279 "created": 0,
280 "background": "transparent",
281 "data": [
282 {
283 "b64_json": "b64_json",
284 "revised_prompt": "revised_prompt",
285 "url": "https://example.com"
286 }
287 ],
288 "output_format": "png",
289 "quality": "low",
290 "size": "1024x1024",
291 "usage": {
292 "input_tokens": 0,
293 "input_tokens_details": {
294 "image_tokens": 0,
295 "text_tokens": 0
296 },
297 "output_tokens": 0,
298 "total_tokens": 0,
299 "output_tokens_details": {
300 "image_tokens": 0,
301 "text_tokens": 0
302 }
303 }
304}
305```