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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +10 -1
- data/examples/audio/record_and_play.rb +19 -0
- data/examples/responses/websocket_workflows.rb +159 -0
- data/lib/openai/helpers/local_audio/errors.rb +27 -0
- data/lib/openai/helpers/local_audio/process.rb +158 -0
- data/lib/openai/helpers/local_audio.rb +157 -0
- data/lib/openai/helpers/realtime/connection.rb +20 -2
- data/lib/openai/helpers/realtime/errors.rb +18 -0
- data/lib/openai/helpers/realtime/recovery.rb +489 -0
- data/lib/openai/helpers/realtime/resources/realtime_extension.rb +26 -1
- data/lib/openai/helpers/realtime.rb +1 -0
- data/lib/openai/models/beta/beta_response_input_item.rb +84 -1
- data/lib/openai/models/beta/beta_response_item.rb +72 -1
- data/lib/openai/models/beta/beta_response_output_item.rb +84 -1
- data/lib/openai/models/beta/beta_responses_client_event.rb +3 -0
- data/lib/openai/models/beta/beta_tool.rb +69 -37
- data/lib/openai/models/beta/response_create_params.rb +3 -0
- data/lib/openai/models/conversations/conversation_item.rb +82 -1
- data/lib/openai/models/image_edit_completed_event.rb +34 -8
- data/lib/openai/models/image_edit_params.rb +64 -44
- data/lib/openai/models/image_edit_partial_image_event.rb +34 -8
- data/lib/openai/models/image_gen_completed_event.rb +34 -8
- data/lib/openai/models/image_gen_partial_image_event.rb +34 -8
- data/lib/openai/models/image_generate_params.rb +51 -35
- data/lib/openai/models/image_model.rb +4 -0
- data/lib/openai/models/images_response.rb +37 -13
- data/lib/openai/models/responses/response_create_params.rb +3 -0
- data/lib/openai/models/responses/response_input_item.rb +84 -1
- data/lib/openai/models/responses/response_item.rb +72 -1
- data/lib/openai/models/responses/response_output_item.rb +84 -1
- data/lib/openai/models/responses/responses_client_event.rb +3 -0
- data/lib/openai/models/responses/tool.rb +69 -37
- data/lib/openai/models/webhooks/live_call_incoming_webhook_event.rb +3 -3
- data/lib/openai/models/webhooks/realtime_call_incoming_webhook_event.rb +5 -3
- data/lib/openai/resources/images.rb +12 -14
- data/lib/openai/version.rb +1 -1
- data/local-audio.md +146 -0
- data/rbi/openai/helpers/local_audio/interface.rbi +110 -0
- data/rbi/openai/helpers/realtime/connection.rbi +18 -2
- data/rbi/openai/helpers/realtime/extensions.rbi +8 -0
- data/rbi/openai/helpers/realtime/recovery.rbi +27 -0
- data/rbi/openai/models/beta/beta_response_input_item.rbi +86 -1
- data/rbi/openai/models/beta/beta_response_item.rbi +78 -1
- data/rbi/openai/models/beta/beta_response_output_item.rbi +84 -1
- data/rbi/openai/models/beta/beta_responses_client_event.rbi +6 -0
- data/rbi/openai/models/beta/beta_tool.rbi +90 -51
- data/rbi/openai/models/beta/response_create_params.rbi +6 -0
- data/rbi/openai/models/conversations/conversation_item.rbi +88 -1
- data/rbi/openai/models/image_edit_completed_event.rbi +20 -9
- data/rbi/openai/models/image_edit_params.rbi +89 -60
- data/rbi/openai/models/image_edit_partial_image_event.rbi +20 -9
- data/rbi/openai/models/image_gen_completed_event.rbi +20 -9
- data/rbi/openai/models/image_gen_partial_image_event.rbi +20 -9
- data/rbi/openai/models/image_generate_params.rbi +71 -48
- data/rbi/openai/models/image_model.rbi +4 -0
- data/rbi/openai/models/images_response.rbi +27 -16
- data/rbi/openai/models/responses/response_create_params.rbi +6 -0
- data/rbi/openai/models/responses/response_input_item.rbi +88 -1
- data/rbi/openai/models/responses/response_item.rbi +80 -1
- data/rbi/openai/models/responses/response_output_item.rbi +84 -1
- data/rbi/openai/models/responses/responses_client_event.rbi +6 -0
- data/rbi/openai/models/responses/tool.rbi +90 -51
- data/rbi/openai/models/webhooks/live_call_incoming_webhook_event.rbi +4 -4
- data/rbi/openai/models/webhooks/realtime_call_incoming_webhook_event.rbi +8 -4
- data/rbi/openai/resources/beta/responses.rbi +6 -2
- data/rbi/openai/resources/images.rbi +106 -76
- data/rbi/openai/resources/responses.rbi +6 -0
- data/realtime.md +101 -0
- data/responses-websocket.md +182 -0
- data/sig/openai/helpers/local_audio/interface.rbs +62 -0
- data/sig/openai/helpers/realtime/connection.rbs +9 -1
- data/sig/openai/helpers/realtime/extensions.rbs +4 -0
- data/sig/openai/helpers/realtime/recovery.rbs +19 -0
- data/sig/openai/models/beta/beta_response_input_item.rbs +39 -2
- data/sig/openai/models/beta/beta_response_item.rbs +39 -2
- data/sig/openai/models/beta/beta_response_output_item.rbs +39 -2
- data/sig/openai/models/beta/beta_tool.rbs +11 -1
- data/sig/openai/models/conversations/conversation_item.rbs +39 -2
- data/sig/openai/models/image_edit_completed_event.rbs +11 -4
- data/sig/openai/models/image_edit_params.rbs +3 -1
- data/sig/openai/models/image_edit_partial_image_event.rbs +11 -4
- data/sig/openai/models/image_gen_completed_event.rbs +11 -4
- data/sig/openai/models/image_gen_partial_image_event.rbs +11 -4
- data/sig/openai/models/image_generate_params.rbs +4 -1
- data/sig/openai/models/image_model.rbs +8 -0
- data/sig/openai/models/images_response.rbs +10 -4
- data/sig/openai/models/responses/response_input_item.rbs +39 -2
- data/sig/openai/models/responses/response_item.rbs +39 -2
- data/sig/openai/models/responses/response_output_item.rbs +39 -2
- data/sig/openai/models/responses/tool.rbs +11 -1
- 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
|
|
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`,
|
|
81
|
-
#
|
|
82
|
-
#
|
|
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
|
-
#
|
|
99
|
-
# `
|
|
100
|
-
#
|
|
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`,
|
|
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.
|
|
139
|
-
#
|
|
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`
|
|
147
|
-
# `gpt-image-2-2026-
|
|
148
|
-
#
|
|
149
|
-
#
|
|
150
|
-
#
|
|
151
|
-
#
|
|
152
|
-
#
|
|
153
|
-
#
|
|
154
|
-
#
|
|
155
|
-
# `
|
|
156
|
-
# `
|
|
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
|
|
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`,
|
|
200
|
-
#
|
|
201
|
-
#
|
|
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
|
-
#
|
|
218
|
-
# `
|
|
219
|
-
#
|
|
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`,
|
|
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.
|
|
258
|
-
#
|
|
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`
|
|
266
|
-
# `gpt-image-2-2026-
|
|
267
|
-
#
|
|
268
|
-
#
|
|
269
|
-
#
|
|
270
|
-
#
|
|
271
|
-
#
|
|
272
|
-
#
|
|
273
|
-
#
|
|
274
|
-
# `
|
|
275
|
-
# `
|
|
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
|
-
#
|
|
322
|
-
# `
|
|
323
|
-
#
|
|
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
|
-
#
|
|
328
|
-
#
|
|
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`
|
|
365
|
-
# `gpt-image-2-2026-
|
|
366
|
-
#
|
|
367
|
-
#
|
|
368
|
-
#
|
|
369
|
-
#
|
|
370
|
-
#
|
|
371
|
-
#
|
|
372
|
-
#
|
|
373
|
-
# `
|
|
374
|
-
# `
|
|
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
|
-
#
|
|
426
|
-
# `
|
|
427
|
-
#
|
|
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
|
-
#
|
|
432
|
-
#
|
|
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`
|
|
469
|
-
# `gpt-image-2-2026-
|
|
470
|
-
#
|
|
471
|
-
#
|
|
472
|
-
#
|
|
473
|
-
#
|
|
474
|
-
#
|
|
475
|
-
#
|
|
476
|
-
#
|
|
477
|
-
# `
|
|
478
|
-
# `
|
|
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.
|