openai 0.86.0 → 0.87.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +10 -1
  4. data/examples/audio/record_and_play.rb +19 -0
  5. data/examples/responses/websocket_workflows.rb +159 -0
  6. data/lib/openai/helpers/local_audio/errors.rb +27 -0
  7. data/lib/openai/helpers/local_audio/process.rb +158 -0
  8. data/lib/openai/helpers/local_audio.rb +157 -0
  9. data/lib/openai/helpers/realtime/connection.rb +20 -2
  10. data/lib/openai/helpers/realtime/errors.rb +18 -0
  11. data/lib/openai/helpers/realtime/recovery.rb +489 -0
  12. data/lib/openai/helpers/realtime/resources/realtime_extension.rb +26 -1
  13. data/lib/openai/helpers/realtime.rb +1 -0
  14. data/lib/openai/models/beta/beta_response_input_item.rb +84 -1
  15. data/lib/openai/models/beta/beta_response_item.rb +72 -1
  16. data/lib/openai/models/beta/beta_response_output_item.rb +84 -1
  17. data/lib/openai/models/beta/beta_responses_client_event.rb +3 -0
  18. data/lib/openai/models/beta/beta_tool.rb +69 -37
  19. data/lib/openai/models/beta/response_create_params.rb +3 -0
  20. data/lib/openai/models/conversations/conversation_item.rb +82 -1
  21. data/lib/openai/models/image_edit_completed_event.rb +34 -8
  22. data/lib/openai/models/image_edit_params.rb +64 -44
  23. data/lib/openai/models/image_edit_partial_image_event.rb +34 -8
  24. data/lib/openai/models/image_gen_completed_event.rb +34 -8
  25. data/lib/openai/models/image_gen_partial_image_event.rb +34 -8
  26. data/lib/openai/models/image_generate_params.rb +51 -35
  27. data/lib/openai/models/image_model.rb +4 -0
  28. data/lib/openai/models/images_response.rb +37 -13
  29. data/lib/openai/models/responses/response_create_params.rb +3 -0
  30. data/lib/openai/models/responses/response_input_item.rb +84 -1
  31. data/lib/openai/models/responses/response_item.rb +72 -1
  32. data/lib/openai/models/responses/response_output_item.rb +84 -1
  33. data/lib/openai/models/responses/responses_client_event.rb +3 -0
  34. data/lib/openai/models/responses/tool.rb +69 -37
  35. data/lib/openai/models/webhooks/live_call_incoming_webhook_event.rb +3 -3
  36. data/lib/openai/models/webhooks/realtime_call_incoming_webhook_event.rb +5 -3
  37. data/lib/openai/resources/images.rb +12 -14
  38. data/lib/openai/version.rb +1 -1
  39. data/local-audio.md +146 -0
  40. data/rbi/openai/helpers/local_audio/interface.rbi +110 -0
  41. data/rbi/openai/helpers/realtime/connection.rbi +18 -2
  42. data/rbi/openai/helpers/realtime/extensions.rbi +8 -0
  43. data/rbi/openai/helpers/realtime/recovery.rbi +27 -0
  44. data/rbi/openai/models/beta/beta_response_input_item.rbi +86 -1
  45. data/rbi/openai/models/beta/beta_response_item.rbi +78 -1
  46. data/rbi/openai/models/beta/beta_response_output_item.rbi +84 -1
  47. data/rbi/openai/models/beta/beta_responses_client_event.rbi +6 -0
  48. data/rbi/openai/models/beta/beta_tool.rbi +90 -51
  49. data/rbi/openai/models/beta/response_create_params.rbi +6 -0
  50. data/rbi/openai/models/conversations/conversation_item.rbi +88 -1
  51. data/rbi/openai/models/image_edit_completed_event.rbi +20 -9
  52. data/rbi/openai/models/image_edit_params.rbi +89 -60
  53. data/rbi/openai/models/image_edit_partial_image_event.rbi +20 -9
  54. data/rbi/openai/models/image_gen_completed_event.rbi +20 -9
  55. data/rbi/openai/models/image_gen_partial_image_event.rbi +20 -9
  56. data/rbi/openai/models/image_generate_params.rbi +71 -48
  57. data/rbi/openai/models/image_model.rbi +4 -0
  58. data/rbi/openai/models/images_response.rbi +27 -16
  59. data/rbi/openai/models/responses/response_create_params.rbi +6 -0
  60. data/rbi/openai/models/responses/response_input_item.rbi +88 -1
  61. data/rbi/openai/models/responses/response_item.rbi +80 -1
  62. data/rbi/openai/models/responses/response_output_item.rbi +84 -1
  63. data/rbi/openai/models/responses/responses_client_event.rbi +6 -0
  64. data/rbi/openai/models/responses/tool.rbi +90 -51
  65. data/rbi/openai/models/webhooks/live_call_incoming_webhook_event.rbi +4 -4
  66. data/rbi/openai/models/webhooks/realtime_call_incoming_webhook_event.rbi +8 -4
  67. data/rbi/openai/resources/beta/responses.rbi +6 -2
  68. data/rbi/openai/resources/images.rbi +106 -76
  69. data/rbi/openai/resources/responses.rbi +6 -0
  70. data/realtime.md +101 -0
  71. data/responses-websocket.md +182 -0
  72. data/sig/openai/helpers/local_audio/interface.rbs +62 -0
  73. data/sig/openai/helpers/realtime/connection.rbs +9 -1
  74. data/sig/openai/helpers/realtime/extensions.rbs +4 -0
  75. data/sig/openai/helpers/realtime/recovery.rbs +19 -0
  76. data/sig/openai/models/beta/beta_response_input_item.rbs +39 -2
  77. data/sig/openai/models/beta/beta_response_item.rbs +39 -2
  78. data/sig/openai/models/beta/beta_response_output_item.rbs +39 -2
  79. data/sig/openai/models/beta/beta_tool.rbs +11 -1
  80. data/sig/openai/models/conversations/conversation_item.rbs +39 -2
  81. data/sig/openai/models/image_edit_completed_event.rbs +11 -4
  82. data/sig/openai/models/image_edit_params.rbs +3 -1
  83. data/sig/openai/models/image_edit_partial_image_event.rbs +11 -4
  84. data/sig/openai/models/image_gen_completed_event.rbs +11 -4
  85. data/sig/openai/models/image_gen_partial_image_event.rbs +11 -4
  86. data/sig/openai/models/image_generate_params.rbs +4 -1
  87. data/sig/openai/models/image_model.rbs +8 -0
  88. data/sig/openai/models/images_response.rbs +10 -4
  89. data/sig/openai/models/responses/response_input_item.rbs +39 -2
  90. data/sig/openai/models/responses/response_item.rbs +39 -2
  91. data/sig/openai/models/responses/response_output_item.rbs +39 -2
  92. data/sig/openai/models/responses/tool.rbs +11 -1
  93. metadata +15 -1
@@ -50,8 +50,7 @@ module OpenAI
50
50
  # See {OpenAI::Resources::Images#edit_stream_raw} for streaming counterpart.
51
51
  #
52
52
  # Creates an edited or extended image given one or more source images and a
53
- # prompt. This endpoint supports GPT Image models (`gpt-image-1.5`, `gpt-image-1`,
54
- # `gpt-image-1-mini`, and `chatgpt-image-latest`) and `dall-e-2`.
53
+ # prompt. This endpoint supports GPT Image models and `dall-e-2`.
55
54
  sig {
56
55
  params(
57
56
  image: OpenAI::ImageEditParams::Image::Variants,
@@ -77,9 +76,11 @@ module OpenAI
77
76
  # The image(s) to edit. Must be a supported image file or an array of images.
78
77
  #
79
78
  # For the GPT image models (`gpt-image-1`, `gpt-image-1-mini`, `gpt-image-1.5`,
80
- # `gpt-image-2`, `gpt-image-2-2026-04-21`, and `chatgpt-image-latest`), each image
81
- # should be a `png`, `webp`, or `jpg` file less than 50MB. You can provide up to
82
- # 16 images.
79
+ # `gpt-image-2`, `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`,
80
+ # `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`,
81
+ # `gpt-image-2.5-flare-2026-09-08`, and `chatgpt-image-latest`), each image should
82
+ # be a `png`, `webp`, or `jpg` file less than 50MB. You can provide up to 16
83
+ # images.
83
84
  #
84
85
  # For `dall-e-2`, you can only provide one image, and it should be a square `png`
85
86
  # file less than 4MB.
@@ -95,9 +96,11 @@ module OpenAI
95
96
  # one of `transparent`, `opaque`, or `auto` (default value). When `auto` is used,
96
97
  # the model will automatically determine the best background for the image.
97
98
  #
98
- # Transparent backgrounds are available for supported GPT Image models. For
99
- # `gpt-image-2` and `gpt-image-2-2026-04-21`, this support is in preview. When
100
- # using `transparent`, set the output format to `png` or `webp`.
99
+ # `gpt-image-2.5-sunburst` and `gpt-image-2.5-flare`, including their `2026-09-08`
100
+ # snapshots, support `opaque` and `transparent` backgrounds. Transparent
101
+ # backgrounds are available for supported GPT Image models. For `gpt-image-2` and
102
+ # `gpt-image-2-2026-04-21`, this support is in preview. When using `transparent`,
103
+ # set the output format to `png` or `webp`.
101
104
  background: nil,
102
105
  # Control how much effort the model will exert to match the style and features,
103
106
  # especially facial features, of input images. This parameter is only supported
@@ -115,7 +118,9 @@ module OpenAI
115
118
  mask: nil,
116
119
  # The model to use for image generation. One of `dall-e-2` or a GPT image model
117
120
  # (`gpt-image-1`, `gpt-image-1-mini`, `gpt-image-1.5`, `gpt-image-2`,
118
- # `gpt-image-2-2026-04-21`, or `chatgpt-image-latest`). Defaults to
121
+ # `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`,
122
+ # `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`,
123
+ # `gpt-image-2.5-flare-2026-09-08`, or `chatgpt-image-latest`). Defaults to
119
124
  # `gpt-image-1.5`.
120
125
  model: nil,
121
126
  # The number of images to generate. Must be between 1 and 10.
@@ -135,25 +140,28 @@ module OpenAI
135
140
  # Note that the final image may be sent before the full number of partial images
136
141
  # are generated if the full image is generated more quickly.
137
142
  partial_images: nil,
138
- # The quality of the image that will be generated for GPT image models. Defaults
139
- # to `auto`.
143
+ # The quality of the image that will be generated for GPT image models. The GPT
144
+ # image models support `low`, `medium`, and `high`. `gpt-image-2.5-sunburst` and
145
+ # `gpt-image-2.5-flare`, including their `2026-09-08` snapshots, also support
146
+ # `xhigh` and `max`. Defaults to `auto`.
140
147
  quality: nil,
141
148
  # The format in which the generated images are returned. Must be one of `url` or
142
149
  # `b64_json`. URLs are only valid for 60 minutes after the image has been
143
150
  # generated. This parameter is only supported for `dall-e-2` (default is `url` for
144
151
  # `dall-e-2`), as GPT image models always return base64-encoded images.
145
152
  response_format: nil,
146
- # The size of the generated images. For `gpt-image-2` and
147
- # `gpt-image-2-2026-04-21`, arbitrary resolutions are supported as `WIDTHxHEIGHT`
148
- # strings, for example `1536x864`. Width and height must both be divisible by 16
149
- # and the requested aspect ratio must be between 1:3 and 3:1. Resolutions above
150
- # `2560x1440` are experimental, and the maximum supported resolution is
151
- # `3840x2160`. The requested size must also satisfy the model's current pixel and
152
- # edge limits. The standard sizes `1024x1024`, `1536x1024`, and `1024x1536` are
153
- # supported by the GPT image models; `auto` is supported for models that allow
154
- # automatic sizing. For `dall-e-2`, use one of `256x256`, `512x512`, or
155
- # `1024x1024`. For `dall-e-3`, use one of `1024x1024`, `1792x1024`, or
156
- # `1024x1792`.
153
+ # The size of the generated images. For `gpt-image-2`, `gpt-image-2-2026-04-21`,
154
+ # `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`,
155
+ # `gpt-image-2.5-flare`, and `gpt-image-2.5-flare-2026-09-08`, arbitrary
156
+ # resolutions are supported as `WIDTHxHEIGHT` strings, for example `1536x864`.
157
+ # Width and height must both be divisible by 16 and the requested aspect ratio
158
+ # must be between 1:3 and 3:1. Resolutions above `2560x1440` are experimental, and
159
+ # the maximum supported resolution is `3840x2160`. The requested size must also
160
+ # satisfy the model's current pixel and edge limits. The standard sizes
161
+ # `1024x1024`, `1536x1024`, and `1024x1536` are supported by the GPT image models;
162
+ # `auto` is supported for models that allow automatic sizing. For `dall-e-2`, use
163
+ # one of `256x256`, `512x512`, or `1024x1024`. For `dall-e-3`, use one of
164
+ # `1024x1024`, `1792x1024`, or `1024x1792`.
157
165
  size: nil,
158
166
  # A unique identifier representing your end-user, which can help OpenAI to monitor
159
167
  # and detect abuse.
@@ -169,8 +177,7 @@ module OpenAI
169
177
  # See {OpenAI::Resources::Images#edit} for non-streaming counterpart.
170
178
  #
171
179
  # Creates an edited or extended image given one or more source images and a
172
- # prompt. This endpoint supports GPT Image models (`gpt-image-1.5`, `gpt-image-1`,
173
- # `gpt-image-1-mini`, and `chatgpt-image-latest`) and `dall-e-2`.
180
+ # prompt. This endpoint supports GPT Image models and `dall-e-2`.
174
181
  sig {
175
182
  params(
176
183
  image: OpenAI::ImageEditParams::Image::Variants,
@@ -196,9 +203,11 @@ module OpenAI
196
203
  # The image(s) to edit. Must be a supported image file or an array of images.
197
204
  #
198
205
  # For the GPT image models (`gpt-image-1`, `gpt-image-1-mini`, `gpt-image-1.5`,
199
- # `gpt-image-2`, `gpt-image-2-2026-04-21`, and `chatgpt-image-latest`), each image
200
- # should be a `png`, `webp`, or `jpg` file less than 50MB. You can provide up to
201
- # 16 images.
206
+ # `gpt-image-2`, `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`,
207
+ # `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`,
208
+ # `gpt-image-2.5-flare-2026-09-08`, and `chatgpt-image-latest`), each image should
209
+ # be a `png`, `webp`, or `jpg` file less than 50MB. You can provide up to 16
210
+ # images.
202
211
  #
203
212
  # For `dall-e-2`, you can only provide one image, and it should be a square `png`
204
213
  # file less than 4MB.
@@ -214,9 +223,11 @@ module OpenAI
214
223
  # one of `transparent`, `opaque`, or `auto` (default value). When `auto` is used,
215
224
  # the model will automatically determine the best background for the image.
216
225
  #
217
- # Transparent backgrounds are available for supported GPT Image models. For
218
- # `gpt-image-2` and `gpt-image-2-2026-04-21`, this support is in preview. When
219
- # using `transparent`, set the output format to `png` or `webp`.
226
+ # `gpt-image-2.5-sunburst` and `gpt-image-2.5-flare`, including their `2026-09-08`
227
+ # snapshots, support `opaque` and `transparent` backgrounds. Transparent
228
+ # backgrounds are available for supported GPT Image models. For `gpt-image-2` and
229
+ # `gpt-image-2-2026-04-21`, this support is in preview. When using `transparent`,
230
+ # set the output format to `png` or `webp`.
220
231
  background: nil,
221
232
  # Control how much effort the model will exert to match the style and features,
222
233
  # especially facial features, of input images. This parameter is only supported
@@ -234,7 +245,9 @@ module OpenAI
234
245
  mask: nil,
235
246
  # The model to use for image generation. One of `dall-e-2` or a GPT image model
236
247
  # (`gpt-image-1`, `gpt-image-1-mini`, `gpt-image-1.5`, `gpt-image-2`,
237
- # `gpt-image-2-2026-04-21`, or `chatgpt-image-latest`). Defaults to
248
+ # `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`,
249
+ # `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`,
250
+ # `gpt-image-2.5-flare-2026-09-08`, or `chatgpt-image-latest`). Defaults to
238
251
  # `gpt-image-1.5`.
239
252
  model: nil,
240
253
  # The number of images to generate. Must be between 1 and 10.
@@ -254,25 +267,28 @@ module OpenAI
254
267
  # Note that the final image may be sent before the full number of partial images
255
268
  # are generated if the full image is generated more quickly.
256
269
  partial_images: nil,
257
- # The quality of the image that will be generated for GPT image models. Defaults
258
- # to `auto`.
270
+ # The quality of the image that will be generated for GPT image models. The GPT
271
+ # image models support `low`, `medium`, and `high`. `gpt-image-2.5-sunburst` and
272
+ # `gpt-image-2.5-flare`, including their `2026-09-08` snapshots, also support
273
+ # `xhigh` and `max`. Defaults to `auto`.
259
274
  quality: nil,
260
275
  # The format in which the generated images are returned. Must be one of `url` or
261
276
  # `b64_json`. URLs are only valid for 60 minutes after the image has been
262
277
  # generated. This parameter is only supported for `dall-e-2` (default is `url` for
263
278
  # `dall-e-2`), as GPT image models always return base64-encoded images.
264
279
  response_format: nil,
265
- # The size of the generated images. For `gpt-image-2` and
266
- # `gpt-image-2-2026-04-21`, arbitrary resolutions are supported as `WIDTHxHEIGHT`
267
- # strings, for example `1536x864`. Width and height must both be divisible by 16
268
- # and the requested aspect ratio must be between 1:3 and 3:1. Resolutions above
269
- # `2560x1440` are experimental, and the maximum supported resolution is
270
- # `3840x2160`. The requested size must also satisfy the model's current pixel and
271
- # edge limits. The standard sizes `1024x1024`, `1536x1024`, and `1024x1536` are
272
- # supported by the GPT image models; `auto` is supported for models that allow
273
- # automatic sizing. For `dall-e-2`, use one of `256x256`, `512x512`, or
274
- # `1024x1024`. For `dall-e-3`, use one of `1024x1024`, `1792x1024`, or
275
- # `1024x1792`.
280
+ # The size of the generated images. For `gpt-image-2`, `gpt-image-2-2026-04-21`,
281
+ # `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`,
282
+ # `gpt-image-2.5-flare`, and `gpt-image-2.5-flare-2026-09-08`, arbitrary
283
+ # resolutions are supported as `WIDTHxHEIGHT` strings, for example `1536x864`.
284
+ # Width and height must both be divisible by 16 and the requested aspect ratio
285
+ # must be between 1:3 and 3:1. Resolutions above `2560x1440` are experimental, and
286
+ # the maximum supported resolution is `3840x2160`. The requested size must also
287
+ # satisfy the model's current pixel and edge limits. The standard sizes
288
+ # `1024x1024`, `1536x1024`, and `1024x1536` are supported by the GPT image models;
289
+ # `auto` is supported for models that allow automatic sizing. For `dall-e-2`, use
290
+ # one of `256x256`, `512x512`, or `1024x1024`. For `dall-e-3`, use one of
291
+ # `1024x1024`, `1792x1024`, or `1024x1792`.
276
292
  size: nil,
277
293
  # A unique identifier representing your end-user, which can help OpenAI to monitor
278
294
  # and detect abuse.
@@ -318,14 +334,18 @@ module OpenAI
318
334
  # one of `transparent`, `opaque`, or `auto` (default value). When `auto` is used,
319
335
  # the model will automatically determine the best background for the image.
320
336
  #
321
- # Transparent backgrounds are available for supported GPT Image models. For
322
- # `gpt-image-2` and `gpt-image-2-2026-04-21`, this support is in preview. When
323
- # using `transparent`, set the output format to `png` or `webp`.
337
+ # `gpt-image-2.5-sunburst` and `gpt-image-2.5-flare`, including their `2026-09-08`
338
+ # snapshots, support `opaque` and `transparent` backgrounds. Transparent
339
+ # backgrounds are available for supported GPT Image models. For `gpt-image-2` and
340
+ # `gpt-image-2-2026-04-21`, this support is in preview. When using `transparent`,
341
+ # set the output format to `png` or `webp`.
324
342
  background: nil,
325
343
  # The model to use for image generation. One of `dall-e-2`, `dall-e-3`, or a GPT
326
344
  # image model (`gpt-image-1`, `gpt-image-1-mini`, `gpt-image-1.5`, `gpt-image-2`,
327
- # or `gpt-image-2-2026-04-21`). Defaults to `dall-e-2` unless a parameter specific
328
- # to the GPT image models is used.
345
+ # `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`,
346
+ # `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`,
347
+ # `gpt-image-2.5-flare-2026-09-08`). Defaults to `dall-e-2` unless a parameter
348
+ # specific to the GPT image models is used.
329
349
  model: nil,
330
350
  # Control the content-moderation level for images generated by the GPT image
331
351
  # models. Must be either `low` for less restrictive filtering or `auto` (default
@@ -353,6 +373,8 @@ module OpenAI
353
373
  # - `auto` (default value) will automatically select the best quality for the
354
374
  # given model.
355
375
  # - `high`, `medium` and `low` are supported for the GPT image models.
376
+ # - `gpt-image-2.5-sunburst` and `gpt-image-2.5-flare`, including their
377
+ # `2026-09-08` snapshots, also support `xhigh` and `max`.
356
378
  # - `hd` and `standard` are supported for `dall-e-3`.
357
379
  # - `standard` is the only option for `dall-e-2`.
358
380
  quality: nil,
@@ -361,17 +383,18 @@ module OpenAI
361
383
  # after the image has been generated. This parameter isn't supported for the GPT
362
384
  # image models, which always return base64-encoded images.
363
385
  response_format: nil,
364
- # The size of the generated images. For `gpt-image-2` and
365
- # `gpt-image-2-2026-04-21`, arbitrary resolutions are supported as `WIDTHxHEIGHT`
366
- # strings, for example `1536x864`. Width and height must both be divisible by 16
367
- # and the requested aspect ratio must be between 1:3 and 3:1. Resolutions above
368
- # `2560x1440` are experimental, and the maximum supported resolution is
369
- # `3840x2160`. The requested size must also satisfy the model's current pixel and
370
- # edge limits. The standard sizes `1024x1024`, `1536x1024`, and `1024x1536` are
371
- # supported by the GPT image models; `auto` is supported for models that allow
372
- # automatic sizing. For `dall-e-2`, use one of `256x256`, `512x512`, or
373
- # `1024x1024`. For `dall-e-3`, use one of `1024x1024`, `1792x1024`, or
374
- # `1024x1792`.
386
+ # The size of the generated images. For `gpt-image-2`, `gpt-image-2-2026-04-21`,
387
+ # `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`,
388
+ # `gpt-image-2.5-flare`, and `gpt-image-2.5-flare-2026-09-08`, arbitrary
389
+ # resolutions are supported as `WIDTHxHEIGHT` strings, for example `1536x864`.
390
+ # Width and height must both be divisible by 16 and the requested aspect ratio
391
+ # must be between 1:3 and 3:1. Resolutions above `2560x1440` are experimental, and
392
+ # the maximum supported resolution is `3840x2160`. The requested size must also
393
+ # satisfy the model's current pixel and edge limits. The standard sizes
394
+ # `1024x1024`, `1536x1024`, and `1024x1536` are supported by the GPT image models;
395
+ # `auto` is supported for models that allow automatic sizing. For `dall-e-2`, use
396
+ # one of `256x256`, `512x512`, or `1024x1024`. For `dall-e-3`, use one of
397
+ # `1024x1024`, `1792x1024`, or `1024x1792`.
375
398
  size: nil,
376
399
  # The style of the generated images. This parameter is only supported for
377
400
  # `dall-e-3`. Must be one of `vivid` or `natural`. Vivid causes the model to lean
@@ -422,14 +445,18 @@ module OpenAI
422
445
  # one of `transparent`, `opaque`, or `auto` (default value). When `auto` is used,
423
446
  # the model will automatically determine the best background for the image.
424
447
  #
425
- # Transparent backgrounds are available for supported GPT Image models. For
426
- # `gpt-image-2` and `gpt-image-2-2026-04-21`, this support is in preview. When
427
- # using `transparent`, set the output format to `png` or `webp`.
448
+ # `gpt-image-2.5-sunburst` and `gpt-image-2.5-flare`, including their `2026-09-08`
449
+ # snapshots, support `opaque` and `transparent` backgrounds. Transparent
450
+ # backgrounds are available for supported GPT Image models. For `gpt-image-2` and
451
+ # `gpt-image-2-2026-04-21`, this support is in preview. When using `transparent`,
452
+ # set the output format to `png` or `webp`.
428
453
  background: nil,
429
454
  # The model to use for image generation. One of `dall-e-2`, `dall-e-3`, or a GPT
430
455
  # image model (`gpt-image-1`, `gpt-image-1-mini`, `gpt-image-1.5`, `gpt-image-2`,
431
- # or `gpt-image-2-2026-04-21`). Defaults to `dall-e-2` unless a parameter specific
432
- # to the GPT image models is used.
456
+ # `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`,
457
+ # `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`,
458
+ # `gpt-image-2.5-flare-2026-09-08`). Defaults to `dall-e-2` unless a parameter
459
+ # specific to the GPT image models is used.
433
460
  model: nil,
434
461
  # Control the content-moderation level for images generated by the GPT image
435
462
  # models. Must be either `low` for less restrictive filtering or `auto` (default
@@ -457,6 +484,8 @@ module OpenAI
457
484
  # - `auto` (default value) will automatically select the best quality for the
458
485
  # given model.
459
486
  # - `high`, `medium` and `low` are supported for the GPT image models.
487
+ # - `gpt-image-2.5-sunburst` and `gpt-image-2.5-flare`, including their
488
+ # `2026-09-08` snapshots, also support `xhigh` and `max`.
460
489
  # - `hd` and `standard` are supported for `dall-e-3`.
461
490
  # - `standard` is the only option for `dall-e-2`.
462
491
  quality: nil,
@@ -465,17 +494,18 @@ module OpenAI
465
494
  # after the image has been generated. This parameter isn't supported for the GPT
466
495
  # image models, which always return base64-encoded images.
467
496
  response_format: nil,
468
- # The size of the generated images. For `gpt-image-2` and
469
- # `gpt-image-2-2026-04-21`, arbitrary resolutions are supported as `WIDTHxHEIGHT`
470
- # strings, for example `1536x864`. Width and height must both be divisible by 16
471
- # and the requested aspect ratio must be between 1:3 and 3:1. Resolutions above
472
- # `2560x1440` are experimental, and the maximum supported resolution is
473
- # `3840x2160`. The requested size must also satisfy the model's current pixel and
474
- # edge limits. The standard sizes `1024x1024`, `1536x1024`, and `1024x1536` are
475
- # supported by the GPT image models; `auto` is supported for models that allow
476
- # automatic sizing. For `dall-e-2`, use one of `256x256`, `512x512`, or
477
- # `1024x1024`. For `dall-e-3`, use one of `1024x1024`, `1792x1024`, or
478
- # `1024x1792`.
497
+ # The size of the generated images. For `gpt-image-2`, `gpt-image-2-2026-04-21`,
498
+ # `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`,
499
+ # `gpt-image-2.5-flare`, and `gpt-image-2.5-flare-2026-09-08`, arbitrary
500
+ # resolutions are supported as `WIDTHxHEIGHT` strings, for example `1536x864`.
501
+ # Width and height must both be divisible by 16 and the requested aspect ratio
502
+ # must be between 1:3 and 3:1. Resolutions above `2560x1440` are experimental, and
503
+ # the maximum supported resolution is `3840x2160`. The requested size must also
504
+ # satisfy the model's current pixel and edge limits. The standard sizes
505
+ # `1024x1024`, `1536x1024`, and `1024x1536` are supported by the GPT image models;
506
+ # `auto` is supported for models that allow automatic sizing. For `dall-e-2`, use
507
+ # one of `256x256`, `512x512`, or `1024x1024`. For `dall-e-3`, use one of
508
+ # `1024x1024`, `1792x1024`, or `1024x1792`.
479
509
  size: nil,
480
510
  # The style of the generated images. This parameter is only supported for
481
511
  # `dall-e-3`. Must be one of `vivid` or `natural`. Vivid causes the model to lean
@@ -241,6 +241,9 @@ module OpenAI
241
241
  # parameter.
242
242
  service_tier: nil,
243
243
  # Whether to store the generated model response for later retrieval via API.
244
+ # Defaults to true when omitted. If set to true, response data will be stored for
245
+ # at least 30 days, subject to the
246
+ # [data retention exceptions](/api/docs/guides/your-data#v1responses).
244
247
  store: nil,
245
248
  # Options for streaming responses. Only set this when you set `stream: true`.
246
249
  stream_options: nil,
@@ -546,6 +549,9 @@ module OpenAI
546
549
  # parameter.
547
550
  service_tier: nil,
548
551
  # Whether to store the generated model response for later retrieval via API.
552
+ # Defaults to true when omitted. If set to true, response data will be stored for
553
+ # at least 30 days, subject to the
554
+ # [data retention exceptions](/api/docs/guides/your-data#v1responses).
549
555
  store: nil,
550
556
  # Options for streaming responses. Only set this when you set `stream: true`.
551
557
  stream_options: nil,
data/realtime.md CHANGED
@@ -76,6 +76,107 @@ types. Invalid client events raise `ArgumentError` with a generic public
76
76
  message; the converter error remains available through `cause` for explicit
77
77
  inspection. `send_raw` and `receive_raw` are text-frame escape hatches.
78
78
 
79
+ ## Reconnect and retained sends
80
+
81
+ Automatic reconnect is disabled by default. Enable it on the existing `connect`
82
+ method for ordinary model sessions:
83
+
84
+ ```ruby
85
+ client.realtime.connect(model: "gpt-realtime-2.1", reconnect: true) do |connection|
86
+ connection.each { |event| handle_event(event) }
87
+ end
88
+ ```
89
+
90
+ Both `receive` and `each` drive recovery. The application block runs once, with
91
+ the same connection object. Recovery opens a **new session**; it does not restore
92
+ conversation history, buffered audio, outstanding tool calls, or an interrupted
93
+ response. The normal server session events remain observable. Sends alone do
94
+ not drive recovery: keep a receiver running to observe disconnects.
95
+
96
+ `max_reconnect_attempts` defaults to 5 and bounds the total additional connection
97
+ attempts over the block's lifetime, including retryable initial handshake
98
+ failures. Backoff starts at 0.5 seconds, doubles to an 8-second cap, and applies
99
+ jitter. Normal close, explicit close, permanent authentication/TLS/protocol
100
+ failures, and exhausted retries stop recovery. Each attempt uses the client's
101
+ existing endpoint and authentication preparation, including workload-identity
102
+ token refresh. `request_options[:max_retries]` remains an HTTP option and must
103
+ not be used to configure WebSocket reconnect.
104
+
105
+ An optional `on_reconnected:` callback receives the same connection before the
106
+ replacement is made available to waiting readers. It can restore application
107
+ state using the usual typed helpers; its exceptions stop recovery. A callback
108
+ may receive events itself, consuming them before the application receiver.
109
+
110
+ ### Optional outbound queue
111
+
112
+ `max_queue_bytes` defaults to **0** (queueing disabled). Set a positive byte
113
+ budget to retain validated, serialized events sent while reconnecting or while
114
+ an explicit queue flush is in progress. Queue-full errors reject the new event
115
+ without evicting accepted events. The budget includes a queued write until it
116
+ settles; empty raw text costs one byte for accounting. Connected sends and
117
+ incoming events have no new payload-size limit.
118
+
119
+ Retained events are **never automatically flushed** into a replacement session.
120
+ Restore any needed state, decide whether the queued work still belongs in that
121
+ session, then call `flush_pending`. Normal connected sends bypass the held queue,
122
+ allowing setup messages to precede it. Only the retained messages have FIFO
123
+ ordering relative to each other. For example:
124
+
125
+ ```ruby
126
+ restore = lambda do |connection|
127
+ connection.session.update(type: :realtime, instructions: "Be concise.")
128
+ # Use this only when the application knows its retained events are valid
129
+ # in the replacement session. Rebuilding earlier conversation state may
130
+ # require additional events and acknowledgements first.
131
+ connection.flush_pending
132
+ end
133
+
134
+ client.realtime.connect(
135
+ model: "gpt-realtime-2.1",
136
+ reconnect: true,
137
+ max_queue_bytes: 1_048_576,
138
+ on_reconnected: restore
139
+ ) do |connection|
140
+ connection.each { |event| handle_event(event) }
141
+ end
142
+ ```
143
+
144
+ The callback is optional even with queueing enabled. After receiving a new
145
+ session's events, application code can restore state and flush the queue itself.
146
+ `pending_messages` returns a snapshot of encoded unsent events;
147
+ `take_pending_messages` removes and returns them without sending. The latter
148
+ raises if a flush is in progress. These accessors return empty arrays on ordinary
149
+ connections without recovery; `flush_pending` on such a connection is a no-op.
150
+
151
+ `OpenAI::Errors::RealtimeQueueFullError` means the event was not accepted.
152
+ `OpenAI::Errors::RealtimeReconnectError` reports a terminal recovery failure or
153
+ an interrupted operation. Its `unsent_messages` contains retained events never
154
+ attempted on the socket. A failed write stops the connection and exposes the
155
+ attempted event as `uncertain_message`; the SDK never retries it. A local write
156
+ completion is not a server acknowledgement, and `event_id` does not establish
157
+ exactly-once delivery. These explicit payload accessors can contain sensitive
158
+ application data; do not log them. Error messages omit their contents.
159
+
160
+ Each waiting sender receives an error describing only its own event. If its write
161
+ was never attempted, that event appears in `unsent_messages` and `uncertain_message`
162
+ is nil, even when another concurrent sender's write caused the connection to fail.
163
+
164
+ When an explicit flush is interrupted by another disconnect, unattempted events
165
+ stay queued and require another explicit flush after recovery. Intentional close
166
+ keeps retained data available through the connection's queue accessors. With
167
+ reconnect enabled, close makes a best-effort attempt (up to one second) to send its
168
+ `code` and `reason`, then releases the socket. A close during a write aborts
169
+ immediately and reports uncertain delivery. Leaving the block cancels and joins recovery
170
+ work. Concurrent producers submit through the connection's mailbox; socket I/O
171
+ stays on its owning Async reactor. Cancelling a waiting operation closes the
172
+ logical connection so an abandoned receive cannot consume a later event.
173
+
174
+ Reconnect uses the optional Async runtime even with a custom transport. Custom
175
+ transports must allow Async cancellation and preserve the cause/status of
176
+ `RealtimeConnectionError` for retry classification. `connect_transcription` and
177
+ `connect_to_call` retain their existing behavior; their session recovery
178
+ semantics are not enabled by this option.
179
+
79
180
  ## Standard text workflows
80
181
 
81
182
  The same generic helpers cover local function results, image content, and MCP
@@ -0,0 +1,182 @@
1
+ # Responses WebSocket workflows
2
+
3
+ Requires `openai` 0.86.0 or later and the optional `async-websocket` gem:
4
+
5
+ ```ruby
6
+ gem "openai", ">= 0.86.0"
7
+ gem "async-websocket"
8
+ ```
9
+
10
+ Responses WebSocket mode connects to `/v1/responses`. It uses Responses events;
11
+ it is distinct from [Realtime sessions](realtime.md). See the
12
+ [platform guide](https://developers.openai.com/api/docs/guides/websocket-mode)
13
+ for the service contract.
14
+
15
+ ## Run the examples
16
+
17
+ The [workflow example](examples/responses/websocket_workflows.rb) demonstrates
18
+ four patterns with one reader and no background worker threads. Keep
19
+ `OPENAI_API_KEY` in your environment. These commands make real API calls:
20
+
21
+ ```sh
22
+ bundle exec ruby examples/responses/websocket_workflows.rb tools
23
+ bundle exec ruby examples/responses/websocket_workflows.rb multiplex
24
+ bundle exec ruby examples/responses/websocket_workflows.rb stored
25
+ bundle exec ruby examples/responses/websocket_workflows.rb stateless
26
+ ```
27
+
28
+ Set `OPENAI_RESPONSES_MODEL` to override `gpt-5.2` and
29
+ `OPENAI_RESPONSES_TIMEOUT` to change the 60-second overall deadline. The example
30
+ prints only a completion marker, not prompts, model output, or server errors.
31
+ The default workflow is `multiplex`. The `stored` workflow requires an account
32
+ that allows response storage; use `stateless` with `store=false`/ZDR.
33
+
34
+ ## Connect, send, and receive
35
+
36
+ ```ruby
37
+ client.responses.connect do |connection|
38
+ connection.response.create(model: "gpt-5.2", input: "Say hello.")
39
+ connection.each do |event|
40
+ case event.type.to_s
41
+ when "response.completed"
42
+ # Save event.response.id and handle event.response.output here.
43
+ break
44
+ when "response.failed", "response.incomplete", "error"
45
+ raise "Responses operation did not complete."
46
+ end
47
+ end
48
+ end
49
+ ```
50
+
51
+ Use the complete example for EOF detection: a connection ending before every
52
+ expected terminal event is not success. `connect` requires a block and closes
53
+ on block exit. Connection options belong in `connect`; model/input fields belong
54
+ in `connection.response.create`.
55
+
56
+ Known events are decoded into generated models on a best-effort basis. New
57
+ event types arrive as `OpenAI::Responses::UnknownServerEvent`. Preserve or handle
58
+ them explicitly where your application needs them. Do not assume every event
59
+ has a response, text delta, or lane ID.
60
+
61
+ ## Sequential tool turns
62
+
63
+ The `tools` workflow forces a call to one known, harmless application function.
64
+ After the response completes, it checks the function name and sends its output
65
+ using the original `call_id`. The next create uses `previous_response_id` and
66
+ only the new `function_call_output` item. It does not resend the previous input
67
+ on the same connection.
68
+
69
+ Tool execution belongs to your application. Validate arguments against your
70
+ tool's contract and authorize effects before execution. Never execute generated
71
+ code or dispatch arbitrary method names from a tool event. The example uses a
72
+ fixed result and does not execute model-provided code.
73
+
74
+ ## Multiplexing and continuation
75
+
76
+ `stream_id` routes events to a lane; `previous_response_id` selects conversation
77
+ history. They are independent. Reusing a lane without a previous response ID
78
+ starts a new response rather than continuing that lane's conversation.
79
+
80
+ The `multiplex` workflow writes two creates, then drains both lanes with one
81
+ reader. Events may interleave and the first terminal event does not finish the
82
+ whole operation. Keep a pending-lane set and retain each completed response ID.
83
+ Omitting `stream_id` uses the default lane; its events omit the field as well.
84
+
85
+ The example fails the whole operation on any error. Production applications can
86
+ route a lane-scoped error to just that lane, while treating a connection-scoped
87
+ error as affecting the connection. Track separate response IDs when multiple
88
+ requests are outstanding within a lane; a lane alone is not a request ID.
89
+
90
+ The server executes same-lane requests in FIFO order. The SDK does not enforce
91
+ lane grammar, schedule lanes, or manage a per-lane queue. Consult the platform
92
+ guide for the current concurrent-response and named-lane limits.
93
+
94
+ To fork, send an existing response ID on a different lane. With `store=false`,
95
+ wait for the fork's `response.in_progress` before advancing the source lane so
96
+ its parent remains available in the connection-local cache.
97
+
98
+ ## Reconnect without replaying uncertain work
99
+
100
+ Both reconnect examples intentionally close a healthy connection **after** a
101
+ completed turn, then open another connection. They do not catch a failed write
102
+ and retry it.
103
+
104
+ - **Stored:** send only the new input plus the stored `previous_response_id`.
105
+ If the service cannot retrieve that response, the application must decide
106
+ whether to reconstruct context and start a new chain.
107
+ - **Stateless:** connection-local state is lost on reconnect. Retain the original
108
+ inputs and every output item, including reasoning and tool items. Request
109
+ `include: ["reasoning.encrypted_content"]` for reasoning-model replay. Send the
110
+ retained history plus new input, omitting `previous_response_id` on the new
111
+ connection. Do not reduce history to displayed assistant text.
112
+
113
+ Retained history can contain sensitive data. Apply your application's retention
114
+ policy; neither the SDK nor this example writes a recovery log. A full-context
115
+ replay starts a new chain and is not an exactly-once retry of a failed turn.
116
+
117
+ Connections have a finite service lifetime (currently up to 60 minutes). Plan
118
+ rotation and persistence at completed-turn boundaries. There is no automatic
119
+ reconnect, rollover, or replay in this SDK connection.
120
+
121
+ ## Deadlines and shutdown
122
+
123
+ An SDK request timeout bounds connection negotiation, not an established
124
+ session's idle lifetime. The example wraps the complete workflow in an Async
125
+ deadline on the owning thread:
126
+
127
+ ```ruby
128
+ require "async"
129
+
130
+ Sync do |task|
131
+ task.with_timeout(60) do
132
+ client.responses.connect do |connection|
133
+ # Send and read on this thread, inside the deadline.
134
+ end
135
+ end
136
+ end
137
+ ```
138
+
139
+ Connections enforce one owning thread and one active reader. Do not call close
140
+ from another thread or nest `receive` inside an active `each`. The Async deadline
141
+ can interrupt an idle network read on the owning thread; the SDK then aborts and
142
+ cleans up the connection. A timeout inside a transport operation can surface as
143
+ `ResponsesConnectionError`, rather than `Async::TimeoutError`. Application code
144
+ that does CPU-bound work without yielding needs its own cancellation strategy.
145
+
146
+ Exiting the block normally performs a close. An exception or poisoned connection
147
+ causes an abort, avoiding a flush of uncertain buffered output. The peer may see
148
+ an abrupt disconnect. This is local shutdown, not a server-side cancellation
149
+ acknowledgment, and it does not guarantee that a response stopped executing.
150
+
151
+ ## Error and compatibility boundaries
152
+
153
+ - `ResponsesSendError#outcome` is `:unknown`: the server may have accepted the
154
+ event. Stop using that connection; do not automatically resend it.
155
+ - A transport read failure poisons the connection. A server `error` event is
156
+ delivered as an event and does not by itself poison it.
157
+ - Malformed JSON raises `ResponsesProtocolError` without exposing the payload;
158
+ the connection permits later reads. Decide whether continuing is appropriate
159
+ for your application.
160
+ - Raw `send_event` supports generated client models or hashes, including
161
+ `response.steer`. There is no `connection.response.steer` convenience method.
162
+ - The platform documents `generate: false` warmup. It can be forwarded through
163
+ create's keyword rest even though 0.86.0 has no named generated `generate`
164
+ keyword. Follow the platform contract; do not send HTTP-only `stream` or
165
+ `background` flags just because generated models expose them.
166
+ - X.509 workload identity and provider runtimes are not supported by this
167
+ entry point. A nonempty `request_options.extra_query` or nonzero
168
+ `request_options.max_retries` is rejected. Supported workload identity has a
169
+ narrow pre-handshake 401 refresh; that is not live-session recovery.
170
+ - Large events are valid. Plan memory and application backpressure for your
171
+ workload without treating a fixed payload size as a protocol maximum.
172
+
173
+ ## Offline verification
174
+
175
+ ```sh
176
+ bundle exec ruby -Itest test/openai/responses_websocket/workflows_test.rb
177
+ ```
178
+
179
+ The tests use real loopback WebSockets and synthetic data, exercise the default
180
+ Responses transport, and make no live API requests. They cover the four example
181
+ patterns, interleaved terminal events, fragmented text, premature EOF, failures,
182
+ idle-read deadlines, and a large event exceeding 32 MiB.