go/resources/images/methods/edit/index.md +0 −336 deleted
File Deleted View Diff
1## Create image edit
2
3`client.Images.Edit(ctx, body) (*ImagesResponse, error)`
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- `body ImageEditParams`
12
13 - `Image param.Field[ImageEditParamsImageUnion]`
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 - `Reader`
26
27 - `[]Reader`
28
29 - `Prompt param.Field[string]`
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 - `Background param.Field[ImageEditParamsBackground]`
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 - `const ImageEditParamsBackgroundTransparent ImageEditParamsBackground = "transparent"`
50
51 - `const ImageEditParamsBackgroundOpaque ImageEditParamsBackground = "opaque"`
52
53 - `const ImageEditParamsBackgroundAuto ImageEditParamsBackground = "auto"`
54
55 - `InputFidelity param.Field[ImageEditParamsInputFidelity]`
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 - `const ImageEditParamsInputFidelityHigh ImageEditParamsInputFidelity = "high"`
60
61 - `const ImageEditParamsInputFidelityLow ImageEditParamsInputFidelity = "low"`
62
63 - `Mask param.Field[Reader]`
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 - `Model param.Field[ImageModel]`
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 - `string`
72
73 - `type ImageModel string`
74
75 - `const ImageModelGPTImage1 ImageModel = "gpt-image-1"`
76
77 - `const ImageModelGPTImage1Mini ImageModel = "gpt-image-1-mini"`
78
79 - `const ImageModelGPTImage2 ImageModel = "gpt-image-2"`
80
81 - `const ImageModelGPTImage2_2026_04_21 ImageModel = "gpt-image-2-2026-04-21"`
82
83 - `const ImageModelGPTImage1_5 ImageModel = "gpt-image-1.5"`
84
85 - `const ImageModelChatgptImageLatest ImageModel = "chatgpt-image-latest"`
86
87 - `const ImageModelDallE2 ImageModel = "dall-e-2"`
88
89 - `const ImageModelDallE3 ImageModel = "dall-e-3"`
90
91 - `N param.Field[int64]`
92
93 The number of images to generate. Must be between 1 and 10.
94
95 - `OutputCompression param.Field[int64]`
96
97 The compression level (0-100%) for the generated images. This parameter
98 is only supported for the GPT image models with the `webp` or `jpeg` output
99 formats, and defaults to 100.
100
101 - `OutputFormat param.Field[ImageEditParamsOutputFormat]`
102
103 The format in which the generated images are returned. This parameter is
104 only supported for the GPT image models. Must be one of `png`, `jpeg`, or `webp`.
105 The default value is `png`.
106
107 - `const ImageEditParamsOutputFormatPNG ImageEditParamsOutputFormat = "png"`
108
109 - `const ImageEditParamsOutputFormatJPEG ImageEditParamsOutputFormat = "jpeg"`
110
111 - `const ImageEditParamsOutputFormatWebP ImageEditParamsOutputFormat = "webp"`
112
113 - `PartialImages param.Field[int64]`
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 param.Field[ImageEditParamsQuality]`
123
124 The quality of the image that will be generated for GPT image models. Defaults to `auto`.
125
126 - `const ImageEditParamsQualityStandard ImageEditParamsQuality = "standard"`
127
128 - `const ImageEditParamsQualityLow ImageEditParamsQuality = "low"`
129
130 - `const ImageEditParamsQualityMedium ImageEditParamsQuality = "medium"`
131
132 - `const ImageEditParamsQualityHigh ImageEditParamsQuality = "high"`
133
134 - `const ImageEditParamsQualityAuto ImageEditParamsQuality = "auto"`
135
136 - `ResponseFormat param.Field[ImageEditParamsResponseFormat]`
137
138 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.
139
140 - `const ImageEditParamsResponseFormatURL ImageEditParamsResponseFormat = "url"`
141
142 - `const ImageEditParamsResponseFormatB64JSON ImageEditParamsResponseFormat = "b64_json"`
143
144 - `Size param.Field[ImageEditParamsSize]`
145
146 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`.
147
148 - `string`
149
150 - `ImageEditParamsSize`
151
152 - `const ImageEditParamsSize256x256 ImageEditParamsSize = "256x256"`
153
154 - `const ImageEditParamsSize512x512 ImageEditParamsSize = "512x512"`
155
156 - `const ImageEditParamsSize1024x1024 ImageEditParamsSize = "1024x1024"`
157
158 - `const ImageEditParamsSize1536x1024 ImageEditParamsSize = "1536x1024"`
159
160 - `const ImageEditParamsSize1024x1536 ImageEditParamsSize = "1024x1536"`
161
162 - `const ImageEditParamsSizeAuto ImageEditParamsSize = "auto"`
163
164 - ``
165
166 - `User param.Field[string]`
167
168 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).
169
170### Returns
171
172- `type ImagesResponse struct{…}`
173
174 The response from the image generation endpoint.
175
176 - `Created int64`
177
178 The Unix timestamp (in seconds) of when the image was created.
179
180 - `Background ImagesResponseBackground`
181
182 The background parameter used for the image generation. Either `transparent` or `opaque`.
183
184 - `const ImagesResponseBackgroundTransparent ImagesResponseBackground = "transparent"`
185
186 - `const ImagesResponseBackgroundOpaque ImagesResponseBackground = "opaque"`
187
188 - `Data []Image`
189
190 The list of generated images.
191
192 - `B64JSON string`
193
194 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`.
195
196 - `RevisedPrompt string`
197
198 For `dall-e-3` only, the revised prompt that was used to generate the image.
199
200 - `URL string`
201
202 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.
203
204 - `OutputFormat ImagesResponseOutputFormat`
205
206 The output format of the image generation. Either `png`, `webp`, or `jpeg`.
207
208 - `const ImagesResponseOutputFormatPNG ImagesResponseOutputFormat = "png"`
209
210 - `const ImagesResponseOutputFormatWebP ImagesResponseOutputFormat = "webp"`
211
212 - `const ImagesResponseOutputFormatJPEG ImagesResponseOutputFormat = "jpeg"`
213
214 - `Quality ImagesResponseQuality`
215
216 The quality of the image generated. Either `low`, `medium`, or `high`.
217
218 - `const ImagesResponseQualityLow ImagesResponseQuality = "low"`
219
220 - `const ImagesResponseQualityMedium ImagesResponseQuality = "medium"`
221
222 - `const ImagesResponseQualityHigh ImagesResponseQuality = "high"`
223
224 - `Size ImagesResponseSize`
225
226 The size of the image generated. Either `1024x1024`, `1024x1536`, or `1536x1024`.
227
228 - `const ImagesResponseSize1024x1024 ImagesResponseSize = "1024x1024"`
229
230 - `const ImagesResponseSize1024x1536 ImagesResponseSize = "1024x1536"`
231
232 - `const ImagesResponseSize1536x1024 ImagesResponseSize = "1536x1024"`
233
234 - `Usage ImagesResponseUsage`
235
236 For `gpt-image-1` only, the token usage information for the image generation.
237
238 - `InputTokens int64`
239
240 The number of tokens (images and text) in the input prompt.
241
242 - `InputTokensDetails ImagesResponseUsageInputTokensDetails`
243
244 The input tokens detailed information for the image generation.
245
246 - `ImageTokens int64`
247
248 The number of image tokens in the input prompt.
249
250 - `TextTokens int64`
251
252 The number of text tokens in the input prompt.
253
254 - `OutputTokens int64`
255
256 The number of output tokens generated by the model.
257
258 - `TotalTokens int64`
259
260 The total number of tokens (images and text) used for the image generation.
261
262 - `OutputTokensDetails ImagesResponseUsageOutputTokensDetails`
263
264 The output token details for the image generation.
265
266 - `ImageTokens int64`
267
268 The number of image output tokens generated by the model.
269
270 - `TextTokens int64`
271
272 The number of text output tokens generated by the model.
273
274### Example
275
276```go
277package main
278
279import (
280 "bytes"
281 "context"
282 "fmt"
283 "io"
284
285 "github.com/openai/openai-go"
286 "github.com/openai/openai-go/option"
287)
288
289func main() {
290 client := openai.NewClient(
291 option.WithAPIKey("My API Key"),
292 )
293 imagesResponse, err := client.Images.Edit(context.TODO(), openai.ImageEditParams{
294 Image: openai.ImageEditParamsImageUnion{
295 OfFile: io.Reader(bytes.NewBuffer([]byte("Example data"))),
296 },
297 Prompt: "A cute baby sea otter wearing a beret",
298 })
299 if err != nil {
300 panic(err.Error())
301 }
302 fmt.Printf("%+v\n", imagesResponse)
303}
304```
305
306#### Response
307
308```json
309{
310 "created": 0,
311 "background": "transparent",
312 "data": [
313 {
314 "b64_json": "b64_json",
315 "revised_prompt": "revised_prompt",
316 "url": "https://example.com"
317 }
318 ],
319 "output_format": "png",
320 "quality": "low",
321 "size": "1024x1024",
322 "usage": {
323 "input_tokens": 0,
324 "input_tokens_details": {
325 "image_tokens": 0,
326 "text_tokens": 0
327 },
328 "output_tokens": 0,
329 "total_tokens": 0,
330 "output_tokens_details": {
331 "image_tokens": 0,
332 "text_tokens": 0
333 }
334 }
335}
336```