openai 0.15.0 → 0.17.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 (174) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +47 -0
  3. data/README.md +14 -20
  4. data/lib/openai/helpers/structured_output/json_schema_converter.rb +20 -21
  5. data/lib/openai/helpers/structured_output/union_of.rb +11 -1
  6. data/lib/openai/internal/transport/base_client.rb +1 -1
  7. data/lib/openai/internal/type/enum.rb +6 -6
  8. data/lib/openai/internal/type/union.rb +13 -17
  9. data/lib/openai/models/beta/assistant_create_params.rb +4 -5
  10. data/lib/openai/models/beta/assistant_update_params.rb +22 -5
  11. data/lib/openai/models/beta/threads/run_create_params.rb +4 -5
  12. data/lib/openai/models/chat/chat_completion_allowed_tool_choice.rb +33 -0
  13. data/lib/openai/models/chat/chat_completion_allowed_tools.rb +64 -0
  14. data/lib/openai/models/chat/chat_completion_assistant_message_param.rb +3 -5
  15. data/lib/openai/models/chat/chat_completion_custom_tool.rb +163 -0
  16. data/lib/openai/models/chat/chat_completion_function_tool.rb +29 -0
  17. data/lib/openai/models/chat/chat_completion_message.rb +3 -5
  18. data/lib/openai/models/chat/chat_completion_message_custom_tool_call.rb +60 -0
  19. data/lib/openai/models/chat/chat_completion_message_function_tool_call.rb +73 -0
  20. data/lib/openai/models/chat/chat_completion_message_tool_call.rb +10 -56
  21. data/lib/openai/models/chat/chat_completion_named_tool_choice.rb +2 -2
  22. data/lib/openai/models/chat/chat_completion_named_tool_choice_custom.rb +42 -0
  23. data/lib/openai/models/chat/chat_completion_store_message.rb +32 -1
  24. data/lib/openai/models/chat/chat_completion_stream_options.rb +14 -1
  25. data/lib/openai/models/chat/chat_completion_tool.rb +12 -14
  26. data/lib/openai/models/chat/chat_completion_tool_choice_option.rb +7 -1
  27. data/lib/openai/models/chat/completion_create_params.rb +65 -16
  28. data/lib/openai/models/chat_model.rb +7 -0
  29. data/lib/openai/models/custom_tool_input_format.rb +76 -0
  30. data/lib/openai/models/evals/create_eval_completions_run_data_source.rb +3 -3
  31. data/lib/openai/models/evals/run_cancel_response.rb +2 -2
  32. data/lib/openai/models/evals/run_create_params.rb +2 -2
  33. data/lib/openai/models/evals/run_create_response.rb +2 -2
  34. data/lib/openai/models/evals/run_list_response.rb +2 -2
  35. data/lib/openai/models/evals/run_retrieve_response.rb +2 -2
  36. data/lib/openai/models/reasoning.rb +4 -5
  37. data/lib/openai/models/reasoning_effort.rb +4 -4
  38. data/lib/openai/models/response_format_text_grammar.rb +27 -0
  39. data/lib/openai/models/response_format_text_python.rb +20 -0
  40. data/lib/openai/models/responses/custom_tool.rb +48 -0
  41. data/lib/openai/models/responses/response.rb +70 -16
  42. data/lib/openai/models/responses/response_create_params.rb +78 -14
  43. data/lib/openai/models/responses/response_custom_tool_call.rb +55 -0
  44. data/lib/openai/models/responses/response_custom_tool_call_input_delta_event.rb +52 -0
  45. data/lib/openai/models/responses/response_custom_tool_call_input_done_event.rb +52 -0
  46. data/lib/openai/models/responses/response_custom_tool_call_output.rb +47 -0
  47. data/lib/openai/models/responses/response_input_item.rb +7 -1
  48. data/lib/openai/models/responses/response_output_item.rb +4 -1
  49. data/lib/openai/models/responses/response_output_item_added_event.rb +2 -2
  50. data/lib/openai/models/responses/response_output_item_done_event.rb +2 -2
  51. data/lib/openai/models/responses/response_reasoning_item.rb +36 -5
  52. data/lib/openai/models/responses/response_reasoning_text_delta_event.rb +63 -0
  53. data/lib/openai/models/responses/response_reasoning_text_done_event.rb +63 -0
  54. data/lib/openai/models/responses/response_retrieve_params.rb +14 -1
  55. data/lib/openai/models/responses/response_stream_event.rb +13 -11
  56. data/lib/openai/models/responses/response_text_config.rb +27 -1
  57. data/lib/openai/models/responses/tool.rb +5 -1
  58. data/lib/openai/models/responses/tool_choice_allowed.rb +73 -0
  59. data/lib/openai/models/responses/tool_choice_custom.rb +28 -0
  60. data/lib/openai/models/vector_store_search_params.rb +6 -1
  61. data/lib/openai/models.rb +6 -0
  62. data/lib/openai/resources/beta/assistants.rb +2 -2
  63. data/lib/openai/resources/beta/threads/runs.rb +2 -2
  64. data/lib/openai/resources/chat/completions.rb +26 -12
  65. data/lib/openai/resources/responses.rb +77 -36
  66. data/lib/openai/version.rb +1 -1
  67. data/lib/openai.rb +19 -2
  68. data/rbi/openai/internal/transport/base_client.rbi +1 -1
  69. data/rbi/openai/models/beta/assistant_create_params.rbi +6 -8
  70. data/rbi/openai/models/beta/assistant_update_params.rbi +36 -8
  71. data/rbi/openai/models/beta/threads/run_create_params.rbi +6 -8
  72. data/rbi/openai/models/chat/chat_completion_allowed_tool_choice.rbi +60 -0
  73. data/rbi/openai/models/chat/chat_completion_allowed_tools.rbi +118 -0
  74. data/rbi/openai/models/chat/chat_completion_assistant_message_param.rbi +27 -4
  75. data/rbi/openai/models/chat/chat_completion_custom_tool.rbi +335 -0
  76. data/rbi/openai/models/chat/chat_completion_function_tool.rbi +51 -0
  77. data/rbi/openai/models/chat/chat_completion_message.rbi +17 -4
  78. data/rbi/openai/models/chat/chat_completion_message_custom_tool_call.rbi +105 -0
  79. data/rbi/openai/models/chat/chat_completion_message_function_tool_call.rbi +118 -0
  80. data/rbi/openai/models/chat/chat_completion_message_tool_call.rbi +9 -92
  81. data/rbi/openai/models/chat/chat_completion_named_tool_choice.rbi +2 -2
  82. data/rbi/openai/models/chat/chat_completion_named_tool_choice_custom.rbi +89 -0
  83. data/rbi/openai/models/chat/chat_completion_store_message.rbi +68 -3
  84. data/rbi/openai/models/chat/chat_completion_stream_options.rbi +30 -2
  85. data/rbi/openai/models/chat/chat_completion_tool.rbi +11 -30
  86. data/rbi/openai/models/chat/chat_completion_tool_choice_option.rbi +3 -1
  87. data/rbi/openai/models/chat/completion_create_params.rbi +150 -31
  88. data/rbi/openai/models/chat_model.rbi +11 -0
  89. data/rbi/openai/models/custom_tool_input_format.rbi +136 -0
  90. data/rbi/openai/models/evals/create_eval_completions_run_data_source.rbi +8 -4
  91. data/rbi/openai/models/evals/run_cancel_response.rbi +2 -0
  92. data/rbi/openai/models/evals/run_create_params.rbi +4 -0
  93. data/rbi/openai/models/evals/run_create_response.rbi +2 -0
  94. data/rbi/openai/models/evals/run_list_response.rbi +2 -0
  95. data/rbi/openai/models/evals/run_retrieve_response.rbi +2 -0
  96. data/rbi/openai/models/reasoning.rbi +6 -8
  97. data/rbi/openai/models/reasoning_effort.rbi +4 -4
  98. data/rbi/openai/models/response_format_text_grammar.rbi +35 -0
  99. data/rbi/openai/models/response_format_text_python.rbi +30 -0
  100. data/rbi/openai/models/responses/custom_tool.rbi +96 -0
  101. data/rbi/openai/models/responses/response.rbi +59 -11
  102. data/rbi/openai/models/responses/response_create_params.rbi +138 -13
  103. data/rbi/openai/models/responses/response_custom_tool_call.rbi +78 -0
  104. data/rbi/openai/models/responses/response_custom_tool_call_input_delta_event.rbi +75 -0
  105. data/rbi/openai/models/responses/response_custom_tool_call_input_done_event.rbi +75 -0
  106. data/rbi/openai/models/responses/response_custom_tool_call_output.rbi +65 -0
  107. data/rbi/openai/models/responses/response_input_item.rbi +2 -0
  108. data/rbi/openai/models/responses/response_output_item.rbi +2 -1
  109. data/rbi/openai/models/responses/response_output_item_added_event.rbi +2 -1
  110. data/rbi/openai/models/responses/response_output_item_done_event.rbi +2 -1
  111. data/rbi/openai/models/responses/response_reasoning_item.rbi +63 -4
  112. data/rbi/openai/models/responses/response_reasoning_text_delta_event.rbi +83 -0
  113. data/rbi/openai/models/responses/{response_reasoning_summary_done_event.rbi → response_reasoning_text_done_event.rbi} +20 -20
  114. data/rbi/openai/models/responses/response_retrieve_params.rbi +21 -0
  115. data/rbi/openai/models/responses/response_stream_event.rbi +4 -2
  116. data/rbi/openai/models/responses/response_text_config.rbi +64 -1
  117. data/rbi/openai/models/responses/tool.rbi +1 -0
  118. data/rbi/openai/models/responses/tool_choice_allowed.rbi +124 -0
  119. data/rbi/openai/models/responses/tool_choice_custom.rbi +39 -0
  120. data/rbi/openai/models/vector_store_search_params.rbi +12 -1
  121. data/rbi/openai/models.rbi +6 -0
  122. data/rbi/openai/resources/beta/assistants.rbi +6 -8
  123. data/rbi/openai/resources/beta/threads/runs.rbi +8 -10
  124. data/rbi/openai/resources/chat/completions.rbi +78 -25
  125. data/rbi/openai/resources/responses.rbi +249 -47
  126. data/sig/openai/internal/transport/base_client.rbs +1 -1
  127. data/sig/openai/models/beta/assistant_update_params.rbs +12 -0
  128. data/sig/openai/models/chat/chat_completion_allowed_tool_choice.rbs +29 -0
  129. data/sig/openai/models/chat/chat_completion_allowed_tools.rbs +38 -0
  130. data/sig/openai/models/chat/chat_completion_assistant_message_param.rbs +6 -6
  131. data/sig/openai/models/chat/chat_completion_custom_tool.rbs +137 -0
  132. data/sig/openai/models/chat/chat_completion_function_tool.rbs +26 -0
  133. data/sig/openai/models/chat/chat_completion_message.rbs +6 -6
  134. data/sig/openai/models/chat/chat_completion_message_custom_tool_call.rbs +46 -0
  135. data/sig/openai/models/chat/chat_completion_message_function_tool_call.rbs +46 -0
  136. data/sig/openai/models/chat/chat_completion_message_tool_call.rbs +6 -35
  137. data/sig/openai/models/chat/chat_completion_named_tool_choice_custom.rbs +39 -0
  138. data/sig/openai/models/chat/chat_completion_store_message.rbs +29 -3
  139. data/sig/openai/models/chat/chat_completion_stream_options.rbs +11 -3
  140. data/sig/openai/models/chat/chat_completion_tool.rbs +6 -15
  141. data/sig/openai/models/chat/chat_completion_tool_choice_option.rbs +2 -0
  142. data/sig/openai/models/chat/completion_create_params.rbs +37 -6
  143. data/sig/openai/models/chat_model.rbs +15 -1
  144. data/sig/openai/models/custom_tool_input_format.rbs +61 -0
  145. data/sig/openai/models/evals/create_eval_completions_run_data_source.rbs +6 -6
  146. data/sig/openai/models/reasoning_effort.rbs +2 -1
  147. data/sig/openai/models/response_format_text_grammar.rbs +15 -0
  148. data/sig/openai/models/response_format_text_python.rbs +13 -0
  149. data/sig/openai/models/responses/custom_tool.rbs +43 -0
  150. data/sig/openai/models/responses/response.rbs +16 -0
  151. data/sig/openai/models/responses/response_create_params.rbs +33 -0
  152. data/sig/openai/models/responses/response_custom_tool_call.rbs +44 -0
  153. data/sig/openai/models/responses/response_custom_tool_call_input_delta_event.rbs +42 -0
  154. data/sig/openai/models/responses/response_custom_tool_call_input_done_event.rbs +42 -0
  155. data/sig/openai/models/responses/response_custom_tool_call_output.rbs +39 -0
  156. data/sig/openai/models/responses/response_input_item.rbs +2 -0
  157. data/sig/openai/models/responses/response_output_item.rbs +1 -0
  158. data/sig/openai/models/responses/response_reasoning_item.rbs +21 -0
  159. data/sig/openai/models/responses/{response_reasoning_summary_delta_event.rbs → response_reasoning_text_delta_event.rbs} +15 -15
  160. data/sig/openai/models/responses/{response_reasoning_summary_done_event.rbs → response_reasoning_text_done_event.rbs} +11 -11
  161. data/sig/openai/models/responses/response_retrieve_params.rbs +7 -0
  162. data/sig/openai/models/responses/response_stream_event.rbs +4 -2
  163. data/sig/openai/models/responses/response_text_config.rbs +22 -3
  164. data/sig/openai/models/responses/tool.rbs +1 -0
  165. data/sig/openai/models/responses/tool_choice_allowed.rbs +43 -0
  166. data/sig/openai/models/responses/tool_choice_custom.rbs +17 -0
  167. data/sig/openai/models/vector_store_search_params.rbs +2 -1
  168. data/sig/openai/models.rbs +6 -0
  169. data/sig/openai/resources/chat/completions.rbs +8 -2
  170. data/sig/openai/resources/responses.rbs +36 -0
  171. metadata +59 -8
  172. data/lib/openai/models/responses/response_reasoning_summary_delta_event.rb +0 -65
  173. data/lib/openai/models/responses/response_reasoning_summary_done_event.rb +0 -60
  174. data/rbi/openai/models/responses/response_reasoning_summary_delta_event.rbi +0 -85
@@ -148,6 +148,15 @@ module OpenAI
148
148
  end
149
149
  attr_writer :prompt
150
150
 
151
+ # Used by OpenAI to cache responses for similar requests to optimize your cache
152
+ # hit rates. Replaces the `user` field.
153
+ # [Learn more](https://platform.openai.com/docs/guides/prompt-caching).
154
+ sig { returns(T.nilable(String)) }
155
+ attr_reader :prompt_cache_key
156
+
157
+ sig { params(prompt_cache_key: String).void }
158
+ attr_writer :prompt_cache_key
159
+
151
160
  # **o-series models only**
152
161
  #
153
162
  # Configuration options for
@@ -158,6 +167,17 @@ module OpenAI
158
167
  sig { params(reasoning: T.nilable(OpenAI::Reasoning::OrHash)).void }
159
168
  attr_writer :reasoning
160
169
 
170
+ # A stable identifier used to help detect users of your application that may be
171
+ # violating OpenAI's usage policies. The IDs should be a string that uniquely
172
+ # identifies each user. We recommend hashing their username or email address, in
173
+ # order to avoid sending us any identifying information.
174
+ # [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
175
+ sig { returns(T.nilable(String)) }
176
+ attr_reader :safety_identifier
177
+
178
+ sig { params(safety_identifier: String).void }
179
+ attr_writer :safety_identifier
180
+
161
181
  # Specifies the processing type used for serving the request.
162
182
  #
163
183
  # - If set to 'auto', then the request will be processed with the service tier
@@ -188,6 +208,24 @@ module OpenAI
188
208
  sig { returns(T.nilable(T::Boolean)) }
189
209
  attr_accessor :store
190
210
 
211
+ # Options for streaming responses. Only set this when you set `stream: true`.
212
+ sig do
213
+ returns(
214
+ T.nilable(OpenAI::Responses::ResponseCreateParams::StreamOptions)
215
+ )
216
+ end
217
+ attr_reader :stream_options
218
+
219
+ sig do
220
+ params(
221
+ stream_options:
222
+ T.nilable(
223
+ OpenAI::Responses::ResponseCreateParams::StreamOptions::OrHash
224
+ )
225
+ ).void
226
+ end
227
+ attr_writer :stream_options
228
+
191
229
  # What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
192
230
  # make the output more random, while lower values like 0.2 will make it more
193
231
  # focused and deterministic. We generally recommend altering this or `top_p` but
@@ -222,9 +260,11 @@ module OpenAI
222
260
  T.nilable(
223
261
  T.any(
224
262
  OpenAI::Responses::ToolChoiceOptions::OrSymbol,
263
+ OpenAI::Responses::ToolChoiceAllowed,
225
264
  OpenAI::Responses::ToolChoiceTypes,
226
265
  OpenAI::Responses::ToolChoiceFunction,
227
- OpenAI::Responses::ToolChoiceMcp
266
+ OpenAI::Responses::ToolChoiceMcp,
267
+ OpenAI::Responses::ToolChoiceCustom
228
268
  )
229
269
  )
230
270
  )
@@ -236,9 +276,11 @@ module OpenAI
236
276
  tool_choice:
237
277
  T.any(
238
278
  OpenAI::Responses::ToolChoiceOptions::OrSymbol,
279
+ OpenAI::Responses::ToolChoiceAllowed::OrHash,
239
280
  OpenAI::Responses::ToolChoiceTypes::OrHash,
240
281
  OpenAI::Responses::ToolChoiceFunction::OrHash,
241
- OpenAI::Responses::ToolChoiceMcp::OrHash
282
+ OpenAI::Responses::ToolChoiceMcp::OrHash,
283
+ OpenAI::Responses::ToolChoiceCustom::OrHash
242
284
  )
243
285
  ).void
244
286
  end
@@ -256,8 +298,10 @@ module OpenAI
256
298
  # Learn more about
257
299
  # [built-in tools](https://platform.openai.com/docs/guides/tools).
258
300
  # - **Function calls (custom tools)**: Functions that are defined by you, enabling
259
- # the model to call your own code. Learn more about
301
+ # the model to call your own code with strongly typed arguments and outputs.
302
+ # Learn more about
260
303
  # [function calling](https://platform.openai.com/docs/guides/function-calling).
304
+ # You can also use custom tools to call your own code.
261
305
  sig do
262
306
  returns(
263
307
  T.nilable(
@@ -270,6 +314,7 @@ module OpenAI
270
314
  OpenAI::Responses::Tool::CodeInterpreter,
271
315
  OpenAI::Responses::Tool::ImageGeneration,
272
316
  OpenAI::Responses::Tool::LocalShell,
317
+ OpenAI::Responses::CustomTool,
273
318
  OpenAI::Responses::WebSearchTool
274
319
  )
275
320
  ]
@@ -290,6 +335,7 @@ module OpenAI
290
335
  OpenAI::Responses::Tool::CodeInterpreter::OrHash,
291
336
  OpenAI::Responses::Tool::ImageGeneration::OrHash,
292
337
  OpenAI::Responses::Tool::LocalShell::OrHash,
338
+ OpenAI::Responses::CustomTool::OrHash,
293
339
  OpenAI::Responses::WebSearchTool::OrHash
294
340
  )
295
341
  ]
@@ -326,9 +372,11 @@ module OpenAI
326
372
  end
327
373
  attr_accessor :truncation
328
374
 
329
- # A stable identifier for your end-users. Used to boost cache hit rates by better
330
- # bucketing similar requests and to help OpenAI detect and prevent abuse.
331
- # [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
375
+ # This field is being replaced by `safety_identifier` and `prompt_cache_key`. Use
376
+ # `prompt_cache_key` instead to maintain caching optimizations. A stable
377
+ # identifier for your end-users. Used to boost cache hit rates by better bucketing
378
+ # similar requests and to help OpenAI detect and prevent abuse.
379
+ # [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
332
380
  sig { returns(T.nilable(String)) }
333
381
  attr_reader :user
334
382
 
@@ -356,20 +404,28 @@ module OpenAI
356
404
  parallel_tool_calls: T.nilable(T::Boolean),
357
405
  previous_response_id: T.nilable(String),
358
406
  prompt: T.nilable(OpenAI::Responses::ResponsePrompt::OrHash),
407
+ prompt_cache_key: String,
359
408
  reasoning: T.nilable(OpenAI::Reasoning::OrHash),
409
+ safety_identifier: String,
360
410
  service_tier:
361
411
  T.nilable(
362
412
  OpenAI::Responses::ResponseCreateParams::ServiceTier::OrSymbol
363
413
  ),
364
414
  store: T.nilable(T::Boolean),
415
+ stream_options:
416
+ T.nilable(
417
+ OpenAI::Responses::ResponseCreateParams::StreamOptions::OrHash
418
+ ),
365
419
  temperature: T.nilable(Float),
366
420
  text: OpenAI::Responses::ResponseTextConfig::OrHash,
367
421
  tool_choice:
368
422
  T.any(
369
423
  OpenAI::Responses::ToolChoiceOptions::OrSymbol,
424
+ OpenAI::Responses::ToolChoiceAllowed::OrHash,
370
425
  OpenAI::Responses::ToolChoiceTypes::OrHash,
371
426
  OpenAI::Responses::ToolChoiceFunction::OrHash,
372
- OpenAI::Responses::ToolChoiceMcp::OrHash
427
+ OpenAI::Responses::ToolChoiceMcp::OrHash,
428
+ OpenAI::Responses::ToolChoiceCustom::OrHash
373
429
  ),
374
430
  tools:
375
431
  T::Array[
@@ -381,6 +437,7 @@ module OpenAI
381
437
  OpenAI::Responses::Tool::CodeInterpreter::OrHash,
382
438
  OpenAI::Responses::Tool::ImageGeneration::OrHash,
383
439
  OpenAI::Responses::Tool::LocalShell::OrHash,
440
+ OpenAI::Responses::CustomTool::OrHash,
384
441
  OpenAI::Responses::WebSearchTool::OrHash
385
442
  )
386
443
  ],
@@ -462,11 +519,21 @@ module OpenAI
462
519
  # Reference to a prompt template and its variables.
463
520
  # [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).
464
521
  prompt: nil,
522
+ # Used by OpenAI to cache responses for similar requests to optimize your cache
523
+ # hit rates. Replaces the `user` field.
524
+ # [Learn more](https://platform.openai.com/docs/guides/prompt-caching).
525
+ prompt_cache_key: nil,
465
526
  # **o-series models only**
466
527
  #
467
528
  # Configuration options for
468
529
  # [reasoning models](https://platform.openai.com/docs/guides/reasoning).
469
530
  reasoning: nil,
531
+ # A stable identifier used to help detect users of your application that may be
532
+ # violating OpenAI's usage policies. The IDs should be a string that uniquely
533
+ # identifies each user. We recommend hashing their username or email address, in
534
+ # order to avoid sending us any identifying information.
535
+ # [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
536
+ safety_identifier: nil,
470
537
  # Specifies the processing type used for serving the request.
471
538
  #
472
539
  # - If set to 'auto', then the request will be processed with the service tier
@@ -487,6 +554,8 @@ module OpenAI
487
554
  service_tier: nil,
488
555
  # Whether to store the generated model response for later retrieval via API.
489
556
  store: nil,
557
+ # Options for streaming responses. Only set this when you set `stream: true`.
558
+ stream_options: nil,
490
559
  # What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
491
560
  # make the output more random, while lower values like 0.2 will make it more
492
561
  # focused and deterministic. We generally recommend altering this or `top_p` but
@@ -514,8 +583,10 @@ module OpenAI
514
583
  # Learn more about
515
584
  # [built-in tools](https://platform.openai.com/docs/guides/tools).
516
585
  # - **Function calls (custom tools)**: Functions that are defined by you, enabling
517
- # the model to call your own code. Learn more about
586
+ # the model to call your own code with strongly typed arguments and outputs.
587
+ # Learn more about
518
588
  # [function calling](https://platform.openai.com/docs/guides/function-calling).
589
+ # You can also use custom tools to call your own code.
519
590
  tools: nil,
520
591
  # An integer between 0 and 20 specifying the number of most likely tokens to
521
592
  # return at each token position, each with an associated log probability.
@@ -534,9 +605,11 @@ module OpenAI
534
605
  # - `disabled` (default): If a model response will exceed the context window size
535
606
  # for a model, the request will fail with a 400 error.
536
607
  truncation: nil,
537
- # A stable identifier for your end-users. Used to boost cache hit rates by better
538
- # bucketing similar requests and to help OpenAI detect and prevent abuse.
539
- # [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
608
+ # This field is being replaced by `safety_identifier` and `prompt_cache_key`. Use
609
+ # `prompt_cache_key` instead to maintain caching optimizations. A stable
610
+ # identifier for your end-users. Used to boost cache hit rates by better bucketing
611
+ # similar requests and to help OpenAI detect and prevent abuse.
612
+ # [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
540
613
  user: nil,
541
614
  request_options: {}
542
615
  )
@@ -564,20 +637,28 @@ module OpenAI
564
637
  parallel_tool_calls: T.nilable(T::Boolean),
565
638
  previous_response_id: T.nilable(String),
566
639
  prompt: T.nilable(OpenAI::Responses::ResponsePrompt),
640
+ prompt_cache_key: String,
567
641
  reasoning: T.nilable(OpenAI::Reasoning),
642
+ safety_identifier: String,
568
643
  service_tier:
569
644
  T.nilable(
570
645
  OpenAI::Responses::ResponseCreateParams::ServiceTier::OrSymbol
571
646
  ),
572
647
  store: T.nilable(T::Boolean),
648
+ stream_options:
649
+ T.nilable(
650
+ OpenAI::Responses::ResponseCreateParams::StreamOptions
651
+ ),
573
652
  temperature: T.nilable(Float),
574
653
  text: OpenAI::Responses::ResponseTextConfig,
575
654
  tool_choice:
576
655
  T.any(
577
656
  OpenAI::Responses::ToolChoiceOptions::OrSymbol,
657
+ OpenAI::Responses::ToolChoiceAllowed,
578
658
  OpenAI::Responses::ToolChoiceTypes,
579
659
  OpenAI::Responses::ToolChoiceFunction,
580
- OpenAI::Responses::ToolChoiceMcp
660
+ OpenAI::Responses::ToolChoiceMcp,
661
+ OpenAI::Responses::ToolChoiceCustom
581
662
  ),
582
663
  tools:
583
664
  T::Array[
@@ -589,6 +670,7 @@ module OpenAI
589
670
  OpenAI::Responses::Tool::CodeInterpreter,
590
671
  OpenAI::Responses::Tool::ImageGeneration,
591
672
  OpenAI::Responses::Tool::LocalShell,
673
+ OpenAI::Responses::CustomTool,
592
674
  OpenAI::Responses::WebSearchTool
593
675
  )
594
676
  ],
@@ -701,6 +783,47 @@ module OpenAI
701
783
  end
702
784
  end
703
785
 
786
+ class StreamOptions < OpenAI::Internal::Type::BaseModel
787
+ OrHash =
788
+ T.type_alias do
789
+ T.any(
790
+ OpenAI::Responses::ResponseCreateParams::StreamOptions,
791
+ OpenAI::Internal::AnyHash
792
+ )
793
+ end
794
+
795
+ # When true, stream obfuscation will be enabled. Stream obfuscation adds random
796
+ # characters to an `obfuscation` field on streaming delta events to normalize
797
+ # payload sizes as a mitigation to certain side-channel attacks. These obfuscation
798
+ # fields are included by default, but add a small amount of overhead to the data
799
+ # stream. You can set `include_obfuscation` to false to optimize for bandwidth if
800
+ # you trust the network links between your application and the OpenAI API.
801
+ sig { returns(T.nilable(T::Boolean)) }
802
+ attr_reader :include_obfuscation
803
+
804
+ sig { params(include_obfuscation: T::Boolean).void }
805
+ attr_writer :include_obfuscation
806
+
807
+ # Options for streaming responses. Only set this when you set `stream: true`.
808
+ sig do
809
+ params(include_obfuscation: T::Boolean).returns(T.attached_class)
810
+ end
811
+ def self.new(
812
+ # When true, stream obfuscation will be enabled. Stream obfuscation adds random
813
+ # characters to an `obfuscation` field on streaming delta events to normalize
814
+ # payload sizes as a mitigation to certain side-channel attacks. These obfuscation
815
+ # fields are included by default, but add a small amount of overhead to the data
816
+ # stream. You can set `include_obfuscation` to false to optimize for bandwidth if
817
+ # you trust the network links between your application and the OpenAI API.
818
+ include_obfuscation: nil
819
+ )
820
+ end
821
+
822
+ sig { override.returns({ include_obfuscation: T::Boolean }) }
823
+ def to_hash
824
+ end
825
+ end
826
+
704
827
  # How the model should select which tool (or tools) to use when generating a
705
828
  # response. See the `tools` parameter to see how to specify which tools the model
706
829
  # can call.
@@ -711,9 +834,11 @@ module OpenAI
711
834
  T.type_alias do
712
835
  T.any(
713
836
  OpenAI::Responses::ToolChoiceOptions::TaggedSymbol,
837
+ OpenAI::Responses::ToolChoiceAllowed,
714
838
  OpenAI::Responses::ToolChoiceTypes,
715
839
  OpenAI::Responses::ToolChoiceFunction,
716
- OpenAI::Responses::ToolChoiceMcp
840
+ OpenAI::Responses::ToolChoiceMcp,
841
+ OpenAI::Responses::ToolChoiceCustom
717
842
  )
718
843
  end
719
844
 
@@ -0,0 +1,78 @@
1
+ # typed: strong
2
+
3
+ module OpenAI
4
+ module Models
5
+ module Responses
6
+ class ResponseCustomToolCall < OpenAI::Internal::Type::BaseModel
7
+ OrHash =
8
+ T.type_alias do
9
+ T.any(
10
+ OpenAI::Responses::ResponseCustomToolCall,
11
+ OpenAI::Internal::AnyHash
12
+ )
13
+ end
14
+
15
+ # An identifier used to map this custom tool call to a tool call output.
16
+ sig { returns(String) }
17
+ attr_accessor :call_id
18
+
19
+ # The input for the custom tool call generated by the model.
20
+ sig { returns(String) }
21
+ attr_accessor :input
22
+
23
+ # The name of the custom tool being called.
24
+ sig { returns(String) }
25
+ attr_accessor :name
26
+
27
+ # The type of the custom tool call. Always `custom_tool_call`.
28
+ sig { returns(Symbol) }
29
+ attr_accessor :type
30
+
31
+ # The unique ID of the custom tool call in the OpenAI platform.
32
+ sig { returns(T.nilable(String)) }
33
+ attr_reader :id
34
+
35
+ sig { params(id: String).void }
36
+ attr_writer :id
37
+
38
+ # A call to a custom tool created by the model.
39
+ sig do
40
+ params(
41
+ call_id: String,
42
+ input: String,
43
+ name: String,
44
+ id: String,
45
+ type: Symbol
46
+ ).returns(T.attached_class)
47
+ end
48
+ def self.new(
49
+ # An identifier used to map this custom tool call to a tool call output.
50
+ call_id:,
51
+ # The input for the custom tool call generated by the model.
52
+ input:,
53
+ # The name of the custom tool being called.
54
+ name:,
55
+ # The unique ID of the custom tool call in the OpenAI platform.
56
+ id: nil,
57
+ # The type of the custom tool call. Always `custom_tool_call`.
58
+ type: :custom_tool_call
59
+ )
60
+ end
61
+
62
+ sig do
63
+ override.returns(
64
+ {
65
+ call_id: String,
66
+ input: String,
67
+ name: String,
68
+ type: Symbol,
69
+ id: String
70
+ }
71
+ )
72
+ end
73
+ def to_hash
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,75 @@
1
+ # typed: strong
2
+
3
+ module OpenAI
4
+ module Models
5
+ module Responses
6
+ class ResponseCustomToolCallInputDeltaEvent < OpenAI::Internal::Type::BaseModel
7
+ OrHash =
8
+ T.type_alias do
9
+ T.any(
10
+ OpenAI::Responses::ResponseCustomToolCallInputDeltaEvent,
11
+ OpenAI::Internal::AnyHash
12
+ )
13
+ end
14
+
15
+ # The incremental input data (delta) for the custom tool call.
16
+ sig { returns(String) }
17
+ attr_accessor :delta
18
+
19
+ # Unique identifier for the API item associated with this event.
20
+ sig { returns(String) }
21
+ attr_accessor :item_id
22
+
23
+ # The index of the output this delta applies to.
24
+ sig { returns(Integer) }
25
+ attr_accessor :output_index
26
+
27
+ # The sequence number of this event.
28
+ sig { returns(Integer) }
29
+ attr_accessor :sequence_number
30
+
31
+ # The event type identifier.
32
+ sig { returns(Symbol) }
33
+ attr_accessor :type
34
+
35
+ # Event representing a delta (partial update) to the input of a custom tool call.
36
+ sig do
37
+ params(
38
+ delta: String,
39
+ item_id: String,
40
+ output_index: Integer,
41
+ sequence_number: Integer,
42
+ type: Symbol
43
+ ).returns(T.attached_class)
44
+ end
45
+ def self.new(
46
+ # The incremental input data (delta) for the custom tool call.
47
+ delta:,
48
+ # Unique identifier for the API item associated with this event.
49
+ item_id:,
50
+ # The index of the output this delta applies to.
51
+ output_index:,
52
+ # The sequence number of this event.
53
+ sequence_number:,
54
+ # The event type identifier.
55
+ type: :"response.custom_tool_call_input.delta"
56
+ )
57
+ end
58
+
59
+ sig do
60
+ override.returns(
61
+ {
62
+ delta: String,
63
+ item_id: String,
64
+ output_index: Integer,
65
+ sequence_number: Integer,
66
+ type: Symbol
67
+ }
68
+ )
69
+ end
70
+ def to_hash
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,75 @@
1
+ # typed: strong
2
+
3
+ module OpenAI
4
+ module Models
5
+ module Responses
6
+ class ResponseCustomToolCallInputDoneEvent < OpenAI::Internal::Type::BaseModel
7
+ OrHash =
8
+ T.type_alias do
9
+ T.any(
10
+ OpenAI::Responses::ResponseCustomToolCallInputDoneEvent,
11
+ OpenAI::Internal::AnyHash
12
+ )
13
+ end
14
+
15
+ # The complete input data for the custom tool call.
16
+ sig { returns(String) }
17
+ attr_accessor :input
18
+
19
+ # Unique identifier for the API item associated with this event.
20
+ sig { returns(String) }
21
+ attr_accessor :item_id
22
+
23
+ # The index of the output this event applies to.
24
+ sig { returns(Integer) }
25
+ attr_accessor :output_index
26
+
27
+ # The sequence number of this event.
28
+ sig { returns(Integer) }
29
+ attr_accessor :sequence_number
30
+
31
+ # The event type identifier.
32
+ sig { returns(Symbol) }
33
+ attr_accessor :type
34
+
35
+ # Event indicating that input for a custom tool call is complete.
36
+ sig do
37
+ params(
38
+ input: String,
39
+ item_id: String,
40
+ output_index: Integer,
41
+ sequence_number: Integer,
42
+ type: Symbol
43
+ ).returns(T.attached_class)
44
+ end
45
+ def self.new(
46
+ # The complete input data for the custom tool call.
47
+ input:,
48
+ # Unique identifier for the API item associated with this event.
49
+ item_id:,
50
+ # The index of the output this event applies to.
51
+ output_index:,
52
+ # The sequence number of this event.
53
+ sequence_number:,
54
+ # The event type identifier.
55
+ type: :"response.custom_tool_call_input.done"
56
+ )
57
+ end
58
+
59
+ sig do
60
+ override.returns(
61
+ {
62
+ input: String,
63
+ item_id: String,
64
+ output_index: Integer,
65
+ sequence_number: Integer,
66
+ type: Symbol
67
+ }
68
+ )
69
+ end
70
+ def to_hash
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,65 @@
1
+ # typed: strong
2
+
3
+ module OpenAI
4
+ module Models
5
+ module Responses
6
+ class ResponseCustomToolCallOutput < OpenAI::Internal::Type::BaseModel
7
+ OrHash =
8
+ T.type_alias do
9
+ T.any(
10
+ OpenAI::Responses::ResponseCustomToolCallOutput,
11
+ OpenAI::Internal::AnyHash
12
+ )
13
+ end
14
+
15
+ # The call ID, used to map this custom tool call output to a custom tool call.
16
+ sig { returns(String) }
17
+ attr_accessor :call_id
18
+
19
+ # The output from the custom tool call generated by your code.
20
+ sig { returns(String) }
21
+ attr_accessor :output
22
+
23
+ # The type of the custom tool call output. Always `custom_tool_call_output`.
24
+ sig { returns(Symbol) }
25
+ attr_accessor :type
26
+
27
+ # The unique ID of the custom tool call output in the OpenAI platform.
28
+ sig { returns(T.nilable(String)) }
29
+ attr_reader :id
30
+
31
+ sig { params(id: String).void }
32
+ attr_writer :id
33
+
34
+ # The output of a custom tool call from your code, being sent back to the model.
35
+ sig do
36
+ params(
37
+ call_id: String,
38
+ output: String,
39
+ id: String,
40
+ type: Symbol
41
+ ).returns(T.attached_class)
42
+ end
43
+ def self.new(
44
+ # The call ID, used to map this custom tool call output to a custom tool call.
45
+ call_id:,
46
+ # The output from the custom tool call generated by your code.
47
+ output:,
48
+ # The unique ID of the custom tool call output in the OpenAI platform.
49
+ id: nil,
50
+ # The type of the custom tool call output. Always `custom_tool_call_output`.
51
+ type: :custom_tool_call_output
52
+ )
53
+ end
54
+
55
+ sig do
56
+ override.returns(
57
+ { call_id: String, output: String, type: Symbol, id: String }
58
+ )
59
+ end
60
+ def to_hash
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -32,6 +32,8 @@ module OpenAI
32
32
  OpenAI::Responses::ResponseInputItem::McpApprovalRequest,
33
33
  OpenAI::Responses::ResponseInputItem::McpApprovalResponse,
34
34
  OpenAI::Responses::ResponseInputItem::McpCall,
35
+ OpenAI::Responses::ResponseCustomToolCallOutput,
36
+ OpenAI::Responses::ResponseCustomToolCall,
35
37
  OpenAI::Responses::ResponseInputItem::ItemReference
36
38
  )
37
39
  end
@@ -21,7 +21,8 @@ module OpenAI
21
21
  OpenAI::Responses::ResponseOutputItem::LocalShellCall,
22
22
  OpenAI::Responses::ResponseOutputItem::McpCall,
23
23
  OpenAI::Responses::ResponseOutputItem::McpListTools,
24
- OpenAI::Responses::ResponseOutputItem::McpApprovalRequest
24
+ OpenAI::Responses::ResponseOutputItem::McpApprovalRequest,
25
+ OpenAI::Responses::ResponseCustomToolCall
25
26
  )
26
27
  end
27
28
 
@@ -44,7 +44,8 @@ module OpenAI
44
44
  OpenAI::Responses::ResponseOutputItem::LocalShellCall::OrHash,
45
45
  OpenAI::Responses::ResponseOutputItem::McpCall::OrHash,
46
46
  OpenAI::Responses::ResponseOutputItem::McpListTools::OrHash,
47
- OpenAI::Responses::ResponseOutputItem::McpApprovalRequest::OrHash
47
+ OpenAI::Responses::ResponseOutputItem::McpApprovalRequest::OrHash,
48
+ OpenAI::Responses::ResponseCustomToolCall::OrHash
48
49
  ),
49
50
  output_index: Integer,
50
51
  sequence_number: Integer,
@@ -44,7 +44,8 @@ module OpenAI
44
44
  OpenAI::Responses::ResponseOutputItem::LocalShellCall::OrHash,
45
45
  OpenAI::Responses::ResponseOutputItem::McpCall::OrHash,
46
46
  OpenAI::Responses::ResponseOutputItem::McpListTools::OrHash,
47
- OpenAI::Responses::ResponseOutputItem::McpApprovalRequest::OrHash
47
+ OpenAI::Responses::ResponseOutputItem::McpApprovalRequest::OrHash,
48
+ OpenAI::Responses::ResponseCustomToolCall::OrHash
48
49
  ),
49
50
  output_index: Integer,
50
51
  sequence_number: Integer,