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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13b85406d88291ad8b4617f040286edefe795c4b0400312d0a630dfe30a70bf6
4
- data.tar.gz: 3467c4167d8db97ecc9bd2dbf049f6795ac7d6474ad8e3b1c1d0414aee1d297e
3
+ metadata.gz: 7ddce47b08338bf4a2eb932fddbcc85b24d713f50b3ce167d459b39fa644f4ce
4
+ data.tar.gz: a2512742b5e084705306598a0f46c71abd407f0ad364bfd7f294fd22226ee91f
5
5
  SHA512:
6
- metadata.gz: d5ea1bd30663111c0cf3d5681469b9186621bf2eb8009f38e3aea031092f5b4a1bf091b484c8bb40b8214977ff29efc19ef03b25ed7479cd69e6c9d528a5f06a
7
- data.tar.gz: d7afee44eb07c19934d5691b7b2d7e55fbdbcd88b82dc3ae65d71cc4e00ab6093836da1c4158e68f8d0fd48a9520993350abb4c29957785edcd68862cafaa3f8
6
+ metadata.gz: 67bbb70c8f49c7b42226f47ace877d55dba4b8544d8d2ec26bd669114fa78f77ad2a3445d40bc35acaab70e342f37621d0ee92a29a4b80b21ecd34666a4b3da1
7
+ data.tar.gz: 140d00ea5c494d0330c26f3345422b8f8efc4d7d31e8e206271dc02598e6c63387749ed4bb140b93e64eaf66bd85bb3f78b25f6767fc50d973b05e2d85f16da6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,128 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.6.0 (2025-08-12)
4
+
5
+ Full Changelog: [v1.5.0...v1.6.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.5.0...v1.6.0)
6
+
7
+ ### Features
8
+
9
+ * **betas:** add context-1m-2025-08-07 ([5bb5064](https://github.com/anthropics/anthropic-sdk-ruby/commit/5bb506416852bcd0c893c643831ec6e52a2cc79d))
10
+
11
+
12
+ ### Chores
13
+
14
+ * collect metadata from type DSL ([69114b1](https://github.com/anthropics/anthropic-sdk-ruby/commit/69114b159e3710c467cbb7c55b8b7526cb5ea8e7))
15
+ * **internal:** update comment in script ([c5bd3b1](https://github.com/anthropics/anthropic-sdk-ruby/commit/c5bd3b144ad399c114e644437820a8785e7399f0))
16
+ * **internal:** update test skipping reason ([6d7c586](https://github.com/anthropics/anthropic-sdk-ruby/commit/6d7c58606a88e6a34b16f19006e44dbf17d657c0))
17
+ * update @stainless-api/prism-cli to v5.15.0 ([356427c](https://github.com/anthropics/anthropic-sdk-ruby/commit/356427c4ec83d134dbcccdf27915eee65e5e8daa))
18
+
19
+ ## 1.5.0 (2025-08-08)
20
+
21
+ Full Changelog: [v1.4.1...v1.5.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.4.1...v1.5.0)
22
+
23
+ ### Features
24
+
25
+ * **api:** search result content blocks ([9a94866](https://github.com/anthropics/anthropic-sdk-ruby/commit/9a9486664e10ce0d02967ab1d5360357ffb72a66))
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * aws bedrock base url ([#673](https://github.com/anthropics/anthropic-sdk-ruby/issues/673)) ([b2996b9](https://github.com/anthropics/anthropic-sdk-ruby/commit/b2996b9349b047c53232ecd63823110ad90c71c3))
31
+
32
+ ## 1.4.1 (2025-08-07)
33
+
34
+ Full Changelog: [v1.4.0...v1.4.1](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.4.0...v1.4.1)
35
+
36
+ ### Bug Fixes
37
+
38
+ * aws bedrock should sign each request follow retries ([#672](https://github.com/anthropics/anthropic-sdk-ruby/issues/672)) ([df9f4e1](https://github.com/anthropics/anthropic-sdk-ruby/commit/df9f4e1aa7e7211dab3d36dd9093092d20649359))
39
+
40
+ ## 1.4.0 (2025-08-05)
41
+
42
+ Full Changelog: [v1.3.0...v1.4.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.3.0...v1.4.0)
43
+
44
+ ### Features
45
+
46
+ * **api:** add claude-opus-4-1-20250805 ([2477a05](https://github.com/anthropics/anthropic-sdk-ruby/commit/2477a05b8b26b047df178264db7d0764ca954954))
47
+ * **api:** adds support for text_editor_20250728 tool ([dff36db](https://github.com/anthropics/anthropic-sdk-ruby/commit/dff36db0eb8b7077ba311f3815eb0065422c2fd4))
48
+ * update streaming error message to say 'required' not 'recommended' ([6272ddd](https://github.com/anthropics/anthropic-sdk-ruby/commit/6272ddd9cd3ae0110afee98159516c3232c65832))
49
+
50
+
51
+ ### Chores
52
+
53
+ * **ci:** setup Ruby on release job ([#111](https://github.com/anthropics/anthropic-sdk-ruby/issues/111)) ([bb5d08f](https://github.com/anthropics/anthropic-sdk-ruby/commit/bb5d08f052b3e65f70d345c45ce59e3e8fe282f3))
54
+ * **client:** add TextEditor_20250429 tool ([3b344dc](https://github.com/anthropics/anthropic-sdk-ruby/commit/3b344dcf2dc759a0a01a1061573115c7a6c8a449))
55
+ * **internal:** increase visibility of internal helper method ([72fb96c](https://github.com/anthropics/anthropic-sdk-ruby/commit/72fb96cdcdb2a6436aaf6d908f010ae16c08bd33))
56
+
57
+ ## 1.3.0 (2025-07-28)
58
+
59
+ Full Changelog: [v1.2.0...v1.3.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.2.0...v1.3.0)
60
+
61
+ ### Features
62
+
63
+ * **api:** removed older deprecated models ([47de6c2](https://github.com/anthropics/anthropic-sdk-ruby/commit/47de6c2860fabd344374aed733df1bcb17988454))
64
+ * **client:** add beta stream implementation and fine grained tool streaming example ([2856b81](https://github.com/anthropics/anthropic-sdk-ruby/commit/2856b8119b99e6487093df3f49216ecc8d1bd3e3))
65
+ * **client:** add beta stream implementation and fine grained tool streaming example ([bc87fd4](https://github.com/anthropics/anthropic-sdk-ruby/commit/bc87fd4afd94a48301fec548a0e7b21f44a24a59))
66
+
67
+
68
+ ### Bug Fixes
69
+
70
+ * **internal:** ensure sorbet test always runs serially ([0b39a19](https://github.com/anthropics/anthropic-sdk-ruby/commit/0b39a1908587597ca5836872333541307f24bdf2))
71
+ * **internal:** ensure vertex client test ordering ([#667](https://github.com/anthropics/anthropic-sdk-ruby/issues/667)) ([d7439fa](https://github.com/anthropics/anthropic-sdk-ruby/commit/d7439fa58664d9a533cacca6a299b3dbbe43ec7f))
72
+
73
+
74
+ ### Chores
75
+
76
+ * add basic tool use example ([#107](https://github.com/anthropics/anthropic-sdk-ruby/issues/107)) ([4452119](https://github.com/anthropics/anthropic-sdk-ruby/commit/445211929b09ff0be9406aad1b3f3604d8bf3794))
77
+ * add Darwin to PLATFORMS in Gemfile.lock ([#104](https://github.com/anthropics/anthropic-sdk-ruby/issues/104)) ([aa5bcbe](https://github.com/anthropics/anthropic-sdk-ruby/commit/aa5bcbedc48cc9a49ba14050fa3ad934a6f95c99))
78
+ * **internal:** run formatter ([87ce979](https://github.com/anthropics/anthropic-sdk-ruby/commit/87ce979a06108f980e8c867d43166fbeeff02ec3))
79
+ * update contribute.md ([aa928a0](https://github.com/anthropics/anthropic-sdk-ruby/commit/aa928a09f08250c9e6e93b884761eb35a9d5b6b4))
80
+
81
+ ## 1.2.0 (2025-07-18)
82
+
83
+ Full Changelog: [v1.1.1...v1.2.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.1.1...v1.2.0)
84
+
85
+ ### Features
86
+
87
+ * **api:** add support for Search Result Content Blocks ([158a7ce](https://github.com/anthropics/anthropic-sdk-ruby/commit/158a7ced1013c3af956554caf41ee08ec5d1db3c))
88
+ * **api:** api update ([cd22765](https://github.com/anthropics/anthropic-sdk-ruby/commit/cd2276536c7960a4f7276ceb9baba8ba5aec196e))
89
+ * **api:** manual updates ([7f51b33](https://github.com/anthropics/anthropic-sdk-ruby/commit/7f51b336943422d230d8704583f42dc6f8a3ac62))
90
+ * **client:** add breaking change detection to CI ([52e342f](https://github.com/anthropics/anthropic-sdk-ruby/commit/52e342fe8c8231ad6b6b6ff68ed522033cd503c7))
91
+ * **client:** add support for new text_editor_20250429 tool ([9049af2](https://github.com/anthropics/anthropic-sdk-ruby/commit/9049af2f634f88d867104f2dc0ddc6396f5f8031))
92
+ * streaming helpers ([#627](https://github.com/anthropics/anthropic-sdk-ruby/issues/627)) ([43fbbf8](https://github.com/anthropics/anthropic-sdk-ruby/commit/43fbbf8a39ac1d99920845ba19da43d7419a5e73))
93
+ * **vertex:** support global region endpoint ([da8c452](https://github.com/anthropics/anthropic-sdk-ruby/commit/da8c452a22c56780f311f4f1ab3477a48ac46891))
94
+
95
+
96
+ ### Bug Fixes
97
+
98
+ * `to_sorbet_type` should not return branded types ([2658903](https://github.com/anthropics/anthropic-sdk-ruby/commit/2658903f13178a133ca679f4b87615e9cddcd813))
99
+ * **ci:** release-doctor — report correct token name ([e30183e](https://github.com/anthropics/anthropic-sdk-ruby/commit/e30183e5561070dfd3dfe041f48e76765975cb3b))
100
+ * **client:** deprecate BetaBase64PDFBlock in favor of BetaRequestDocumentBlock ([f75705b](https://github.com/anthropics/anthropic-sdk-ruby/commit/f75705bfb4af3160b2fa7208adfad10719cd17a7))
101
+ * default content-type for text in multi-part formdata uploads should be text/plain ([0a91592](https://github.com/anthropics/anthropic-sdk-ruby/commit/0a915925fc93ca7ad191bab33dba8c72b6c48a2a))
102
+ * **internal:** fix: should publish to ruby gems when a release is created ([cc88c6c](https://github.com/anthropics/anthropic-sdk-ruby/commit/cc88c6c7c164c5bb1937e12cefb4d91f05fec157))
103
+ * issue where we cannot mutate arrays on base model derivatives ([446c8be](https://github.com/anthropics/anthropic-sdk-ruby/commit/446c8be0eb77a29641d472ea36cbaf6f786f7e3a))
104
+
105
+
106
+ ### Chores
107
+
108
+ * add `license` to the gemspec ([#101](https://github.com/anthropics/anthropic-sdk-ruby/issues/101)) ([af509a7](https://github.com/anthropics/anthropic-sdk-ruby/commit/af509a735c0e985e615f9279bc070dc090874df8))
109
+ * add RBS types for helpers/streaming ([#631](https://github.com/anthropics/anthropic-sdk-ruby/issues/631)) ([0d7941d](https://github.com/anthropics/anthropic-sdk-ruby/commit/0d7941df6628b1500f7e7e8def88f613d7bcf2fa))
110
+ * **api:** mark claude-3-opus-20240229 as deprecated ([1edd9bd](https://github.com/anthropics/anthropic-sdk-ruby/commit/1edd9bdf0bf508f5467daf92c4b1db11128d70ea))
111
+ * **api:** update BetaCitationSearchResultLocation ([b294f7e](https://github.com/anthropics/anthropic-sdk-ruby/commit/b294f7e2bfd44d01504eeb7e30b37926ca7200e2))
112
+ * **ci:** enable for pull requests ([31bbb43](https://github.com/anthropics/anthropic-sdk-ruby/commit/31bbb43d02cc56505ad5ec8d737801b73f9f5fd8))
113
+ * **ci:** link to correct github repo ([37b5902](https://github.com/anthropics/anthropic-sdk-ruby/commit/37b59027a26268ad5bb20ee6530c7f0c630bc5b5))
114
+ * **ci:** only run for pushes and fork pull requests ([8d3c942](https://github.com/anthropics/anthropic-sdk-ruby/commit/8d3c9425afe873a49e403c7a8a36f14642191a89))
115
+ * **internal:** allow streams to also be unwrapped on a per-row basis ([a271d21](https://github.com/anthropics/anthropic-sdk-ruby/commit/a271d21d2f01a9f7c9c2d126b1f3d9b0611dd8cd))
116
+ * **internal:** codegen related update ([8b12fd6](https://github.com/anthropics/anthropic-sdk-ruby/commit/8b12fd6e8ec1c06d3cbf7d20c63c6933538d0983))
117
+ * remove workaround for updating arrays in place in streaming ([#643](https://github.com/anthropics/anthropic-sdk-ruby/issues/643)) ([e0a30b8](https://github.com/anthropics/anthropic-sdk-ruby/commit/e0a30b8128624566f673ac77f97c305953b11c63))
118
+
119
+
120
+ ### Documentation
121
+
122
+ * model in examples ([18ba0b6](https://github.com/anthropics/anthropic-sdk-ruby/commit/18ba0b62bd8f87b84766265726090ca2265a64b7))
123
+ * update documentation in MessageStream ([#630](https://github.com/anthropics/anthropic-sdk-ruby/issues/630)) ([4795c73](https://github.com/anthropics/anthropic-sdk-ruby/commit/4795c73f0628d2bc710f77bd0868be18c53ec31a))
124
+ * update models and non-beta ([a4ea04e](https://github.com/anthropics/anthropic-sdk-ruby/commit/a4ea04eaf88e608612512d39d07051842beaf500))
125
+
3
126
  ## 1.1.1 (2025-05-28)
4
127
 
5
128
  Full Changelog: [v1.1.0...v1.1.1](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.1.0...v1.1.1)
data/README.md CHANGED
@@ -15,7 +15,7 @@ To use this gem, install via Bundler by adding the following to your application
15
15
  <!-- x-release-please-start-version -->
16
16
 
17
17
  ```ruby
18
- gem "anthropic", "~> 1.1.1"
18
+ gem "anthropic", "~> 1.6.0"
19
19
  ```
20
20
 
21
21
  <!-- x-release-please-end -->
@@ -39,7 +39,7 @@ anthropic = Anthropic::Client.new(
39
39
  message = anthropic.messages.create(
40
40
  max_tokens: 1024,
41
41
  messages: [{role: "user", content: "Hello, Claude"}],
42
- model: :"claude-3-7-sonnet-latest"
42
+ model: :"claude-sonnet-4-20250514"
43
43
  )
44
44
 
45
45
  puts(message.content)
@@ -49,13 +49,11 @@ puts(message.content)
49
49
 
50
50
  We provide support for streaming responses using Server-Sent Events (SSE).
51
51
 
52
- **coming soon**: `anthropic.messages.stream` will have [Python SDK](https://github.com/anthropics/anthropic-sdk-python?tab=readme-ov-file#streaming-helpers) style streaming response helpers.
53
-
54
52
  ```ruby
55
- stream = anthropic.messages.stream_raw(
53
+ stream = anthropic.messages.stream(
56
54
  max_tokens: 1024,
57
55
  messages: [{role: "user", content: "Hello, Claude"}],
58
- model: :"claude-3-7-sonnet-latest"
56
+ model: :"claude-sonnet-4-20250514"
59
57
  )
60
58
 
61
59
  stream.each do |message|
@@ -63,6 +61,24 @@ stream.each do |message|
63
61
  end
64
62
  ```
65
63
 
64
+ ### Streaming Helpers
65
+
66
+ This library provides several conveniences for streaming messages, for example:
67
+
68
+ ```ruby
69
+ stream = anthropic.messages.stream(
70
+ max_tokens: 1024,
71
+ messages: [{role: :user, content: "Say hello there!"}],
72
+ model: :"claude-sonnet-4-20250514"
73
+ )
74
+
75
+ stream.text.each do |text|
76
+ print(text)
77
+ end
78
+ ```
79
+
80
+ Streaming with `anthropic.messages.stream(...)` exposes [various helpers for your convenience](helpers.md) including accumulation & SDK-specific events.
81
+
66
82
  ### Pagination
67
83
 
68
84
  List methods in the Anthropic API are paginated.
@@ -70,7 +86,7 @@ List methods in the Anthropic API are paginated.
70
86
  This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
71
87
 
72
88
  ```ruby
73
- page = anthropic.beta.messages.batches.list(limit: 20)
89
+ page = anthropic.messages.batches.list(limit: 20)
74
90
 
75
91
  # Fetch single item from page.
76
92
  batch = page.data[0]
@@ -122,7 +138,7 @@ begin
122
138
  message = anthropic.messages.create(
123
139
  max_tokens: 1024,
124
140
  messages: [{role: "user", content: "Hello, Claude"}],
125
- model: :"claude-3-7-sonnet-latest"
141
+ model: :"claude-sonnet-4-20250514"
126
142
  )
127
143
  rescue Anthropic::Errors::APIConnectionError => e
128
144
  puts("The server could not be reached")
@@ -169,7 +185,7 @@ anthropic = Anthropic::Client.new(
169
185
  anthropic.messages.create(
170
186
  max_tokens: 1024,
171
187
  messages: [{role: "user", content: "Hello, Claude"}],
172
- model: :"claude-3-7-sonnet-latest",
188
+ model: :"claude-sonnet-4-20250514",
173
189
  request_options: {max_retries: 5}
174
190
  )
175
191
  ```
@@ -188,7 +204,7 @@ anthropic = Anthropic::Client.new(
188
204
  anthropic.messages.create(
189
205
  max_tokens: 1024,
190
206
  messages: [{role: "user", content: "Hello, Claude"}],
191
- model: :"claude-3-7-sonnet-latest",
207
+ model: :"claude-sonnet-4-20250514",
192
208
  request_options: {timeout: 5}
193
209
  )
194
210
  ```
@@ -219,7 +235,7 @@ message = anthropic.messages.create(
219
235
  content: "Hello, Claude"
220
236
  }
221
237
  ],
222
- model: "anthropic.claude-3-5-sonnet-20241022-v2:0"
238
+ model: "anthropic.claude-sonnet-4-20250514-v2:0"
223
239
  )
224
240
 
225
241
  puts(message)
@@ -247,7 +263,7 @@ message = anthropic.messages.create(
247
263
  content: "Hello, Claude"
248
264
  }
249
265
  ],
250
- model: "claude-3-7-sonnet@20250219"
266
+ model: "claude-sonnet-4@20250514"
251
267
  )
252
268
 
253
269
  puts(message)
@@ -284,7 +300,7 @@ message =
284
300
  anthropic.messages.create(
285
301
  max_tokens: 1024,
286
302
  messages: [{role: "user", content: "Hello, Claude"}],
287
- model: :"claude-3-7-sonnet-latest",
303
+ model: :"claude-sonnet-4-20250514",
288
304
  request_options: {
289
305
  extra_query: {my_query_parameter: value},
290
306
  extra_body: {my_body_parameter: value},
@@ -333,7 +349,7 @@ You can provide typesafe request parameters like so:
333
349
  anthropic.messages.create(
334
350
  max_tokens: 1024,
335
351
  messages: [Anthropic::MessageParam.new(role: "user", content: "Hello, Claude")],
336
- model: :"claude-3-7-sonnet-latest"
352
+ model: :"claude-sonnet-4-20250514"
337
353
  )
338
354
  ```
339
355
 
@@ -344,14 +360,14 @@ Or, equivalently:
344
360
  anthropic.messages.create(
345
361
  max_tokens: 1024,
346
362
  messages: [{role: "user", content: "Hello, Claude"}],
347
- model: :"claude-3-7-sonnet-latest"
363
+ model: :"claude-sonnet-4-20250514"
348
364
  )
349
365
 
350
366
  # You can also splat a full Params class:
351
367
  params = Anthropic::MessageCreateParams.new(
352
368
  max_tokens: 1024,
353
369
  messages: [Anthropic::MessageParam.new(role: "user", content: "Hello, Claude")],
354
- model: :"claude-3-7-sonnet-latest"
370
+ model: :"claude-sonnet-4-20250514"
355
371
  )
356
372
  anthropic.messages.create(**params)
357
373
  ```
@@ -21,7 +21,10 @@ module Anthropic
21
21
  "claude-opus-4-0": 8_192,
22
22
  "claude-4-opus-20250514": 8_192,
23
23
  "anthropic.claude-opus-4-20250514-v1:0": 8_192,
24
- "claude-opus-4@20250514": 8_192
24
+ "claude-opus-4@20250514": 8_192,
25
+ "claude-opus-4-1-20250805": 8192,
26
+ "anthropic.claude-opus-4-1-20250805-v1:0": 8192,
27
+ "claude-opus-4-1@20250805": 8192
25
28
  }.freeze
26
29
 
27
30
  # @return [String, nil]
@@ -78,7 +81,7 @@ module Anthropic
78
81
  expected_time = maximum_time * max_tokens / 128_000.0
79
82
  if expected_time > default_time || (max_nonstreaming_tokens && max_tokens > max_nonstreaming_tokens)
80
83
  raise ArgumentError.new(
81
- "Streaming is strongly recommended for operations that may take longer than 10 minutes. " \
84
+ "Streaming is required for operations that may take longer than 10 minutes. " \
82
85
  "See https://github.com/anthropics/anthropic-sdk-ruby#long-requests for more details"
83
86
  )
84
87
  end
@@ -9,6 +9,28 @@ module Anthropic
9
9
  end
10
10
 
11
11
  class ConversionError < Anthropic::Errors::Error
12
+ # @return [StandardError, nil]
13
+ def cause = @cause.nil? ? super : @cause
14
+
15
+ # @api private
16
+ #
17
+ # @param on [Class<StandardError>]
18
+ # @param method [Symbol]
19
+ # @param target [Object]
20
+ # @param value [Object]
21
+ # @param cause [StandardError, nil]
22
+ def initialize(on:, method:, target:, value:, cause: nil)
23
+ cls = on.name.split("::").last
24
+
25
+ message = [
26
+ "Failed to parse #{cls}.#{method} from #{value.class} to #{target.inspect}.",
27
+ "To get the unparsed API response, use #{cls}[#{method.inspect}].",
28
+ cause && "Cause: #{cause.message}"
29
+ ].filter(&:itself).join(" ")
30
+
31
+ @cause = cause
32
+ super(message)
33
+ end
12
34
  end
13
35
 
14
36
  class APIError < Anthropic::Errors::Error
@@ -50,10 +50,10 @@ module Anthropic
50
50
  def initialize(
51
51
  aws_region: nil,
52
52
  base_url: nil,
53
- max_retries: DEFAULT_MAX_RETRIES,
54
- timeout: DEFAULT_TIMEOUT_IN_SECONDS,
55
- initial_retry_delay: DEFAULT_INITIAL_RETRY_DELAY,
56
- max_retry_delay: DEFAULT_MAX_RETRY_DELAY,
53
+ max_retries: self.class::DEFAULT_MAX_RETRIES,
54
+ timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
55
+ initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
56
+ max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY,
57
57
  aws_access_key: nil,
58
58
  aws_secret_key: nil,
59
59
  aws_session_token: nil,
@@ -165,6 +165,36 @@ module Anthropic
165
165
  request_input
166
166
  end
167
167
 
168
+ # @api private
169
+ #
170
+ # Very private API, do not use
171
+ #
172
+ # @param request [Hash{Symbol=>Object}] .
173
+ #
174
+ # @option request [Symbol] :method
175
+ #
176
+ # @option request [URI::Generic] :url
177
+ #
178
+ # @option request [Hash{String=>String}] :headers
179
+ #
180
+ # @option request [Object] :body
181
+ #
182
+ # @return [Hash{Symbol, Object}]
183
+ private def transform_request(request)
184
+ sliced = super.slice(
185
+ :method,
186
+ :url,
187
+ :headers,
188
+ :body
189
+ ).transform_keys(method: :http_method)
190
+ body = StringIO.new(body.to_a.join) if (body = sliced.fetch(:body)).is_a?(Enumerator)
191
+
192
+ signed = @signer.sign_request({**sliced, body: body})
193
+
194
+ headers = Anthropic::Internal::Util.normalized_headers(request.fetch(:headers), signed.headers)
195
+ {**request, headers: headers}
196
+ end
197
+
168
198
  # @param aws_region [String, nil]
169
199
  #
170
200
  # @param aws_secret_key [String, nil]
@@ -0,0 +1,141 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Anthropic
4
+ module Helpers
5
+ module Streaming
6
+ class TextEvent < Anthropic::Internal::Type::BaseModel
7
+ # @!attribute type
8
+ #
9
+ # @return [Symbol, :text]
10
+ required :type, const: :text
11
+
12
+ # @!attribute text
13
+ # The text delta received in this streaming event.
14
+ #
15
+ # @return [String]
16
+ required :text, String
17
+
18
+ # @!attribute snapshot
19
+ # The entire accumulated text up to this point in the stream.
20
+ #
21
+ # @return [String]
22
+ required :snapshot, String
23
+ end
24
+
25
+ class CitationEvent < Anthropic::Internal::Type::BaseModel
26
+ # @!attribute type
27
+ #
28
+ # @return [Symbol, :citation]
29
+ required :type, const: :citation
30
+
31
+ # @!attribute citation
32
+ # The new citation received in this streaming event.
33
+ #
34
+ # @return [Anthropic::Models::CitationCharLocation, Anthropic::Models::CitationPageLocation, Anthropic::Models::CitationContentBlockLocation, Anthropic::Models::CitationsWebSearchResultLocation]
35
+ required :citation, union: -> { Anthropic::CitationsDelta::Citation }
36
+
37
+ # @!attribute snapshot
38
+ # All of the accumulated citations up to this point in the stream.
39
+ #
40
+ # @return [Array<Anthropic::Models::CitationCharLocation, Anthropic::Models::CitationPageLocation, Anthropic::Models::CitationContentBlockLocation, Anthropic::Models::CitationsWebSearchResultLocation>]
41
+ required :snapshot,
42
+ -> {
43
+ Anthropic::Internal::Type::ArrayOf[union: Anthropic::CitationsDelta::Citation]
44
+ }
45
+ end
46
+
47
+ class ThinkingEvent < Anthropic::Internal::Type::BaseModel
48
+ # @!attribute type
49
+ #
50
+ # @return [Symbol, :thinking]
51
+ required :type, const: :thinking
52
+
53
+ # @!attribute thinking
54
+ # The thinking delta received in this streaming event.
55
+ #
56
+ # @return [String]
57
+ required :thinking, String
58
+
59
+ # @!attribute snapshot
60
+ # The accumulated thinking content up to this point in the stream.
61
+ #
62
+ # @return [String]
63
+ required :snapshot, String
64
+ end
65
+
66
+ class SignatureEvent < Anthropic::Internal::Type::BaseModel
67
+ # @!attribute type
68
+ #
69
+ # @return [Symbol, :signature]
70
+ required :type, const: :signature
71
+
72
+ # @!attribute signature
73
+ # The signature of the thinking block.
74
+ #
75
+ # @return [String]
76
+ required :signature, String
77
+ end
78
+
79
+ class InputJsonEvent < Anthropic::Internal::Type::BaseModel
80
+ # @!attribute type
81
+ #
82
+ # @return [Symbol, :input_json]
83
+ required :type, const: :input_json
84
+
85
+ # @!attribute partial_json
86
+ # A partial JSON string delta received in this streaming event.
87
+ #
88
+ # Example:
89
+ # ```
90
+ # "{'location':,"
91
+ # ```
92
+ #
93
+ # @return [String]
94
+ required :partial_json, String
95
+
96
+ # @!attribute snapshot
97
+ # The currently accumulated parsed object up to this point in the stream.
98
+ #
99
+ # Example:
100
+ # ```
101
+ # {'location': 'San Francisco, CA'}
102
+ # ```
103
+ #
104
+ # @return [Object]
105
+ required :snapshot, Anthropic::Internal::Type::Unknown
106
+ end
107
+
108
+ class MessageStopEvent < Anthropic::Models::RawMessageStopEvent
109
+ # @!attribute type
110
+ #
111
+ # @return [Symbol, :message_stop]
112
+ required :type, const: :message_stop
113
+
114
+ # @!attribute message
115
+ # The completed message when streaming ends.
116
+ #
117
+ # @return [Anthropic::Models::Message]
118
+ required :message, Anthropic::Models::Message
119
+ end
120
+
121
+ class ContentBlockStopEvent < Anthropic::Models::RawContentBlockStopEvent
122
+ # @!attribute index
123
+ # The index of the content block that has stopped streaming.
124
+ #
125
+ # @return [Integer]
126
+ required :index, Integer
127
+
128
+ # @!attribute type
129
+ #
130
+ # @return [Symbol, :content_block_stop]
131
+ required :type, const: :content_block_stop
132
+
133
+ # @!attribute content_block
134
+ # The completed content block when streaming for this block ends.
135
+ #
136
+ # @return [Anthropic::Models::TextBlock, Anthropic::Models::ToolUseBlock]
137
+ required :content_block, Anthropic::Models::ContentBlock
138
+ end
139
+ end
140
+ end
141
+ end