cli/resources/images/methods/generate/index.md +0 −227 deleted
File Deleted View Diff
1## Create image
2
3`$ openai images generate`
4
5**post** `/images/generations`
6
7Creates an image given a prompt. [Learn more](https://platform.openai.com/docs/guides/images).
8
9### Parameters
10
11- `--prompt: string`
12
13 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`.
14
15- `--background: optional "transparent" or "opaque" or "auto"`
16
17 Allows to set transparency for the background of the generated image(s).
18 This parameter is only supported for GPT image models that support
19 transparent backgrounds. Must be one of `transparent`, `opaque`, or
20 `auto` (default value). When `auto` is used, the model will
21 automatically determine the best background for the image.
22
23 `gpt-image-2` and `gpt-image-2-2026-04-21` do not support
24 transparent backgrounds. Requests with `background` set to
25 `transparent` will return an error for these models; use `opaque` or
26 `auto` instead.
27
28 If `transparent`, the output format needs to support transparency,
29 so it should be set to either `png` (default value) or `webp`.
30
31- `--model: optional string or ImageModel`
32
33 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.
34
35- `--moderation: optional "low" or "auto"`
36
37 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).
38
39- `--n: optional number`
40
41 The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only `n=1` is supported.
42
43- `--output-compression: optional number`
44
45 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.
46
47- `--output-format: optional "png" or "jpeg" or "webp"`
48
49 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`.
50
51- `--partial-images: optional number`
52
53 The number of partial images to generate. This parameter is used for
54 streaming responses that return partial images. Value must be between 0 and 3.
55 When set to 0, the response will be a single image sent in one streaming event.
56
57 Note that the final image may be sent before the full number of partial images
58 are generated if the full image is generated more quickly.
59
60- `--quality: optional "standard" or "hd" or "low" or 3 more`
61
62 The quality of the image that will be generated.
63
64 - `auto` (default value) will automatically select the best quality for the given model.
65 - `high`, `medium` and `low` are supported for the GPT image models.
66 - `hd` and `standard` are supported for `dall-e-3`.
67 - `standard` is the only option for `dall-e-2`.
68
69- `--response-format: optional "url" or "b64_json"`
70
71 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.
72
73- `--size: optional string or "auto" or "1024x1024" or "1536x1024" or 5 more`
74
75 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`.
76
77- `--style: optional "vivid" or "natural"`
78
79 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.
80
81- `--user: optional string`
82
83 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).
84
85### Returns
86
87- `images_response: object { created, background, data, 4 more }`
88
89 The response from the image generation endpoint.
90
91 - `created: number`
92
93 The Unix timestamp (in seconds) of when the image was created.
94
95 - `background: optional "transparent" or "opaque"`
96
97 The background parameter used for the image generation. Either `transparent` or `opaque`.
98
99 - `"transparent"`
100
101 - `"opaque"`
102
103 - `data: optional array of Image`
104
105 The list of generated images.
106
107 - `b64_json: optional string`
108
109 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`.
110
111 - `revised_prompt: optional string`
112
113 For `dall-e-3` only, the revised prompt that was used to generate the image.
114
115 - `url: optional string`
116
117 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.
118
119 - `output_format: optional "png" or "webp" or "jpeg"`
120
121 The output format of the image generation. Either `png`, `webp`, or `jpeg`.
122
123 - `"png"`
124
125 - `"webp"`
126
127 - `"jpeg"`
128
129 - `quality: optional "low" or "medium" or "high"`
130
131 The quality of the image generated. Either `low`, `medium`, or `high`.
132
133 - `"low"`
134
135 - `"medium"`
136
137 - `"high"`
138
139 - `size: optional "1024x1024" or "1024x1536" or "1536x1024"`
140
141 The size of the image generated. Either `1024x1024`, `1024x1536`, or `1536x1024`.
142
143 - `"1024x1024"`
144
145 - `"1024x1536"`
146
147 - `"1536x1024"`
148
149 - `usage: optional object { input_tokens, input_tokens_details, output_tokens, 2 more }`
150
151 For `gpt-image-1` only, the token usage information for the image generation.
152
153 - `input_tokens: number`
154
155 The number of tokens (images and text) in the input prompt.
156
157 - `input_tokens_details: object { image_tokens, text_tokens }`
158
159 The input tokens detailed information for the image generation.
160
161 - `image_tokens: number`
162
163 The number of image tokens in the input prompt.
164
165 - `text_tokens: number`
166
167 The number of text tokens in the input prompt.
168
169 - `output_tokens: number`
170
171 The number of output tokens generated by the model.
172
173 - `total_tokens: number`
174
175 The total number of tokens (images and text) used for the image generation.
176
177 - `output_tokens_details: optional object { image_tokens, text_tokens }`
178
179 The output token details for the image generation.
180
181 - `image_tokens: number`
182
183 The number of image output tokens generated by the model.
184
185 - `text_tokens: number`
186
187 The number of text output tokens generated by the model.
188
189### Example
190
191```cli
192openai images generate \
193 --api-key 'My API Key' \
194 --prompt 'A cute baby sea otter'
195```
196
197#### Response
198
199```json
200{
201 "created": 0,
202 "background": "transparent",
203 "data": [
204 {
205 "b64_json": "b64_json",
206 "revised_prompt": "revised_prompt",
207 "url": "https://example.com"
208 }
209 ],
210 "output_format": "png",
211 "quality": "low",
212 "size": "1024x1024",
213 "usage": {
214 "input_tokens": 0,
215 "input_tokens_details": {
216 "image_tokens": 0,
217 "text_tokens": 0
218 },
219 "output_tokens": 0,
220 "total_tokens": 0,
221 "output_tokens_details": {
222 "image_tokens": 0,
223 "text_tokens": 0
224 }
225 }
226}
227```