resources/images/methods/generate/index.md +0 −404 deleted
File Deleted View Diff
1## Create image
2
3**post** `/images/generations`
4
5Creates an image given a prompt. [Learn more](/api/docs/guides/images-vision).
6
7### Body Parameters
8
9- `prompt: string`
10
11 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`.
12
13- `background: optional "transparent" or "opaque" or "auto" or null`
14
15 Set the background of the generated image(s). This parameter is only supported for
16 the GPT image models. Must be one of `transparent`, `opaque`, or `auto` (default
17 value). When `auto` is used, the model will automatically determine the best
18 background for the image.
19
20 `gpt-image-2.5-sunburst` and `gpt-image-2.5-flare`, including their `2026-09-08`
21 snapshots, support `opaque` and `transparent` backgrounds. Transparent backgrounds
22 are available for supported GPT Image models. For `gpt-image-2` and
23 `gpt-image-2-2026-04-21`, this support is in preview. When using `transparent`,
24 set the output format to `png` or `webp`.
25
26 - `"transparent"`
27
28 - `"opaque"`
29
30 - `"auto"`
31
32- `model: optional string or ImageModel or null`
33
34 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`, `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, `gpt-image-2.5-flare-2026-09-08`). Defaults to `dall-e-2` unless a parameter specific to the GPT image models is used.
35
36 - `string`
37
38 - `ImageModel = "gpt-image-1.5" or "gpt-image-2" or "gpt-image-2-2026-04-21" or 8 more`
39
40 - `"gpt-image-1.5"`
41
42 - `"gpt-image-2"`
43
44 - `"gpt-image-2-2026-04-21"`
45
46 - `"gpt-image-2.5-sunburst"`
47
48 - `"gpt-image-2.5-sunburst-2026-09-08"`
49
50 - `"gpt-image-2.5-flare"`
51
52 - `"gpt-image-2.5-flare-2026-09-08"`
53
54 - `"dall-e-2"`
55
56 - `"dall-e-3"`
57
58 - `"gpt-image-1"`
59
60 - `"gpt-image-1-mini"`
61
62- `moderation: optional "low" or "auto" or null`
63
64 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).
65
66 - `"low"`
67
68 - `"auto"`
69
70- `n: optional number or null`
71
72 The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only `n=1` is supported.
73
74- `output_compression: optional number or null`
75
76 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.
77
78- `output_format: optional "png" or "jpeg" or "webp" or null`
79
80 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`.
81
82 - `"png"`
83
84 - `"jpeg"`
85
86 - `"webp"`
87
88- `partial_images: optional number or null`
89
90 The number of partial images to generate. This parameter is used for
91 streaming responses that return partial images. Value must be between 0 and 3.
92 When set to 0, the response will be a single image sent in one streaming event.
93
94 Note that the final image may be sent before the full number of partial images
95 are generated if the full image is generated more quickly.
96
97- `quality: optional "standard" or "hd" or "low" or 5 more or null`
98
99 The quality of the image that will be generated.
100
101 - `auto` (default value) will automatically select the best quality for the given
102 model.
103 - `high`, `medium` and `low` are supported for the GPT image models.
104 - `gpt-image-2.5-sunburst` and `gpt-image-2.5-flare`, including their `2026-09-08`
105 snapshots, also support `xhigh` and `max`.
106 - `hd` and `standard` are supported for `dall-e-3`.
107 - `standard` is the only option for `dall-e-2`.
108
109 - `"standard"`
110
111 - `"hd"`
112
113 - `"low"`
114
115 - `"medium"`
116
117 - `"high"`
118
119 - `"xhigh"`
120
121 - `"max"`
122
123 - `"auto"`
124
125- `response_format: optional "url" or "b64_json" or null`
126
127 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.
128
129 - `"url"`
130
131 - `"b64_json"`
132
133- `size: optional string or "auto" or "1024x1024" or "1536x1024" or 5 more or null`
134
135 The size of the generated images. For `gpt-image-2`, `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, and `gpt-image-2.5-flare-2026-09-08`, 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 - `string`
138
139 - `"auto" or "1024x1024" or "1536x1024" or 5 more`
140
141 The size of the generated images. For `gpt-image-2`, `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, and `gpt-image-2.5-flare-2026-09-08`, 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`.
142
143 - `"auto"`
144
145 - `"1024x1024"`
146
147 - `"1536x1024"`
148
149 - `"1024x1536"`
150
151 - `"256x256"`
152
153 - `"512x512"`
154
155 - `"1792x1024"`
156
157 - `"1024x1792"`
158
159- `stream: optional boolean or null`
160
161 Generate the image in streaming mode. Defaults to `false`. See the
162 [Image generation guide](/api/docs/guides/image-generation) for more information.
163 This parameter is only supported for the GPT image models.
164
165- `style: optional "vivid" or "natural" or null`
166
167 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.
168
169 - `"vivid"`
170
171 - `"natural"`
172
173- `user: optional string`
174
175 A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/api/docs/guides/safety-best-practices#implement-safety-identifiers).
176
177### Returns
178
179- `ImagesResponse object { created, background, data, 4 more }`
180
181 The response from the image generation endpoint.
182
183 - `created: number`
184
185 The Unix timestamp (in seconds) of when the image was created.
186
187 - `background: optional "transparent" or "opaque"`
188
189 The background parameter used for the image generation. Either `transparent` or `opaque`.
190
191 - `"transparent"`
192
193 - `"opaque"`
194
195 - `data: optional array of Image`
196
197 The list of generated images.
198
199 - `b64_json: optional string`
200
201 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`.
202
203 - `revised_prompt: optional string`
204
205 For `dall-e-3` only, the revised prompt that was used to generate the image.
206
207 - `url: optional string`
208
209 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.
210
211 - `output_format: optional "png" or "webp" or "jpeg"`
212
213 The output format of the image generation. Either `png`, `webp`, or `jpeg`.
214
215 - `"png"`
216
217 - `"webp"`
218
219 - `"jpeg"`
220
221 - `quality: optional "low" or "medium" or "high" or 2 more`
222
223 The quality of the image generated. One of `low`, `medium`, `high`, `xhigh`, or `max`.
224
225 - `"low"`
226
227 - `"medium"`
228
229 - `"high"`
230
231 - `"xhigh"`
232
233 - `"max"`
234
235 - `size: optional string or "1024x1024" or "1024x1536" or "1536x1024"`
236
237 The image dimensions as a `WIDTHxHEIGHT` string, for example `1536x864`.
238
239 - `string`
240
241 - `"1024x1024" or "1024x1536" or "1536x1024"`
242
243 The image dimensions as a `WIDTHxHEIGHT` string, for example `1536x864`.
244
245 - `"1024x1024"`
246
247 - `"1024x1536"`
248
249 - `"1536x1024"`
250
251 - `usage: optional object { input_tokens, input_tokens_details, output_tokens, 2 more }`
252
253 For `gpt-image-1` only, the token usage information for the image generation.
254
255 - `input_tokens: number`
256
257 The number of tokens (images and text) in the input prompt.
258
259 - `input_tokens_details: object { image_tokens, text_tokens }`
260
261 The input tokens detailed information for the image generation.
262
263 - `image_tokens: number`
264
265 The number of image tokens in the input prompt.
266
267 - `text_tokens: number`
268
269 The number of text tokens in the input prompt.
270
271 - `output_tokens: number`
272
273 The number of output tokens generated by the model.
274
275 - `total_tokens: number`
276
277 The total number of tokens (images and text) used for the image generation.
278
279 - `output_tokens_details: optional object { image_tokens, text_tokens }`
280
281 The output token details for the image generation.
282
283 - `image_tokens: number`
284
285 The number of image output tokens generated by the model.
286
287 - `text_tokens: number`
288
289 The number of text output tokens generated by the model.
290
291### Example
292
293```http
294curl https://api.openai.com/v1/images/generations \
295 -H 'Content-Type: application/json' \
296 -H "Authorization: Bearer $OPENAI_API_KEY" \
297 -d '{
298 "prompt": "A cute baby sea otter",
299 "background": "transparent",
300 "moderation": "low",
301 "n": 1,
302 "output_compression": 100,
303 "output_format": "png",
304 "partial_images": 1,
305 "quality": "medium",
306 "response_format": "url",
307 "style": "vivid",
308 "user": "user-1234"
309 }'
310```
311
312#### Response
313
314```json
315{
316 "created": 0,
317 "background": "transparent",
318 "data": [
319 {
320 "b64_json": "b64_json",
321 "revised_prompt": "revised_prompt",
322 "url": "https://example.com"
323 }
324 ],
325 "output_format": "png",
326 "quality": "low",
327 "size": "1024x1024",
328 "usage": {
329 "input_tokens": 0,
330 "input_tokens_details": {
331 "image_tokens": 0,
332 "text_tokens": 0
333 },
334 "output_tokens": 0,
335 "total_tokens": 0,
336 "output_tokens_details": {
337 "image_tokens": 0,
338 "text_tokens": 0
339 }
340 }
341}
342```
343
344### Generate image
345
346```http
347curl https://api.openai.com/v1/images/generations \
348 -H "Content-Type: application/json" \
349 -H "Authorization: Bearer $OPENAI_API_KEY" \
350 -d '{
351 "model": "gpt-image-2.5-flare",
352 "prompt": "A cute baby sea otter",
353 "n": 1,
354 "size": "1024x1024"
355 }'
356```
357
358#### Response
359
360```json
361{
362 "created": 1713833628,
363 "data": [
364 {
365 "b64_json": "..."
366 }
367 ],
368 "usage": {
369 "total_tokens": 100,
370 "input_tokens": 50,
371 "output_tokens": 50,
372 "input_tokens_details": {
373 "text_tokens": 10,
374 "image_tokens": 40
375 }
376 }
377}
378```
379
380### Streaming
381
382```http
383curl https://api.openai.com/v1/images/generations \
384 -H "Content-Type: application/json" \
385 -H "Authorization: Bearer $OPENAI_API_KEY" \
386 -d '{
387 "model": "gpt-image-2.5-flare",
388 "prompt": "A cute baby sea otter",
389 "n": 1,
390 "size": "1024x1024",
391 "stream": true
392 }' \
393 --no-buffer
394```
395
396#### Response
397
398```json
399event: image_generation.partial_image
400data: {"type":"image_generation.partial_image","b64_json":"...","partial_image_index":0}
401
402event: image_generation.completed
403data: {"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}}}
404```