go/resources/images/index.md +0 −1684 deleted
File Deleted View Diff
1# Images
2
3## Create image
4
5`client.Images.Generate(ctx, body) (*ImagesResponse, error)`
6
7**post** `/images/generations`
8
9Creates an image given a prompt. [Learn more](https://platform.openai.com/docs/guides/images).
10
11### Parameters
12
13- `body ImageGenerateParams`
14
15 - `Prompt param.Field[string]`
16
17 A text description of the desired image(s). The maximum length is 32000 characters for the GPT image models, 1000 characters for `dall-e-2` and 4000 characters for `dall-e-3`.
18
19 - `Background param.Field[ImageGenerateParamsBackground]`
20
21 Allows to set transparency for the background of the generated image(s).
22 This parameter is only supported for GPT image models that support
23 transparent backgrounds. Must be one of `transparent`, `opaque`, or
24 `auto` (default value). When `auto` is used, the model will
25 automatically determine the best background for the image.
26
27 `gpt-image-2` and `gpt-image-2-2026-04-21` do not support
28 transparent backgrounds. Requests with `background` set to
29 `transparent` will return an error for these models; use `opaque` or
30 `auto` instead.
31
32 If `transparent`, the output format needs to support transparency,
33 so it should be set to either `png` (default value) or `webp`.
34
35 - `const ImageGenerateParamsBackgroundTransparent ImageGenerateParamsBackground = "transparent"`
36
37 - `const ImageGenerateParamsBackgroundOpaque ImageGenerateParamsBackground = "opaque"`
38
39 - `const ImageGenerateParamsBackgroundAuto ImageGenerateParamsBackground = "auto"`
40
41 - `Model param.Field[ImageModel]`
42
43 The model to use for image generation. One of `dall-e-2`, `dall-e-3`, or a GPT image model (`gpt-image-1`, `gpt-image-1-mini`, `gpt-image-1.5`, `gpt-image-2`, or `gpt-image-2-2026-04-21`). Defaults to `dall-e-2` unless a parameter specific to the GPT image models is used.
44
45 - `string`
46
47 - `type ImageModel string`
48
49 - `const ImageModelGPTImage1 ImageModel = "gpt-image-1"`
50
51 - `const ImageModelGPTImage1Mini ImageModel = "gpt-image-1-mini"`
52
53 - `const ImageModelGPTImage2 ImageModel = "gpt-image-2"`
54
55 - `const ImageModelGPTImage2_2026_04_21 ImageModel = "gpt-image-2-2026-04-21"`
56
57 - `const ImageModelGPTImage1_5 ImageModel = "gpt-image-1.5"`
58
59 - `const ImageModelChatgptImageLatest ImageModel = "chatgpt-image-latest"`
60
61 - `const ImageModelDallE2 ImageModel = "dall-e-2"`
62
63 - `const ImageModelDallE3 ImageModel = "dall-e-3"`
64
65 - `Moderation param.Field[ImageGenerateParamsModeration]`
66
67 Control the content-moderation level for images generated by the GPT image models. Must be either `low` for less restrictive filtering or `auto` (default value).
68
69 - `const ImageGenerateParamsModerationLow ImageGenerateParamsModeration = "low"`
70
71 - `const ImageGenerateParamsModerationAuto ImageGenerateParamsModeration = "auto"`
72
73 - `N param.Field[int64]`
74
75 The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only `n=1` is supported.
76
77 - `OutputCompression param.Field[int64]`
78
79 The compression level (0-100%) for the generated images. This parameter is only supported for the GPT image models with the `webp` or `jpeg` output formats, and defaults to 100.
80
81 - `OutputFormat param.Field[ImageGenerateParamsOutputFormat]`
82
83 The format in which the generated images are returned. This parameter is only supported for the GPT image models. Must be one of `png`, `jpeg`, or `webp`.
84
85 - `const ImageGenerateParamsOutputFormatPNG ImageGenerateParamsOutputFormat = "png"`
86
87 - `const ImageGenerateParamsOutputFormatJPEG ImageGenerateParamsOutputFormat = "jpeg"`
88
89 - `const ImageGenerateParamsOutputFormatWebP ImageGenerateParamsOutputFormat = "webp"`
90
91 - `PartialImages param.Field[int64]`
92
93 The number of partial images to generate. This parameter is used for
94 streaming responses that return partial images. Value must be between 0 and 3.
95 When set to 0, the response will be a single image sent in one streaming event.
96
97 Note that the final image may be sent before the full number of partial images
98 are generated if the full image is generated more quickly.
99
100 - `Quality param.Field[ImageGenerateParamsQuality]`
101
102 The quality of the image that will be generated.
103
104 - `auto` (default value) will automatically select the best quality for the given model.
105 - `high`, `medium` and `low` are supported for the GPT image models.
106 - `hd` and `standard` are supported for `dall-e-3`.
107 - `standard` is the only option for `dall-e-2`.
108
109 - `const ImageGenerateParamsQualityStandard ImageGenerateParamsQuality = "standard"`
110
111 - `const ImageGenerateParamsQualityHD ImageGenerateParamsQuality = "hd"`
112
113 - `const ImageGenerateParamsQualityLow ImageGenerateParamsQuality = "low"`
114
115 - `const ImageGenerateParamsQualityMedium ImageGenerateParamsQuality = "medium"`
116
117 - `const ImageGenerateParamsQualityHigh ImageGenerateParamsQuality = "high"`
118
119 - `const ImageGenerateParamsQualityAuto ImageGenerateParamsQuality = "auto"`
120
121 - `ResponseFormat param.Field[ImageGenerateParamsResponseFormat]`
122
123 The format in which generated images with `dall-e-2` and `dall-e-3` 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 isn't supported for the GPT image models, which always return base64-encoded images.
124
125 - `const ImageGenerateParamsResponseFormatURL ImageGenerateParamsResponseFormat = "url"`
126
127 - `const ImageGenerateParamsResponseFormatB64JSON ImageGenerateParamsResponseFormat = "b64_json"`
128
129 - `Size param.Field[ImageGenerateParamsSize]`
130
131 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`.
132
133 - `string`
134
135 - `ImageGenerateParamsSize`
136
137 - `const ImageGenerateParamsSizeAuto ImageGenerateParamsSize = "auto"`
138
139 - `const ImageGenerateParamsSize1024x1024 ImageGenerateParamsSize = "1024x1024"`
140
141 - `const ImageGenerateParamsSize1536x1024 ImageGenerateParamsSize = "1536x1024"`
142
143 - `const ImageGenerateParamsSize1024x1536 ImageGenerateParamsSize = "1024x1536"`
144
145 - `const ImageGenerateParamsSize256x256 ImageGenerateParamsSize = "256x256"`
146
147 - `const ImageGenerateParamsSize512x512 ImageGenerateParamsSize = "512x512"`
148
149 - `const ImageGenerateParamsSize1792x1024 ImageGenerateParamsSize = "1792x1024"`
150
151 - `const ImageGenerateParamsSize1024x1792 ImageGenerateParamsSize = "1024x1792"`
152
153 - ``
154
155 - `Style param.Field[ImageGenerateParamsStyle]`
156
157 The style of the generated images. This parameter is only supported for `dall-e-3`. Must be one of `vivid` or `natural`. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images.
158
159 - `const ImageGenerateParamsStyleVivid ImageGenerateParamsStyle = "vivid"`
160
161 - `const ImageGenerateParamsStyleNatural ImageGenerateParamsStyle = "natural"`
162
163 - `User param.Field[string]`
164
165 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).
166
167### Returns
168
169- `type ImagesResponse struct{…}`
170
171 The response from the image generation endpoint.
172
173 - `Created int64`
174
175 The Unix timestamp (in seconds) of when the image was created.
176
177 - `Background ImagesResponseBackground`
178
179 The background parameter used for the image generation. Either `transparent` or `opaque`.
180
181 - `const ImagesResponseBackgroundTransparent ImagesResponseBackground = "transparent"`
182
183 - `const ImagesResponseBackgroundOpaque ImagesResponseBackground = "opaque"`
184
185 - `Data []Image`
186
187 The list of generated images.
188
189 - `B64JSON 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 - `RevisedPrompt string`
194
195 For `dall-e-3` only, the revised prompt that was used to generate the image.
196
197 - `URL 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 - `OutputFormat ImagesResponseOutputFormat`
202
203 The output format of the image generation. Either `png`, `webp`, or `jpeg`.
204
205 - `const ImagesResponseOutputFormatPNG ImagesResponseOutputFormat = "png"`
206
207 - `const ImagesResponseOutputFormatWebP ImagesResponseOutputFormat = "webp"`
208
209 - `const ImagesResponseOutputFormatJPEG ImagesResponseOutputFormat = "jpeg"`
210
211 - `Quality ImagesResponseQuality`
212
213 The quality of the image generated. Either `low`, `medium`, or `high`.
214
215 - `const ImagesResponseQualityLow ImagesResponseQuality = "low"`
216
217 - `const ImagesResponseQualityMedium ImagesResponseQuality = "medium"`
218
219 - `const ImagesResponseQualityHigh ImagesResponseQuality = "high"`
220
221 - `Size ImagesResponseSize`
222
223 The size of the image generated. Either `1024x1024`, `1024x1536`, or `1536x1024`.
224
225 - `const ImagesResponseSize1024x1024 ImagesResponseSize = "1024x1024"`
226
227 - `const ImagesResponseSize1024x1536 ImagesResponseSize = "1024x1536"`
228
229 - `const ImagesResponseSize1536x1024 ImagesResponseSize = "1536x1024"`
230
231 - `Usage ImagesResponseUsage`
232
233 For `gpt-image-1` only, the token usage information for the image generation.
234
235 - `InputTokens int64`
236
237 The number of tokens (images and text) in the input prompt.
238
239 - `InputTokensDetails ImagesResponseUsageInputTokensDetails`
240
241 The input tokens detailed information for the image generation.
242
243 - `ImageTokens int64`
244
245 The number of image tokens in the input prompt.
246
247 - `TextTokens int64`
248
249 The number of text tokens in the input prompt.
250
251 - `OutputTokens int64`
252
253 The number of output tokens generated by the model.
254
255 - `TotalTokens int64`
256
257 The total number of tokens (images and text) used for the image generation.
258
259 - `OutputTokensDetails ImagesResponseUsageOutputTokensDetails`
260
261 The output token details for the image generation.
262
263 - `ImageTokens int64`
264
265 The number of image output tokens generated by the model.
266
267 - `TextTokens int64`
268
269 The number of text output tokens generated by the model.
270
271### Example
272
273```go
274package main
275
276import (
277 "context"
278 "fmt"
279
280 "github.com/openai/openai-go"
281 "github.com/openai/openai-go/option"
282)
283
284func main() {
285 client := openai.NewClient(
286 option.WithAPIKey("My API Key"),
287 )
288 imagesResponse, err := client.Images.Generate(context.TODO(), openai.ImageGenerateParams{
289 Prompt: "A cute baby sea otter",
290 })
291 if err != nil {
292 panic(err.Error())
293 }
294 fmt.Printf("%+v\n", imagesResponse)
295}
296```
297
298#### Response
299
300```json
301{
302 "created": 0,
303 "background": "transparent",
304 "data": [
305 {
306 "b64_json": "b64_json",
307 "revised_prompt": "revised_prompt",
308 "url": "https://example.com"
309 }
310 ],
311 "output_format": "png",
312 "quality": "low",
313 "size": "1024x1024",
314 "usage": {
315 "input_tokens": 0,
316 "input_tokens_details": {
317 "image_tokens": 0,
318 "text_tokens": 0
319 },
320 "output_tokens": 0,
321 "total_tokens": 0,
322 "output_tokens_details": {
323 "image_tokens": 0,
324 "text_tokens": 0
325 }
326 }
327}
328```
329
330## Create image edit
331
332`client.Images.Edit(ctx, body) (*ImagesResponse, error)`
333
334**post** `/images/edits`
335
336Creates 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`.
337
338### Parameters
339
340- `body ImageEditParams`
341
342 - `Image param.Field[ImageEditParamsImageUnion]`
343
344 The image(s) to edit. Must be a supported image file or an array of images.
345
346 For the GPT image models (`gpt-image-1`, `gpt-image-1-mini`,
347 `gpt-image-1.5`, `gpt-image-2`, `gpt-image-2-2026-04-21`, and
348 `chatgpt-image-latest`), each image should be a `png`, `webp`, or
349 `jpg` file less than 50MB. You can provide up to 16 images.
350
351 For `dall-e-2`, you can only provide one image, and it should be a
352 square `png` file less than 4MB.
353
354 - `Reader`
355
356 - `[]Reader`
357
358 - `Prompt param.Field[string]`
359
360 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.
361
362 - `Background param.Field[ImageEditParamsBackground]`
363
364 Allows to set transparency for the background of the generated image(s).
365 This parameter is only supported for GPT image models that support
366 transparent backgrounds. Must be one of `transparent`, `opaque`, or
367 `auto` (default value). When `auto` is used, the model will
368 automatically determine the best background for the image.
369
370 `gpt-image-2` and `gpt-image-2-2026-04-21` do not support
371 transparent backgrounds. Requests with `background` set to
372 `transparent` will return an error for these models; use `opaque` or
373 `auto` instead.
374
375 If `transparent`, the output format needs to support transparency,
376 so it should be set to either `png` (default value) or `webp`.
377
378 - `const ImageEditParamsBackgroundTransparent ImageEditParamsBackground = "transparent"`
379
380 - `const ImageEditParamsBackgroundOpaque ImageEditParamsBackground = "opaque"`
381
382 - `const ImageEditParamsBackgroundAuto ImageEditParamsBackground = "auto"`
383
384 - `InputFidelity param.Field[ImageEditParamsInputFidelity]`
385
386 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`.
387
388 - `const ImageEditParamsInputFidelityHigh ImageEditParamsInputFidelity = "high"`
389
390 - `const ImageEditParamsInputFidelityLow ImageEditParamsInputFidelity = "low"`
391
392 - `Mask param.Field[Reader]`
393
394 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`.
395
396 - `Model param.Field[ImageModel]`
397
398 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`.
399
400 - `string`
401
402 - `type ImageModel string`
403
404 - `const ImageModelGPTImage1 ImageModel = "gpt-image-1"`
405
406 - `const ImageModelGPTImage1Mini ImageModel = "gpt-image-1-mini"`
407
408 - `const ImageModelGPTImage2 ImageModel = "gpt-image-2"`
409
410 - `const ImageModelGPTImage2_2026_04_21 ImageModel = "gpt-image-2-2026-04-21"`
411
412 - `const ImageModelGPTImage1_5 ImageModel = "gpt-image-1.5"`
413
414 - `const ImageModelChatgptImageLatest ImageModel = "chatgpt-image-latest"`
415
416 - `const ImageModelDallE2 ImageModel = "dall-e-2"`
417
418 - `const ImageModelDallE3 ImageModel = "dall-e-3"`
419
420 - `N param.Field[int64]`
421
422 The number of images to generate. Must be between 1 and 10.
423
424 - `OutputCompression param.Field[int64]`
425
426 The compression level (0-100%) for the generated images. This parameter
427 is only supported for the GPT image models with the `webp` or `jpeg` output
428 formats, and defaults to 100.
429
430 - `OutputFormat param.Field[ImageEditParamsOutputFormat]`
431
432 The format in which the generated images are returned. This parameter is
433 only supported for the GPT image models. Must be one of `png`, `jpeg`, or `webp`.
434 The default value is `png`.
435
436 - `const ImageEditParamsOutputFormatPNG ImageEditParamsOutputFormat = "png"`
437
438 - `const ImageEditParamsOutputFormatJPEG ImageEditParamsOutputFormat = "jpeg"`
439
440 - `const ImageEditParamsOutputFormatWebP ImageEditParamsOutputFormat = "webp"`
441
442 - `PartialImages param.Field[int64]`
443
444 The number of partial images to generate. This parameter is used for
445 streaming responses that return partial images. Value must be between 0 and 3.
446 When set to 0, the response will be a single image sent in one streaming event.
447
448 Note that the final image may be sent before the full number of partial images
449 are generated if the full image is generated more quickly.
450
451 - `Quality param.Field[ImageEditParamsQuality]`
452
453 The quality of the image that will be generated for GPT image models. Defaults to `auto`.
454
455 - `const ImageEditParamsQualityStandard ImageEditParamsQuality = "standard"`
456
457 - `const ImageEditParamsQualityLow ImageEditParamsQuality = "low"`
458
459 - `const ImageEditParamsQualityMedium ImageEditParamsQuality = "medium"`
460
461 - `const ImageEditParamsQualityHigh ImageEditParamsQuality = "high"`
462
463 - `const ImageEditParamsQualityAuto ImageEditParamsQuality = "auto"`
464
465 - `ResponseFormat param.Field[ImageEditParamsResponseFormat]`
466
467 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.
468
469 - `const ImageEditParamsResponseFormatURL ImageEditParamsResponseFormat = "url"`
470
471 - `const ImageEditParamsResponseFormatB64JSON ImageEditParamsResponseFormat = "b64_json"`
472
473 - `Size param.Field[ImageEditParamsSize]`
474
475 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`.
476
477 - `string`
478
479 - `ImageEditParamsSize`
480
481 - `const ImageEditParamsSize256x256 ImageEditParamsSize = "256x256"`
482
483 - `const ImageEditParamsSize512x512 ImageEditParamsSize = "512x512"`
484
485 - `const ImageEditParamsSize1024x1024 ImageEditParamsSize = "1024x1024"`
486
487 - `const ImageEditParamsSize1536x1024 ImageEditParamsSize = "1536x1024"`
488
489 - `const ImageEditParamsSize1024x1536 ImageEditParamsSize = "1024x1536"`
490
491 - `const ImageEditParamsSizeAuto ImageEditParamsSize = "auto"`
492
493 - ``
494
495 - `User param.Field[string]`
496
497 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).
498
499### Returns
500
501- `type ImagesResponse struct{…}`
502
503 The response from the image generation endpoint.
504
505 - `Created int64`
506
507 The Unix timestamp (in seconds) of when the image was created.
508
509 - `Background ImagesResponseBackground`
510
511 The background parameter used for the image generation. Either `transparent` or `opaque`.
512
513 - `const ImagesResponseBackgroundTransparent ImagesResponseBackground = "transparent"`
514
515 - `const ImagesResponseBackgroundOpaque ImagesResponseBackground = "opaque"`
516
517 - `Data []Image`
518
519 The list of generated images.
520
521 - `B64JSON string`
522
523 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`.
524
525 - `RevisedPrompt string`
526
527 For `dall-e-3` only, the revised prompt that was used to generate the image.
528
529 - `URL string`
530
531 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.
532
533 - `OutputFormat ImagesResponseOutputFormat`
534
535 The output format of the image generation. Either `png`, `webp`, or `jpeg`.
536
537 - `const ImagesResponseOutputFormatPNG ImagesResponseOutputFormat = "png"`
538
539 - `const ImagesResponseOutputFormatWebP ImagesResponseOutputFormat = "webp"`
540
541 - `const ImagesResponseOutputFormatJPEG ImagesResponseOutputFormat = "jpeg"`
542
543 - `Quality ImagesResponseQuality`
544
545 The quality of the image generated. Either `low`, `medium`, or `high`.
546
547 - `const ImagesResponseQualityLow ImagesResponseQuality = "low"`
548
549 - `const ImagesResponseQualityMedium ImagesResponseQuality = "medium"`
550
551 - `const ImagesResponseQualityHigh ImagesResponseQuality = "high"`
552
553 - `Size ImagesResponseSize`
554
555 The size of the image generated. Either `1024x1024`, `1024x1536`, or `1536x1024`.
556
557 - `const ImagesResponseSize1024x1024 ImagesResponseSize = "1024x1024"`
558
559 - `const ImagesResponseSize1024x1536 ImagesResponseSize = "1024x1536"`
560
561 - `const ImagesResponseSize1536x1024 ImagesResponseSize = "1536x1024"`
562
563 - `Usage ImagesResponseUsage`
564
565 For `gpt-image-1` only, the token usage information for the image generation.
566
567 - `InputTokens int64`
568
569 The number of tokens (images and text) in the input prompt.
570
571 - `InputTokensDetails ImagesResponseUsageInputTokensDetails`
572
573 The input tokens detailed information for the image generation.
574
575 - `ImageTokens int64`
576
577 The number of image tokens in the input prompt.
578
579 - `TextTokens int64`
580
581 The number of text tokens in the input prompt.
582
583 - `OutputTokens int64`
584
585 The number of output tokens generated by the model.
586
587 - `TotalTokens int64`
588
589 The total number of tokens (images and text) used for the image generation.
590
591 - `OutputTokensDetails ImagesResponseUsageOutputTokensDetails`
592
593 The output token details for the image generation.
594
595 - `ImageTokens int64`
596
597 The number of image output tokens generated by the model.
598
599 - `TextTokens int64`
600
601 The number of text output tokens generated by the model.
602
603### Example
604
605```go
606package main
607
608import (
609 "bytes"
610 "context"
611 "fmt"
612 "io"
613
614 "github.com/openai/openai-go"
615 "github.com/openai/openai-go/option"
616)
617
618func main() {
619 client := openai.NewClient(
620 option.WithAPIKey("My API Key"),
621 )
622 imagesResponse, err := client.Images.Edit(context.TODO(), openai.ImageEditParams{
623 Image: openai.ImageEditParamsImageUnion{
624 OfFile: io.Reader(bytes.NewBuffer([]byte("Example data"))),
625 },
626 Prompt: "A cute baby sea otter wearing a beret",
627 })
628 if err != nil {
629 panic(err.Error())
630 }
631 fmt.Printf("%+v\n", imagesResponse)
632}
633```
634
635#### Response
636
637```json
638{
639 "created": 0,
640 "background": "transparent",
641 "data": [
642 {
643 "b64_json": "b64_json",
644 "revised_prompt": "revised_prompt",
645 "url": "https://example.com"
646 }
647 ],
648 "output_format": "png",
649 "quality": "low",
650 "size": "1024x1024",
651 "usage": {
652 "input_tokens": 0,
653 "input_tokens_details": {
654 "image_tokens": 0,
655 "text_tokens": 0
656 },
657 "output_tokens": 0,
658 "total_tokens": 0,
659 "output_tokens_details": {
660 "image_tokens": 0,
661 "text_tokens": 0
662 }
663 }
664}
665```
666
667## Create image variation
668
669`client.Images.NewVariation(ctx, body) (*ImagesResponse, error)`
670
671**post** `/images/variations`
672
673Creates a variation of a given image. This endpoint only supports `dall-e-2`.
674
675### Parameters
676
677- `body ImageNewVariationParams`
678
679 - `Image param.Field[Reader]`
680
681 The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square.
682
683 - `Model param.Field[ImageModel]`
684
685 The model to use for image generation. Only `dall-e-2` is supported at this time.
686
687 - `string`
688
689 - `type ImageModel string`
690
691 - `const ImageModelGPTImage1 ImageModel = "gpt-image-1"`
692
693 - `const ImageModelGPTImage1Mini ImageModel = "gpt-image-1-mini"`
694
695 - `const ImageModelGPTImage2 ImageModel = "gpt-image-2"`
696
697 - `const ImageModelGPTImage2_2026_04_21 ImageModel = "gpt-image-2-2026-04-21"`
698
699 - `const ImageModelGPTImage1_5 ImageModel = "gpt-image-1.5"`
700
701 - `const ImageModelChatgptImageLatest ImageModel = "chatgpt-image-latest"`
702
703 - `const ImageModelDallE2 ImageModel = "dall-e-2"`
704
705 - `const ImageModelDallE3 ImageModel = "dall-e-3"`
706
707 - `N param.Field[int64]`
708
709 The number of images to generate. Must be between 1 and 10.
710
711 - `ResponseFormat param.Field[ImageNewVariationParamsResponseFormat]`
712
713 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.
714
715 - `const ImageNewVariationParamsResponseFormatURL ImageNewVariationParamsResponseFormat = "url"`
716
717 - `const ImageNewVariationParamsResponseFormatB64JSON ImageNewVariationParamsResponseFormat = "b64_json"`
718
719 - `Size param.Field[ImageNewVariationParamsSize]`
720
721 The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`.
722
723 - `const ImageNewVariationParamsSize256x256 ImageNewVariationParamsSize = "256x256"`
724
725 - `const ImageNewVariationParamsSize512x512 ImageNewVariationParamsSize = "512x512"`
726
727 - `const ImageNewVariationParamsSize1024x1024 ImageNewVariationParamsSize = "1024x1024"`
728
729 - `User param.Field[string]`
730
731 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).
732
733### Returns
734
735- `type ImagesResponse struct{…}`
736
737 The response from the image generation endpoint.
738
739 - `Created int64`
740
741 The Unix timestamp (in seconds) of when the image was created.
742
743 - `Background ImagesResponseBackground`
744
745 The background parameter used for the image generation. Either `transparent` or `opaque`.
746
747 - `const ImagesResponseBackgroundTransparent ImagesResponseBackground = "transparent"`
748
749 - `const ImagesResponseBackgroundOpaque ImagesResponseBackground = "opaque"`
750
751 - `Data []Image`
752
753 The list of generated images.
754
755 - `B64JSON string`
756
757 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`.
758
759 - `RevisedPrompt string`
760
761 For `dall-e-3` only, the revised prompt that was used to generate the image.
762
763 - `URL string`
764
765 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.
766
767 - `OutputFormat ImagesResponseOutputFormat`
768
769 The output format of the image generation. Either `png`, `webp`, or `jpeg`.
770
771 - `const ImagesResponseOutputFormatPNG ImagesResponseOutputFormat = "png"`
772
773 - `const ImagesResponseOutputFormatWebP ImagesResponseOutputFormat = "webp"`
774
775 - `const ImagesResponseOutputFormatJPEG ImagesResponseOutputFormat = "jpeg"`
776
777 - `Quality ImagesResponseQuality`
778
779 The quality of the image generated. Either `low`, `medium`, or `high`.
780
781 - `const ImagesResponseQualityLow ImagesResponseQuality = "low"`
782
783 - `const ImagesResponseQualityMedium ImagesResponseQuality = "medium"`
784
785 - `const ImagesResponseQualityHigh ImagesResponseQuality = "high"`
786
787 - `Size ImagesResponseSize`
788
789 The size of the image generated. Either `1024x1024`, `1024x1536`, or `1536x1024`.
790
791 - `const ImagesResponseSize1024x1024 ImagesResponseSize = "1024x1024"`
792
793 - `const ImagesResponseSize1024x1536 ImagesResponseSize = "1024x1536"`
794
795 - `const ImagesResponseSize1536x1024 ImagesResponseSize = "1536x1024"`
796
797 - `Usage ImagesResponseUsage`
798
799 For `gpt-image-1` only, the token usage information for the image generation.
800
801 - `InputTokens int64`
802
803 The number of tokens (images and text) in the input prompt.
804
805 - `InputTokensDetails ImagesResponseUsageInputTokensDetails`
806
807 The input tokens detailed information for the image generation.
808
809 - `ImageTokens int64`
810
811 The number of image tokens in the input prompt.
812
813 - `TextTokens int64`
814
815 The number of text tokens in the input prompt.
816
817 - `OutputTokens int64`
818
819 The number of output tokens generated by the model.
820
821 - `TotalTokens int64`
822
823 The total number of tokens (images and text) used for the image generation.
824
825 - `OutputTokensDetails ImagesResponseUsageOutputTokensDetails`
826
827 The output token details for the image generation.
828
829 - `ImageTokens int64`
830
831 The number of image output tokens generated by the model.
832
833 - `TextTokens int64`
834
835 The number of text output tokens generated by the model.
836
837### Example
838
839```go
840package main
841
842import (
843 "bytes"
844 "context"
845 "fmt"
846 "io"
847
848 "github.com/openai/openai-go"
849 "github.com/openai/openai-go/option"
850)
851
852func main() {
853 client := openai.NewClient(
854 option.WithAPIKey("My API Key"),
855 )
856 imagesResponse, err := client.Images.NewVariation(context.TODO(), openai.ImageNewVariationParams{
857 Image: io.Reader(bytes.NewBuffer([]byte("Example data"))),
858 })
859 if err != nil {
860 panic(err.Error())
861 }
862 fmt.Printf("%+v\n", imagesResponse.Created)
863}
864```
865
866#### Response
867
868```json
869{
870 "created": 0,
871 "background": "transparent",
872 "data": [
873 {
874 "b64_json": "b64_json",
875 "revised_prompt": "revised_prompt",
876 "url": "https://example.com"
877 }
878 ],
879 "output_format": "png",
880 "quality": "low",
881 "size": "1024x1024",
882 "usage": {
883 "input_tokens": 0,
884 "input_tokens_details": {
885 "image_tokens": 0,
886 "text_tokens": 0
887 },
888 "output_tokens": 0,
889 "total_tokens": 0,
890 "output_tokens_details": {
891 "image_tokens": 0,
892 "text_tokens": 0
893 }
894 }
895}
896```
897
898## Domain Types
899
900### Image
901
902- `type Image struct{…}`
903
904 Represents the content or the URL of an image generated by the OpenAI API.
905
906 - `B64JSON string`
907
908 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`.
909
910 - `RevisedPrompt string`
911
912 For `dall-e-3` only, the revised prompt that was used to generate the image.
913
914 - `URL string`
915
916 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.
917
918### Image Edit Completed Event
919
920- `type ImageEditCompletedEvent struct{…}`
921
922 Emitted when image editing has completed and the final image is available.
923
924 - `B64JSON string`
925
926 Base64-encoded final edited image data, suitable for rendering as an image.
927
928 - `Background ImageEditCompletedEventBackground`
929
930 The background setting for the edited image.
931
932 - `const ImageEditCompletedEventBackgroundTransparent ImageEditCompletedEventBackground = "transparent"`
933
934 - `const ImageEditCompletedEventBackgroundOpaque ImageEditCompletedEventBackground = "opaque"`
935
936 - `const ImageEditCompletedEventBackgroundAuto ImageEditCompletedEventBackground = "auto"`
937
938 - `CreatedAt int64`
939
940 The Unix timestamp when the event was created.
941
942 - `OutputFormat ImageEditCompletedEventOutputFormat`
943
944 The output format for the edited image.
945
946 - `const ImageEditCompletedEventOutputFormatPNG ImageEditCompletedEventOutputFormat = "png"`
947
948 - `const ImageEditCompletedEventOutputFormatWebP ImageEditCompletedEventOutputFormat = "webp"`
949
950 - `const ImageEditCompletedEventOutputFormatJPEG ImageEditCompletedEventOutputFormat = "jpeg"`
951
952 - `Quality ImageEditCompletedEventQuality`
953
954 The quality setting for the edited image.
955
956 - `const ImageEditCompletedEventQualityLow ImageEditCompletedEventQuality = "low"`
957
958 - `const ImageEditCompletedEventQualityMedium ImageEditCompletedEventQuality = "medium"`
959
960 - `const ImageEditCompletedEventQualityHigh ImageEditCompletedEventQuality = "high"`
961
962 - `const ImageEditCompletedEventQualityAuto ImageEditCompletedEventQuality = "auto"`
963
964 - `Size ImageEditCompletedEventSize`
965
966 The size of the edited image.
967
968 - `const ImageEditCompletedEventSize1024x1024 ImageEditCompletedEventSize = "1024x1024"`
969
970 - `const ImageEditCompletedEventSize1024x1536 ImageEditCompletedEventSize = "1024x1536"`
971
972 - `const ImageEditCompletedEventSize1536x1024 ImageEditCompletedEventSize = "1536x1024"`
973
974 - `const ImageEditCompletedEventSizeAuto ImageEditCompletedEventSize = "auto"`
975
976 - `Type ImageEditCompleted`
977
978 The type of the event. Always `image_edit.completed`.
979
980 - `const ImageEditCompletedImageEditCompleted ImageEditCompleted = "image_edit.completed"`
981
982 - `Usage ImageEditCompletedEventUsage`
983
984 For the GPT image models only, the token usage information for the image generation.
985
986 - `InputTokens int64`
987
988 The number of tokens (images and text) in the input prompt.
989
990 - `InputTokensDetails ImageEditCompletedEventUsageInputTokensDetails`
991
992 The input tokens detailed information for the image generation.
993
994 - `ImageTokens int64`
995
996 The number of image tokens in the input prompt.
997
998 - `TextTokens int64`
999
1000 The number of text tokens in the input prompt.
1001
1002 - `OutputTokens int64`
1003
1004 The number of image tokens in the output image.
1005
1006 - `TotalTokens int64`
1007
1008 The total number of tokens (images and text) used for the image generation.
1009
1010### Image Edit Partial Image Event
1011
1012- `type ImageEditPartialImageEvent struct{…}`
1013
1014 Emitted when a partial image is available during image editing streaming.
1015
1016 - `B64JSON string`
1017
1018 Base64-encoded partial image data, suitable for rendering as an image.
1019
1020 - `Background ImageEditPartialImageEventBackground`
1021
1022 The background setting for the requested edited image.
1023
1024 - `const ImageEditPartialImageEventBackgroundTransparent ImageEditPartialImageEventBackground = "transparent"`
1025
1026 - `const ImageEditPartialImageEventBackgroundOpaque ImageEditPartialImageEventBackground = "opaque"`
1027
1028 - `const ImageEditPartialImageEventBackgroundAuto ImageEditPartialImageEventBackground = "auto"`
1029
1030 - `CreatedAt int64`
1031
1032 The Unix timestamp when the event was created.
1033
1034 - `OutputFormat ImageEditPartialImageEventOutputFormat`
1035
1036 The output format for the requested edited image.
1037
1038 - `const ImageEditPartialImageEventOutputFormatPNG ImageEditPartialImageEventOutputFormat = "png"`
1039
1040 - `const ImageEditPartialImageEventOutputFormatWebP ImageEditPartialImageEventOutputFormat = "webp"`
1041
1042 - `const ImageEditPartialImageEventOutputFormatJPEG ImageEditPartialImageEventOutputFormat = "jpeg"`
1043
1044 - `PartialImageIndex int64`
1045
1046 0-based index for the partial image (streaming).
1047
1048 - `Quality ImageEditPartialImageEventQuality`
1049
1050 The quality setting for the requested edited image.
1051
1052 - `const ImageEditPartialImageEventQualityLow ImageEditPartialImageEventQuality = "low"`
1053
1054 - `const ImageEditPartialImageEventQualityMedium ImageEditPartialImageEventQuality = "medium"`
1055
1056 - `const ImageEditPartialImageEventQualityHigh ImageEditPartialImageEventQuality = "high"`
1057
1058 - `const ImageEditPartialImageEventQualityAuto ImageEditPartialImageEventQuality = "auto"`
1059
1060 - `Size ImageEditPartialImageEventSize`
1061
1062 The size of the requested edited image.
1063
1064 - `const ImageEditPartialImageEventSize1024x1024 ImageEditPartialImageEventSize = "1024x1024"`
1065
1066 - `const ImageEditPartialImageEventSize1024x1536 ImageEditPartialImageEventSize = "1024x1536"`
1067
1068 - `const ImageEditPartialImageEventSize1536x1024 ImageEditPartialImageEventSize = "1536x1024"`
1069
1070 - `const ImageEditPartialImageEventSizeAuto ImageEditPartialImageEventSize = "auto"`
1071
1072 - `Type ImageEditPartialImage`
1073
1074 The type of the event. Always `image_edit.partial_image`.
1075
1076 - `const ImageEditPartialImageImageEditPartialImage ImageEditPartialImage = "image_edit.partial_image"`
1077
1078### Image Edit Stream Event
1079
1080- `type ImageEditStreamEventUnion interface{…}`
1081
1082 Emitted when a partial image is available during image editing streaming.
1083
1084 - `type ImageEditPartialImageEvent struct{…}`
1085
1086 Emitted when a partial image is available during image editing streaming.
1087
1088 - `B64JSON string`
1089
1090 Base64-encoded partial image data, suitable for rendering as an image.
1091
1092 - `Background ImageEditPartialImageEventBackground`
1093
1094 The background setting for the requested edited image.
1095
1096 - `const ImageEditPartialImageEventBackgroundTransparent ImageEditPartialImageEventBackground = "transparent"`
1097
1098 - `const ImageEditPartialImageEventBackgroundOpaque ImageEditPartialImageEventBackground = "opaque"`
1099
1100 - `const ImageEditPartialImageEventBackgroundAuto ImageEditPartialImageEventBackground = "auto"`
1101
1102 - `CreatedAt int64`
1103
1104 The Unix timestamp when the event was created.
1105
1106 - `OutputFormat ImageEditPartialImageEventOutputFormat`
1107
1108 The output format for the requested edited image.
1109
1110 - `const ImageEditPartialImageEventOutputFormatPNG ImageEditPartialImageEventOutputFormat = "png"`
1111
1112 - `const ImageEditPartialImageEventOutputFormatWebP ImageEditPartialImageEventOutputFormat = "webp"`
1113
1114 - `const ImageEditPartialImageEventOutputFormatJPEG ImageEditPartialImageEventOutputFormat = "jpeg"`
1115
1116 - `PartialImageIndex int64`
1117
1118 0-based index for the partial image (streaming).
1119
1120 - `Quality ImageEditPartialImageEventQuality`
1121
1122 The quality setting for the requested edited image.
1123
1124 - `const ImageEditPartialImageEventQualityLow ImageEditPartialImageEventQuality = "low"`
1125
1126 - `const ImageEditPartialImageEventQualityMedium ImageEditPartialImageEventQuality = "medium"`
1127
1128 - `const ImageEditPartialImageEventQualityHigh ImageEditPartialImageEventQuality = "high"`
1129
1130 - `const ImageEditPartialImageEventQualityAuto ImageEditPartialImageEventQuality = "auto"`
1131
1132 - `Size ImageEditPartialImageEventSize`
1133
1134 The size of the requested edited image.
1135
1136 - `const ImageEditPartialImageEventSize1024x1024 ImageEditPartialImageEventSize = "1024x1024"`
1137
1138 - `const ImageEditPartialImageEventSize1024x1536 ImageEditPartialImageEventSize = "1024x1536"`
1139
1140 - `const ImageEditPartialImageEventSize1536x1024 ImageEditPartialImageEventSize = "1536x1024"`
1141
1142 - `const ImageEditPartialImageEventSizeAuto ImageEditPartialImageEventSize = "auto"`
1143
1144 - `Type ImageEditPartialImage`
1145
1146 The type of the event. Always `image_edit.partial_image`.
1147
1148 - `const ImageEditPartialImageImageEditPartialImage ImageEditPartialImage = "image_edit.partial_image"`
1149
1150 - `type ImageEditCompletedEvent struct{…}`
1151
1152 Emitted when image editing has completed and the final image is available.
1153
1154 - `B64JSON string`
1155
1156 Base64-encoded final edited image data, suitable for rendering as an image.
1157
1158 - `Background ImageEditCompletedEventBackground`
1159
1160 The background setting for the edited image.
1161
1162 - `const ImageEditCompletedEventBackgroundTransparent ImageEditCompletedEventBackground = "transparent"`
1163
1164 - `const ImageEditCompletedEventBackgroundOpaque ImageEditCompletedEventBackground = "opaque"`
1165
1166 - `const ImageEditCompletedEventBackgroundAuto ImageEditCompletedEventBackground = "auto"`
1167
1168 - `CreatedAt int64`
1169
1170 The Unix timestamp when the event was created.
1171
1172 - `OutputFormat ImageEditCompletedEventOutputFormat`
1173
1174 The output format for the edited image.
1175
1176 - `const ImageEditCompletedEventOutputFormatPNG ImageEditCompletedEventOutputFormat = "png"`
1177
1178 - `const ImageEditCompletedEventOutputFormatWebP ImageEditCompletedEventOutputFormat = "webp"`
1179
1180 - `const ImageEditCompletedEventOutputFormatJPEG ImageEditCompletedEventOutputFormat = "jpeg"`
1181
1182 - `Quality ImageEditCompletedEventQuality`
1183
1184 The quality setting for the edited image.
1185
1186 - `const ImageEditCompletedEventQualityLow ImageEditCompletedEventQuality = "low"`
1187
1188 - `const ImageEditCompletedEventQualityMedium ImageEditCompletedEventQuality = "medium"`
1189
1190 - `const ImageEditCompletedEventQualityHigh ImageEditCompletedEventQuality = "high"`
1191
1192 - `const ImageEditCompletedEventQualityAuto ImageEditCompletedEventQuality = "auto"`
1193
1194 - `Size ImageEditCompletedEventSize`
1195
1196 The size of the edited image.
1197
1198 - `const ImageEditCompletedEventSize1024x1024 ImageEditCompletedEventSize = "1024x1024"`
1199
1200 - `const ImageEditCompletedEventSize1024x1536 ImageEditCompletedEventSize = "1024x1536"`
1201
1202 - `const ImageEditCompletedEventSize1536x1024 ImageEditCompletedEventSize = "1536x1024"`
1203
1204 - `const ImageEditCompletedEventSizeAuto ImageEditCompletedEventSize = "auto"`
1205
1206 - `Type ImageEditCompleted`
1207
1208 The type of the event. Always `image_edit.completed`.
1209
1210 - `const ImageEditCompletedImageEditCompleted ImageEditCompleted = "image_edit.completed"`
1211
1212 - `Usage ImageEditCompletedEventUsage`
1213
1214 For the GPT image models only, the token usage information for the image generation.
1215
1216 - `InputTokens int64`
1217
1218 The number of tokens (images and text) in the input prompt.
1219
1220 - `InputTokensDetails ImageEditCompletedEventUsageInputTokensDetails`
1221
1222 The input tokens detailed information for the image generation.
1223
1224 - `ImageTokens int64`
1225
1226 The number of image tokens in the input prompt.
1227
1228 - `TextTokens int64`
1229
1230 The number of text tokens in the input prompt.
1231
1232 - `OutputTokens int64`
1233
1234 The number of image tokens in the output image.
1235
1236 - `TotalTokens int64`
1237
1238 The total number of tokens (images and text) used for the image generation.
1239
1240### Image Gen Completed Event
1241
1242- `type ImageGenCompletedEvent struct{…}`
1243
1244 Emitted when image generation has completed and the final image is available.
1245
1246 - `B64JSON string`
1247
1248 Base64-encoded image data, suitable for rendering as an image.
1249
1250 - `Background ImageGenCompletedEventBackground`
1251
1252 The background setting for the generated image.
1253
1254 - `const ImageGenCompletedEventBackgroundTransparent ImageGenCompletedEventBackground = "transparent"`
1255
1256 - `const ImageGenCompletedEventBackgroundOpaque ImageGenCompletedEventBackground = "opaque"`
1257
1258 - `const ImageGenCompletedEventBackgroundAuto ImageGenCompletedEventBackground = "auto"`
1259
1260 - `CreatedAt int64`
1261
1262 The Unix timestamp when the event was created.
1263
1264 - `OutputFormat ImageGenCompletedEventOutputFormat`
1265
1266 The output format for the generated image.
1267
1268 - `const ImageGenCompletedEventOutputFormatPNG ImageGenCompletedEventOutputFormat = "png"`
1269
1270 - `const ImageGenCompletedEventOutputFormatWebP ImageGenCompletedEventOutputFormat = "webp"`
1271
1272 - `const ImageGenCompletedEventOutputFormatJPEG ImageGenCompletedEventOutputFormat = "jpeg"`
1273
1274 - `Quality ImageGenCompletedEventQuality`
1275
1276 The quality setting for the generated image.
1277
1278 - `const ImageGenCompletedEventQualityLow ImageGenCompletedEventQuality = "low"`
1279
1280 - `const ImageGenCompletedEventQualityMedium ImageGenCompletedEventQuality = "medium"`
1281
1282 - `const ImageGenCompletedEventQualityHigh ImageGenCompletedEventQuality = "high"`
1283
1284 - `const ImageGenCompletedEventQualityAuto ImageGenCompletedEventQuality = "auto"`
1285
1286 - `Size ImageGenCompletedEventSize`
1287
1288 The size of the generated image.
1289
1290 - `const ImageGenCompletedEventSize1024x1024 ImageGenCompletedEventSize = "1024x1024"`
1291
1292 - `const ImageGenCompletedEventSize1024x1536 ImageGenCompletedEventSize = "1024x1536"`
1293
1294 - `const ImageGenCompletedEventSize1536x1024 ImageGenCompletedEventSize = "1536x1024"`
1295
1296 - `const ImageGenCompletedEventSizeAuto ImageGenCompletedEventSize = "auto"`
1297
1298 - `Type ImageGenerationCompleted`
1299
1300 The type of the event. Always `image_generation.completed`.
1301
1302 - `const ImageGenerationCompletedImageGenerationCompleted ImageGenerationCompleted = "image_generation.completed"`
1303
1304 - `Usage ImageGenCompletedEventUsage`
1305
1306 For the GPT image models only, the token usage information for the image generation.
1307
1308 - `InputTokens int64`
1309
1310 The number of tokens (images and text) in the input prompt.
1311
1312 - `InputTokensDetails ImageGenCompletedEventUsageInputTokensDetails`
1313
1314 The input tokens detailed information for the image generation.
1315
1316 - `ImageTokens int64`
1317
1318 The number of image tokens in the input prompt.
1319
1320 - `TextTokens int64`
1321
1322 The number of text tokens in the input prompt.
1323
1324 - `OutputTokens int64`
1325
1326 The number of image tokens in the output image.
1327
1328 - `TotalTokens int64`
1329
1330 The total number of tokens (images and text) used for the image generation.
1331
1332### Image Gen Partial Image Event
1333
1334- `type ImageGenPartialImageEvent struct{…}`
1335
1336 Emitted when a partial image is available during image generation streaming.
1337
1338 - `B64JSON string`
1339
1340 Base64-encoded partial image data, suitable for rendering as an image.
1341
1342 - `Background ImageGenPartialImageEventBackground`
1343
1344 The background setting for the requested image.
1345
1346 - `const ImageGenPartialImageEventBackgroundTransparent ImageGenPartialImageEventBackground = "transparent"`
1347
1348 - `const ImageGenPartialImageEventBackgroundOpaque ImageGenPartialImageEventBackground = "opaque"`
1349
1350 - `const ImageGenPartialImageEventBackgroundAuto ImageGenPartialImageEventBackground = "auto"`
1351
1352 - `CreatedAt int64`
1353
1354 The Unix timestamp when the event was created.
1355
1356 - `OutputFormat ImageGenPartialImageEventOutputFormat`
1357
1358 The output format for the requested image.
1359
1360 - `const ImageGenPartialImageEventOutputFormatPNG ImageGenPartialImageEventOutputFormat = "png"`
1361
1362 - `const ImageGenPartialImageEventOutputFormatWebP ImageGenPartialImageEventOutputFormat = "webp"`
1363
1364 - `const ImageGenPartialImageEventOutputFormatJPEG ImageGenPartialImageEventOutputFormat = "jpeg"`
1365
1366 - `PartialImageIndex int64`
1367
1368 0-based index for the partial image (streaming).
1369
1370 - `Quality ImageGenPartialImageEventQuality`
1371
1372 The quality setting for the requested image.
1373
1374 - `const ImageGenPartialImageEventQualityLow ImageGenPartialImageEventQuality = "low"`
1375
1376 - `const ImageGenPartialImageEventQualityMedium ImageGenPartialImageEventQuality = "medium"`
1377
1378 - `const ImageGenPartialImageEventQualityHigh ImageGenPartialImageEventQuality = "high"`
1379
1380 - `const ImageGenPartialImageEventQualityAuto ImageGenPartialImageEventQuality = "auto"`
1381
1382 - `Size ImageGenPartialImageEventSize`
1383
1384 The size of the requested image.
1385
1386 - `const ImageGenPartialImageEventSize1024x1024 ImageGenPartialImageEventSize = "1024x1024"`
1387
1388 - `const ImageGenPartialImageEventSize1024x1536 ImageGenPartialImageEventSize = "1024x1536"`
1389
1390 - `const ImageGenPartialImageEventSize1536x1024 ImageGenPartialImageEventSize = "1536x1024"`
1391
1392 - `const ImageGenPartialImageEventSizeAuto ImageGenPartialImageEventSize = "auto"`
1393
1394 - `Type ImageGenerationPartialImage`
1395
1396 The type of the event. Always `image_generation.partial_image`.
1397
1398 - `const ImageGenerationPartialImageImageGenerationPartialImage ImageGenerationPartialImage = "image_generation.partial_image"`
1399
1400### Image Gen Stream Event
1401
1402- `type ImageGenStreamEventUnion interface{…}`
1403
1404 Emitted when a partial image is available during image generation streaming.
1405
1406 - `type ImageGenPartialImageEvent struct{…}`
1407
1408 Emitted when a partial image is available during image generation streaming.
1409
1410 - `B64JSON string`
1411
1412 Base64-encoded partial image data, suitable for rendering as an image.
1413
1414 - `Background ImageGenPartialImageEventBackground`
1415
1416 The background setting for the requested image.
1417
1418 - `const ImageGenPartialImageEventBackgroundTransparent ImageGenPartialImageEventBackground = "transparent"`
1419
1420 - `const ImageGenPartialImageEventBackgroundOpaque ImageGenPartialImageEventBackground = "opaque"`
1421
1422 - `const ImageGenPartialImageEventBackgroundAuto ImageGenPartialImageEventBackground = "auto"`
1423
1424 - `CreatedAt int64`
1425
1426 The Unix timestamp when the event was created.
1427
1428 - `OutputFormat ImageGenPartialImageEventOutputFormat`
1429
1430 The output format for the requested image.
1431
1432 - `const ImageGenPartialImageEventOutputFormatPNG ImageGenPartialImageEventOutputFormat = "png"`
1433
1434 - `const ImageGenPartialImageEventOutputFormatWebP ImageGenPartialImageEventOutputFormat = "webp"`
1435
1436 - `const ImageGenPartialImageEventOutputFormatJPEG ImageGenPartialImageEventOutputFormat = "jpeg"`
1437
1438 - `PartialImageIndex int64`
1439
1440 0-based index for the partial image (streaming).
1441
1442 - `Quality ImageGenPartialImageEventQuality`
1443
1444 The quality setting for the requested image.
1445
1446 - `const ImageGenPartialImageEventQualityLow ImageGenPartialImageEventQuality = "low"`
1447
1448 - `const ImageGenPartialImageEventQualityMedium ImageGenPartialImageEventQuality = "medium"`
1449
1450 - `const ImageGenPartialImageEventQualityHigh ImageGenPartialImageEventQuality = "high"`
1451
1452 - `const ImageGenPartialImageEventQualityAuto ImageGenPartialImageEventQuality = "auto"`
1453
1454 - `Size ImageGenPartialImageEventSize`
1455
1456 The size of the requested image.
1457
1458 - `const ImageGenPartialImageEventSize1024x1024 ImageGenPartialImageEventSize = "1024x1024"`
1459
1460 - `const ImageGenPartialImageEventSize1024x1536 ImageGenPartialImageEventSize = "1024x1536"`
1461
1462 - `const ImageGenPartialImageEventSize1536x1024 ImageGenPartialImageEventSize = "1536x1024"`
1463
1464 - `const ImageGenPartialImageEventSizeAuto ImageGenPartialImageEventSize = "auto"`
1465
1466 - `Type ImageGenerationPartialImage`
1467
1468 The type of the event. Always `image_generation.partial_image`.
1469
1470 - `const ImageGenerationPartialImageImageGenerationPartialImage ImageGenerationPartialImage = "image_generation.partial_image"`
1471
1472 - `type ImageGenCompletedEvent struct{…}`
1473
1474 Emitted when image generation has completed and the final image is available.
1475
1476 - `B64JSON string`
1477
1478 Base64-encoded image data, suitable for rendering as an image.
1479
1480 - `Background ImageGenCompletedEventBackground`
1481
1482 The background setting for the generated image.
1483
1484 - `const ImageGenCompletedEventBackgroundTransparent ImageGenCompletedEventBackground = "transparent"`
1485
1486 - `const ImageGenCompletedEventBackgroundOpaque ImageGenCompletedEventBackground = "opaque"`
1487
1488 - `const ImageGenCompletedEventBackgroundAuto ImageGenCompletedEventBackground = "auto"`
1489
1490 - `CreatedAt int64`
1491
1492 The Unix timestamp when the event was created.
1493
1494 - `OutputFormat ImageGenCompletedEventOutputFormat`
1495
1496 The output format for the generated image.
1497
1498 - `const ImageGenCompletedEventOutputFormatPNG ImageGenCompletedEventOutputFormat = "png"`
1499
1500 - `const ImageGenCompletedEventOutputFormatWebP ImageGenCompletedEventOutputFormat = "webp"`
1501
1502 - `const ImageGenCompletedEventOutputFormatJPEG ImageGenCompletedEventOutputFormat = "jpeg"`
1503
1504 - `Quality ImageGenCompletedEventQuality`
1505
1506 The quality setting for the generated image.
1507
1508 - `const ImageGenCompletedEventQualityLow ImageGenCompletedEventQuality = "low"`
1509
1510 - `const ImageGenCompletedEventQualityMedium ImageGenCompletedEventQuality = "medium"`
1511
1512 - `const ImageGenCompletedEventQualityHigh ImageGenCompletedEventQuality = "high"`
1513
1514 - `const ImageGenCompletedEventQualityAuto ImageGenCompletedEventQuality = "auto"`
1515
1516 - `Size ImageGenCompletedEventSize`
1517
1518 The size of the generated image.
1519
1520 - `const ImageGenCompletedEventSize1024x1024 ImageGenCompletedEventSize = "1024x1024"`
1521
1522 - `const ImageGenCompletedEventSize1024x1536 ImageGenCompletedEventSize = "1024x1536"`
1523
1524 - `const ImageGenCompletedEventSize1536x1024 ImageGenCompletedEventSize = "1536x1024"`
1525
1526 - `const ImageGenCompletedEventSizeAuto ImageGenCompletedEventSize = "auto"`
1527
1528 - `Type ImageGenerationCompleted`
1529
1530 The type of the event. Always `image_generation.completed`.
1531
1532 - `const ImageGenerationCompletedImageGenerationCompleted ImageGenerationCompleted = "image_generation.completed"`
1533
1534 - `Usage ImageGenCompletedEventUsage`
1535
1536 For the GPT image models only, the token usage information for the image generation.
1537
1538 - `InputTokens int64`
1539
1540 The number of tokens (images and text) in the input prompt.
1541
1542 - `InputTokensDetails ImageGenCompletedEventUsageInputTokensDetails`
1543
1544 The input tokens detailed information for the image generation.
1545
1546 - `ImageTokens int64`
1547
1548 The number of image tokens in the input prompt.
1549
1550 - `TextTokens int64`
1551
1552 The number of text tokens in the input prompt.
1553
1554 - `OutputTokens int64`
1555
1556 The number of image tokens in the output image.
1557
1558 - `TotalTokens int64`
1559
1560 The total number of tokens (images and text) used for the image generation.
1561
1562### Image Model
1563
1564- `type ImageModel string`
1565
1566 - `const ImageModelGPTImage1 ImageModel = "gpt-image-1"`
1567
1568 - `const ImageModelGPTImage1Mini ImageModel = "gpt-image-1-mini"`
1569
1570 - `const ImageModelGPTImage2 ImageModel = "gpt-image-2"`
1571
1572 - `const ImageModelGPTImage2_2026_04_21 ImageModel = "gpt-image-2-2026-04-21"`
1573
1574 - `const ImageModelGPTImage1_5 ImageModel = "gpt-image-1.5"`
1575
1576 - `const ImageModelChatgptImageLatest ImageModel = "chatgpt-image-latest"`
1577
1578 - `const ImageModelDallE2 ImageModel = "dall-e-2"`
1579
1580 - `const ImageModelDallE3 ImageModel = "dall-e-3"`
1581
1582### Images Response
1583
1584- `type ImagesResponse struct{…}`
1585
1586 The response from the image generation endpoint.
1587
1588 - `Created int64`
1589
1590 The Unix timestamp (in seconds) of when the image was created.
1591
1592 - `Background ImagesResponseBackground`
1593
1594 The background parameter used for the image generation. Either `transparent` or `opaque`.
1595
1596 - `const ImagesResponseBackgroundTransparent ImagesResponseBackground = "transparent"`
1597
1598 - `const ImagesResponseBackgroundOpaque ImagesResponseBackground = "opaque"`
1599
1600 - `Data []Image`
1601
1602 The list of generated images.
1603
1604 - `B64JSON string`
1605
1606 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`.
1607
1608 - `RevisedPrompt string`
1609
1610 For `dall-e-3` only, the revised prompt that was used to generate the image.
1611
1612 - `URL string`
1613
1614 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.
1615
1616 - `OutputFormat ImagesResponseOutputFormat`
1617
1618 The output format of the image generation. Either `png`, `webp`, or `jpeg`.
1619
1620 - `const ImagesResponseOutputFormatPNG ImagesResponseOutputFormat = "png"`
1621
1622 - `const ImagesResponseOutputFormatWebP ImagesResponseOutputFormat = "webp"`
1623
1624 - `const ImagesResponseOutputFormatJPEG ImagesResponseOutputFormat = "jpeg"`
1625
1626 - `Quality ImagesResponseQuality`
1627
1628 The quality of the image generated. Either `low`, `medium`, or `high`.
1629
1630 - `const ImagesResponseQualityLow ImagesResponseQuality = "low"`
1631
1632 - `const ImagesResponseQualityMedium ImagesResponseQuality = "medium"`
1633
1634 - `const ImagesResponseQualityHigh ImagesResponseQuality = "high"`
1635
1636 - `Size ImagesResponseSize`
1637
1638 The size of the image generated. Either `1024x1024`, `1024x1536`, or `1536x1024`.
1639
1640 - `const ImagesResponseSize1024x1024 ImagesResponseSize = "1024x1024"`
1641
1642 - `const ImagesResponseSize1024x1536 ImagesResponseSize = "1024x1536"`
1643
1644 - `const ImagesResponseSize1536x1024 ImagesResponseSize = "1536x1024"`
1645
1646 - `Usage ImagesResponseUsage`
1647
1648 For `gpt-image-1` only, the token usage information for the image generation.
1649
1650 - `InputTokens int64`
1651
1652 The number of tokens (images and text) in the input prompt.
1653
1654 - `InputTokensDetails ImagesResponseUsageInputTokensDetails`
1655
1656 The input tokens detailed information for the image generation.
1657
1658 - `ImageTokens int64`
1659
1660 The number of image tokens in the input prompt.
1661
1662 - `TextTokens int64`
1663
1664 The number of text tokens in the input prompt.
1665
1666 - `OutputTokens int64`
1667
1668 The number of output tokens generated by the model.
1669
1670 - `TotalTokens int64`
1671
1672 The total number of tokens (images and text) used for the image generation.
1673
1674 - `OutputTokensDetails ImagesResponseUsageOutputTokensDetails`
1675
1676 The output token details for the image generation.
1677
1678 - `ImageTokens int64`
1679
1680 The number of image output tokens generated by the model.
1681
1682 - `TextTokens int64`
1683
1684 The number of text output tokens generated by the model.