anthropic 1.1.1 → 1.6.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 (197) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +123 -0
  3. data/README.md +32 -16
  4. data/lib/anthropic/client.rb +5 -2
  5. data/lib/anthropic/errors.rb +22 -0
  6. data/lib/anthropic/helpers/bedrock/client.rb +34 -4
  7. data/lib/anthropic/helpers/streaming/events.rb +141 -0
  8. data/lib/anthropic/helpers/streaming/message_stream.rb +238 -0
  9. data/lib/anthropic/helpers/streaming.rb +37 -0
  10. data/lib/anthropic/helpers/vertex/client.rb +4 -1
  11. data/lib/anthropic/internal/stream.rb +4 -2
  12. data/lib/anthropic/internal/transport/base_client.rb +29 -3
  13. data/lib/anthropic/internal/type/array_of.rb +7 -1
  14. data/lib/anthropic/internal/type/base_model.rb +80 -24
  15. data/lib/anthropic/internal/type/base_stream.rb +3 -1
  16. data/lib/anthropic/internal/type/boolean.rb +7 -1
  17. data/lib/anthropic/internal/type/converter.rb +69 -34
  18. data/lib/anthropic/internal/type/enum.rb +16 -5
  19. data/lib/anthropic/internal/type/file_input.rb +6 -1
  20. data/lib/anthropic/internal/type/hash_of.rb +7 -1
  21. data/lib/anthropic/internal/type/union.rb +26 -16
  22. data/lib/anthropic/internal/type/unknown.rb +7 -1
  23. data/lib/anthropic/internal/util.rb +8 -9
  24. data/lib/anthropic/models/anthropic_beta.rb +3 -0
  25. data/lib/anthropic/models/beta/beta_base64_pdf_block.rb +1 -65
  26. data/lib/anthropic/models/beta/beta_citation_char_location.rb +7 -1
  27. data/lib/anthropic/models/beta/beta_citation_content_block_location.rb +7 -1
  28. data/lib/anthropic/models/beta/beta_citation_page_location.rb +7 -1
  29. data/lib/anthropic/models/beta/beta_citation_search_result_location.rb +55 -0
  30. data/lib/anthropic/models/beta/beta_citation_search_result_location_param.rb +55 -0
  31. data/lib/anthropic/models/beta/beta_citations_delta.rb +5 -3
  32. data/lib/anthropic/models/beta/beta_content_block.rb +5 -5
  33. data/lib/anthropic/models/beta/beta_content_block_param.rb +20 -17
  34. data/lib/anthropic/models/beta/beta_message.rb +6 -2
  35. data/lib/anthropic/models/beta/beta_message_param.rb +3 -3
  36. data/lib/anthropic/models/beta/beta_raw_content_block_start_event.rb +7 -7
  37. data/lib/anthropic/models/beta/beta_request_document_block.rb +75 -0
  38. data/lib/anthropic/models/beta/beta_search_result_block_param.rb +55 -0
  39. data/lib/anthropic/models/beta/beta_text_block.rb +2 -2
  40. data/lib/anthropic/models/beta/beta_text_block_param.rb +2 -2
  41. data/lib/anthropic/models/beta/beta_text_citation.rb +3 -1
  42. data/lib/anthropic/models/beta/beta_text_citation_param.rb +3 -1
  43. data/lib/anthropic/models/beta/beta_tool.rb +7 -1
  44. data/lib/anthropic/models/beta/beta_tool_result_block_param.rb +6 -4
  45. data/lib/anthropic/models/beta/beta_tool_text_editor_20250728.rb +49 -0
  46. data/lib/anthropic/models/beta/beta_tool_union.rb +9 -7
  47. data/lib/anthropic/models/beta/message_count_tokens_params.rb +18 -10
  48. data/lib/anthropic/models/beta/message_create_params.rb +9 -3
  49. data/lib/anthropic/models/beta/messages/batch_create_params.rb +9 -3
  50. data/lib/anthropic/models/citation_char_location.rb +7 -1
  51. data/lib/anthropic/models/citation_content_block_location.rb +7 -1
  52. data/lib/anthropic/models/citation_page_location.rb +7 -1
  53. data/lib/anthropic/models/citation_search_result_location_param.rb +51 -0
  54. data/lib/anthropic/models/citations_delta.rb +5 -3
  55. data/lib/anthropic/models/citations_search_result_location.rb +51 -0
  56. data/lib/anthropic/models/content_block.rb +5 -5
  57. data/lib/anthropic/models/content_block_param.rb +14 -11
  58. data/lib/anthropic/models/message.rb +6 -2
  59. data/lib/anthropic/models/message_count_tokens_params.rb +9 -3
  60. data/lib/anthropic/models/message_count_tokens_tool.rb +5 -1
  61. data/lib/anthropic/models/message_create_params.rb +9 -3
  62. data/lib/anthropic/models/message_param.rb +3 -3
  63. data/lib/anthropic/models/messages/batch_create_params.rb +9 -3
  64. data/lib/anthropic/models/model.rb +10 -21
  65. data/lib/anthropic/models/raw_content_block_start_event.rb +7 -7
  66. data/lib/anthropic/models/search_result_block_param.rb +51 -0
  67. data/lib/anthropic/models/text_block.rb +2 -2
  68. data/lib/anthropic/models/text_block_param.rb +2 -2
  69. data/lib/anthropic/models/text_citation.rb +3 -1
  70. data/lib/anthropic/models/text_citation_param.rb +3 -1
  71. data/lib/anthropic/models/tool.rb +7 -1
  72. data/lib/anthropic/models/tool_result_block_param.rb +6 -4
  73. data/lib/anthropic/models/tool_text_editor_20250429.rb +36 -0
  74. data/lib/anthropic/models/tool_text_editor_20250728.rb +45 -0
  75. data/lib/anthropic/models/tool_union.rb +5 -1
  76. data/lib/anthropic/models/tool_use_block.rb +6 -0
  77. data/lib/anthropic/models.rb +14 -4
  78. data/lib/anthropic/resources/beta/messages.rb +73 -6
  79. data/lib/anthropic/resources/messages.rb +68 -7
  80. data/lib/anthropic/streaming.rb +5 -0
  81. data/lib/anthropic/version.rb +1 -1
  82. data/lib/anthropic.rb +14 -0
  83. data/rbi/anthropic/errors.rbi +16 -0
  84. data/rbi/anthropic/helpers/bedrock/client.rbi +17 -6
  85. data/rbi/anthropic/helpers/streaming/events.rbi +95 -0
  86. data/rbi/anthropic/helpers/streaming/message_stream.rbi +73 -0
  87. data/rbi/anthropic/helpers/vertex/client.rbi +17 -6
  88. data/rbi/anthropic/internal/transport/base_client.rbi +1 -1
  89. data/rbi/anthropic/internal/type/base_stream.rbi +8 -1
  90. data/rbi/anthropic/internal/type/boolean.rbi +2 -0
  91. data/rbi/anthropic/internal/type/converter.rbi +69 -15
  92. data/rbi/anthropic/internal/type/union.rbi +14 -2
  93. data/rbi/anthropic/internal/type/unknown.rbi +2 -0
  94. data/rbi/anthropic/internal/util.rbi +2 -0
  95. data/rbi/anthropic/models/anthropic_beta.rbi +2 -0
  96. data/rbi/anthropic/models/beta/beta_base64_pdf_block.rbi +1 -128
  97. data/rbi/anthropic/models/beta/beta_citation_char_location.rbi +6 -0
  98. data/rbi/anthropic/models/beta/beta_citation_content_block_location.rbi +6 -0
  99. data/rbi/anthropic/models/beta/beta_citation_page_location.rbi +6 -0
  100. data/rbi/anthropic/models/beta/beta_citation_search_result_location.rbi +78 -0
  101. data/rbi/anthropic/models/beta/beta_citation_search_result_location_param.rbi +79 -0
  102. data/rbi/anthropic/models/beta/beta_citations_delta.rbi +4 -2
  103. data/rbi/anthropic/models/beta/beta_content_block.rbi +3 -3
  104. data/rbi/anthropic/models/beta/beta_content_block_param.rbi +8 -7
  105. data/rbi/anthropic/models/beta/beta_message.rbi +11 -3
  106. data/rbi/anthropic/models/beta/beta_raw_content_block_start_event.rbi +6 -6
  107. data/rbi/anthropic/models/beta/beta_request_document_block.rbi +140 -0
  108. data/rbi/anthropic/models/beta/beta_search_result_block_param.rbi +91 -0
  109. data/rbi/anthropic/models/beta/beta_text_block.rbi +2 -1
  110. data/rbi/anthropic/models/beta/beta_text_block_param.rbi +6 -3
  111. data/rbi/anthropic/models/beta/beta_text_citation.rbi +2 -1
  112. data/rbi/anthropic/models/beta/beta_text_citation_param.rbi +2 -1
  113. data/rbi/anthropic/models/beta/beta_tool.rbi +14 -5
  114. data/rbi/anthropic/models/beta/beta_tool_result_block_param.rbi +2 -1
  115. data/rbi/anthropic/models/beta/beta_tool_text_editor_20250728.rbi +82 -0
  116. data/rbi/anthropic/models/beta/beta_tool_union.rbi +6 -5
  117. data/rbi/anthropic/models/beta/message_count_tokens_params.rbi +44 -27
  118. data/rbi/anthropic/models/beta/message_create_params.rbi +38 -22
  119. data/rbi/anthropic/models/beta/messages/batch_create_params.rbi +38 -22
  120. data/rbi/anthropic/models/citation_char_location.rbi +6 -0
  121. data/rbi/anthropic/models/citation_content_block_location.rbi +6 -0
  122. data/rbi/anthropic/models/citation_page_location.rbi +6 -0
  123. data/rbi/anthropic/models/citation_search_result_location_param.rbi +74 -0
  124. data/rbi/anthropic/models/citations_delta.rbi +4 -2
  125. data/rbi/anthropic/models/citations_search_result_location.rbi +74 -0
  126. data/rbi/anthropic/models/content_block.rbi +3 -3
  127. data/rbi/anthropic/models/content_block_param.rbi +6 -5
  128. data/rbi/anthropic/models/message.rbi +11 -3
  129. data/rbi/anthropic/models/message_count_tokens_params.rbi +22 -2
  130. data/rbi/anthropic/models/message_count_tokens_tool.rbi +2 -0
  131. data/rbi/anthropic/models/message_create_params.rbi +22 -2
  132. data/rbi/anthropic/models/messages/batch_create_params.rbi +22 -2
  133. data/rbi/anthropic/models/model.rbi +4 -8
  134. data/rbi/anthropic/models/raw_content_block_start_event.rbi +6 -6
  135. data/rbi/anthropic/models/search_result_block_param.rbi +77 -0
  136. data/rbi/anthropic/models/text_block.rbi +2 -1
  137. data/rbi/anthropic/models/text_block_param.rbi +6 -3
  138. data/rbi/anthropic/models/text_citation.rbi +2 -1
  139. data/rbi/anthropic/models/text_citation_param.rbi +2 -1
  140. data/rbi/anthropic/models/tool.rbi +16 -5
  141. data/rbi/anthropic/models/tool_result_block_param.rbi +5 -1
  142. data/rbi/anthropic/models/tool_text_editor_20250429.rbi +62 -0
  143. data/rbi/anthropic/models/tool_text_editor_20250728.rbi +72 -0
  144. data/rbi/anthropic/models/tool_union.rbi +2 -0
  145. data/rbi/anthropic/models.rbi +12 -0
  146. data/rbi/anthropic/resources/beta/messages.rbi +39 -18
  147. data/rbi/anthropic/resources/messages.rbi +318 -3
  148. data/rbi/anthropic/streaming.rbi +5 -0
  149. data/sig/anthropic/errors.rbs +9 -0
  150. data/sig/anthropic/helpers/streaming/events.rbs +117 -0
  151. data/sig/anthropic/helpers/streaming/message_stream.rbs +57 -0
  152. data/sig/anthropic/internal/transport/base_client.rbs +1 -1
  153. data/sig/anthropic/internal/type/base_stream.rbs +4 -0
  154. data/sig/anthropic/internal/type/converter.rbs +24 -1
  155. data/sig/anthropic/internal/type/union.rbs +2 -2
  156. data/sig/anthropic/models/anthropic_beta.rbs +2 -0
  157. data/sig/anthropic/models/beta/beta_base64_pdf_block.rbs +1 -58
  158. data/sig/anthropic/models/beta/beta_citation_char_location.rbs +5 -0
  159. data/sig/anthropic/models/beta/beta_citation_content_block_location.rbs +5 -0
  160. data/sig/anthropic/models/beta/beta_citation_page_location.rbs +5 -0
  161. data/sig/anthropic/models/beta/beta_citation_search_result_location.rbs +54 -0
  162. data/sig/anthropic/models/beta/beta_citation_search_result_location_param.rbs +54 -0
  163. data/sig/anthropic/models/beta/beta_citations_delta.rbs +1 -0
  164. data/sig/anthropic/models/beta/beta_content_block.rbs +2 -2
  165. data/sig/anthropic/models/beta/beta_content_block_param.rbs +9 -8
  166. data/sig/anthropic/models/beta/beta_raw_content_block_start_event.rbs +2 -2
  167. data/sig/anthropic/models/beta/beta_request_document_block.rbs +66 -0
  168. data/sig/anthropic/models/beta/beta_search_result_block_param.rbs +53 -0
  169. data/sig/anthropic/models/beta/beta_text_citation.rbs +1 -0
  170. data/sig/anthropic/models/beta/beta_text_citation_param.rbs +1 -0
  171. data/sig/anthropic/models/beta/beta_tool.rbs +14 -3
  172. data/sig/anthropic/models/beta/beta_tool_result_block_param.rbs +1 -0
  173. data/sig/anthropic/models/beta/beta_tool_text_editor_20250728.rbs +39 -0
  174. data/sig/anthropic/models/beta/beta_tool_union.rbs +5 -4
  175. data/sig/anthropic/models/beta/message_count_tokens_params.rbs +5 -4
  176. data/sig/anthropic/models/citation_char_location.rbs +5 -0
  177. data/sig/anthropic/models/citation_content_block_location.rbs +5 -0
  178. data/sig/anthropic/models/citation_page_location.rbs +5 -0
  179. data/sig/anthropic/models/citation_search_result_location_param.rbs +50 -0
  180. data/sig/anthropic/models/citations_delta.rbs +1 -0
  181. data/sig/anthropic/models/citations_search_result_location.rbs +50 -0
  182. data/sig/anthropic/models/content_block.rbs +2 -2
  183. data/sig/anthropic/models/content_block_param.rbs +6 -5
  184. data/sig/anthropic/models/message_count_tokens_tool.rbs +2 -0
  185. data/sig/anthropic/models/model.rbs +4 -10
  186. data/sig/anthropic/models/raw_content_block_start_event.rbs +2 -2
  187. data/sig/anthropic/models/search_result_block_param.rbs +49 -0
  188. data/sig/anthropic/models/text_citation.rbs +1 -0
  189. data/sig/anthropic/models/text_citation_param.rbs +1 -0
  190. data/sig/anthropic/models/tool.rbs +14 -3
  191. data/sig/anthropic/models/tool_result_block_param.rbs +4 -1
  192. data/sig/anthropic/models/tool_text_editor_20250429.rbs +30 -0
  193. data/sig/anthropic/models/tool_text_editor_20250728.rbs +35 -0
  194. data/sig/anthropic/models/tool_union.rbs +2 -0
  195. data/sig/anthropic/models.rbs +10 -0
  196. data/sig/anthropic/streaming.rbs +3 -0
  197. metadata +44 -3
@@ -48,15 +48,16 @@ module Anthropic
48
48
  T::Array[
49
49
  T.any(
50
50
  Anthropic::Beta::BetaTool::OrHash,
51
- Anthropic::Beta::BetaToolComputerUse20241022::OrHash,
52
51
  Anthropic::Beta::BetaToolBash20241022::OrHash,
53
- Anthropic::Beta::BetaToolTextEditor20241022::OrHash,
54
- Anthropic::Beta::BetaToolComputerUse20250124::OrHash,
55
52
  Anthropic::Beta::BetaToolBash20250124::OrHash,
53
+ Anthropic::Beta::BetaCodeExecutionTool20250522::OrHash,
54
+ Anthropic::Beta::BetaToolComputerUse20241022::OrHash,
55
+ Anthropic::Beta::BetaToolComputerUse20250124::OrHash,
56
+ Anthropic::Beta::BetaToolTextEditor20241022::OrHash,
56
57
  Anthropic::Beta::BetaToolTextEditor20250124::OrHash,
57
58
  Anthropic::Beta::BetaToolTextEditor20250429::OrHash,
58
- Anthropic::Beta::BetaWebSearchTool20250305::OrHash,
59
- Anthropic::Beta::BetaCodeExecutionTool20250522::OrHash
59
+ Anthropic::Beta::BetaToolTextEditor20250728::OrHash,
60
+ Anthropic::Beta::BetaWebSearchTool20250305::OrHash
60
61
  )
61
62
  ],
62
63
  top_k: Integer,
@@ -162,7 +163,7 @@ module Anthropic
162
163
  # the top-level `system` parameter — there is no `"system"` role for input
163
164
  # messages in the Messages API.
164
165
  #
165
- # There is a limit of 100000 messages in a single request.
166
+ # There is a limit of 100,000 messages in a single request.
166
167
  messages:,
167
168
  # Body param: The model that will complete your prompt.\n\nSee
168
169
  # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
@@ -225,6 +226,12 @@ module Anthropic
225
226
  # those tools using the tool input generated by the model and then optionally
226
227
  # return results back to the model using `tool_result` content blocks.
227
228
  #
229
+ # There are two types of tools: **client tools** and **server tools**. The
230
+ # behavior described below applies to client tools. For
231
+ # [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
232
+ # see their individual documentation as each has its own behavior (e.g., the
233
+ # [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
234
+ #
228
235
  # Each tool definition includes:
229
236
  #
230
237
  # - `name`: Name of the tool.
@@ -356,15 +363,16 @@ module Anthropic
356
363
  T::Array[
357
364
  T.any(
358
365
  Anthropic::Beta::BetaTool::OrHash,
359
- Anthropic::Beta::BetaToolComputerUse20241022::OrHash,
360
366
  Anthropic::Beta::BetaToolBash20241022::OrHash,
361
- Anthropic::Beta::BetaToolTextEditor20241022::OrHash,
362
- Anthropic::Beta::BetaToolComputerUse20250124::OrHash,
363
367
  Anthropic::Beta::BetaToolBash20250124::OrHash,
368
+ Anthropic::Beta::BetaCodeExecutionTool20250522::OrHash,
369
+ Anthropic::Beta::BetaToolComputerUse20241022::OrHash,
370
+ Anthropic::Beta::BetaToolComputerUse20250124::OrHash,
371
+ Anthropic::Beta::BetaToolTextEditor20241022::OrHash,
364
372
  Anthropic::Beta::BetaToolTextEditor20250124::OrHash,
365
373
  Anthropic::Beta::BetaToolTextEditor20250429::OrHash,
366
- Anthropic::Beta::BetaWebSearchTool20250305::OrHash,
367
- Anthropic::Beta::BetaCodeExecutionTool20250522::OrHash
374
+ Anthropic::Beta::BetaToolTextEditor20250728::OrHash,
375
+ Anthropic::Beta::BetaWebSearchTool20250305::OrHash
368
376
  )
369
377
  ],
370
378
  top_k: Integer,
@@ -474,7 +482,7 @@ module Anthropic
474
482
  # the top-level `system` parameter — there is no `"system"` role for input
475
483
  # messages in the Messages API.
476
484
  #
477
- # There is a limit of 100000 messages in a single request.
485
+ # There is a limit of 100,000 messages in a single request.
478
486
  messages:,
479
487
  # Body param: The model that will complete your prompt.\n\nSee
480
488
  # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
@@ -537,6 +545,12 @@ module Anthropic
537
545
  # those tools using the tool input generated by the model and then optionally
538
546
  # return results back to the model using `tool_result` content blocks.
539
547
  #
548
+ # There are two types of tools: **client tools** and **server tools**. The
549
+ # behavior described below applies to client tools. For
550
+ # [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
551
+ # see their individual documentation as each has its own behavior (e.g., the
552
+ # [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
553
+ #
540
554
  # Each tool definition includes:
541
555
  #
542
556
  # - `name`: Name of the tool.
@@ -660,15 +674,16 @@ module Anthropic
660
674
  T::Array[
661
675
  T.any(
662
676
  Anthropic::Beta::BetaTool::OrHash,
663
- Anthropic::Beta::BetaToolComputerUse20241022::OrHash,
664
677
  Anthropic::Beta::BetaToolBash20241022::OrHash,
665
- Anthropic::Beta::BetaToolTextEditor20241022::OrHash,
666
- Anthropic::Beta::BetaToolComputerUse20250124::OrHash,
667
678
  Anthropic::Beta::BetaToolBash20250124::OrHash,
679
+ Anthropic::Beta::BetaCodeExecutionTool20250522::OrHash,
680
+ Anthropic::Beta::BetaToolComputerUse20241022::OrHash,
681
+ Anthropic::Beta::BetaToolComputerUse20250124::OrHash,
682
+ Anthropic::Beta::BetaToolTextEditor20241022::OrHash,
668
683
  Anthropic::Beta::BetaToolTextEditor20250124::OrHash,
669
684
  Anthropic::Beta::BetaToolTextEditor20250429::OrHash,
670
- Anthropic::Beta::BetaWebSearchTool20250305::OrHash,
671
- Anthropic::Beta::BetaCodeExecutionTool20250522::OrHash
685
+ Anthropic::Beta::BetaToolTextEditor20250728::OrHash,
686
+ Anthropic::Beta::BetaWebSearchTool20250305::OrHash
672
687
  )
673
688
  ],
674
689
  betas: T::Array[T.any(String, Anthropic::AnthropicBeta::OrSymbol)],
@@ -763,7 +778,7 @@ module Anthropic
763
778
  # the top-level `system` parameter — there is no `"system"` role for input
764
779
  # messages in the Messages API.
765
780
  #
766
- # There is a limit of 100000 messages in a single request.
781
+ # There is a limit of 100,000 messages in a single request.
767
782
  messages:,
768
783
  # Body param: The model that will complete your prompt.\n\nSee
769
784
  # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
@@ -797,6 +812,12 @@ module Anthropic
797
812
  # those tools using the tool input generated by the model and then optionally
798
813
  # return results back to the model using `tool_result` content blocks.
799
814
  #
815
+ # There are two types of tools: **client tools** and **server tools**. The
816
+ # behavior described below applies to client tools. For
817
+ # [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
818
+ # see their individual documentation as each has its own behavior (e.g., the
819
+ # [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
820
+ #
800
821
  # Each tool definition includes:
801
822
  #
802
823
  # - `name`: Name of the tool.
@@ -43,6 +43,8 @@ module Anthropic
43
43
  Anthropic::Tool::OrHash,
44
44
  Anthropic::ToolBash20250124::OrHash,
45
45
  Anthropic::ToolTextEditor20250124::OrHash,
46
+ Anthropic::ToolTextEditor20250429::OrHash,
47
+ Anthropic::ToolTextEditor20250728::OrHash,
46
48
  Anthropic::WebSearchTool20250305::OrHash
47
49
  )
48
50
  ],
@@ -148,7 +150,7 @@ module Anthropic
148
150
  # the top-level `system` parameter — there is no `"system"` role for input
149
151
  # messages in the Messages API.
150
152
  #
151
- # There is a limit of 100000 messages in a single request.
153
+ # There is a limit of 100,000 messages in a single request.
152
154
  messages:,
153
155
  # The model that will complete your prompt.\n\nSee
154
156
  # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
@@ -207,6 +209,12 @@ module Anthropic
207
209
  # those tools using the tool input generated by the model and then optionally
208
210
  # return results back to the model using `tool_result` content blocks.
209
211
  #
212
+ # There are two types of tools: **client tools** and **server tools**. The
213
+ # behavior described below applies to client tools. For
214
+ # [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
215
+ # see their individual documentation as each has its own behavior (e.g., the
216
+ # [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
217
+ #
210
218
  # Each tool definition includes:
211
219
  #
212
220
  # - `name`: Name of the tool.
@@ -304,6 +312,297 @@ module Anthropic
304
312
  # conversations.
305
313
  #
306
314
  # Learn more about the Messages API in our [user guide](/en/docs/initial-setup)
315
+ sig do
316
+ params(
317
+ max_tokens: Integer,
318
+ messages:
319
+ T::Array[
320
+ T.any(
321
+ Anthropic::Models::MessageParam,
322
+ Anthropic::Internal::AnyHash
323
+ )
324
+ ],
325
+ model: T.any(Anthropic::Models::Model::OrSymbol, String),
326
+ metadata:
327
+ T.any(Anthropic::Models::Metadata, Anthropic::Internal::AnyHash),
328
+ stop_sequences: T::Array[String],
329
+ system_:
330
+ T.any(
331
+ String,
332
+ T::Array[
333
+ T.any(
334
+ Anthropic::Models::TextBlockParam,
335
+ Anthropic::Internal::AnyHash
336
+ )
337
+ ]
338
+ ),
339
+ temperature: Float,
340
+ thinking:
341
+ T.any(
342
+ Anthropic::Models::ThinkingConfigEnabled,
343
+ Anthropic::Internal::AnyHash,
344
+ Anthropic::Models::ThinkingConfigDisabled
345
+ ),
346
+ tool_choice:
347
+ T.any(
348
+ Anthropic::Models::ToolChoiceAuto,
349
+ Anthropic::Internal::AnyHash,
350
+ Anthropic::Models::ToolChoiceAny,
351
+ Anthropic::Models::ToolChoiceTool,
352
+ Anthropic::Models::ToolChoiceNone
353
+ ),
354
+ tools:
355
+ T::Array[
356
+ T.any(
357
+ Anthropic::Models::Tool,
358
+ Anthropic::Internal::AnyHash,
359
+ Anthropic::Models::ToolBash20250124,
360
+ Anthropic::Models::ToolTextEditor20250124
361
+ )
362
+ ],
363
+ top_k: Integer,
364
+ top_p: Float,
365
+ stream: T.noreturn,
366
+ request_options:
367
+ T.nilable(
368
+ T.any(Anthropic::RequestOptions, Anthropic::Internal::AnyHash)
369
+ )
370
+ ).returns(Anthropic::Helpers::Streaming::MessageStream)
371
+ end
372
+ def stream(
373
+ # The maximum number of tokens to generate before stopping.
374
+ #
375
+ # Note that our models may stop _before_ reaching this maximum. This parameter
376
+ # only specifies the absolute maximum number of tokens to generate.
377
+ #
378
+ # Different models have different maximum values for this parameter. See
379
+ # [models](https://docs.anthropic.com/en/docs/models-overview) for details.
380
+ max_tokens:,
381
+ # Input messages.
382
+ #
383
+ # Our models are trained to operate on alternating `user` and `assistant`
384
+ # conversational turns. When creating a new `Message`, you specify the prior
385
+ # conversational turns with the `messages` parameter, and the model then generates
386
+ # the next `Message` in the conversation. Consecutive `user` or `assistant` turns
387
+ # in your request will be combined into a single turn.
388
+ #
389
+ # Each input message must be an object with a `role` and `content`. You can
390
+ # specify a single `user`-role message, or you can include multiple `user` and
391
+ # `assistant` messages.
392
+ #
393
+ # If the final message uses the `assistant` role, the response content will
394
+ # continue immediately from the content in that message. This can be used to
395
+ # constrain part of the model's response.
396
+ #
397
+ # Example with a single `user` message:
398
+ #
399
+ # ```json
400
+ # [{ "role": "user", "content": "Hello, Claude" }]
401
+ # ```
402
+ #
403
+ # Example with multiple conversational turns:
404
+ #
405
+ # ```json
406
+ # [
407
+ # { "role": "user", "content": "Hello there." },
408
+ # { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
409
+ # { "role": "user", "content": "Can you explain LLMs in plain English?" }
410
+ # ]
411
+ # ```
412
+ #
413
+ # Example with a partially-filled response from Claude:
414
+ #
415
+ # ```json
416
+ # [
417
+ # {
418
+ # "role": "user",
419
+ # "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
420
+ # },
421
+ # { "role": "assistant", "content": "The best answer is (" }
422
+ # ]
423
+ # ```
424
+ #
425
+ # Each input message `content` may be either a single `string` or an array of
426
+ # content blocks, where each block has a specific `type`. Using a `string` for
427
+ # `content` is shorthand for an array of one content block of type `"text"`. The
428
+ # following input messages are equivalent:
429
+ #
430
+ # ```json
431
+ # { "role": "user", "content": "Hello, Claude" }
432
+ # ```
433
+ #
434
+ # ```json
435
+ # { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
436
+ # ```
437
+ #
438
+ # Starting with Claude 3 models, you can also send image content blocks:
439
+ #
440
+ # ```json
441
+ # {
442
+ # "role": "user",
443
+ # "content": [
444
+ # {
445
+ # "type": "image",
446
+ # "source": {
447
+ # "type": "base64",
448
+ # "media_type": "image/jpeg",
449
+ # "data": "/9j/4AAQSkZJRg..."
450
+ # }
451
+ # },
452
+ # { "type": "text", "text": "What is in this image?" }
453
+ # ]
454
+ # }
455
+ # ```
456
+ #
457
+ # We currently support the `base64` source type for images, and the `image/jpeg`,
458
+ # `image/png`, `image/gif`, and `image/webp` media types.
459
+ #
460
+ # See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
461
+ # more input examples.
462
+ #
463
+ # Note that if you want to include a
464
+ # [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
465
+ # the top-level `system` parameter — there is no `"system"` role for input
466
+ # messages in the Messages API.
467
+ messages:,
468
+ # The model that will complete your prompt.\n\nSee
469
+ # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
470
+ # details and options.
471
+ model:,
472
+ # An object describing metadata about the request.
473
+ metadata: nil,
474
+ # Custom text sequences that will cause the model to stop generating.
475
+ #
476
+ # Our models will normally stop when they have naturally completed their turn,
477
+ # which will result in a response `stop_reason` of `"end_turn"`.
478
+ #
479
+ # If you want the model to stop generating when it encounters custom strings of
480
+ # text, you can use the `stop_sequences` parameter. If the model encounters one of
481
+ # the custom sequences, the response `stop_reason` value will be `"stop_sequence"`
482
+ # and the response `stop_sequence` value will contain the matched stop sequence.
483
+ stop_sequences: nil,
484
+ # System prompt.
485
+ #
486
+ # A system prompt is a way of providing context and instructions to Claude, such
487
+ # as specifying a particular goal or role. See our
488
+ # [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
489
+ system_: nil,
490
+ # Amount of randomness injected into the response.
491
+ #
492
+ # Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
493
+ # for analytical / multiple choice, and closer to `1.0` for creative and
494
+ # generative tasks.
495
+ #
496
+ # Note that even with `temperature` of `0.0`, the results will not be fully
497
+ # deterministic.
498
+ temperature: nil,
499
+ # Configuration for enabling Claude's extended thinking.
500
+ #
501
+ # When enabled, responses include `thinking` content blocks showing Claude's
502
+ # thinking process before the final answer. Requires a minimum budget of 1,024
503
+ # tokens and counts towards your `max_tokens` limit.
504
+ #
505
+ # See
506
+ # [extended thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)
507
+ # for details.
508
+ thinking: nil,
509
+ # How the model should use the provided tools. The model can use a specific tool,
510
+ # any available tool, decide by itself, or not use tools at all.
511
+ tool_choice: nil,
512
+ # Definitions of tools that the model may use.
513
+ #
514
+ # If you include `tools` in your API request, the model may return `tool_use`
515
+ # content blocks that represent the model's use of those tools. You can then run
516
+ # those tools using the tool input generated by the model and then optionally
517
+ # return results back to the model using `tool_result` content blocks.
518
+ #
519
+ # Each tool definition includes:
520
+ #
521
+ # - `name`: Name of the tool.
522
+ # - `description`: Optional, but strongly-recommended description of the tool.
523
+ # - `input_schema`: [JSON schema](https://json-schema.org/draft/2020-12) for the
524
+ # tool `input` shape that the model will produce in `tool_use` output content
525
+ # blocks.
526
+ #
527
+ # For example, if you defined `tools` as:
528
+ #
529
+ # ```json
530
+ # [
531
+ # {
532
+ # "name": "get_stock_price",
533
+ # "description": "Get the current stock price for a given ticker symbol.",
534
+ # "input_schema": {
535
+ # "type": "object",
536
+ # "properties": {
537
+ # "ticker": {
538
+ # "type": "string",
539
+ # "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
540
+ # }
541
+ # },
542
+ # "required": ["ticker"]
543
+ # }
544
+ # }
545
+ # ]
546
+ # ```
547
+ #
548
+ # And then asked the model "What's the S&P 500 at today?", the model might produce
549
+ # `tool_use` content blocks in the response like this:
550
+ #
551
+ # ```json
552
+ # [
553
+ # {
554
+ # "type": "tool_use",
555
+ # "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
556
+ # "name": "get_stock_price",
557
+ # "input": { "ticker": "^GSPC" }
558
+ # }
559
+ # ]
560
+ # ```
561
+ #
562
+ # You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
563
+ # input, and return the following back to the model in a subsequent `user`
564
+ # message:
565
+ #
566
+ # ```json
567
+ # [
568
+ # {
569
+ # "type": "tool_result",
570
+ # "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
571
+ # "content": "259.75 USD"
572
+ # }
573
+ # ]
574
+ # ```
575
+ #
576
+ # Tools can be used for workflows that include running client-side tools and
577
+ # functions, or more generally whenever you want the model to produce a particular
578
+ # JSON structure of output.
579
+ #
580
+ # See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
581
+ tools: nil,
582
+ # Only sample from the top K options for each subsequent token.
583
+ #
584
+ # Used to remove "long tail" low probability responses.
585
+ # [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
586
+ #
587
+ # Recommended for advanced use cases only. You usually only need to use
588
+ # `temperature`.
589
+ top_k: nil,
590
+ # Use nucleus sampling.
591
+ #
592
+ # In nucleus sampling, we compute the cumulative distribution over all the options
593
+ # for each subsequent token in decreasing probability order and cut it off once it
594
+ # reaches a particular probability specified by `top_p`. You should either alter
595
+ # `temperature` or `top_p`, but not both.
596
+ #
597
+ # Recommended for advanced use cases only. You usually only need to use
598
+ # `temperature`.
599
+ top_p: nil,
600
+ # There is no need to provide `stream:`. Instead, use `#stream_raw` or `#create`
601
+ # for streaming and non-streaming use cases, respectively.
602
+ stream: true,
603
+ request_options: {}
604
+ )
605
+ end
307
606
  sig do
308
607
  params(
309
608
  max_tokens: Integer,
@@ -332,6 +631,8 @@ module Anthropic
332
631
  Anthropic::Tool::OrHash,
333
632
  Anthropic::ToolBash20250124::OrHash,
334
633
  Anthropic::ToolTextEditor20250124::OrHash,
634
+ Anthropic::ToolTextEditor20250429::OrHash,
635
+ Anthropic::ToolTextEditor20250728::OrHash,
335
636
  Anthropic::WebSearchTool20250305::OrHash
336
637
  )
337
638
  ],
@@ -441,7 +742,7 @@ module Anthropic
441
742
  # the top-level `system` parameter — there is no `"system"` role for input
442
743
  # messages in the Messages API.
443
744
  #
444
- # There is a limit of 100000 messages in a single request.
745
+ # There is a limit of 100,000 messages in a single request.
445
746
  messages:,
446
747
  # The model that will complete your prompt.\n\nSee
447
748
  # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
@@ -500,6 +801,12 @@ module Anthropic
500
801
  # those tools using the tool input generated by the model and then optionally
501
802
  # return results back to the model using `tool_result` content blocks.
502
803
  #
804
+ # There are two types of tools: **client tools** and **server tools**. The
805
+ # behavior described below applies to client tools. For
806
+ # [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
807
+ # see their individual documentation as each has its own behavior (e.g., the
808
+ # [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
809
+ #
503
810
  # Each tool definition includes:
504
811
  #
505
812
  # - `name`: Name of the tool.
@@ -618,6 +925,8 @@ module Anthropic
618
925
  Anthropic::Tool::OrHash,
619
926
  Anthropic::ToolBash20250124::OrHash,
620
927
  Anthropic::ToolTextEditor20250124::OrHash,
928
+ Anthropic::ToolTextEditor20250429::OrHash,
929
+ Anthropic::ToolTextEditor20250728::OrHash,
621
930
  Anthropic::WebSearchTool20250305::OrHash
622
931
  )
623
932
  ],
@@ -712,7 +1021,7 @@ module Anthropic
712
1021
  # the top-level `system` parameter — there is no `"system"` role for input
713
1022
  # messages in the Messages API.
714
1023
  #
715
- # There is a limit of 100000 messages in a single request.
1024
+ # There is a limit of 100,000 messages in a single request.
716
1025
  messages:,
717
1026
  # The model that will complete your prompt.\n\nSee
718
1027
  # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
@@ -744,6 +1053,12 @@ module Anthropic
744
1053
  # those tools using the tool input generated by the model and then optionally
745
1054
  # return results back to the model using `tool_result` content blocks.
746
1055
  #
1056
+ # There are two types of tools: **client tools** and **server tools**. The
1057
+ # behavior described below applies to client tools. For
1058
+ # [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
1059
+ # see their individual documentation as each has its own behavior (e.g., the
1060
+ # [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
1061
+ #
747
1062
  # Each tool definition includes:
748
1063
  #
749
1064
  # - `name`: Name of the tool.
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Anthropic
4
+ Streaming = Anthropic::Helpers::Streaming
5
+ end
@@ -5,6 +5,15 @@ module Anthropic
5
5
  end
6
6
 
7
7
  class ConversionError < Anthropic::Errors::Error
8
+ def cause: -> StandardError?
9
+
10
+ def initialize: (
11
+ on: Class,
12
+ method: Symbol,
13
+ target: top,
14
+ value: top,
15
+ ?cause: StandardError?
16
+ ) -> void
8
17
  end
9
18
 
10
19
  class APIError < Anthropic::Errors::Error
@@ -0,0 +1,117 @@
1
+ module Anthropic
2
+ module Helpers
3
+ module Streaming
4
+ type text_event = { type: :text, text: String, snapshot: String }
5
+
6
+ class TextEvent < Anthropic::Internal::Type::BaseModel
7
+ attr_accessor type: :text
8
+
9
+ attr_accessor text: String
10
+
11
+ attr_accessor snapshot: String
12
+
13
+ def initialize: (text: String, snapshot: String, ?type: :text) -> void
14
+ end
15
+
16
+ type citation_event =
17
+ {
18
+ type: :citation,
19
+ citation: Anthropic::Models::CitationsDelta::citation,
20
+ snapshot: ::Array[Anthropic::Models::CitationsDelta::citation]
21
+ }
22
+
23
+ class CitationEvent < Anthropic::Internal::Type::BaseModel
24
+ attr_accessor type: :citation
25
+
26
+ attr_accessor citation: Anthropic::Models::CitationsDelta::citation
27
+
28
+ attr_accessor snapshot: ::Array[Anthropic::Models::CitationsDelta::citation]
29
+
30
+ def initialize: (
31
+ citation: Anthropic::Models::CitationsDelta::citation,
32
+ snapshot: ::Array[Anthropic::Models::CitationsDelta::citation],
33
+ ?type: :citation
34
+ ) -> void
35
+ end
36
+
37
+ type thinking_event =
38
+ { type: :thinking, thinking: String, snapshot: String }
39
+
40
+ class ThinkingEvent < Anthropic::Internal::Type::BaseModel
41
+ attr_accessor type: :thinking
42
+
43
+ attr_accessor thinking: String
44
+
45
+ attr_accessor snapshot: String
46
+
47
+ def initialize: (
48
+ thinking: String,
49
+ snapshot: String,
50
+ ?type: :thinking
51
+ ) -> void
52
+ end
53
+
54
+ type signature_event = { type: :signature, signature: String }
55
+
56
+ class SignatureEvent < Anthropic::Internal::Type::BaseModel
57
+ attr_accessor type: :signature
58
+
59
+ attr_accessor signature: String
60
+
61
+ def initialize: (signature: String, ?type: :signature) -> void
62
+ end
63
+
64
+ type input_json_event =
65
+ { type: :input_json, partial_json: String, snapshot: untyped }
66
+
67
+ class InputJsonEvent < Anthropic::Internal::Type::BaseModel
68
+ attr_accessor type: :input_json
69
+
70
+ attr_accessor partial_json: String
71
+
72
+ attr_accessor snapshot: untyped
73
+
74
+ def initialize: (
75
+ partial_json: String,
76
+ snapshot: untyped,
77
+ ?type: :input_json
78
+ ) -> void
79
+ end
80
+
81
+ type message_stop_event =
82
+ { type: :message_stop, message: Anthropic::Models::message }
83
+
84
+ class MessageStopEvent < Anthropic::Models::RawMessageStopEvent
85
+ attr_accessor type: :message_stop
86
+
87
+ attr_accessor message: Anthropic::Models::message
88
+
89
+ def initialize: (
90
+ message: Anthropic::Models::message,
91
+ ?type: :message_stop
92
+ ) -> void
93
+ end
94
+
95
+ type content_block_stop_event =
96
+ {
97
+ type: :content_block_stop,
98
+ index: Integer,
99
+ content_block: Anthropic::Models::content_block
100
+ }
101
+
102
+ class ContentBlockStopEvent < Anthropic::Models::RawContentBlockStopEvent
103
+ attr_accessor type: :content_block_stop
104
+
105
+ attr_accessor index: Integer
106
+
107
+ attr_accessor content_block: Anthropic::Models::content_block
108
+
109
+ def initialize: (
110
+ index: Integer,
111
+ content_block: Anthropic::Models::content_block,
112
+ ?type: :content_block_stop
113
+ ) -> void
114
+ end
115
+ end
116
+ end
117
+ end