anthropic 1.23.0 → 1.24.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 (194) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -0
  3. data/README.md +16 -437
  4. data/lib/anthropic/internal/util.rb +31 -0
  5. data/lib/anthropic/models/beta/beta_code_execution_tool_20250522.rb +6 -0
  6. data/lib/anthropic/models/beta/beta_code_execution_tool_20250825.rb +6 -0
  7. data/lib/anthropic/models/beta/beta_code_execution_tool_20260120.rb +6 -0
  8. data/lib/anthropic/models/beta/beta_iterations_usage.rb +4 -2
  9. data/lib/anthropic/models/beta/beta_memory_tool_20250818.rb +6 -0
  10. data/lib/anthropic/models/beta/beta_thinking_config_adaptive.rb +34 -1
  11. data/lib/anthropic/models/beta/beta_thinking_config_enabled.rb +31 -1
  12. data/lib/anthropic/models/beta/beta_tool.rb +6 -0
  13. data/lib/anthropic/models/beta/beta_tool_bash_20241022.rb +6 -0
  14. data/lib/anthropic/models/beta/beta_tool_bash_20250124.rb +6 -0
  15. data/lib/anthropic/models/beta/beta_tool_computer_use_20241022.rb +6 -0
  16. data/lib/anthropic/models/beta/beta_tool_computer_use_20250124.rb +6 -0
  17. data/lib/anthropic/models/beta/beta_tool_computer_use_20251124.rb +6 -0
  18. data/lib/anthropic/models/beta/beta_tool_search_tool_bm25_20251119.rb +6 -0
  19. data/lib/anthropic/models/beta/beta_tool_search_tool_regex_20251119.rb +6 -0
  20. data/lib/anthropic/models/beta/beta_tool_text_editor_20241022.rb +6 -0
  21. data/lib/anthropic/models/beta/beta_tool_text_editor_20250124.rb +6 -0
  22. data/lib/anthropic/models/beta/beta_tool_text_editor_20250429.rb +6 -0
  23. data/lib/anthropic/models/beta/beta_tool_text_editor_20250728.rb +6 -0
  24. data/lib/anthropic/models/beta/beta_tool_union.rb +4 -1
  25. data/lib/anthropic/models/beta/beta_web_fetch_tool_20250910.rb +6 -0
  26. data/lib/anthropic/models/beta/beta_web_fetch_tool_20260209.rb +6 -0
  27. data/lib/anthropic/models/beta/beta_web_fetch_tool_20260309.rb +136 -0
  28. data/lib/anthropic/models/beta/beta_web_search_tool_20250305.rb +6 -0
  29. data/lib/anthropic/models/beta/beta_web_search_tool_20260209.rb +6 -0
  30. data/lib/anthropic/models/beta/file_delete_params.rb +9 -1
  31. data/lib/anthropic/models/beta/file_download_params.rb +9 -1
  32. data/lib/anthropic/models/beta/file_retrieve_metadata_params.rb +9 -1
  33. data/lib/anthropic/models/beta/message_count_tokens_params.rb +6 -3
  34. data/lib/anthropic/models/beta/message_create_params.rb +2 -2
  35. data/lib/anthropic/models/beta/messages/batch_cancel_params.rb +9 -1
  36. data/lib/anthropic/models/beta/messages/batch_create_params.rb +2 -2
  37. data/lib/anthropic/models/beta/messages/batch_delete_params.rb +9 -1
  38. data/lib/anthropic/models/beta/messages/batch_results_params.rb +9 -1
  39. data/lib/anthropic/models/beta/messages/batch_retrieve_params.rb +9 -1
  40. data/lib/anthropic/models/beta/model_retrieve_params.rb +9 -1
  41. data/lib/anthropic/models/beta/skill_delete_params.rb +14 -1
  42. data/lib/anthropic/models/beta/skill_retrieve_params.rb +14 -1
  43. data/lib/anthropic/models/beta/skills/version_create_params.rb +11 -1
  44. data/lib/anthropic/models/beta/skills/version_delete_params.rb +11 -1
  45. data/lib/anthropic/models/beta/skills/version_list_params.rb +11 -1
  46. data/lib/anthropic/models/beta/skills/version_retrieve_params.rb +11 -1
  47. data/lib/anthropic/models/code_execution_tool_20250522.rb +6 -0
  48. data/lib/anthropic/models/code_execution_tool_20250825.rb +6 -0
  49. data/lib/anthropic/models/code_execution_tool_20260120.rb +6 -0
  50. data/lib/anthropic/models/memory_tool_20250818.rb +6 -0
  51. data/lib/anthropic/models/message_count_tokens_params.rb +2 -2
  52. data/lib/anthropic/models/message_count_tokens_tool.rb +4 -1
  53. data/lib/anthropic/models/message_create_params.rb +2 -2
  54. data/lib/anthropic/models/messages/batch_cancel_params.rb +9 -1
  55. data/lib/anthropic/models/messages/batch_create_params.rb +2 -2
  56. data/lib/anthropic/models/messages/batch_delete_params.rb +9 -1
  57. data/lib/anthropic/models/messages/batch_results_params.rb +9 -1
  58. data/lib/anthropic/models/messages/batch_retrieve_params.rb +9 -1
  59. data/lib/anthropic/models/model.rb +31 -81
  60. data/lib/anthropic/models/model_retrieve_params.rb +9 -1
  61. data/lib/anthropic/models/thinking_config_adaptive.rb +34 -1
  62. data/lib/anthropic/models/thinking_config_enabled.rb +33 -1
  63. data/lib/anthropic/models/tool.rb +6 -0
  64. data/lib/anthropic/models/tool_bash_20250124.rb +6 -0
  65. data/lib/anthropic/models/tool_search_tool_bm25_20251119.rb +6 -0
  66. data/lib/anthropic/models/tool_search_tool_regex_20251119.rb +6 -0
  67. data/lib/anthropic/models/tool_text_editor_20250124.rb +6 -0
  68. data/lib/anthropic/models/tool_text_editor_20250429.rb +6 -0
  69. data/lib/anthropic/models/tool_text_editor_20250728.rb +6 -0
  70. data/lib/anthropic/models/tool_union.rb +4 -1
  71. data/lib/anthropic/models/web_fetch_tool_20250910.rb +6 -0
  72. data/lib/anthropic/models/web_fetch_tool_20260209.rb +6 -0
  73. data/lib/anthropic/models/web_fetch_tool_20260309.rb +132 -0
  74. data/lib/anthropic/models/web_search_tool_20250305.rb +6 -0
  75. data/lib/anthropic/models/web_search_tool_20260209.rb +6 -0
  76. data/lib/anthropic/models.rb +2 -0
  77. data/lib/anthropic/resources/beta/files.rb +3 -2
  78. data/lib/anthropic/resources/beta/messages/batches.rb +3 -2
  79. data/lib/anthropic/resources/beta/messages.rb +3 -3
  80. data/lib/anthropic/resources/beta/models.rb +3 -2
  81. data/lib/anthropic/resources/beta/skills/versions.rb +3 -2
  82. data/lib/anthropic/resources/beta/skills.rb +3 -2
  83. data/lib/anthropic/resources/messages/batches.rb +2 -1
  84. data/lib/anthropic/resources/messages.rb +3 -3
  85. data/lib/anthropic/resources/models.rb +3 -2
  86. data/lib/anthropic/version.rb +1 -1
  87. data/lib/anthropic.rb +2 -0
  88. data/rbi/anthropic/internal/util.rbi +20 -0
  89. data/rbi/anthropic/models/beta/beta_code_execution_tool_20250522.rbi +6 -0
  90. data/rbi/anthropic/models/beta/beta_code_execution_tool_20250825.rbi +6 -0
  91. data/rbi/anthropic/models/beta/beta_code_execution_tool_20260120.rbi +6 -0
  92. data/rbi/anthropic/models/beta/beta_memory_tool_20250818.rbi +6 -0
  93. data/rbi/anthropic/models/beta/beta_thinking_config_adaptive.rbi +79 -3
  94. data/rbi/anthropic/models/beta/beta_thinking_config_enabled.rbi +73 -2
  95. data/rbi/anthropic/models/beta/beta_tool.rbi +6 -0
  96. data/rbi/anthropic/models/beta/beta_tool_bash_20241022.rbi +6 -0
  97. data/rbi/anthropic/models/beta/beta_tool_bash_20250124.rbi +6 -0
  98. data/rbi/anthropic/models/beta/beta_tool_computer_use_20241022.rbi +6 -0
  99. data/rbi/anthropic/models/beta/beta_tool_computer_use_20250124.rbi +6 -0
  100. data/rbi/anthropic/models/beta/beta_tool_computer_use_20251124.rbi +6 -0
  101. data/rbi/anthropic/models/beta/beta_tool_search_tool_bm25_20251119.rbi +6 -0
  102. data/rbi/anthropic/models/beta/beta_tool_search_tool_regex_20251119.rbi +6 -0
  103. data/rbi/anthropic/models/beta/beta_tool_text_editor_20241022.rbi +6 -0
  104. data/rbi/anthropic/models/beta/beta_tool_text_editor_20250124.rbi +6 -0
  105. data/rbi/anthropic/models/beta/beta_tool_text_editor_20250429.rbi +6 -0
  106. data/rbi/anthropic/models/beta/beta_tool_text_editor_20250728.rbi +6 -0
  107. data/rbi/anthropic/models/beta/beta_tool_union.rbi +1 -0
  108. data/rbi/anthropic/models/beta/beta_web_fetch_tool_20250910.rbi +6 -0
  109. data/rbi/anthropic/models/beta/beta_web_fetch_tool_20260209.rbi +6 -0
  110. data/rbi/anthropic/models/beta/beta_web_fetch_tool_20260309.rbi +240 -0
  111. data/rbi/anthropic/models/beta/beta_web_search_tool_20250305.rbi +6 -0
  112. data/rbi/anthropic/models/beta/beta_web_search_tool_20260209.rbi +6 -0
  113. data/rbi/anthropic/models/beta/file_delete_params.rbi +8 -0
  114. data/rbi/anthropic/models/beta/file_download_params.rbi +8 -0
  115. data/rbi/anthropic/models/beta/file_retrieve_metadata_params.rbi +8 -0
  116. data/rbi/anthropic/models/beta/message_count_tokens_params.rbi +5 -0
  117. data/rbi/anthropic/models/beta/message_create_params.rbi +4 -0
  118. data/rbi/anthropic/models/beta/messages/batch_cancel_params.rbi +8 -0
  119. data/rbi/anthropic/models/beta/messages/batch_create_params.rbi +4 -0
  120. data/rbi/anthropic/models/beta/messages/batch_delete_params.rbi +8 -0
  121. data/rbi/anthropic/models/beta/messages/batch_results_params.rbi +8 -0
  122. data/rbi/anthropic/models/beta/messages/batch_retrieve_params.rbi +8 -0
  123. data/rbi/anthropic/models/beta/model_retrieve_params.rbi +8 -0
  124. data/rbi/anthropic/models/beta/skill_delete_params.rbi +12 -0
  125. data/rbi/anthropic/models/beta/skill_retrieve_params.rbi +12 -0
  126. data/rbi/anthropic/models/beta/skills/version_create_params.rbi +12 -0
  127. data/rbi/anthropic/models/beta/skills/version_delete_params.rbi +12 -0
  128. data/rbi/anthropic/models/beta/skills/version_list_params.rbi +12 -0
  129. data/rbi/anthropic/models/beta/skills/version_retrieve_params.rbi +12 -0
  130. data/rbi/anthropic/models/code_execution_tool_20250522.rbi +6 -0
  131. data/rbi/anthropic/models/code_execution_tool_20250825.rbi +6 -0
  132. data/rbi/anthropic/models/code_execution_tool_20260120.rbi +6 -0
  133. data/rbi/anthropic/models/memory_tool_20250818.rbi +6 -0
  134. data/rbi/anthropic/models/message_count_tokens_params.rbi +4 -0
  135. data/rbi/anthropic/models/message_count_tokens_tool.rbi +1 -0
  136. data/rbi/anthropic/models/message_create_params.rbi +4 -0
  137. data/rbi/anthropic/models/messages/batch_cancel_params.rbi +21 -5
  138. data/rbi/anthropic/models/messages/batch_create_params.rbi +4 -0
  139. data/rbi/anthropic/models/messages/batch_delete_params.rbi +21 -5
  140. data/rbi/anthropic/models/messages/batch_results_params.rbi +21 -5
  141. data/rbi/anthropic/models/messages/batch_retrieve_params.rbi +21 -5
  142. data/rbi/anthropic/models/model.rbi +28 -56
  143. data/rbi/anthropic/models/model_retrieve_params.rbi +8 -0
  144. data/rbi/anthropic/models/thinking_config_adaptive.rbi +66 -3
  145. data/rbi/anthropic/models/thinking_config_enabled.rbi +63 -2
  146. data/rbi/anthropic/models/tool.rbi +6 -0
  147. data/rbi/anthropic/models/tool_bash_20250124.rbi +6 -0
  148. data/rbi/anthropic/models/tool_search_tool_bm25_20251119.rbi +6 -0
  149. data/rbi/anthropic/models/tool_search_tool_regex_20251119.rbi +6 -0
  150. data/rbi/anthropic/models/tool_text_editor_20250124.rbi +6 -0
  151. data/rbi/anthropic/models/tool_text_editor_20250429.rbi +6 -0
  152. data/rbi/anthropic/models/tool_text_editor_20250728.rbi +6 -0
  153. data/rbi/anthropic/models/tool_union.rbi +1 -0
  154. data/rbi/anthropic/models/web_fetch_tool_20250910.rbi +6 -0
  155. data/rbi/anthropic/models/web_fetch_tool_20260209.rbi +6 -0
  156. data/rbi/anthropic/models/web_fetch_tool_20260309.rbi +219 -0
  157. data/rbi/anthropic/models/web_search_tool_20250305.rbi +6 -0
  158. data/rbi/anthropic/models/web_search_tool_20260209.rbi +6 -0
  159. data/rbi/anthropic/models.rbi +2 -0
  160. data/rbi/anthropic/resources/beta/messages.rbi +3 -0
  161. data/rbi/anthropic/resources/messages.rbi +3 -0
  162. data/sig/anthropic/internal/util.rbs +10 -0
  163. data/sig/anthropic/models/beta/beta_thinking_config_adaptive.rbs +26 -3
  164. data/sig/anthropic/models/beta/beta_thinking_config_enabled.rbs +28 -3
  165. data/sig/anthropic/models/beta/beta_tool_union.rbs +1 -0
  166. data/sig/anthropic/models/beta/beta_web_fetch_tool_20260309.rbs +102 -0
  167. data/sig/anthropic/models/beta/file_delete_params.rbs +5 -1
  168. data/sig/anthropic/models/beta/file_download_params.rbs +5 -1
  169. data/sig/anthropic/models/beta/file_retrieve_metadata_params.rbs +5 -1
  170. data/sig/anthropic/models/beta/message_count_tokens_params.rbs +1 -0
  171. data/sig/anthropic/models/beta/messages/batch_cancel_params.rbs +8 -1
  172. data/sig/anthropic/models/beta/messages/batch_delete_params.rbs +8 -1
  173. data/sig/anthropic/models/beta/messages/batch_results_params.rbs +8 -1
  174. data/sig/anthropic/models/beta/messages/batch_retrieve_params.rbs +8 -1
  175. data/sig/anthropic/models/beta/model_retrieve_params.rbs +5 -1
  176. data/sig/anthropic/models/beta/skill_delete_params.rbs +5 -1
  177. data/sig/anthropic/models/beta/skill_retrieve_params.rbs +5 -1
  178. data/sig/anthropic/models/beta/skills/version_create_params.rbs +5 -0
  179. data/sig/anthropic/models/beta/skills/version_delete_params.rbs +5 -0
  180. data/sig/anthropic/models/beta/skills/version_list_params.rbs +5 -0
  181. data/sig/anthropic/models/beta/skills/version_retrieve_params.rbs +5 -0
  182. data/sig/anthropic/models/message_count_tokens_tool.rbs +1 -0
  183. data/sig/anthropic/models/messages/batch_cancel_params.rbs +12 -3
  184. data/sig/anthropic/models/messages/batch_delete_params.rbs +12 -3
  185. data/sig/anthropic/models/messages/batch_results_params.rbs +12 -3
  186. data/sig/anthropic/models/messages/batch_retrieve_params.rbs +12 -3
  187. data/sig/anthropic/models/model.rbs +28 -56
  188. data/sig/anthropic/models/model_retrieve_params.rbs +5 -1
  189. data/sig/anthropic/models/thinking_config_adaptive.rbs +26 -3
  190. data/sig/anthropic/models/thinking_config_enabled.rbs +29 -3
  191. data/sig/anthropic/models/tool_union.rbs +1 -0
  192. data/sig/anthropic/models/web_fetch_tool_20260309.rbs +98 -0
  193. data/sig/anthropic/models.rbs +2 -0
  194. metadata +8 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e7f34d5d181c452996ffe49befe4bea248cd67a952eb8853cabf5d0ced185ef
4
- data.tar.gz: 6945acf587c974e918efdbac79a408b1e3dfc787925037ca938f90cb4b601743
3
+ metadata.gz: d8e994ed4ea60cbaf7aee144bcabab2da5406df0c604d5dab2687b8ba226ec47
4
+ data.tar.gz: 963a20b35842c61557dc0cd60a1afbf00116653cfa120f1291fc840c4562933b
5
5
  SHA512:
6
- metadata.gz: f1f562c0d5bfa17193f8d4952cdf91b2ed68777f87d7a72ed4ce993a457acbdcee4bb9256329a97b4a49513216c077e404b93b06f58241344174a52d956dd84f
7
- data.tar.gz: 8e28e293264fa8cf7cd2611211a98f99e524df4485f9d16455b0a6a53e7a6cab3423859c3168b6ab1ea6b18ee071f1761880592c37d4944aa99feb9ea22ec012
6
+ metadata.gz: 2df975c4dde315c09393d07959e77315ce1bf725e0955c56085c0c0f444207b988e07ee7e2a78a688fb50df1781448f2c9c6a6ec00ea40a42ccb3597aa615308
7
+ data.tar.gz: 466afa0cd510de890dcd18e075a8ebb378877ce10636184eda10bc185c11ce4d4095d81cc778aa314b07011d8f476ce62ca30694993c60826992ee5f0a135882
data/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.24.0 (2026-03-16)
4
+
5
+ Full Changelog: [v1.23.0...v1.24.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.23.0...v1.24.0)
6
+
7
+ ### Features
8
+
9
+ * **api:** chore(config): clean up model enum list ([#31](https://github.com/anthropics/anthropic-sdk-ruby/issues/31)) ([8549634](https://github.com/anthropics/anthropic-sdk-ruby/commit/8549634385a81b071ac05f02c74a5d5d36ea98fa))
10
+ * **api:** GA thinking-display-setting ([227f58a](https://github.com/anthropics/anthropic-sdk-ruby/commit/227f58acb9944be56d21ea9fe46af8b5d9e1c891))
11
+ * **tests:** update mock server ([2312be3](https://github.com/anthropics/anthropic-sdk-ruby/commit/2312be3b2f0f9846d70fa5ee7264463452349e21))
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * **client:** update model references from claude-3-opus-20240229 to claude-opus-4-6 ([#831](https://github.com/anthropics/anthropic-sdk-ruby/issues/831)) ([0c56fe4](https://github.com/anthropics/anthropic-sdk-ruby/commit/0c56fe4e7d279b9228613982f97c4836d7267a43))
17
+ * properly mock time in ruby ci tests ([a56c1fe](https://github.com/anthropics/anthropic-sdk-ruby/commit/a56c1fe2bb14d1238855c41c791d69b44904f691))
18
+
19
+
20
+ ### Chores
21
+
22
+ * **internal:** codegen related update ([0cf7f7e](https://github.com/anthropics/anthropic-sdk-ruby/commit/0cf7f7e485248290f54a83e907fb9623585c15f5))
23
+ * **internal:** codegen related update ([a2218e5](https://github.com/anthropics/anthropic-sdk-ruby/commit/a2218e53a85e7544bedc8b55c8e5a9d4ef4dd35c))
24
+ * **internal:** codegen related update ([b77acd4](https://github.com/anthropics/anthropic-sdk-ruby/commit/b77acd489387413cda40134f6a9463dfe850c71d))
25
+ * **tests:** unskip tests that are now supported in steady ([9fe434d](https://github.com/anthropics/anthropic-sdk-ruby/commit/9fe434d6afdc979897754e5127c56f541bb6eb76))
26
+
27
+
28
+ ### Documentation
29
+
30
+ * streamline README, centralize documentation at docs.anthropic.com ([396688b](https://github.com/anthropics/anthropic-sdk-ruby/commit/396688b823bf08690714c4f42160b4aa20d86880))
31
+
3
32
  ## 1.23.0 (2026-02-19)
4
33
 
5
34
  Full Changelog: [v1.22.0...v1.23.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.22.0...v1.23.0)
data/README.md CHANGED
@@ -1,32 +1,26 @@
1
- # Anthropic Ruby API library
1
+ # Claude SDK for Ruby
2
2
 
3
- The Anthropic Ruby library provides convenient access to the Anthropic REST API from any Ruby 3.2.0+ application. It ships with comprehensive types & docstrings in Yard, RBS, and RBI – [see below](https://github.com/anthropics/anthropic-sdk-ruby#Sorbet) for usage with Sorbet. The standard library's `net/http` is used as the HTTP transport, with connection pooling via the `connection_pool` gem.
3
+ [![Gem Version](https://img.shields.io/gem/v/anthropic.svg)](https://rubygems.org/gems/anthropic)
4
4
 
5
- ## Documentation
5
+ The Claude SDK for Ruby provides access to the [Claude API](https://docs.anthropic.com/en/api/) from Ruby applications.
6
6
 
7
- Documentation for releases of this gem can be found [on RubyDoc](https://gemdocs.org/gems/anthropic).
7
+ ## Documentation
8
8
 
9
- The REST API documentation can be found on [docs.anthropic.com](https://docs.anthropic.com/claude/reference/).
9
+ Full documentation is available at **[platform.claude.com/docs/en/api/sdks/ruby](https://platform.claude.com/docs/en/api/sdks/ruby)**.
10
10
 
11
11
  ## Installation
12
12
 
13
- To use this gem, install via Bundler by adding the following to your application's `Gemfile`:
13
+ Add to your application's Gemfile:
14
14
 
15
15
  <!-- x-release-please-start-version -->
16
16
 
17
17
  ```ruby
18
- gem "anthropic", "~> 1.23.0"
18
+ gem "anthropic", "~> 1.24.0"
19
19
  ```
20
20
 
21
21
  <!-- x-release-please-end -->
22
22
 
23
- ## Feedback
24
-
25
- If you have recommendations, notice bugs, find things confusing, or anything else, create a github issue. Don't be shy -- we're very open to hearing any thoughts and musings you have!
26
-
27
- Feel free to make an issue for more substantial issues. For smaller issues or stream-of-thought, you can use the [pinned issue here](https://github.com/anthropics/anthropic-sdk-ruby/issues/85).
28
-
29
- ## Usage
23
+ ## Getting started
30
24
 
31
25
  ```ruby
32
26
  require "bundler/setup"
@@ -39,439 +33,24 @@ anthropic = Anthropic::Client.new(
39
33
  message = anthropic.messages.create(
40
34
  max_tokens: 1024,
41
35
  messages: [{role: "user", content: "Hello, Claude"}],
42
- model: "claude-sonnet-4-5-20250929"
36
+ model: "claude-opus-4-6"
43
37
  )
44
38
 
45
39
  puts(message.content)
46
40
  ```
47
41
 
48
- ### Streaming
49
-
50
- We provide support for streaming responses using Server-Sent Events (SSE).
51
-
52
- ```ruby
53
- stream = anthropic.messages.stream(
54
- max_tokens: 1024,
55
- messages: [{role: "user", content: "Hello, Claude"}],
56
- model: "claude-sonnet-4-5-20250929"
57
- )
58
-
59
- stream.each do |message|
60
- puts(message.type)
61
- end
62
- ```
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-5-20250929"
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
-
82
- ### Input Schema & Tool Calling
83
-
84
- We have helper mechanisms to define structured data classes for tools and let Claude automatically execute them.
85
-
86
- Please refer to [helpers.md](helpers.md) for more detailed usage information.
87
-
88
- ```ruby
89
- class CalculatorInput < Anthropic::BaseModel
90
- required :lhs, Float
91
- required :rhs, Float
92
- required :operator, Anthropic::InputSchema::EnumOf[:+, :-, :*, :/]
93
- end
94
-
95
- class Calculator < Anthropic::BaseTool
96
- input_schema CalculatorInput
97
-
98
- def call(expr)
99
- expr.lhs.public_send(expr.operator, expr.rhs)
100
- end
101
- end
102
-
103
- # Automatically handles tool execution loop
104
- client.beta.messages.tool_runner(
105
- model: "claude-sonnet-4-5-20250929",
106
- max_tokens: 1024,
107
- messages: [{role: "user", content: "What's 15 * 7?"}],
108
- tools: [Calculator.new]
109
- ).each_message { puts _1.content }
110
- ```
111
-
112
- ### Structured Outputs
113
-
114
- Constrain Claude's responses to follow a specific JSON schema using the `output_config` parameter:
115
-
116
- ```ruby
117
- class FamousNumber < Anthropic::BaseModel
118
- required :value, Float
119
- optional :reason, String, doc: "why is this number mathematically significant?"
120
- end
121
-
122
- class Output < Anthropic::BaseModel
123
- required :numbers, Anthropic::ArrayOf[FamousNumber], min_length: 3, max_length: 5
124
- end
125
-
126
- message = anthropic.messages.create(
127
- model: "claude-sonnet-4-5-20250929",
128
- max_tokens: 1024,
129
- messages: [{role: "user", content: "give me some famous numbers"}],
130
- output_config: {format: Output}
131
- )
132
-
133
- # Access the parsed response
134
- message.parsed_output
135
- # => #<Output numbers=[#<FamousNumber value=3.14159... reason="Pi is...">...]>
136
- ```
137
-
138
- For streaming and more examples, see [helpers.md](helpers.md#structured-outputs).
139
-
140
- ### Pagination
141
-
142
- List methods in the Anthropic API are paginated.
143
-
144
- This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
145
-
146
- ```ruby
147
- page = anthropic.messages.batches.list(limit: 20)
148
-
149
- # Fetch single item from page.
150
- batch = page.data[0]
151
- puts(batch.id)
152
-
153
- # Automatically fetches more pages as needed.
154
- page.auto_paging_each do |batch|
155
- puts(batch.id)
156
- end
157
- ```
158
-
159
- Alternatively, you can use the `#next_page?` and `#next_page` methods for more granular control working with pages.
160
-
161
- ```ruby
162
- if page.next_page?
163
- new_page = page.next_page
164
- puts(new_page.data[0].id)
165
- end
166
- ```
167
-
168
- ### File uploads
169
-
170
- Request parameters that correspond to file uploads can be passed as raw contents, a [`Pathname`](https://rubyapi.org/3.2/o/pathname) instance, [`StringIO`](https://rubyapi.org/3.2/o/stringio), or more.
171
-
172
- ```ruby
173
- require "pathname"
174
-
175
- # Use `Pathname` to send the filename and/or avoid paging a large file into memory:
176
- file_metadata = anthropic.beta.files.upload(file: Pathname("/path/to/file"))
177
-
178
- # Alternatively, pass file contents or a `StringIO` directly:
179
- file_metadata = anthropic.beta.files.upload(file: File.read("/path/to/file"))
180
-
181
- # Or, to control the filename and/or content type:
182
- file = Anthropic::FilePart.new(File.read("/path/to/file"), filename: "/path/to/file", content_type: "…")
183
- file_metadata = anthropic.beta.files.upload(file: file)
184
-
185
- puts(file_metadata.id)
186
- ```
187
-
188
- Note that you can also pass a raw `IO` descriptor, but this disables retries, as the library can't be sure if the descriptor is a file or pipe (which cannot be rewound).
189
-
190
- ### Handling errors
191
-
192
- When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of `Anthropic::Errors::APIError` will be thrown:
193
-
194
- ```ruby
195
- begin
196
- message = anthropic.messages.create(
197
- max_tokens: 1024,
198
- messages: [{role: "user", content: "Hello, Claude"}],
199
- model: "claude-sonnet-4-5-20250929"
200
- )
201
- rescue Anthropic::Errors::APIConnectionError => e
202
- puts("The server could not be reached")
203
- puts(e.cause) # an underlying Exception, likely raised within `net/http`
204
- rescue Anthropic::Errors::RateLimitError => e
205
- puts("A 429 status code was received; we should back off a bit.")
206
- rescue Anthropic::Errors::APIStatusError => e
207
- puts("Another non-200-range status code was received")
208
- puts(e.status)
209
- end
210
- ```
211
-
212
- Error codes are as follows:
213
-
214
- | Cause | Error Type |
215
- | ---------------- | -------------------------- |
216
- | HTTP 400 | `BadRequestError` |
217
- | HTTP 401 | `AuthenticationError` |
218
- | HTTP 403 | `PermissionDeniedError` |
219
- | HTTP 404 | `NotFoundError` |
220
- | HTTP 409 | `ConflictError` |
221
- | HTTP 422 | `UnprocessableEntityError` |
222
- | HTTP 429 | `RateLimitError` |
223
- | HTTP >= 500 | `InternalServerError` |
224
- | Other HTTP error | `APIStatusError` |
225
- | Timeout | `APITimeoutError` |
226
- | Network error | `APIConnectionError` |
227
-
228
- ### Retries
229
-
230
- Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
231
-
232
- Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, >=500 Internal errors, and timeouts will all be retried by default.
233
-
234
- You can use the `max_retries` option to configure or disable this:
235
-
236
- ```ruby
237
- # Configure the default for all requests:
238
- anthropic = Anthropic::Client.new(
239
- max_retries: 0 # default is 2
240
- )
241
-
242
- # Or, configure per-request:
243
- anthropic.messages.create(
244
- max_tokens: 1024,
245
- messages: [{role: "user", content: "Hello, Claude"}],
246
- model: "claude-sonnet-4-5-20250929",
247
- request_options: {max_retries: 5}
248
- )
249
- ```
250
-
251
- ### Timeouts
252
-
253
- By default, requests will time out after 600 seconds. You can use the timeout option to configure or disable this:
254
-
255
- ```ruby
256
- # Configure the default for all requests:
257
- anthropic = Anthropic::Client.new(
258
- timeout: nil # default is 600
259
- )
260
-
261
- # Or, configure per-request:
262
- anthropic.messages.create(
263
- max_tokens: 1024,
264
- messages: [{role: "user", content: "Hello, Claude"}],
265
- model: "claude-sonnet-4-5-20250929",
266
- request_options: {timeout: 5}
267
- )
268
- ```
269
-
270
- On timeout, `Anthropic::Errors::APITimeoutError` is raised.
271
-
272
- Note that requests that time out are retried by default.
273
-
274
- ## AWS Bedrock
275
-
276
- This library also provides support for the [Anthropic Bedrock API](https://aws.amazon.com/bedrock/claude/) if you install this library with the `aws-sdk-bedrockruntime` gem.
277
-
278
- You can then instantiate a separate `Anthropic::BedrockClient` class, and use AWS's standard guide for configuring credentials (see [the aws-sdk-ruby gem README](https://github.com/aws/aws-sdk-ruby?tab=readme-ov-file#configuration) or [AWS Documentation](https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html#credchain)). It has the same API as the base `Anthropic::Client` class.
279
-
280
- Note that the model ID required is different for Bedrock models, and, depending on the model you want to use, you will need to use either the AWS's model ID for Anthropic models -- which can be found in [AWS's Bedrock model catalog](https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html) -- or an inference profile id (e.g. `us.anthropic.claude-3-5-haiku-20241022-v1:0` for Claude 3.5 Haiku).
281
-
282
- ```ruby
283
- require "bundler/setup"
284
- require "anthropic"
285
-
286
- anthropic = Anthropic::BedrockClient.new
287
-
288
- message = anthropic.messages.create(
289
- max_tokens: 1024,
290
- messages: [
291
- {
292
- role: "user",
293
- content: "Hello, Claude"
294
- }
295
- ],
296
- model: "anthropic.claude-sonnet-4-5-20250929-v2:0"
297
- )
298
-
299
- puts(message)
300
- ```
301
-
302
- For more examples see [`examples/bedrock`](examples/bedrock).
303
-
304
- ## Google Vertex
305
-
306
- This library also provides support for the [Anthropic Vertex API](https://cloud.google.com/vertex-ai?hl=en) if you install this library with the `googleauth` gem.
307
-
308
- You can then import and instantiate a separate `Anthropic::VertexClient` class, and use Google's guide for configuring [Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc). It has the same API as the base `Anthropic::Client` class.
309
-
310
- ```ruby
311
- require "bundler/setup"
312
- require "anthropic"
313
-
314
- anthropic = Anthropic::VertexClient.new(region: "us-east5", project_id: "my-project-id")
315
-
316
- message = anthropic.messages.create(
317
- max_tokens: 1024,
318
- messages: [
319
- {
320
- role: "user",
321
- content: "Hello, Claude"
322
- }
323
- ],
324
- model: "claude-sonnet-4@20250514"
325
- )
326
-
327
- puts(message)
328
- ```
329
-
330
- For more examples see [`examples/vertex`](examples/vertex).
331
-
332
- ## Advanced concepts
333
-
334
- ### BaseModel
335
-
336
- All parameter and response objects inherit from `Anthropic::Internal::Type::BaseModel`, which provides several conveniences, including:
337
-
338
- 1. All fields, including unknown ones, are accessible with `obj[:prop]` syntax, and can be destructured with `obj => {prop: prop}` or pattern-matching syntax.
339
-
340
- 2. Structural equivalence for equality; if two API calls return the same values, comparing the responses with == will return true.
341
-
342
- 3. Both instances and the classes themselves can be pretty-printed.
343
-
344
- 4. Helpers such as `#to_h`, `#deep_to_h`, `#to_json`, and `#to_yaml`.
345
-
346
- ### Making custom or undocumented requests
347
-
348
- #### Undocumented properties
349
-
350
- You can send undocumented parameters to any endpoint, and read undocumented response properties, like so:
351
-
352
- > [!WARNING]
353
- >
354
- > The `extra_` parameters of the same name overrides the documented parameters. For security reasons, ensure these methods are only used with trusted input data.
355
-
356
- ```ruby
357
- message =
358
- anthropic.messages.create(
359
- max_tokens: 1024,
360
- messages: [{role: "user", content: "Hello, Claude"}],
361
- model: "claude-sonnet-4-5-20250929",
362
- request_options: {
363
- extra_query: {my_query_parameter: value},
364
- extra_body: {my_body_parameter: value},
365
- extra_headers: {"my-header": value}
366
- }
367
- )
368
-
369
- puts(message[:my_undocumented_property])
370
- ```
371
-
372
- #### Undocumented request params
373
-
374
- If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` under the `request_options:` parameter when making a request, as seen in the examples above.
375
-
376
- #### Undocumented endpoints
377
-
378
- To make requests to undocumented endpoints while retaining the benefit of auth, retries, and so on, you can make requests using `client.request`, like so:
379
-
380
- ```ruby
381
- response = client.request(
382
- method: :post,
383
- path: '/undocumented/endpoint',
384
- query: {"dog": "woof"},
385
- headers: {"useful-header": "interesting-value"},
386
- body: {"hello": "world"}
387
- )
388
- ```
389
-
390
- ### Concurrency & connection pooling
391
-
392
- The `Anthropic::Client` instances are threadsafe, but are only are fork-safe when there are no in-flight HTTP requests.
393
-
394
- Each instance of `Anthropic::Client` has its own HTTP connection pool with a default size of 99. As such, we recommend instantiating the client once per application in most settings.
395
-
396
- When all available connections from the pool are checked out, requests wait for a new connection to become available, with queue time counting towards the request timeout.
397
-
398
- Unless otherwise specified, other classes in the SDK do not have locks protecting their underlying data structure.
399
-
400
- ## Sorbet
401
-
402
- This library provides comprehensive [RBI](https://sorbet.org/docs/rbi) definitions, and has no dependency on sorbet-runtime.
403
-
404
- You can provide typesafe request parameters like so:
405
-
406
- ```ruby
407
- anthropic.messages.create(
408
- max_tokens: 1024,
409
- messages: [Anthropic::MessageParam.new(role: "user", content: "Hello, Claude")],
410
- model: "claude-sonnet-4-5-20250929"
411
- )
412
- ```
413
-
414
- Or, equivalently:
415
-
416
- ```ruby
417
- # Hashes work, but are not typesafe:
418
- anthropic.messages.create(
419
- max_tokens: 1024,
420
- messages: [{role: "user", content: "Hello, Claude"}],
421
- model: "claude-sonnet-4-5-20250929"
422
- )
423
-
424
- # You can also splat a full Params class:
425
- params = Anthropic::MessageCreateParams.new(
426
- max_tokens: 1024,
427
- messages: [Anthropic::MessageParam.new(role: "user", content: "Hello, Claude")],
428
- model: "claude-sonnet-4-5-20250929"
429
- )
430
- anthropic.messages.create(**params)
431
- ```
432
-
433
- ### Enums
434
-
435
- Since this library does not depend on `sorbet-runtime`, it cannot provide [`T::Enum`](https://sorbet.org/docs/tenum) instances. Instead, we provide "tagged symbols" instead, which is always a primitive at runtime:
436
-
437
- ```ruby
438
- # :auto
439
- puts(Anthropic::MessageCreateParams::ServiceTier::AUTO)
440
-
441
- # Revealed type: `T.all(Anthropic::MessageCreateParams::ServiceTier, Symbol)`
442
- T.reveal_type(Anthropic::MessageCreateParams::ServiceTier::AUTO)
443
- ```
444
-
445
- Enum parameters have a "relaxed" type, so you can either pass in enum constants or their literal value:
446
-
447
- ```ruby
448
- # Using the enum constants preserves the tagged type information:
449
- anthropic.messages.create(
450
- service_tier: Anthropic::MessageCreateParams::ServiceTier::AUTO,
451
- # …
452
- )
453
-
454
- # Literal values are also permissible:
455
- anthropic.messages.create(
456
- service_tier: :auto,
457
- # …
458
- )
459
- ```
460
-
461
- ## Versioning
462
-
463
- This package follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions. As the library is in initial development and has a major version of `0`, APIs may change at any time.
464
-
465
- This package considers improvements to the (non-runtime) `*.rbi` and `*.rbs` type definitions to be non-breaking changes.
466
-
467
42
  ## Requirements
468
43
 
469
- Ruby 3.2.0 or higher.
44
+ Ruby 3.2.0+
470
45
 
471
46
  ## Contributing
472
47
 
473
- See [the contributing documentation](https://github.com/anthropics/anthropic-sdk-ruby/tree/main/CONTRIBUTING.md).
48
+ See [CONTRIBUTING.md](./CONTRIBUTING.md).
49
+
50
+ ## License
51
+
52
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
474
53
 
475
54
  ## Acknowledgements
476
55
 
477
- Thank you [@alexrudall](https://github.com/alexrudall) for giving feedback, donating the `anthropic` Ruby Gem name, and paving the way by building the first Anthropic Ruby SDK.
56
+ Thank you [@alexrudall](https://github.com/alexrudall) for giving feedback, donating the anthropic Ruby Gem name, and paving the way by building the first Anthropic Ruby SDK.
@@ -490,6 +490,37 @@ module Anthropic
490
490
  JSONL_CONTENT = %r{^application/(:?x-(?:n|l)djson)|(:?(?:x-)?jsonl)}
491
491
 
492
492
  class << self
493
+ # @api private
494
+ #
495
+ # @param query [Hash{Symbol=>Object}]
496
+ #
497
+ # @return [Hash{Symbol=>Object}]
498
+ def encode_query_params(query)
499
+ out = {}
500
+ query.each { write_query_param_element!(out, _1, _2) }
501
+ out
502
+ end
503
+
504
+ # @api private
505
+ #
506
+ # @param collection [Hash{Symbol=>Object}]
507
+ # @param key [String]
508
+ # @param element [Object]
509
+ #
510
+ # @return [nil]
511
+ private def write_query_param_element!(collection, key, element)
512
+ case element
513
+ in Hash
514
+ element.each do |name, value|
515
+ write_query_param_element!(collection, "#{key}[#{name}]", value)
516
+ end
517
+ in Array
518
+ collection[key] = element.map(&:to_s).join(",")
519
+ else
520
+ collection[key] = element.to_s
521
+ end
522
+ end
523
+
493
524
  # @api private
494
525
  #
495
526
  # @param y [Enumerator::Yielder]
@@ -58,6 +58,12 @@ module Anthropic
58
58
  #
59
59
  # @param type [Symbol, :code_execution_20250522]
60
60
 
61
+ # Specifies who can invoke a tool.
62
+ #
63
+ # Values: direct: The model can call this tool directly. code_execution_20250825:
64
+ # The tool can be called from the code execution environment (v1).
65
+ # code_execution_20260120: The tool can be called from the code execution
66
+ # environment (v2 with persistence).
61
67
  module AllowedCaller
62
68
  extend Anthropic::Internal::Type::Enum
63
69
 
@@ -58,6 +58,12 @@ module Anthropic
58
58
  #
59
59
  # @param type [Symbol, :code_execution_20250825]
60
60
 
61
+ # Specifies who can invoke a tool.
62
+ #
63
+ # Values: direct: The model can call this tool directly. code_execution_20250825:
64
+ # The tool can be called from the code execution environment (v1).
65
+ # code_execution_20260120: The tool can be called from the code execution
66
+ # environment (v2 with persistence).
61
67
  module AllowedCaller
62
68
  extend Anthropic::Internal::Type::Enum
63
69
 
@@ -61,6 +61,12 @@ module Anthropic
61
61
  #
62
62
  # @param type [Symbol, :code_execution_20260120]
63
63
 
64
+ # Specifies who can invoke a tool.
65
+ #
66
+ # Values: direct: The model can call this tool directly. code_execution_20250825:
67
+ # The tool can be called from the code execution environment (v1).
68
+ # code_execution_20260120: The tool can be called from the code execution
69
+ # environment (v2 with persistence).
64
70
  module AllowedCaller
65
71
  extend Anthropic::Internal::Type::Enum
66
72
 
@@ -7,11 +7,13 @@ module Anthropic
7
7
  module BetaIterationsUsageItem
8
8
  extend Anthropic::Internal::Type::Union
9
9
 
10
+ discriminator :type
11
+
10
12
  # Token usage for a sampling iteration.
11
- variant -> { Anthropic::Beta::BetaMessageIterationUsage }
13
+ variant :message, -> { Anthropic::Beta::BetaMessageIterationUsage }
12
14
 
13
15
  # Token usage for a compaction iteration.
14
- variant -> { Anthropic::Beta::BetaCompactionIterationUsage }
16
+ variant :compaction, -> { Anthropic::Beta::BetaCompactionIterationUsage }
15
17
 
16
18
  # @!method self.variants
17
19
  # @return [Array(Anthropic::Models::Beta::BetaMessageIterationUsage, Anthropic::Models::Beta::BetaCompactionIterationUsage)]
@@ -66,6 +66,12 @@ module Anthropic
66
66
  #
67
67
  # @param type [Symbol, :memory_20250818]
68
68
 
69
+ # Specifies who can invoke a tool.
70
+ #
71
+ # Values: direct: The model can call this tool directly. code_execution_20250825:
72
+ # The tool can be called from the code execution environment (v1).
73
+ # code_execution_20260120: The tool can be called from the code execution
74
+ # environment (v2 with persistence).
69
75
  module AllowedCaller
70
76
  extend Anthropic::Internal::Type::Enum
71
77