ruby/resources/images/methods/edit/index.md +0 −319 deleted
File Deleted View Diff
1## Create image edit
2
3`images.edit(**kwargs) -> ImagesResponse`
4
5**post** `/images/edits`
6
7Creates an edited or extended image given one or more source images and a prompt. This endpoint supports GPT Image models (`gpt-image-1.5`, `gpt-image-1`, `gpt-image-1-mini`, and `chatgpt-image-latest`) and `dall-e-2`.
8
9### Parameters
10
11- `image: String | Array[String]`
12
13 The image(s) to edit. Must be a supported image file or an array of images.
14
15 For the GPT image models (`gpt-image-1`, `gpt-image-1-mini`,
16 `gpt-image-1.5`, `gpt-image-2`, `gpt-image-2-2026-04-21`, and
17 `chatgpt-image-latest`), each image should be a `png`, `webp`, or
18 `jpg` file less than 50MB. You can provide up to 16 images.
19
20 For `dall-e-2`, you can only provide one image, and it should be a
21 square `png` file less than 4MB.
22
23 - `String = String`
24
25 - `UnionMember1 = Array[String]`
26
27- `prompt: String`
28
29 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.
30
31- `background: :transparent | :opaque | :auto`
32
33 Allows to set transparency for the background of the generated image(s).
34 This parameter is only supported for GPT image models that support
35 transparent backgrounds. Must be one of `transparent`, `opaque`, or
36 `auto` (default value). When `auto` is used, the model will
37 automatically determine the best background for the image.
38
39 `gpt-image-2` and `gpt-image-2-2026-04-21` do not support
40 transparent backgrounds. Requests with `background` set to
41 `transparent` will return an error for these models; use `opaque` or
42 `auto` instead.
43
44 If `transparent`, the output format needs to support transparency,
45 so it should be set to either `png` (default value) or `webp`.
46
47 - `:transparent`
48
49 - `:opaque`
50
51 - `:auto`
52
53- `input_fidelity: :high | :low`
54
55 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`.
56
57 - `:high`
58
59 - `:low`
60
61- `mask: String`
62
63 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`.
64
65- `model: String | ImageModel`
66
67 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`.
68
69 - `String = String`
70
71 - `ImageModel = :"gpt-image-1" | :"gpt-image-1-mini" | :"gpt-image-2" | 5 more`
72
73 - `:"gpt-image-1"`
74
75 - `:"gpt-image-1-mini"`
76
77 - `:"gpt-image-2"`
78
79 - `:"gpt-image-2-2026-04-21"`
80
81 - `:"gpt-image-1.5"`
82
83 - `:"chatgpt-image-latest"`
84
85 - `:"dall-e-2"`
86
87 - `:"dall-e-3"`
88
89- `n: Integer`
90
91 The number of images to generate. Must be between 1 and 10.
92
93- `output_compression: Integer`
94
95 The compression level (0-100%) for the generated images. This parameter
96 is only supported for the GPT image models with the `webp` or `jpeg` output
97 formats, and defaults to 100.
98
99- `output_format: :png | :jpeg | :webp`
100
101 The format in which the generated images are returned. This parameter is
102 only supported for the GPT image models. Must be one of `png`, `jpeg`, or `webp`.
103 The default value is `png`.
104
105 - `:png`
106
107 - `:jpeg`
108
109 - `:webp`
110
111- `partial_images: Integer`
112
113 The number of partial images to generate. This parameter is used for
114 streaming responses that return partial images. Value must be between 0 and 3.
115 When set to 0, the response will be a single image sent in one streaming event.
116
117 Note that the final image may be sent before the full number of partial images
118 are generated if the full image is generated more quickly.
119
120- `quality: :standard | :low | :medium | 2 more`
121
122 The quality of the image that will be generated for GPT image models. Defaults to `auto`.
123
124 - `:standard`
125
126 - `:low`
127
128 - `:medium`
129
130 - `:high`
131
132 - `:auto`
133
134- `response_format: :url | :b64_json`
135
136 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.
137
138 - `:url`
139
140 - `:b64_json`
141
142- `size: String | :"256x256" | :"512x512" | :"1024x1024" | 3 more`
143
144 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`.
145
146 - `String = String`
147
148 - `Size = :"256x256" | :"512x512" | :"1024x1024" | 3 more`
149
150 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`.
151
152 - `:"256x256"`
153
154 - `:"512x512"`
155
156 - `:"1024x1024"`
157
158 - `:"1536x1024"`
159
160 - `:"1024x1536"`
161
162 - `:auto`
163
164- `stream: bool`
165
166 Edit the image in streaming mode. Defaults to `false`. See the
167 [Image generation guide](https://platform.openai.com/docs/guides/image-generation) for more information.
168
169- `user: String`
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: Integer`
180
181 The Unix timestamp (in seconds) of when the image was created.
182
183 - `background: :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: Array[Image]`
192
193 The list of generated images.
194
195 - `b64_json: String`
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: String`
200
201 For `dall-e-3` only, the revised prompt that was used to generate the image.
202
203 - `url: String`
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: :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: :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: :"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: Usage{ input_tokens, input_tokens_details, output_tokens, 2 more}`
238
239 For `gpt-image-1` only, the token usage information for the image generation.
240
241 - `input_tokens: Integer`
242
243 The number of tokens (images and text) in the input prompt.
244
245 - `input_tokens_details: InputTokensDetails{ image_tokens, text_tokens}`
246
247 The input tokens detailed information for the image generation.
248
249 - `image_tokens: Integer`
250
251 The number of image tokens in the input prompt.
252
253 - `text_tokens: Integer`
254
255 The number of text tokens in the input prompt.
256
257 - `output_tokens: Integer`
258
259 The number of output tokens generated by the model.
260
261 - `total_tokens: Integer`
262
263 The total number of tokens (images and text) used for the image generation.
264
265 - `output_tokens_details: OutputTokensDetails{ image_tokens, text_tokens}`
266
267 The output token details for the image generation.
268
269 - `image_tokens: Integer`
270
271 The number of image output tokens generated by the model.
272
273 - `text_tokens: Integer`
274
275 The number of text output tokens generated by the model.
276
277### Example
278
279```ruby
280require "openai"
281
282openai = OpenAI::Client.new(api_key: "My API Key")
283
284images_response = openai.images.edit(image: StringIO.new("Example data"), prompt: "A cute baby sea otter wearing a beret")
285
286puts(images_response)
287```
288
289#### Response
290
291```json
292{
293 "created": 0,
294 "background": "transparent",
295 "data": [
296 {
297 "b64_json": "b64_json",
298 "revised_prompt": "revised_prompt",
299 "url": "https://example.com"
300 }
301 ],
302 "output_format": "png",
303 "quality": "low",
304 "size": "1024x1024",
305 "usage": {
306 "input_tokens": 0,
307 "input_tokens_details": {
308 "image_tokens": 0,
309 "text_tokens": 0
310 },
311 "output_tokens": 0,
312 "total_tokens": 0,
313 "output_tokens_details": {
314 "image_tokens": 0,
315 "text_tokens": 0
316 }
317 }
318}
319```