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
@@ -5,41 +5,22 @@ module OpenAI
5
5
  ChatCompletionTool = Chat::ChatCompletionTool
6
6
 
7
7
  module Chat
8
- class ChatCompletionTool < OpenAI::Internal::Type::BaseModel
9
- OrHash =
8
+ # A function tool that can be used to generate a response.
9
+ module ChatCompletionTool
10
+ extend OpenAI::Internal::Type::Union
11
+
12
+ Variants =
10
13
  T.type_alias do
11
- T.any(OpenAI::Chat::ChatCompletionTool, OpenAI::Internal::AnyHash)
14
+ T.any(
15
+ OpenAI::Chat::ChatCompletionFunctionTool,
16
+ OpenAI::Chat::ChatCompletionCustomTool
17
+ )
12
18
  end
13
19
 
14
- sig { returns(OpenAI::FunctionDefinition) }
15
- attr_reader :function
16
-
17
- sig { params(function: OpenAI::FunctionDefinition::OrHash).void }
18
- attr_writer :function
19
-
20
- # The type of the tool. Currently, only `function` is supported.
21
- sig { returns(Symbol) }
22
- attr_accessor :type
23
-
24
- sig do
25
- params(
26
- function: OpenAI::FunctionDefinition::OrHash,
27
- type: Symbol
28
- ).returns(T.attached_class)
29
- end
30
- def self.new(
31
- function:,
32
- # The type of the tool. Currently, only `function` is supported.
33
- type: :function
34
- )
35
- end
36
-
37
20
  sig do
38
- override.returns(
39
- { function: OpenAI::FunctionDefinition, type: Symbol }
40
- )
21
+ override.returns(T::Array[OpenAI::Chat::ChatCompletionTool::Variants])
41
22
  end
42
- def to_hash
23
+ def self.variants
43
24
  end
44
25
  end
45
26
  end
@@ -21,7 +21,9 @@ module OpenAI
21
21
  T.type_alias do
22
22
  T.any(
23
23
  OpenAI::Chat::ChatCompletionToolChoiceOption::Auto::TaggedSymbol,
24
- OpenAI::Chat::ChatCompletionNamedToolChoice
24
+ OpenAI::Chat::ChatCompletionAllowedToolChoice,
25
+ OpenAI::Chat::ChatCompletionNamedToolChoice,
26
+ OpenAI::Chat::ChatCompletionNamedToolChoiceCustom
25
27
  )
26
28
  end
27
29
 
@@ -216,12 +216,20 @@ module OpenAI
216
216
  sig { returns(T.nilable(Float)) }
217
217
  attr_accessor :presence_penalty
218
218
 
219
- # **o-series models only**
220
- #
219
+ # Used by OpenAI to cache responses for similar requests to optimize your cache
220
+ # hit rates. Replaces the `user` field.
221
+ # [Learn more](https://platform.openai.com/docs/guides/prompt-caching).
222
+ sig { returns(T.nilable(String)) }
223
+ attr_reader :prompt_cache_key
224
+
225
+ sig { params(prompt_cache_key: String).void }
226
+ attr_writer :prompt_cache_key
227
+
221
228
  # Constrains effort on reasoning for
222
229
  # [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
223
- # supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
224
- # result in faster responses and fewer tokens used on reasoning in a response.
230
+ # supported values are `minimal`, `low`, `medium`, and `high`. Reducing reasoning
231
+ # effort can result in faster responses and fewer tokens used on reasoning in a
232
+ # response.
225
233
  sig { returns(T.nilable(OpenAI::ReasoningEffort::OrSymbol)) }
226
234
  attr_accessor :reasoning_effort
227
235
 
@@ -262,6 +270,17 @@ module OpenAI
262
270
  end
263
271
  attr_writer :response_format
264
272
 
273
+ # A stable identifier used to help detect users of your application that may be
274
+ # violating OpenAI's usage policies. The IDs should be a string that uniquely
275
+ # identifies each user. We recommend hashing their username or email address, in
276
+ # order to avoid sending us any identifying information.
277
+ # [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
278
+ sig { returns(T.nilable(String)) }
279
+ attr_reader :safety_identifier
280
+
281
+ sig { params(safety_identifier: String).void }
282
+ attr_writer :safety_identifier
283
+
265
284
  # This feature is in Beta. If specified, our system will make a best effort to
266
285
  # sample deterministically, such that repeated requests with the same `seed` and
267
286
  # parameters should return the same result. Determinism is not guaranteed, and you
@@ -348,7 +367,9 @@ module OpenAI
348
367
  T.nilable(
349
368
  T.any(
350
369
  OpenAI::Chat::ChatCompletionToolChoiceOption::Auto::OrSymbol,
351
- OpenAI::Chat::ChatCompletionNamedToolChoice
370
+ OpenAI::Chat::ChatCompletionAllowedToolChoice,
371
+ OpenAI::Chat::ChatCompletionNamedToolChoice,
372
+ OpenAI::Chat::ChatCompletionNamedToolChoiceCustom
352
373
  )
353
374
  )
354
375
  )
@@ -360,16 +381,29 @@ module OpenAI
360
381
  tool_choice:
361
382
  T.any(
362
383
  OpenAI::Chat::ChatCompletionToolChoiceOption::Auto::OrSymbol,
363
- OpenAI::Chat::ChatCompletionNamedToolChoice::OrHash
384
+ OpenAI::Chat::ChatCompletionAllowedToolChoice::OrHash,
385
+ OpenAI::Chat::ChatCompletionNamedToolChoice::OrHash,
386
+ OpenAI::Chat::ChatCompletionNamedToolChoiceCustom::OrHash
364
387
  )
365
388
  ).void
366
389
  end
367
390
  attr_writer :tool_choice
368
391
 
369
- # A list of tools the model may call. Currently, only functions are supported as a
370
- # tool. Use this to provide a list of functions the model may generate JSON inputs
371
- # for. A max of 128 functions are supported.
372
- sig { returns(T.nilable(T::Array[OpenAI::Chat::ChatCompletionTool])) }
392
+ # A list of tools the model may call. You can provide either
393
+ # [custom tools](https://platform.openai.com/docs/guides/function-calling#custom-tools)
394
+ # or [function tools](https://platform.openai.com/docs/guides/function-calling).
395
+ sig do
396
+ returns(
397
+ T.nilable(
398
+ T::Array[
399
+ T.any(
400
+ OpenAI::Chat::ChatCompletionFunctionTool,
401
+ OpenAI::Chat::ChatCompletionCustomTool
402
+ )
403
+ ]
404
+ )
405
+ )
406
+ end
373
407
  attr_reader :tools
374
408
 
375
409
  sig do
@@ -377,8 +411,9 @@ module OpenAI
377
411
  tools:
378
412
  T::Array[
379
413
  T.any(
380
- OpenAI::Chat::ChatCompletionTool::OrHash,
381
- OpenAI::StructuredOutput::JsonSchemaConverter
414
+ OpenAI::StructuredOutput::JsonSchemaConverter,
415
+ OpenAI::Chat::ChatCompletionFunctionTool::OrHash,
416
+ OpenAI::Chat::ChatCompletionCustomTool::OrHash
382
417
  )
383
418
  ]
384
419
  ).void
@@ -399,15 +434,27 @@ module OpenAI
399
434
  sig { returns(T.nilable(Float)) }
400
435
  attr_accessor :top_p
401
436
 
402
- # A stable identifier for your end-users. Used to boost cache hit rates by better
403
- # bucketing similar requests and to help OpenAI detect and prevent abuse.
404
- # [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
437
+ # This field is being replaced by `safety_identifier` and `prompt_cache_key`. Use
438
+ # `prompt_cache_key` instead to maintain caching optimizations. A stable
439
+ # identifier for your end-users. Used to boost cache hit rates by better bucketing
440
+ # similar requests and to help OpenAI detect and prevent abuse.
441
+ # [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
405
442
  sig { returns(T.nilable(String)) }
406
443
  attr_reader :user
407
444
 
408
445
  sig { params(user: String).void }
409
446
  attr_writer :user
410
447
 
448
+ # Constrains the verbosity of the model's response. Lower values will result in
449
+ # more concise responses, while higher values will result in more verbose
450
+ # responses. Currently supported values are `low`, `medium`, and `high`.
451
+ sig do
452
+ returns(
453
+ T.nilable(OpenAI::Chat::CompletionCreateParams::Verbosity::OrSymbol)
454
+ )
455
+ end
456
+ attr_accessor :verbosity
457
+
411
458
  # This tool searches the web for relevant results to use in a response. Learn more
412
459
  # about the
413
460
  # [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).
@@ -465,6 +512,7 @@ module OpenAI
465
512
  prediction:
466
513
  T.nilable(OpenAI::Chat::ChatCompletionPredictionContent::OrHash),
467
514
  presence_penalty: T.nilable(Float),
515
+ prompt_cache_key: String,
468
516
  reasoning_effort: T.nilable(OpenAI::ReasoningEffort::OrSymbol),
469
517
  response_format:
470
518
  T.any(
@@ -473,6 +521,7 @@ module OpenAI
473
521
  OpenAI::StructuredOutput::JsonSchemaConverter,
474
522
  OpenAI::ResponseFormatJSONObject::OrHash
475
523
  ),
524
+ safety_identifier: String,
476
525
  seed: T.nilable(Integer),
477
526
  service_tier:
478
527
  T.nilable(
@@ -487,18 +536,25 @@ module OpenAI
487
536
  tool_choice:
488
537
  T.any(
489
538
  OpenAI::Chat::ChatCompletionToolChoiceOption::Auto::OrSymbol,
490
- OpenAI::Chat::ChatCompletionNamedToolChoice::OrHash
539
+ OpenAI::Chat::ChatCompletionAllowedToolChoice::OrHash,
540
+ OpenAI::Chat::ChatCompletionNamedToolChoice::OrHash,
541
+ OpenAI::Chat::ChatCompletionNamedToolChoiceCustom::OrHash
491
542
  ),
492
543
  tools:
493
544
  T::Array[
494
545
  T.any(
495
- OpenAI::Chat::ChatCompletionTool::OrHash,
496
- OpenAI::StructuredOutput::JsonSchemaConverter
546
+ OpenAI::StructuredOutput::JsonSchemaConverter,
547
+ OpenAI::Chat::ChatCompletionFunctionTool::OrHash,
548
+ OpenAI::Chat::ChatCompletionCustomTool::OrHash
497
549
  )
498
550
  ],
499
551
  top_logprobs: T.nilable(Integer),
500
552
  top_p: T.nilable(Float),
501
553
  user: String,
554
+ verbosity:
555
+ T.nilable(
556
+ OpenAI::Chat::CompletionCreateParams::Verbosity::OrSymbol
557
+ ),
502
558
  web_search_options:
503
559
  OpenAI::Chat::CompletionCreateParams::WebSearchOptions::OrHash,
504
560
  request_options: OpenAI::RequestOptions::OrHash
@@ -603,12 +659,15 @@ module OpenAI
603
659
  # whether they appear in the text so far, increasing the model's likelihood to
604
660
  # talk about new topics.
605
661
  presence_penalty: nil,
606
- # **o-series models only**
607
- #
662
+ # Used by OpenAI to cache responses for similar requests to optimize your cache
663
+ # hit rates. Replaces the `user` field.
664
+ # [Learn more](https://platform.openai.com/docs/guides/prompt-caching).
665
+ prompt_cache_key: nil,
608
666
  # Constrains effort on reasoning for
609
667
  # [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
610
- # supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
611
- # result in faster responses and fewer tokens used on reasoning in a response.
668
+ # supported values are `minimal`, `low`, `medium`, and `high`. Reducing reasoning
669
+ # effort can result in faster responses and fewer tokens used on reasoning in a
670
+ # response.
612
671
  reasoning_effort: nil,
613
672
  # An object specifying the format that the model must output.
614
673
  #
@@ -621,6 +680,12 @@ module OpenAI
621
680
  # ensures the message the model generates is valid JSON. Using `json_schema` is
622
681
  # preferred for models that support it.
623
682
  response_format: nil,
683
+ # A stable identifier used to help detect users of your application that may be
684
+ # violating OpenAI's usage policies. The IDs should be a string that uniquely
685
+ # identifies each user. We recommend hashing their username or email address, in
686
+ # order to avoid sending us any identifying information.
687
+ # [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
688
+ safety_identifier: nil,
624
689
  # This feature is in Beta. If specified, our system will make a best effort to
625
690
  # sample deterministically, such that repeated requests with the same `seed` and
626
691
  # parameters should return the same result. Determinism is not guaranteed, and you
@@ -673,9 +738,9 @@ module OpenAI
673
738
  # `none` is the default when no tools are present. `auto` is the default if tools
674
739
  # are present.
675
740
  tool_choice: nil,
676
- # A list of tools the model may call. Currently, only functions are supported as a
677
- # tool. Use this to provide a list of functions the model may generate JSON inputs
678
- # for. A max of 128 functions are supported.
741
+ # A list of tools the model may call. You can provide either
742
+ # [custom tools](https://platform.openai.com/docs/guides/function-calling#custom-tools)
743
+ # or [function tools](https://platform.openai.com/docs/guides/function-calling).
679
744
  tools: nil,
680
745
  # An integer between 0 and 20 specifying the number of most likely tokens to
681
746
  # return at each token position, each with an associated log probability.
@@ -687,10 +752,16 @@ module OpenAI
687
752
  #
688
753
  # We generally recommend altering this or `temperature` but not both.
689
754
  top_p: nil,
690
- # A stable identifier for your end-users. Used to boost cache hit rates by better
691
- # bucketing similar requests and to help OpenAI detect and prevent abuse.
692
- # [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
755
+ # This field is being replaced by `safety_identifier` and `prompt_cache_key`. Use
756
+ # `prompt_cache_key` instead to maintain caching optimizations. A stable
757
+ # identifier for your end-users. Used to boost cache hit rates by better bucketing
758
+ # similar requests and to help OpenAI detect and prevent abuse.
759
+ # [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
693
760
  user: nil,
761
+ # Constrains the verbosity of the model's response. Lower values will result in
762
+ # more concise responses, while higher values will result in more verbose
763
+ # responses. Currently supported values are `low`, `medium`, and `high`.
764
+ verbosity: nil,
694
765
  # This tool searches the web for relevant results to use in a response. Learn more
695
766
  # about the
696
767
  # [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).
@@ -739,6 +810,7 @@ module OpenAI
739
810
  prediction:
740
811
  T.nilable(OpenAI::Chat::ChatCompletionPredictionContent),
741
812
  presence_penalty: T.nilable(Float),
813
+ prompt_cache_key: String,
742
814
  reasoning_effort: T.nilable(OpenAI::ReasoningEffort::OrSymbol),
743
815
  response_format:
744
816
  T.any(
@@ -746,6 +818,7 @@ module OpenAI
746
818
  OpenAI::ResponseFormatJSONSchema,
747
819
  OpenAI::ResponseFormatJSONObject
748
820
  ),
821
+ safety_identifier: String,
749
822
  seed: T.nilable(Integer),
750
823
  service_tier:
751
824
  T.nilable(
@@ -760,18 +833,25 @@ module OpenAI
760
833
  tool_choice:
761
834
  T.any(
762
835
  OpenAI::Chat::ChatCompletionToolChoiceOption::Auto::OrSymbol,
763
- OpenAI::Chat::ChatCompletionNamedToolChoice
836
+ OpenAI::Chat::ChatCompletionAllowedToolChoice,
837
+ OpenAI::Chat::ChatCompletionNamedToolChoice,
838
+ OpenAI::Chat::ChatCompletionNamedToolChoiceCustom
764
839
  ),
765
840
  tools:
766
841
  T::Array[
767
842
  T.any(
768
- OpenAI::Chat::ChatCompletionTool,
769
- OpenAI::StructuredOutput::JsonSchemaConverter
843
+ OpenAI::StructuredOutput::JsonSchemaConverter,
844
+ OpenAI::Chat::ChatCompletionFunctionTool,
845
+ OpenAI::Chat::ChatCompletionCustomTool
770
846
  )
771
847
  ],
772
848
  top_logprobs: T.nilable(Integer),
773
849
  top_p: T.nilable(Float),
774
850
  user: String,
851
+ verbosity:
852
+ T.nilable(
853
+ OpenAI::Chat::CompletionCreateParams::Verbosity::OrSymbol
854
+ ),
775
855
  web_search_options:
776
856
  OpenAI::Chat::CompletionCreateParams::WebSearchOptions,
777
857
  request_options: OpenAI::RequestOptions
@@ -1099,6 +1179,45 @@ module OpenAI
1099
1179
  )
1100
1180
  end
1101
1181
 
1182
+ # Constrains the verbosity of the model's response. Lower values will result in
1183
+ # more concise responses, while higher values will result in more verbose
1184
+ # responses. Currently supported values are `low`, `medium`, and `high`.
1185
+ module Verbosity
1186
+ extend OpenAI::Internal::Type::Enum
1187
+
1188
+ TaggedSymbol =
1189
+ T.type_alias do
1190
+ T.all(Symbol, OpenAI::Chat::CompletionCreateParams::Verbosity)
1191
+ end
1192
+ OrSymbol = T.type_alias { T.any(Symbol, String) }
1193
+
1194
+ LOW =
1195
+ T.let(
1196
+ :low,
1197
+ OpenAI::Chat::CompletionCreateParams::Verbosity::TaggedSymbol
1198
+ )
1199
+ MEDIUM =
1200
+ T.let(
1201
+ :medium,
1202
+ OpenAI::Chat::CompletionCreateParams::Verbosity::TaggedSymbol
1203
+ )
1204
+ HIGH =
1205
+ T.let(
1206
+ :high,
1207
+ OpenAI::Chat::CompletionCreateParams::Verbosity::TaggedSymbol
1208
+ )
1209
+
1210
+ sig do
1211
+ override.returns(
1212
+ T::Array[
1213
+ OpenAI::Chat::CompletionCreateParams::Verbosity::TaggedSymbol
1214
+ ]
1215
+ )
1216
+ end
1217
+ def self.values
1218
+ end
1219
+ end
1220
+
1102
1221
  class WebSearchOptions < OpenAI::Internal::Type::BaseModel
1103
1222
  OrHash =
1104
1223
  T.type_alias do
@@ -8,6 +8,17 @@ module OpenAI
8
8
  TaggedSymbol = T.type_alias { T.all(Symbol, OpenAI::ChatModel) }
9
9
  OrSymbol = T.type_alias { T.any(Symbol, String) }
10
10
 
11
+ GPT_5 = T.let(:"gpt-5", OpenAI::ChatModel::TaggedSymbol)
12
+ GPT_5_MINI = T.let(:"gpt-5-mini", OpenAI::ChatModel::TaggedSymbol)
13
+ GPT_5_NANO = T.let(:"gpt-5-nano", OpenAI::ChatModel::TaggedSymbol)
14
+ GPT_5_2025_08_07 =
15
+ T.let(:"gpt-5-2025-08-07", OpenAI::ChatModel::TaggedSymbol)
16
+ GPT_5_MINI_2025_08_07 =
17
+ T.let(:"gpt-5-mini-2025-08-07", OpenAI::ChatModel::TaggedSymbol)
18
+ GPT_5_NANO_2025_08_07 =
19
+ T.let(:"gpt-5-nano-2025-08-07", OpenAI::ChatModel::TaggedSymbol)
20
+ GPT_5_CHAT_LATEST =
21
+ T.let(:"gpt-5-chat-latest", OpenAI::ChatModel::TaggedSymbol)
11
22
  GPT_4_1 = T.let(:"gpt-4.1", OpenAI::ChatModel::TaggedSymbol)
12
23
  GPT_4_1_MINI = T.let(:"gpt-4.1-mini", OpenAI::ChatModel::TaggedSymbol)
13
24
  GPT_4_1_NANO = T.let(:"gpt-4.1-nano", OpenAI::ChatModel::TaggedSymbol)
@@ -0,0 +1,136 @@
1
+ # typed: strong
2
+
3
+ module OpenAI
4
+ module Models
5
+ # The input format for the custom tool. Default is unconstrained text.
6
+ module CustomToolInputFormat
7
+ extend OpenAI::Internal::Type::Union
8
+
9
+ Variants =
10
+ T.type_alias do
11
+ T.any(
12
+ OpenAI::CustomToolInputFormat::Text,
13
+ OpenAI::CustomToolInputFormat::Grammar
14
+ )
15
+ end
16
+
17
+ class Text < OpenAI::Internal::Type::BaseModel
18
+ OrHash =
19
+ T.type_alias do
20
+ T.any(
21
+ OpenAI::CustomToolInputFormat::Text,
22
+ OpenAI::Internal::AnyHash
23
+ )
24
+ end
25
+
26
+ # Unconstrained text format. Always `text`.
27
+ sig { returns(Symbol) }
28
+ attr_accessor :type
29
+
30
+ # Unconstrained free-form text.
31
+ sig { params(type: Symbol).returns(T.attached_class) }
32
+ def self.new(
33
+ # Unconstrained text format. Always `text`.
34
+ type: :text
35
+ )
36
+ end
37
+
38
+ sig { override.returns({ type: Symbol }) }
39
+ def to_hash
40
+ end
41
+ end
42
+
43
+ class Grammar < OpenAI::Internal::Type::BaseModel
44
+ OrHash =
45
+ T.type_alias do
46
+ T.any(
47
+ OpenAI::CustomToolInputFormat::Grammar,
48
+ OpenAI::Internal::AnyHash
49
+ )
50
+ end
51
+
52
+ # The grammar definition.
53
+ sig { returns(String) }
54
+ attr_accessor :definition
55
+
56
+ # The syntax of the grammar definition. One of `lark` or `regex`.
57
+ sig do
58
+ returns(OpenAI::CustomToolInputFormat::Grammar::Syntax::OrSymbol)
59
+ end
60
+ attr_accessor :syntax
61
+
62
+ # Grammar format. Always `grammar`.
63
+ sig { returns(Symbol) }
64
+ attr_accessor :type
65
+
66
+ # A grammar defined by the user.
67
+ sig do
68
+ params(
69
+ definition: String,
70
+ syntax: OpenAI::CustomToolInputFormat::Grammar::Syntax::OrSymbol,
71
+ type: Symbol
72
+ ).returns(T.attached_class)
73
+ end
74
+ def self.new(
75
+ # The grammar definition.
76
+ definition:,
77
+ # The syntax of the grammar definition. One of `lark` or `regex`.
78
+ syntax:,
79
+ # Grammar format. Always `grammar`.
80
+ type: :grammar
81
+ )
82
+ end
83
+
84
+ sig do
85
+ override.returns(
86
+ {
87
+ definition: String,
88
+ syntax: OpenAI::CustomToolInputFormat::Grammar::Syntax::OrSymbol,
89
+ type: Symbol
90
+ }
91
+ )
92
+ end
93
+ def to_hash
94
+ end
95
+
96
+ # The syntax of the grammar definition. One of `lark` or `regex`.
97
+ module Syntax
98
+ extend OpenAI::Internal::Type::Enum
99
+
100
+ TaggedSymbol =
101
+ T.type_alias do
102
+ T.all(Symbol, OpenAI::CustomToolInputFormat::Grammar::Syntax)
103
+ end
104
+ OrSymbol = T.type_alias { T.any(Symbol, String) }
105
+
106
+ LARK =
107
+ T.let(
108
+ :lark,
109
+ OpenAI::CustomToolInputFormat::Grammar::Syntax::TaggedSymbol
110
+ )
111
+ REGEX =
112
+ T.let(
113
+ :regex,
114
+ OpenAI::CustomToolInputFormat::Grammar::Syntax::TaggedSymbol
115
+ )
116
+
117
+ sig do
118
+ override.returns(
119
+ T::Array[
120
+ OpenAI::CustomToolInputFormat::Grammar::Syntax::TaggedSymbol
121
+ ]
122
+ )
123
+ end
124
+ def self.values
125
+ end
126
+ end
127
+ end
128
+
129
+ sig do
130
+ override.returns(T::Array[OpenAI::CustomToolInputFormat::Variants])
131
+ end
132
+ def self.variants
133
+ end
134
+ end
135
+ end
136
+ end
@@ -935,12 +935,16 @@ module OpenAI
935
935
  # A list of tools the model may call. Currently, only functions are supported as a
936
936
  # tool. Use this to provide a list of functions the model may generate JSON inputs
937
937
  # for. A max of 128 functions are supported.
938
- sig { returns(T.nilable(T::Array[OpenAI::Chat::ChatCompletionTool])) }
938
+ sig do
939
+ returns(
940
+ T.nilable(T::Array[OpenAI::Chat::ChatCompletionFunctionTool])
941
+ )
942
+ end
939
943
  attr_reader :tools
940
944
 
941
945
  sig do
942
946
  params(
943
- tools: T::Array[OpenAI::Chat::ChatCompletionTool::OrHash]
947
+ tools: T::Array[OpenAI::Chat::ChatCompletionFunctionTool::OrHash]
944
948
  ).void
945
949
  end
946
950
  attr_writer :tools
@@ -963,7 +967,7 @@ module OpenAI
963
967
  ),
964
968
  seed: Integer,
965
969
  temperature: Float,
966
- tools: T::Array[OpenAI::Chat::ChatCompletionTool::OrHash],
970
+ tools: T::Array[OpenAI::Chat::ChatCompletionFunctionTool::OrHash],
967
971
  top_p: Float
968
972
  ).returns(T.attached_class)
969
973
  end
@@ -1006,7 +1010,7 @@ module OpenAI
1006
1010
  ),
1007
1011
  seed: Integer,
1008
1012
  temperature: Float,
1009
- tools: T::Array[OpenAI::Chat::ChatCompletionTool],
1013
+ tools: T::Array[OpenAI::Chat::ChatCompletionFunctionTool],
1010
1014
  top_p: Float
1011
1015
  }
1012
1016
  )
@@ -1174,6 +1174,7 @@ module OpenAI
1174
1174
  OpenAI::Responses::Tool::CodeInterpreter::OrHash,
1175
1175
  OpenAI::Responses::Tool::ImageGeneration::OrHash,
1176
1176
  OpenAI::Responses::Tool::LocalShell::OrHash,
1177
+ OpenAI::Responses::CustomTool::OrHash,
1177
1178
  OpenAI::Responses::WebSearchTool::OrHash
1178
1179
  )
1179
1180
  ]
@@ -1205,6 +1206,7 @@ module OpenAI
1205
1206
  OpenAI::Responses::Tool::CodeInterpreter::OrHash,
1206
1207
  OpenAI::Responses::Tool::ImageGeneration::OrHash,
1207
1208
  OpenAI::Responses::Tool::LocalShell::OrHash,
1209
+ OpenAI::Responses::CustomTool::OrHash,
1208
1210
  OpenAI::Responses::WebSearchTool::OrHash
1209
1211
  )
1210
1212
  ],
@@ -1125,6 +1125,7 @@ module OpenAI
1125
1125
  OpenAI::Responses::Tool::CodeInterpreter,
1126
1126
  OpenAI::Responses::Tool::ImageGeneration,
1127
1127
  OpenAI::Responses::Tool::LocalShell,
1128
+ OpenAI::Responses::CustomTool,
1128
1129
  OpenAI::Responses::WebSearchTool
1129
1130
  )
1130
1131
  ]
@@ -1145,6 +1146,7 @@ module OpenAI
1145
1146
  OpenAI::Responses::Tool::CodeInterpreter::OrHash,
1146
1147
  OpenAI::Responses::Tool::ImageGeneration::OrHash,
1147
1148
  OpenAI::Responses::Tool::LocalShell::OrHash,
1149
+ OpenAI::Responses::CustomTool::OrHash,
1148
1150
  OpenAI::Responses::WebSearchTool::OrHash
1149
1151
  )
1150
1152
  ]
@@ -1176,6 +1178,7 @@ module OpenAI
1176
1178
  OpenAI::Responses::Tool::CodeInterpreter::OrHash,
1177
1179
  OpenAI::Responses::Tool::ImageGeneration::OrHash,
1178
1180
  OpenAI::Responses::Tool::LocalShell::OrHash,
1181
+ OpenAI::Responses::CustomTool::OrHash,
1179
1182
  OpenAI::Responses::WebSearchTool::OrHash
1180
1183
  )
1181
1184
  ],
@@ -1233,6 +1236,7 @@ module OpenAI
1233
1236
  OpenAI::Responses::Tool::CodeInterpreter,
1234
1237
  OpenAI::Responses::Tool::ImageGeneration,
1235
1238
  OpenAI::Responses::Tool::LocalShell,
1239
+ OpenAI::Responses::CustomTool,
1236
1240
  OpenAI::Responses::WebSearchTool
1237
1241
  )
1238
1242
  ],
@@ -1174,6 +1174,7 @@ module OpenAI
1174
1174
  OpenAI::Responses::Tool::CodeInterpreter::OrHash,
1175
1175
  OpenAI::Responses::Tool::ImageGeneration::OrHash,
1176
1176
  OpenAI::Responses::Tool::LocalShell::OrHash,
1177
+ OpenAI::Responses::CustomTool::OrHash,
1177
1178
  OpenAI::Responses::WebSearchTool::OrHash
1178
1179
  )
1179
1180
  ]
@@ -1205,6 +1206,7 @@ module OpenAI
1205
1206
  OpenAI::Responses::Tool::CodeInterpreter::OrHash,
1206
1207
  OpenAI::Responses::Tool::ImageGeneration::OrHash,
1207
1208
  OpenAI::Responses::Tool::LocalShell::OrHash,
1209
+ OpenAI::Responses::CustomTool::OrHash,
1208
1210
  OpenAI::Responses::WebSearchTool::OrHash
1209
1211
  )
1210
1212
  ],
@@ -1170,6 +1170,7 @@ module OpenAI
1170
1170
  OpenAI::Responses::Tool::CodeInterpreter::OrHash,
1171
1171
  OpenAI::Responses::Tool::ImageGeneration::OrHash,
1172
1172
  OpenAI::Responses::Tool::LocalShell::OrHash,
1173
+ OpenAI::Responses::CustomTool::OrHash,
1173
1174
  OpenAI::Responses::WebSearchTool::OrHash
1174
1175
  )
1175
1176
  ]
@@ -1201,6 +1202,7 @@ module OpenAI
1201
1202
  OpenAI::Responses::Tool::CodeInterpreter::OrHash,
1202
1203
  OpenAI::Responses::Tool::ImageGeneration::OrHash,
1203
1204
  OpenAI::Responses::Tool::LocalShell::OrHash,
1205
+ OpenAI::Responses::CustomTool::OrHash,
1204
1206
  OpenAI::Responses::WebSearchTool::OrHash
1205
1207
  )
1206
1208
  ],