python/resources/images/index.md +0 −1821 deleted
File Deleted View Diff
1# Images
2
3## Create image
4
5`images.generate(ImageGenerateParams**kwargs) -> ImagesResponse`
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- `prompt: str`
14
15 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`.
16
17- `background: Optional[Literal["transparent", "opaque", "auto"]]`
18
19 Allows to set transparency for the background of the generated image(s).
20 This parameter is only supported for GPT image models that support
21 transparent backgrounds. Must be one of `transparent`, `opaque`, or
22 `auto` (default value). When `auto` is used, the model will
23 automatically determine the best background for the image.
24
25 `gpt-image-2` and `gpt-image-2-2026-04-21` do not support
26 transparent backgrounds. Requests with `background` set to
27 `transparent` will return an error for these models; use `opaque` or
28 `auto` instead.
29
30 If `transparent`, the output format needs to support transparency,
31 so it should be set to either `png` (default value) or `webp`.
32
33 - `"transparent"`
34
35 - `"opaque"`
36
37 - `"auto"`
38
39- `model: Optional[Union[str, ImageModel, null]]`
40
41 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.
42
43 - `str`
44
45 - `Literal["gpt-image-1", "gpt-image-1-mini", "gpt-image-2", 5 more]`
46
47 - `"gpt-image-1"`
48
49 - `"gpt-image-1-mini"`
50
51 - `"gpt-image-2"`
52
53 - `"gpt-image-2-2026-04-21"`
54
55 - `"gpt-image-1.5"`
56
57 - `"chatgpt-image-latest"`
58
59 - `"dall-e-2"`
60
61 - `"dall-e-3"`
62
63- `moderation: Optional[Literal["low", "auto"]]`
64
65 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).
66
67 - `"low"`
68
69 - `"auto"`
70
71- `n: Optional[int]`
72
73 The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only `n=1` is supported.
74
75- `output_compression: Optional[int]`
76
77 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.
78
79- `output_format: Optional[Literal["png", "jpeg", "webp"]]`
80
81 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`.
82
83 - `"png"`
84
85 - `"jpeg"`
86
87 - `"webp"`
88
89- `partial_images: Optional[int]`
90
91 The number of partial images to generate. This parameter is used for
92 streaming responses that return partial images. Value must be between 0 and 3.
93 When set to 0, the response will be a single image sent in one streaming event.
94
95 Note that the final image may be sent before the full number of partial images
96 are generated if the full image is generated more quickly.
97
98- `quality: Optional[Literal["standard", "hd", "low", 3 more]]`
99
100 The quality of the image that will be generated.
101
102 - `auto` (default value) will automatically select the best quality for the given model.
103 - `high`, `medium` and `low` are supported for the GPT image models.
104 - `hd` and `standard` are supported for `dall-e-3`.
105 - `standard` is the only option for `dall-e-2`.
106
107 - `"standard"`
108
109 - `"hd"`
110
111 - `"low"`
112
113 - `"medium"`
114
115 - `"high"`
116
117 - `"auto"`
118
119- `response_format: Optional[Literal["url", "b64_json"]]`
120
121 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.
122
123 - `"url"`
124
125 - `"b64_json"`
126
127- `size: Optional[Union[str, Literal["auto", "1024x1024", "1536x1024", 5 more], null]]`
128
129 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`.
130
131 - `str`
132
133 - `Literal["auto", "1024x1024", "1536x1024", 5 more]`
134
135 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`.
136
137 - `"auto"`
138
139 - `"1024x1024"`
140
141 - `"1536x1024"`
142
143 - `"1024x1536"`
144
145 - `"256x256"`
146
147 - `"512x512"`
148
149 - `"1792x1024"`
150
151 - `"1024x1792"`
152
153- `stream: Optional[Literal[false]]`
154
155 Generate the image in streaming mode. Defaults to `false`. See the
156 [Image generation guide](https://platform.openai.com/docs/guides/image-generation) for more information.
157 This parameter is only supported for the GPT image models.
158
159 - `false`
160
161- `style: Optional[Literal["vivid", "natural"]]`
162
163 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.
164
165 - `"vivid"`
166
167 - `"natural"`
168
169- `user: Optional[str]`
170
171 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).
172
173### Returns
174
175- `class ImagesResponse: …`
176
177 The response from the image generation endpoint.
178
179 - `created: int`
180
181 The Unix timestamp (in seconds) of when the image was created.
182
183 - `background: Optional[Literal["transparent", "opaque"]]`
184
185 The background parameter used for the image generation. Either `transparent` or `opaque`.
186
187 - `"transparent"`
188
189 - `"opaque"`
190
191 - `data: Optional[List[Image]]`
192
193 The list of generated images.
194
195 - `b64_json: Optional[str]`
196
197 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`.
198
199 - `revised_prompt: Optional[str]`
200
201 For `dall-e-3` only, the revised prompt that was used to generate the image.
202
203 - `url: Optional[str]`
204
205 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.
206
207 - `output_format: Optional[Literal["png", "webp", "jpeg"]]`
208
209 The output format of the image generation. Either `png`, `webp`, or `jpeg`.
210
211 - `"png"`
212
213 - `"webp"`
214
215 - `"jpeg"`
216
217 - `quality: Optional[Literal["low", "medium", "high"]]`
218
219 The quality of the image generated. Either `low`, `medium`, or `high`.
220
221 - `"low"`
222
223 - `"medium"`
224
225 - `"high"`
226
227 - `size: Optional[Literal["1024x1024", "1024x1536", "1536x1024"]]`
228
229 The size of the image generated. Either `1024x1024`, `1024x1536`, or `1536x1024`.
230
231 - `"1024x1024"`
232
233 - `"1024x1536"`
234
235 - `"1536x1024"`
236
237 - `usage: Optional[Usage]`
238
239 For `gpt-image-1` only, the token usage information for the image generation.
240
241 - `input_tokens: int`
242
243 The number of tokens (images and text) in the input prompt.
244
245 - `input_tokens_details: UsageInputTokensDetails`
246
247 The input tokens detailed information for the image generation.
248
249 - `image_tokens: int`
250
251 The number of image tokens in the input prompt.
252
253 - `text_tokens: int`
254
255 The number of text tokens in the input prompt.
256
257 - `output_tokens: int`
258
259 The number of output tokens generated by the model.
260
261 - `total_tokens: int`
262
263 The total number of tokens (images and text) used for the image generation.
264
265 - `output_tokens_details: Optional[UsageOutputTokensDetails]`
266
267 The output token details for the image generation.
268
269 - `image_tokens: int`
270
271 The number of image output tokens generated by the model.
272
273 - `text_tokens: int`
274
275 The number of text output tokens generated by the model.
276
277### Example
278
279```python
280import os
281from openai import OpenAI
282
283client = OpenAI(
284 api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
285)
286for image in client.images.generate(
287 prompt="A cute baby sea otter",
288):
289 print(image)
290```
291
292#### Response
293
294```json
295{
296 "created": 0,
297 "background": "transparent",
298 "data": [
299 {
300 "b64_json": "b64_json",
301 "revised_prompt": "revised_prompt",
302 "url": "https://example.com"
303 }
304 ],
305 "output_format": "png",
306 "quality": "low",
307 "size": "1024x1024",
308 "usage": {
309 "input_tokens": 0,
310 "input_tokens_details": {
311 "image_tokens": 0,
312 "text_tokens": 0
313 },
314 "output_tokens": 0,
315 "total_tokens": 0,
316 "output_tokens_details": {
317 "image_tokens": 0,
318 "text_tokens": 0
319 }
320 }
321}
322```
323
324### Generate image
325
326```python
327import base64
328from openai import OpenAI
329client = OpenAI()
330
331img = client.images.generate(
332 model="gpt-image-1.5",
333 prompt="A cute baby sea otter",
334 n=1,
335 size="1024x1024"
336)
337
338image_bytes = base64.b64decode(img.data[0].b64_json)
339with open("output.png", "wb") as f:
340 f.write(image_bytes)
341```
342
343#### Response
344
345```json
346{
347 "created": 1713833628,
348 "data": [
349 {
350 "b64_json": "..."
351 }
352 ],
353 "usage": {
354 "total_tokens": 100,
355 "input_tokens": 50,
356 "output_tokens": 50,
357 "input_tokens_details": {
358 "text_tokens": 10,
359 "image_tokens": 40
360 }
361 }
362}
363```
364
365### Streaming
366
367```python
368from openai import OpenAI
369
370client = OpenAI()
371
372stream = client.images.generate(
373 model="gpt-image-1.5",
374 prompt="A cute baby sea otter",
375 n=1,
376 size="1024x1024",
377 stream=True
378)
379
380for event in stream:
381 print(event)
382```
383
384#### Response
385
386```json
387event: image_generation.partial_image
388data: {"type":"image_generation.partial_image","b64_json":"...","partial_image_index":0}
389
390event: image_generation.completed
391data: {"type":"image_generation.completed","b64_json":"...","usage":{"total_tokens":100,"input_tokens":50,"output_tokens":50,"input_tokens_details":{"text_tokens":10,"image_tokens":40}}}
392```
393
394## Create image edit
395
396`images.edit(ImageEditParams**kwargs) -> ImagesResponse`
397
398**post** `/images/edits`
399
400Creates 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`.
401
402### Parameters
403
404- `image: Union[FileTypes, Sequence[FileTypes]]`
405
406 The image(s) to edit. Must be a supported image file or an array of images.
407
408 For the GPT image models (`gpt-image-1`, `gpt-image-1-mini`,
409 `gpt-image-1.5`, `gpt-image-2`, `gpt-image-2-2026-04-21`, and
410 `chatgpt-image-latest`), each image should be a `png`, `webp`, or
411 `jpg` file less than 50MB. You can provide up to 16 images.
412
413 For `dall-e-2`, you can only provide one image, and it should be a
414 square `png` file less than 4MB.
415
416 - `FileTypes`
417
418 - `Sequence[FileTypes]`
419
420- `prompt: str`
421
422 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.
423
424- `background: Optional[Literal["transparent", "opaque", "auto"]]`
425
426 Allows to set transparency for the background of the generated image(s).
427 This parameter is only supported for GPT image models that support
428 transparent backgrounds. Must be one of `transparent`, `opaque`, or
429 `auto` (default value). When `auto` is used, the model will
430 automatically determine the best background for the image.
431
432 `gpt-image-2` and `gpt-image-2-2026-04-21` do not support
433 transparent backgrounds. Requests with `background` set to
434 `transparent` will return an error for these models; use `opaque` or
435 `auto` instead.
436
437 If `transparent`, the output format needs to support transparency,
438 so it should be set to either `png` (default value) or `webp`.
439
440 - `"transparent"`
441
442 - `"opaque"`
443
444 - `"auto"`
445
446- `input_fidelity: Optional[Literal["high", "low"]]`
447
448 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`.
449
450 - `"high"`
451
452 - `"low"`
453
454- `mask: Optional[FileTypes]`
455
456 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`.
457
458- `model: Optional[Union[str, ImageModel, null]]`
459
460 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`.
461
462 - `str`
463
464 - `Literal["gpt-image-1", "gpt-image-1-mini", "gpt-image-2", 5 more]`
465
466 - `"gpt-image-1"`
467
468 - `"gpt-image-1-mini"`
469
470 - `"gpt-image-2"`
471
472 - `"gpt-image-2-2026-04-21"`
473
474 - `"gpt-image-1.5"`
475
476 - `"chatgpt-image-latest"`
477
478 - `"dall-e-2"`
479
480 - `"dall-e-3"`
481
482- `n: Optional[int]`
483
484 The number of images to generate. Must be between 1 and 10.
485
486- `output_compression: Optional[int]`
487
488 The compression level (0-100%) for the generated images. This parameter
489 is only supported for the GPT image models with the `webp` or `jpeg` output
490 formats, and defaults to 100.
491
492- `output_format: Optional[Literal["png", "jpeg", "webp"]]`
493
494 The format in which the generated images are returned. This parameter is
495 only supported for the GPT image models. Must be one of `png`, `jpeg`, or `webp`.
496 The default value is `png`.
497
498 - `"png"`
499
500 - `"jpeg"`
501
502 - `"webp"`
503
504- `partial_images: Optional[int]`
505
506 The number of partial images to generate. This parameter is used for
507 streaming responses that return partial images. Value must be between 0 and 3.
508 When set to 0, the response will be a single image sent in one streaming event.
509
510 Note that the final image may be sent before the full number of partial images
511 are generated if the full image is generated more quickly.
512
513- `quality: Optional[Literal["standard", "low", "medium", 2 more]]`
514
515 The quality of the image that will be generated for GPT image models. Defaults to `auto`.
516
517 - `"standard"`
518
519 - `"low"`
520
521 - `"medium"`
522
523 - `"high"`
524
525 - `"auto"`
526
527- `response_format: Optional[Literal["url", "b64_json"]]`
528
529 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.
530
531 - `"url"`
532
533 - `"b64_json"`
534
535- `size: Optional[Union[str, Literal["256x256", "512x512", "1024x1024", 3 more], null]]`
536
537 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`.
538
539 - `str`
540
541 - `Literal["256x256", "512x512", "1024x1024", 3 more]`
542
543 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`.
544
545 - `"256x256"`
546
547 - `"512x512"`
548
549 - `"1024x1024"`
550
551 - `"1536x1024"`
552
553 - `"1024x1536"`
554
555 - `"auto"`
556
557- `stream: Optional[Literal[false]]`
558
559 Edit the image in streaming mode. Defaults to `false`. See the
560 [Image generation guide](https://platform.openai.com/docs/guides/image-generation) for more information.
561
562 - `false`
563
564- `user: Optional[str]`
565
566 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).
567
568### Returns
569
570- `class ImagesResponse: …`
571
572 The response from the image generation endpoint.
573
574 - `created: int`
575
576 The Unix timestamp (in seconds) of when the image was created.
577
578 - `background: Optional[Literal["transparent", "opaque"]]`
579
580 The background parameter used for the image generation. Either `transparent` or `opaque`.
581
582 - `"transparent"`
583
584 - `"opaque"`
585
586 - `data: Optional[List[Image]]`
587
588 The list of generated images.
589
590 - `b64_json: Optional[str]`
591
592 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`.
593
594 - `revised_prompt: Optional[str]`
595
596 For `dall-e-3` only, the revised prompt that was used to generate the image.
597
598 - `url: Optional[str]`
599
600 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.
601
602 - `output_format: Optional[Literal["png", "webp", "jpeg"]]`
603
604 The output format of the image generation. Either `png`, `webp`, or `jpeg`.
605
606 - `"png"`
607
608 - `"webp"`
609
610 - `"jpeg"`
611
612 - `quality: Optional[Literal["low", "medium", "high"]]`
613
614 The quality of the image generated. Either `low`, `medium`, or `high`.
615
616 - `"low"`
617
618 - `"medium"`
619
620 - `"high"`
621
622 - `size: Optional[Literal["1024x1024", "1024x1536", "1536x1024"]]`
623
624 The size of the image generated. Either `1024x1024`, `1024x1536`, or `1536x1024`.
625
626 - `"1024x1024"`
627
628 - `"1024x1536"`
629
630 - `"1536x1024"`
631
632 - `usage: Optional[Usage]`
633
634 For `gpt-image-1` only, the token usage information for the image generation.
635
636 - `input_tokens: int`
637
638 The number of tokens (images and text) in the input prompt.
639
640 - `input_tokens_details: UsageInputTokensDetails`
641
642 The input tokens detailed information for the image generation.
643
644 - `image_tokens: int`
645
646 The number of image tokens in the input prompt.
647
648 - `text_tokens: int`
649
650 The number of text tokens in the input prompt.
651
652 - `output_tokens: int`
653
654 The number of output tokens generated by the model.
655
656 - `total_tokens: int`
657
658 The total number of tokens (images and text) used for the image generation.
659
660 - `output_tokens_details: Optional[UsageOutputTokensDetails]`
661
662 The output token details for the image generation.
663
664 - `image_tokens: int`
665
666 The number of image output tokens generated by the model.
667
668 - `text_tokens: int`
669
670 The number of text output tokens generated by the model.
671
672### Example
673
674```python
675import os
676from openai import OpenAI
677
678client = OpenAI(
679 api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
680)
681for image in client.images.edit(
682 image=b"Example data",
683 prompt="A cute baby sea otter wearing a beret",
684):
685 print(image)
686```
687
688#### Response
689
690```json
691{
692 "created": 0,
693 "background": "transparent",
694 "data": [
695 {
696 "b64_json": "b64_json",
697 "revised_prompt": "revised_prompt",
698 "url": "https://example.com"
699 }
700 ],
701 "output_format": "png",
702 "quality": "low",
703 "size": "1024x1024",
704 "usage": {
705 "input_tokens": 0,
706 "input_tokens_details": {
707 "image_tokens": 0,
708 "text_tokens": 0
709 },
710 "output_tokens": 0,
711 "total_tokens": 0,
712 "output_tokens_details": {
713 "image_tokens": 0,
714 "text_tokens": 0
715 }
716 }
717}
718```
719
720### Edit image
721
722```python
723import base64
724from openai import OpenAI
725client = OpenAI()
726
727prompt = """
728Generate a photorealistic image of a gift basket on a white background
729labeled 'Relax & Unwind' with a ribbon and handwriting-like font,
730containing all the items in the reference pictures.
731"""
732
733result = client.images.edit(
734 model="gpt-image-1.5",
735 image=[
736 open("body-lotion.png", "rb"),
737 open("bath-bomb.png", "rb"),
738 open("incense-kit.png", "rb"),
739 open("soap.png", "rb"),
740 ],
741 prompt=prompt
742)
743
744image_base64 = result.data[0].b64_json
745image_bytes = base64.b64decode(image_base64)
746
747# Save the image to a file
748with open("gift-basket.png", "wb") as f:
749 f.write(image_bytes)
750```
751
752### Streaming
753
754```python
755from openai import OpenAI
756
757client = OpenAI()
758
759prompt = """
760Generate a photorealistic image of a gift basket on a white background
761labeled 'Relax & Unwind' with a ribbon and handwriting-like font,
762containing all the items in the reference pictures.
763"""
764
765stream = client.images.edit(
766 model="gpt-image-1.5",
767 image=[
768 open("body-lotion.png", "rb"),
769 open("bath-bomb.png", "rb"),
770 open("incense-kit.png", "rb"),
771 open("soap.png", "rb"),
772 ],
773 prompt=prompt,
774 stream=True
775)
776
777for event in stream:
778 print(event)
779```
780
781#### Response
782
783```json
784event: image_edit.partial_image
785data: {"type":"image_edit.partial_image","b64_json":"...","partial_image_index":0}
786
787event: image_edit.completed
788data: {"type":"image_edit.completed","b64_json":"...","usage":{"total_tokens":100,"input_tokens":50,"output_tokens":50,"input_tokens_details":{"text_tokens":10,"image_tokens":40}}}
789```
790
791## Create image variation
792
793`images.create_variation(ImageCreateVariationParams**kwargs) -> ImagesResponse`
794
795**post** `/images/variations`
796
797Creates a variation of a given image. This endpoint only supports `dall-e-2`.
798
799### Parameters
800
801- `image: FileTypes`
802
803 The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square.
804
805- `model: Optional[Union[str, ImageModel, null]]`
806
807 The model to use for image generation. Only `dall-e-2` is supported at this time.
808
809 - `str`
810
811 - `Literal["gpt-image-1", "gpt-image-1-mini", "gpt-image-2", 5 more]`
812
813 - `"gpt-image-1"`
814
815 - `"gpt-image-1-mini"`
816
817 - `"gpt-image-2"`
818
819 - `"gpt-image-2-2026-04-21"`
820
821 - `"gpt-image-1.5"`
822
823 - `"chatgpt-image-latest"`
824
825 - `"dall-e-2"`
826
827 - `"dall-e-3"`
828
829- `n: Optional[int]`
830
831 The number of images to generate. Must be between 1 and 10.
832
833- `response_format: Optional[Literal["url", "b64_json"]]`
834
835 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.
836
837 - `"url"`
838
839 - `"b64_json"`
840
841- `size: Optional[Literal["256x256", "512x512", "1024x1024"]]`
842
843 The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`.
844
845 - `"256x256"`
846
847 - `"512x512"`
848
849 - `"1024x1024"`
850
851- `user: Optional[str]`
852
853 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).
854
855### Returns
856
857- `class ImagesResponse: …`
858
859 The response from the image generation endpoint.
860
861 - `created: int`
862
863 The Unix timestamp (in seconds) of when the image was created.
864
865 - `background: Optional[Literal["transparent", "opaque"]]`
866
867 The background parameter used for the image generation. Either `transparent` or `opaque`.
868
869 - `"transparent"`
870
871 - `"opaque"`
872
873 - `data: Optional[List[Image]]`
874
875 The list of generated images.
876
877 - `b64_json: Optional[str]`
878
879 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`.
880
881 - `revised_prompt: Optional[str]`
882
883 For `dall-e-3` only, the revised prompt that was used to generate the image.
884
885 - `url: Optional[str]`
886
887 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.
888
889 - `output_format: Optional[Literal["png", "webp", "jpeg"]]`
890
891 The output format of the image generation. Either `png`, `webp`, or `jpeg`.
892
893 - `"png"`
894
895 - `"webp"`
896
897 - `"jpeg"`
898
899 - `quality: Optional[Literal["low", "medium", "high"]]`
900
901 The quality of the image generated. Either `low`, `medium`, or `high`.
902
903 - `"low"`
904
905 - `"medium"`
906
907 - `"high"`
908
909 - `size: Optional[Literal["1024x1024", "1024x1536", "1536x1024"]]`
910
911 The size of the image generated. Either `1024x1024`, `1024x1536`, or `1536x1024`.
912
913 - `"1024x1024"`
914
915 - `"1024x1536"`
916
917 - `"1536x1024"`
918
919 - `usage: Optional[Usage]`
920
921 For `gpt-image-1` only, the token usage information for the image generation.
922
923 - `input_tokens: int`
924
925 The number of tokens (images and text) in the input prompt.
926
927 - `input_tokens_details: UsageInputTokensDetails`
928
929 The input tokens detailed information for the image generation.
930
931 - `image_tokens: int`
932
933 The number of image tokens in the input prompt.
934
935 - `text_tokens: int`
936
937 The number of text tokens in the input prompt.
938
939 - `output_tokens: int`
940
941 The number of output tokens generated by the model.
942
943 - `total_tokens: int`
944
945 The total number of tokens (images and text) used for the image generation.
946
947 - `output_tokens_details: Optional[UsageOutputTokensDetails]`
948
949 The output token details for the image generation.
950
951 - `image_tokens: int`
952
953 The number of image output tokens generated by the model.
954
955 - `text_tokens: int`
956
957 The number of text output tokens generated by the model.
958
959### Example
960
961```python
962import os
963from openai import OpenAI
964
965client = OpenAI(
966 api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
967)
968images_response = client.images.create_variation(
969 image=b"Example data",
970)
971print(images_response.created)
972```
973
974#### Response
975
976```json
977{
978 "created": 0,
979 "background": "transparent",
980 "data": [
981 {
982 "b64_json": "b64_json",
983 "revised_prompt": "revised_prompt",
984 "url": "https://example.com"
985 }
986 ],
987 "output_format": "png",
988 "quality": "low",
989 "size": "1024x1024",
990 "usage": {
991 "input_tokens": 0,
992 "input_tokens_details": {
993 "image_tokens": 0,
994 "text_tokens": 0
995 },
996 "output_tokens": 0,
997 "total_tokens": 0,
998 "output_tokens_details": {
999 "image_tokens": 0,
1000 "text_tokens": 0
1001 }
1002 }
1003}
1004```
1005
1006### Example
1007
1008```python
1009from openai import OpenAI
1010client = OpenAI()
1011
1012response = client.images.create_variation(
1013 image=open("image_edit_original.png", "rb"),
1014 n=2,
1015 size="1024x1024"
1016)
1017```
1018
1019#### Response
1020
1021```json
1022{
1023 "created": 1589478378,
1024 "data": [
1025 {
1026 "url": "https://..."
1027 },
1028 {
1029 "url": "https://..."
1030 }
1031 ]
1032}
1033```
1034
1035## Domain Types
1036
1037### Image
1038
1039- `class Image: …`
1040
1041 Represents the content or the URL of an image generated by the OpenAI API.
1042
1043 - `b64_json: Optional[str]`
1044
1045 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`.
1046
1047 - `revised_prompt: Optional[str]`
1048
1049 For `dall-e-3` only, the revised prompt that was used to generate the image.
1050
1051 - `url: Optional[str]`
1052
1053 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.
1054
1055### Image Edit Completed Event
1056
1057- `class ImageEditCompletedEvent: …`
1058
1059 Emitted when image editing has completed and the final image is available.
1060
1061 - `b64_json: str`
1062
1063 Base64-encoded final edited image data, suitable for rendering as an image.
1064
1065 - `background: Literal["transparent", "opaque", "auto"]`
1066
1067 The background setting for the edited image.
1068
1069 - `"transparent"`
1070
1071 - `"opaque"`
1072
1073 - `"auto"`
1074
1075 - `created_at: int`
1076
1077 The Unix timestamp when the event was created.
1078
1079 - `output_format: Literal["png", "webp", "jpeg"]`
1080
1081 The output format for the edited image.
1082
1083 - `"png"`
1084
1085 - `"webp"`
1086
1087 - `"jpeg"`
1088
1089 - `quality: Literal["low", "medium", "high", "auto"]`
1090
1091 The quality setting for the edited image.
1092
1093 - `"low"`
1094
1095 - `"medium"`
1096
1097 - `"high"`
1098
1099 - `"auto"`
1100
1101 - `size: Literal["1024x1024", "1024x1536", "1536x1024", "auto"]`
1102
1103 The size of the edited image.
1104
1105 - `"1024x1024"`
1106
1107 - `"1024x1536"`
1108
1109 - `"1536x1024"`
1110
1111 - `"auto"`
1112
1113 - `type: Literal["image_edit.completed"]`
1114
1115 The type of the event. Always `image_edit.completed`.
1116
1117 - `"image_edit.completed"`
1118
1119 - `usage: Usage`
1120
1121 For the GPT image models only, the token usage information for the image generation.
1122
1123 - `input_tokens: int`
1124
1125 The number of tokens (images and text) in the input prompt.
1126
1127 - `input_tokens_details: UsageInputTokensDetails`
1128
1129 The input tokens detailed information for the image generation.
1130
1131 - `image_tokens: int`
1132
1133 The number of image tokens in the input prompt.
1134
1135 - `text_tokens: int`
1136
1137 The number of text tokens in the input prompt.
1138
1139 - `output_tokens: int`
1140
1141 The number of image tokens in the output image.
1142
1143 - `total_tokens: int`
1144
1145 The total number of tokens (images and text) used for the image generation.
1146
1147### Image Edit Partial Image Event
1148
1149- `class ImageEditPartialImageEvent: …`
1150
1151 Emitted when a partial image is available during image editing streaming.
1152
1153 - `b64_json: str`
1154
1155 Base64-encoded partial image data, suitable for rendering as an image.
1156
1157 - `background: Literal["transparent", "opaque", "auto"]`
1158
1159 The background setting for the requested edited image.
1160
1161 - `"transparent"`
1162
1163 - `"opaque"`
1164
1165 - `"auto"`
1166
1167 - `created_at: int`
1168
1169 The Unix timestamp when the event was created.
1170
1171 - `output_format: Literal["png", "webp", "jpeg"]`
1172
1173 The output format for the requested edited image.
1174
1175 - `"png"`
1176
1177 - `"webp"`
1178
1179 - `"jpeg"`
1180
1181 - `partial_image_index: int`
1182
1183 0-based index for the partial image (streaming).
1184
1185 - `quality: Literal["low", "medium", "high", "auto"]`
1186
1187 The quality setting for the requested edited image.
1188
1189 - `"low"`
1190
1191 - `"medium"`
1192
1193 - `"high"`
1194
1195 - `"auto"`
1196
1197 - `size: Literal["1024x1024", "1024x1536", "1536x1024", "auto"]`
1198
1199 The size of the requested edited image.
1200
1201 - `"1024x1024"`
1202
1203 - `"1024x1536"`
1204
1205 - `"1536x1024"`
1206
1207 - `"auto"`
1208
1209 - `type: Literal["image_edit.partial_image"]`
1210
1211 The type of the event. Always `image_edit.partial_image`.
1212
1213 - `"image_edit.partial_image"`
1214
1215### Image Edit Stream Event
1216
1217- `ImageEditStreamEvent`
1218
1219 Emitted when a partial image is available during image editing streaming.
1220
1221 - `class ImageEditPartialImageEvent: …`
1222
1223 Emitted when a partial image is available during image editing streaming.
1224
1225 - `b64_json: str`
1226
1227 Base64-encoded partial image data, suitable for rendering as an image.
1228
1229 - `background: Literal["transparent", "opaque", "auto"]`
1230
1231 The background setting for the requested edited image.
1232
1233 - `"transparent"`
1234
1235 - `"opaque"`
1236
1237 - `"auto"`
1238
1239 - `created_at: int`
1240
1241 The Unix timestamp when the event was created.
1242
1243 - `output_format: Literal["png", "webp", "jpeg"]`
1244
1245 The output format for the requested edited image.
1246
1247 - `"png"`
1248
1249 - `"webp"`
1250
1251 - `"jpeg"`
1252
1253 - `partial_image_index: int`
1254
1255 0-based index for the partial image (streaming).
1256
1257 - `quality: Literal["low", "medium", "high", "auto"]`
1258
1259 The quality setting for the requested edited image.
1260
1261 - `"low"`
1262
1263 - `"medium"`
1264
1265 - `"high"`
1266
1267 - `"auto"`
1268
1269 - `size: Literal["1024x1024", "1024x1536", "1536x1024", "auto"]`
1270
1271 The size of the requested edited image.
1272
1273 - `"1024x1024"`
1274
1275 - `"1024x1536"`
1276
1277 - `"1536x1024"`
1278
1279 - `"auto"`
1280
1281 - `type: Literal["image_edit.partial_image"]`
1282
1283 The type of the event. Always `image_edit.partial_image`.
1284
1285 - `"image_edit.partial_image"`
1286
1287 - `class ImageEditCompletedEvent: …`
1288
1289 Emitted when image editing has completed and the final image is available.
1290
1291 - `b64_json: str`
1292
1293 Base64-encoded final edited image data, suitable for rendering as an image.
1294
1295 - `background: Literal["transparent", "opaque", "auto"]`
1296
1297 The background setting for the edited image.
1298
1299 - `"transparent"`
1300
1301 - `"opaque"`
1302
1303 - `"auto"`
1304
1305 - `created_at: int`
1306
1307 The Unix timestamp when the event was created.
1308
1309 - `output_format: Literal["png", "webp", "jpeg"]`
1310
1311 The output format for the edited image.
1312
1313 - `"png"`
1314
1315 - `"webp"`
1316
1317 - `"jpeg"`
1318
1319 - `quality: Literal["low", "medium", "high", "auto"]`
1320
1321 The quality setting for the edited image.
1322
1323 - `"low"`
1324
1325 - `"medium"`
1326
1327 - `"high"`
1328
1329 - `"auto"`
1330
1331 - `size: Literal["1024x1024", "1024x1536", "1536x1024", "auto"]`
1332
1333 The size of the edited image.
1334
1335 - `"1024x1024"`
1336
1337 - `"1024x1536"`
1338
1339 - `"1536x1024"`
1340
1341 - `"auto"`
1342
1343 - `type: Literal["image_edit.completed"]`
1344
1345 The type of the event. Always `image_edit.completed`.
1346
1347 - `"image_edit.completed"`
1348
1349 - `usage: Usage`
1350
1351 For the GPT image models only, the token usage information for the image generation.
1352
1353 - `input_tokens: int`
1354
1355 The number of tokens (images and text) in the input prompt.
1356
1357 - `input_tokens_details: UsageInputTokensDetails`
1358
1359 The input tokens detailed information for the image generation.
1360
1361 - `image_tokens: int`
1362
1363 The number of image tokens in the input prompt.
1364
1365 - `text_tokens: int`
1366
1367 The number of text tokens in the input prompt.
1368
1369 - `output_tokens: int`
1370
1371 The number of image tokens in the output image.
1372
1373 - `total_tokens: int`
1374
1375 The total number of tokens (images and text) used for the image generation.
1376
1377### Image Gen Completed Event
1378
1379- `class ImageGenCompletedEvent: …`
1380
1381 Emitted when image generation has completed and the final image is available.
1382
1383 - `b64_json: str`
1384
1385 Base64-encoded image data, suitable for rendering as an image.
1386
1387 - `background: Literal["transparent", "opaque", "auto"]`
1388
1389 The background setting for the generated image.
1390
1391 - `"transparent"`
1392
1393 - `"opaque"`
1394
1395 - `"auto"`
1396
1397 - `created_at: int`
1398
1399 The Unix timestamp when the event was created.
1400
1401 - `output_format: Literal["png", "webp", "jpeg"]`
1402
1403 The output format for the generated image.
1404
1405 - `"png"`
1406
1407 - `"webp"`
1408
1409 - `"jpeg"`
1410
1411 - `quality: Literal["low", "medium", "high", "auto"]`
1412
1413 The quality setting for the generated image.
1414
1415 - `"low"`
1416
1417 - `"medium"`
1418
1419 - `"high"`
1420
1421 - `"auto"`
1422
1423 - `size: Literal["1024x1024", "1024x1536", "1536x1024", "auto"]`
1424
1425 The size of the generated image.
1426
1427 - `"1024x1024"`
1428
1429 - `"1024x1536"`
1430
1431 - `"1536x1024"`
1432
1433 - `"auto"`
1434
1435 - `type: Literal["image_generation.completed"]`
1436
1437 The type of the event. Always `image_generation.completed`.
1438
1439 - `"image_generation.completed"`
1440
1441 - `usage: Usage`
1442
1443 For the GPT image models only, the token usage information for the image generation.
1444
1445 - `input_tokens: int`
1446
1447 The number of tokens (images and text) in the input prompt.
1448
1449 - `input_tokens_details: UsageInputTokensDetails`
1450
1451 The input tokens detailed information for the image generation.
1452
1453 - `image_tokens: int`
1454
1455 The number of image tokens in the input prompt.
1456
1457 - `text_tokens: int`
1458
1459 The number of text tokens in the input prompt.
1460
1461 - `output_tokens: int`
1462
1463 The number of image tokens in the output image.
1464
1465 - `total_tokens: int`
1466
1467 The total number of tokens (images and text) used for the image generation.
1468
1469### Image Gen Partial Image Event
1470
1471- `class ImageGenPartialImageEvent: …`
1472
1473 Emitted when a partial image is available during image generation streaming.
1474
1475 - `b64_json: str`
1476
1477 Base64-encoded partial image data, suitable for rendering as an image.
1478
1479 - `background: Literal["transparent", "opaque", "auto"]`
1480
1481 The background setting for the requested image.
1482
1483 - `"transparent"`
1484
1485 - `"opaque"`
1486
1487 - `"auto"`
1488
1489 - `created_at: int`
1490
1491 The Unix timestamp when the event was created.
1492
1493 - `output_format: Literal["png", "webp", "jpeg"]`
1494
1495 The output format for the requested image.
1496
1497 - `"png"`
1498
1499 - `"webp"`
1500
1501 - `"jpeg"`
1502
1503 - `partial_image_index: int`
1504
1505 0-based index for the partial image (streaming).
1506
1507 - `quality: Literal["low", "medium", "high", "auto"]`
1508
1509 The quality setting for the requested image.
1510
1511 - `"low"`
1512
1513 - `"medium"`
1514
1515 - `"high"`
1516
1517 - `"auto"`
1518
1519 - `size: Literal["1024x1024", "1024x1536", "1536x1024", "auto"]`
1520
1521 The size of the requested image.
1522
1523 - `"1024x1024"`
1524
1525 - `"1024x1536"`
1526
1527 - `"1536x1024"`
1528
1529 - `"auto"`
1530
1531 - `type: Literal["image_generation.partial_image"]`
1532
1533 The type of the event. Always `image_generation.partial_image`.
1534
1535 - `"image_generation.partial_image"`
1536
1537### Image Gen Stream Event
1538
1539- `ImageGenStreamEvent`
1540
1541 Emitted when a partial image is available during image generation streaming.
1542
1543 - `class ImageGenPartialImageEvent: …`
1544
1545 Emitted when a partial image is available during image generation streaming.
1546
1547 - `b64_json: str`
1548
1549 Base64-encoded partial image data, suitable for rendering as an image.
1550
1551 - `background: Literal["transparent", "opaque", "auto"]`
1552
1553 The background setting for the requested image.
1554
1555 - `"transparent"`
1556
1557 - `"opaque"`
1558
1559 - `"auto"`
1560
1561 - `created_at: int`
1562
1563 The Unix timestamp when the event was created.
1564
1565 - `output_format: Literal["png", "webp", "jpeg"]`
1566
1567 The output format for the requested image.
1568
1569 - `"png"`
1570
1571 - `"webp"`
1572
1573 - `"jpeg"`
1574
1575 - `partial_image_index: int`
1576
1577 0-based index for the partial image (streaming).
1578
1579 - `quality: Literal["low", "medium", "high", "auto"]`
1580
1581 The quality setting for the requested image.
1582
1583 - `"low"`
1584
1585 - `"medium"`
1586
1587 - `"high"`
1588
1589 - `"auto"`
1590
1591 - `size: Literal["1024x1024", "1024x1536", "1536x1024", "auto"]`
1592
1593 The size of the requested image.
1594
1595 - `"1024x1024"`
1596
1597 - `"1024x1536"`
1598
1599 - `"1536x1024"`
1600
1601 - `"auto"`
1602
1603 - `type: Literal["image_generation.partial_image"]`
1604
1605 The type of the event. Always `image_generation.partial_image`.
1606
1607 - `"image_generation.partial_image"`
1608
1609 - `class ImageGenCompletedEvent: …`
1610
1611 Emitted when image generation has completed and the final image is available.
1612
1613 - `b64_json: str`
1614
1615 Base64-encoded image data, suitable for rendering as an image.
1616
1617 - `background: Literal["transparent", "opaque", "auto"]`
1618
1619 The background setting for the generated image.
1620
1621 - `"transparent"`
1622
1623 - `"opaque"`
1624
1625 - `"auto"`
1626
1627 - `created_at: int`
1628
1629 The Unix timestamp when the event was created.
1630
1631 - `output_format: Literal["png", "webp", "jpeg"]`
1632
1633 The output format for the generated image.
1634
1635 - `"png"`
1636
1637 - `"webp"`
1638
1639 - `"jpeg"`
1640
1641 - `quality: Literal["low", "medium", "high", "auto"]`
1642
1643 The quality setting for the generated image.
1644
1645 - `"low"`
1646
1647 - `"medium"`
1648
1649 - `"high"`
1650
1651 - `"auto"`
1652
1653 - `size: Literal["1024x1024", "1024x1536", "1536x1024", "auto"]`
1654
1655 The size of the generated image.
1656
1657 - `"1024x1024"`
1658
1659 - `"1024x1536"`
1660
1661 - `"1536x1024"`
1662
1663 - `"auto"`
1664
1665 - `type: Literal["image_generation.completed"]`
1666
1667 The type of the event. Always `image_generation.completed`.
1668
1669 - `"image_generation.completed"`
1670
1671 - `usage: Usage`
1672
1673 For the GPT image models only, the token usage information for the image generation.
1674
1675 - `input_tokens: int`
1676
1677 The number of tokens (images and text) in the input prompt.
1678
1679 - `input_tokens_details: UsageInputTokensDetails`
1680
1681 The input tokens detailed information for the image generation.
1682
1683 - `image_tokens: int`
1684
1685 The number of image tokens in the input prompt.
1686
1687 - `text_tokens: int`
1688
1689 The number of text tokens in the input prompt.
1690
1691 - `output_tokens: int`
1692
1693 The number of image tokens in the output image.
1694
1695 - `total_tokens: int`
1696
1697 The total number of tokens (images and text) used for the image generation.
1698
1699### Image Model
1700
1701- `Literal["gpt-image-1", "gpt-image-1-mini", "gpt-image-2", 5 more]`
1702
1703 - `"gpt-image-1"`
1704
1705 - `"gpt-image-1-mini"`
1706
1707 - `"gpt-image-2"`
1708
1709 - `"gpt-image-2-2026-04-21"`
1710
1711 - `"gpt-image-1.5"`
1712
1713 - `"chatgpt-image-latest"`
1714
1715 - `"dall-e-2"`
1716
1717 - `"dall-e-3"`
1718
1719### Images Response
1720
1721- `class ImagesResponse: …`
1722
1723 The response from the image generation endpoint.
1724
1725 - `created: int`
1726
1727 The Unix timestamp (in seconds) of when the image was created.
1728
1729 - `background: Optional[Literal["transparent", "opaque"]]`
1730
1731 The background parameter used for the image generation. Either `transparent` or `opaque`.
1732
1733 - `"transparent"`
1734
1735 - `"opaque"`
1736
1737 - `data: Optional[List[Image]]`
1738
1739 The list of generated images.
1740
1741 - `b64_json: Optional[str]`
1742
1743 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`.
1744
1745 - `revised_prompt: Optional[str]`
1746
1747 For `dall-e-3` only, the revised prompt that was used to generate the image.
1748
1749 - `url: Optional[str]`
1750
1751 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.
1752
1753 - `output_format: Optional[Literal["png", "webp", "jpeg"]]`
1754
1755 The output format of the image generation. Either `png`, `webp`, or `jpeg`.
1756
1757 - `"png"`
1758
1759 - `"webp"`
1760
1761 - `"jpeg"`
1762
1763 - `quality: Optional[Literal["low", "medium", "high"]]`
1764
1765 The quality of the image generated. Either `low`, `medium`, or `high`.
1766
1767 - `"low"`
1768
1769 - `"medium"`
1770
1771 - `"high"`
1772
1773 - `size: Optional[Literal["1024x1024", "1024x1536", "1536x1024"]]`
1774
1775 The size of the image generated. Either `1024x1024`, `1024x1536`, or `1536x1024`.
1776
1777 - `"1024x1024"`
1778
1779 - `"1024x1536"`
1780
1781 - `"1536x1024"`
1782
1783 - `usage: Optional[Usage]`
1784
1785 For `gpt-image-1` only, the token usage information for the image generation.
1786
1787 - `input_tokens: int`
1788
1789 The number of tokens (images and text) in the input prompt.
1790
1791 - `input_tokens_details: UsageInputTokensDetails`
1792
1793 The input tokens detailed information for the image generation.
1794
1795 - `image_tokens: int`
1796
1797 The number of image tokens in the input prompt.
1798
1799 - `text_tokens: int`
1800
1801 The number of text tokens in the input prompt.
1802
1803 - `output_tokens: int`
1804
1805 The number of output tokens generated by the model.
1806
1807 - `total_tokens: int`
1808
1809 The total number of tokens (images and text) used for the image generation.
1810
1811 - `output_tokens_details: Optional[UsageOutputTokensDetails]`
1812
1813 The output token details for the image generation.
1814
1815 - `image_tokens: int`
1816
1817 The number of image output tokens generated by the model.
1818
1819 - `text_tokens: int`
1820
1821 The number of text output tokens generated by the model.