anthropic 1.48.2 → 1.50.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 (239) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -0
  3. data/README.md +1 -1
  4. data/lib/anthropic/client.rb +8 -2
  5. data/lib/anthropic/errors.rb +14 -0
  6. data/lib/anthropic/helpers/aws/client.rb +3 -3
  7. data/lib/anthropic/helpers/aws_auth.rb +39 -29
  8. data/lib/anthropic/helpers/bedrock/client.rb +99 -67
  9. data/lib/anthropic/helpers/bedrock/event_stream.rb +92 -0
  10. data/lib/anthropic/helpers/bedrock/mantle_client.rb +3 -3
  11. data/lib/anthropic/helpers/stainless_helper_header.rb +43 -0
  12. data/lib/anthropic/helpers/tools/runner.rb +8 -4
  13. data/lib/anthropic/helpers/vertex/client.rb +99 -55
  14. data/lib/anthropic/internal/stream.rb +1 -1
  15. data/lib/anthropic/internal/transport/base_client.rb +196 -33
  16. data/lib/anthropic/internal/util.rb +37 -1
  17. data/lib/anthropic/middleware.rb +435 -0
  18. data/lib/anthropic/models/beta/agent_create_params.rb +3 -1
  19. data/lib/anthropic/models/beta/agent_update_params.rb +6 -3
  20. data/lib/anthropic/models/beta/beta_advisor_tool_20260301.rb +3 -1
  21. data/lib/anthropic/models/beta/beta_cache_control_ephemeral.rb +6 -2
  22. data/lib/anthropic/models/beta/beta_code_execution_tool_20250522.rb +3 -1
  23. data/lib/anthropic/models/beta/beta_code_execution_tool_20250825.rb +3 -1
  24. data/lib/anthropic/models/beta/beta_code_execution_tool_20260120.rb +3 -1
  25. data/lib/anthropic/models/beta/beta_code_execution_tool_20260521.rb +86 -0
  26. data/lib/anthropic/models/beta/beta_content_block.rb +3 -3
  27. data/lib/anthropic/models/beta/beta_content_block_param.rb +10 -12
  28. data/lib/anthropic/models/beta/beta_fallback_block.rb +13 -5
  29. data/lib/anthropic/models/beta/beta_fallback_block_param.rb +22 -13
  30. data/lib/anthropic/models/beta/beta_fallback_refusal_trigger.rb +45 -0
  31. data/lib/anthropic/models/beta/beta_memory_tool_20250818.rb +3 -1
  32. data/lib/anthropic/models/beta/beta_raw_content_block_start_event.rb +3 -3
  33. data/lib/anthropic/models/beta/beta_refusal_stop_details.rb +4 -7
  34. data/lib/anthropic/models/beta/beta_tool.rb +3 -1
  35. data/lib/anthropic/models/beta/beta_tool_bash_20241022.rb +3 -1
  36. data/lib/anthropic/models/beta/beta_tool_bash_20250124.rb +3 -1
  37. data/lib/anthropic/models/beta/beta_tool_computer_use_20241022.rb +3 -1
  38. data/lib/anthropic/models/beta/beta_tool_computer_use_20250124.rb +3 -1
  39. data/lib/anthropic/models/beta/beta_tool_computer_use_20251124.rb +3 -1
  40. data/lib/anthropic/models/beta/beta_tool_search_tool_bm25_20251119.rb +3 -1
  41. data/lib/anthropic/models/beta/beta_tool_search_tool_regex_20251119.rb +3 -1
  42. data/lib/anthropic/models/beta/beta_tool_text_editor_20241022.rb +3 -1
  43. data/lib/anthropic/models/beta/beta_tool_text_editor_20250124.rb +3 -1
  44. data/lib/anthropic/models/beta/beta_tool_text_editor_20250429.rb +3 -1
  45. data/lib/anthropic/models/beta/beta_tool_text_editor_20250728.rb +3 -1
  46. data/lib/anthropic/models/beta/beta_tool_union.rb +4 -1
  47. data/lib/anthropic/models/beta/beta_web_fetch_tool_20250910.rb +3 -1
  48. data/lib/anthropic/models/beta/beta_web_fetch_tool_20260209.rb +3 -1
  49. data/lib/anthropic/models/beta/beta_web_fetch_tool_20260309.rb +3 -1
  50. data/lib/anthropic/models/beta/beta_web_search_tool_20250305.rb +3 -1
  51. data/lib/anthropic/models/beta/beta_web_search_tool_20260209.rb +3 -1
  52. data/lib/anthropic/models/beta/beta_webhook_event.rb +2 -2
  53. data/lib/anthropic/models/beta/beta_webhook_event_data.rb +3 -1
  54. data/lib/anthropic/models/beta/beta_webhook_session_updated_event_data.rb +41 -0
  55. data/lib/anthropic/models/beta/message_count_tokens_params.rb +6 -3
  56. data/lib/anthropic/models/beta/message_create_params.rb +12 -12
  57. data/lib/anthropic/models/beta/messages/batch_create_params.rb +15 -13
  58. data/lib/anthropic/models/beta/unwrap_webhook_event.rb +2 -2
  59. data/lib/anthropic/models/cache_control_ephemeral.rb +6 -2
  60. data/lib/anthropic/models/code_execution_tool_20250522.rb +3 -1
  61. data/lib/anthropic/models/code_execution_tool_20250825.rb +3 -1
  62. data/lib/anthropic/models/code_execution_tool_20260120.rb +3 -1
  63. data/lib/anthropic/models/code_execution_tool_20260521.rb +82 -0
  64. data/lib/anthropic/models/memory_tool_20250818.rb +3 -1
  65. data/lib/anthropic/models/message_count_tokens_params.rb +2 -2
  66. data/lib/anthropic/models/message_count_tokens_tool.rb +4 -1
  67. data/lib/anthropic/models/message_create_params.rb +12 -3
  68. data/lib/anthropic/models/messages/batch_create_params.rb +14 -3
  69. data/lib/anthropic/models/refusal_stop_details.rb +4 -7
  70. data/lib/anthropic/models/tool.rb +3 -1
  71. data/lib/anthropic/models/tool_bash_20250124.rb +3 -1
  72. data/lib/anthropic/models/tool_search_tool_bm25_20251119.rb +3 -1
  73. data/lib/anthropic/models/tool_search_tool_regex_20251119.rb +3 -1
  74. data/lib/anthropic/models/tool_text_editor_20250124.rb +3 -1
  75. data/lib/anthropic/models/tool_text_editor_20250429.rb +3 -1
  76. data/lib/anthropic/models/tool_text_editor_20250728.rb +3 -1
  77. data/lib/anthropic/models/tool_union.rb +4 -1
  78. data/lib/anthropic/models/web_fetch_tool_20250910.rb +3 -1
  79. data/lib/anthropic/models/web_fetch_tool_20260209.rb +3 -1
  80. data/lib/anthropic/models/web_fetch_tool_20260309.rb +3 -1
  81. data/lib/anthropic/models/web_search_tool_20250305.rb +3 -1
  82. data/lib/anthropic/models/web_search_tool_20260209.rb +3 -1
  83. data/lib/anthropic/models.rb +2 -0
  84. data/lib/anthropic/request_options.rb +9 -0
  85. data/lib/anthropic/resources/beta/messages/batches.rb +4 -2
  86. data/lib/anthropic/resources/beta/messages.rb +12 -12
  87. data/lib/anthropic/resources/messages/batches.rb +7 -3
  88. data/lib/anthropic/resources/messages.rb +58 -42
  89. data/lib/anthropic/version.rb +1 -1
  90. data/lib/anthropic.rb +7 -0
  91. data/rbi/anthropic/client.rbi +7 -2
  92. data/rbi/anthropic/errors.rbi +5 -0
  93. data/rbi/anthropic/helpers/aws/client.rbi +3 -6
  94. data/rbi/anthropic/helpers/bedrock/client.rbi +24 -13
  95. data/rbi/anthropic/helpers/bedrock/event_stream.rbi +25 -0
  96. data/rbi/anthropic/helpers/bedrock/mantle_client.rbi +3 -6
  97. data/rbi/anthropic/helpers/vertex/client.rbi +28 -8
  98. data/rbi/anthropic/internal/transport/base_client.rbi +39 -4
  99. data/rbi/anthropic/internal/util.rbi +5 -0
  100. data/rbi/anthropic/middleware.rbi +338 -0
  101. data/rbi/anthropic/models/beta/agent_create_params.rbi +6 -2
  102. data/rbi/anthropic/models/beta/agent_update_params.rbi +10 -4
  103. data/rbi/anthropic/models/beta/beta_advisor_tool_20260301.rbi +7 -1
  104. data/rbi/anthropic/models/beta/beta_cache_control_ephemeral.rbi +9 -3
  105. data/rbi/anthropic/models/beta/beta_code_execution_tool_20250522.rbi +7 -1
  106. data/rbi/anthropic/models/beta/beta_code_execution_tool_20250825.rbi +7 -1
  107. data/rbi/anthropic/models/beta/beta_code_execution_tool_20260120.rbi +7 -1
  108. data/rbi/anthropic/models/beta/beta_code_execution_tool_20260521.rbi +178 -0
  109. data/rbi/anthropic/models/beta/beta_fallback_block.rbi +19 -4
  110. data/rbi/anthropic/models/beta/beta_fallback_block_param.rbi +23 -13
  111. data/rbi/anthropic/models/beta/beta_fallback_refusal_trigger.rbi +113 -0
  112. data/rbi/anthropic/models/beta/beta_memory_tool_20250818.rbi +7 -1
  113. data/rbi/anthropic/models/beta/beta_refusal_stop_details.rbi +8 -9
  114. data/rbi/anthropic/models/beta/beta_tool.rbi +7 -1
  115. data/rbi/anthropic/models/beta/beta_tool_bash_20241022.rbi +7 -1
  116. data/rbi/anthropic/models/beta/beta_tool_bash_20250124.rbi +7 -1
  117. data/rbi/anthropic/models/beta/beta_tool_computer_use_20241022.rbi +7 -1
  118. data/rbi/anthropic/models/beta/beta_tool_computer_use_20250124.rbi +7 -1
  119. data/rbi/anthropic/models/beta/beta_tool_computer_use_20251124.rbi +7 -1
  120. data/rbi/anthropic/models/beta/beta_tool_search_tool_bm25_20251119.rbi +7 -1
  121. data/rbi/anthropic/models/beta/beta_tool_search_tool_regex_20251119.rbi +7 -1
  122. data/rbi/anthropic/models/beta/beta_tool_text_editor_20241022.rbi +7 -1
  123. data/rbi/anthropic/models/beta/beta_tool_text_editor_20250124.rbi +7 -1
  124. data/rbi/anthropic/models/beta/beta_tool_text_editor_20250429.rbi +7 -1
  125. data/rbi/anthropic/models/beta/beta_tool_text_editor_20250728.rbi +7 -1
  126. data/rbi/anthropic/models/beta/beta_tool_union.rbi +1 -0
  127. data/rbi/anthropic/models/beta/beta_web_fetch_tool_20250910.rbi +7 -1
  128. data/rbi/anthropic/models/beta/beta_web_fetch_tool_20260209.rbi +7 -1
  129. data/rbi/anthropic/models/beta/beta_web_fetch_tool_20260309.rbi +7 -1
  130. data/rbi/anthropic/models/beta/beta_web_search_tool_20250305.rbi +7 -1
  131. data/rbi/anthropic/models/beta/beta_web_search_tool_20260209.rbi +7 -1
  132. data/rbi/anthropic/models/beta/beta_webhook_event.rbi +6 -3
  133. data/rbi/anthropic/models/beta/beta_webhook_event_data.rbi +2 -1
  134. data/rbi/anthropic/models/beta/beta_webhook_session_updated_event_data.rbi +63 -0
  135. data/rbi/anthropic/models/beta/message_count_tokens_params.rbi +5 -0
  136. data/rbi/anthropic/models/beta/message_create_params.rbi +17 -10
  137. data/rbi/anthropic/models/beta/messages/batch_create_params.rbi +24 -13
  138. data/rbi/anthropic/models/beta/unwrap_webhook_event.rbi +2 -1
  139. data/rbi/anthropic/models/cache_control_ephemeral.rbi +9 -3
  140. data/rbi/anthropic/models/code_execution_tool_20250522.rbi +7 -1
  141. data/rbi/anthropic/models/code_execution_tool_20250825.rbi +7 -1
  142. data/rbi/anthropic/models/code_execution_tool_20260120.rbi +7 -1
  143. data/rbi/anthropic/models/code_execution_tool_20260521.rbi +168 -0
  144. data/rbi/anthropic/models/memory_tool_20250818.rbi +7 -1
  145. data/rbi/anthropic/models/message_count_tokens_params.rbi +4 -0
  146. data/rbi/anthropic/models/message_count_tokens_tool.rbi +1 -0
  147. data/rbi/anthropic/models/message_create_params.rbi +17 -0
  148. data/rbi/anthropic/models/messages/batch_create_params.rbi +21 -0
  149. data/rbi/anthropic/models/refusal_stop_details.rbi +8 -9
  150. data/rbi/anthropic/models/tool.rbi +7 -1
  151. data/rbi/anthropic/models/tool_bash_20250124.rbi +7 -1
  152. data/rbi/anthropic/models/tool_search_tool_bm25_20251119.rbi +7 -1
  153. data/rbi/anthropic/models/tool_search_tool_regex_20251119.rbi +7 -1
  154. data/rbi/anthropic/models/tool_text_editor_20250124.rbi +7 -1
  155. data/rbi/anthropic/models/tool_text_editor_20250429.rbi +7 -1
  156. data/rbi/anthropic/models/tool_text_editor_20250728.rbi +7 -1
  157. data/rbi/anthropic/models/tool_union.rbi +1 -0
  158. data/rbi/anthropic/models/web_fetch_tool_20250910.rbi +7 -1
  159. data/rbi/anthropic/models/web_fetch_tool_20260209.rbi +7 -1
  160. data/rbi/anthropic/models/web_fetch_tool_20260309.rbi +7 -1
  161. data/rbi/anthropic/models/web_search_tool_20250305.rbi +7 -1
  162. data/rbi/anthropic/models/web_search_tool_20260209.rbi +7 -1
  163. data/rbi/anthropic/models.rbi +2 -0
  164. data/rbi/anthropic/request_options.rbi +5 -0
  165. data/rbi/anthropic/resources/beta/agents.rbi +7 -2
  166. data/rbi/anthropic/resources/beta/messages/batches.rbi +7 -0
  167. data/rbi/anthropic/resources/beta/messages.rbi +13 -8
  168. data/rbi/anthropic/resources/messages/batches.rbi +9 -2
  169. data/rbi/anthropic/resources/messages.rbi +57 -42
  170. data/rbi/lib/anthropic/helpers/stainless_helper_header.rbi +17 -0
  171. data/sig/anthropic/client.rbs +2 -1
  172. data/sig/anthropic/errors.rbs +3 -0
  173. data/sig/anthropic/helpers/bedrock/client.rbs +12 -4
  174. data/sig/anthropic/helpers/vertex/client.rbs +17 -4
  175. data/sig/anthropic/internal/transport/base_client.rbs +18 -3
  176. data/sig/anthropic/internal/util.rbs +2 -0
  177. data/sig/anthropic/middleware.rbs +117 -0
  178. data/sig/anthropic/models/beta/beta_advisor_tool_20260301.rbs +5 -1
  179. data/sig/anthropic/models/beta/beta_code_execution_tool_20250522.rbs +5 -1
  180. data/sig/anthropic/models/beta/beta_code_execution_tool_20250825.rbs +5 -1
  181. data/sig/anthropic/models/beta/beta_code_execution_tool_20260120.rbs +5 -1
  182. data/sig/anthropic/models/beta/beta_code_execution_tool_20260521.rbs +74 -0
  183. data/sig/anthropic/models/beta/beta_fallback_block.rbs +5 -0
  184. data/sig/anthropic/models/beta/beta_fallback_block_param.rbs +9 -2
  185. data/sig/anthropic/models/beta/beta_fallback_refusal_trigger.rbs +48 -0
  186. data/sig/anthropic/models/beta/beta_memory_tool_20250818.rbs +5 -1
  187. data/sig/anthropic/models/beta/beta_refusal_stop_details.rbs +7 -1
  188. data/sig/anthropic/models/beta/beta_tool.rbs +5 -1
  189. data/sig/anthropic/models/beta/beta_tool_bash_20241022.rbs +5 -1
  190. data/sig/anthropic/models/beta/beta_tool_bash_20250124.rbs +5 -1
  191. data/sig/anthropic/models/beta/beta_tool_computer_use_20241022.rbs +5 -1
  192. data/sig/anthropic/models/beta/beta_tool_computer_use_20250124.rbs +5 -1
  193. data/sig/anthropic/models/beta/beta_tool_computer_use_20251124.rbs +5 -1
  194. data/sig/anthropic/models/beta/beta_tool_search_tool_bm25_20251119.rbs +5 -1
  195. data/sig/anthropic/models/beta/beta_tool_search_tool_regex_20251119.rbs +5 -1
  196. data/sig/anthropic/models/beta/beta_tool_text_editor_20241022.rbs +5 -1
  197. data/sig/anthropic/models/beta/beta_tool_text_editor_20250124.rbs +5 -1
  198. data/sig/anthropic/models/beta/beta_tool_text_editor_20250429.rbs +5 -1
  199. data/sig/anthropic/models/beta/beta_tool_text_editor_20250728.rbs +5 -1
  200. data/sig/anthropic/models/beta/beta_tool_union.rbs +1 -0
  201. data/sig/anthropic/models/beta/beta_web_fetch_tool_20250910.rbs +5 -1
  202. data/sig/anthropic/models/beta/beta_web_fetch_tool_20260209.rbs +5 -1
  203. data/sig/anthropic/models/beta/beta_web_fetch_tool_20260309.rbs +5 -1
  204. data/sig/anthropic/models/beta/beta_web_search_tool_20250305.rbs +5 -1
  205. data/sig/anthropic/models/beta/beta_web_search_tool_20260209.rbs +5 -1
  206. data/sig/anthropic/models/beta/beta_webhook_event_data.rbs +1 -0
  207. data/sig/anthropic/models/beta/beta_webhook_session_updated_event_data.rbs +39 -0
  208. data/sig/anthropic/models/beta/message_count_tokens_params.rbs +1 -0
  209. data/sig/anthropic/models/beta/message_create_params.rbs +8 -6
  210. data/sig/anthropic/models/beta/messages/batch_create_params.rbs +11 -9
  211. data/sig/anthropic/models/code_execution_tool_20250522.rbs +5 -1
  212. data/sig/anthropic/models/code_execution_tool_20250825.rbs +5 -1
  213. data/sig/anthropic/models/code_execution_tool_20260120.rbs +5 -1
  214. data/sig/anthropic/models/code_execution_tool_20260521.rbs +70 -0
  215. data/sig/anthropic/models/memory_tool_20250818.rbs +5 -1
  216. data/sig/anthropic/models/message_count_tokens_tool.rbs +1 -0
  217. data/sig/anthropic/models/message_create_params.rbs +8 -1
  218. data/sig/anthropic/models/messages/batch_create_params.rbs +10 -1
  219. data/sig/anthropic/models/refusal_stop_details.rbs +7 -1
  220. data/sig/anthropic/models/tool.rbs +5 -1
  221. data/sig/anthropic/models/tool_bash_20250124.rbs +5 -1
  222. data/sig/anthropic/models/tool_search_tool_bm25_20251119.rbs +5 -1
  223. data/sig/anthropic/models/tool_search_tool_regex_20251119.rbs +5 -1
  224. data/sig/anthropic/models/tool_text_editor_20250124.rbs +5 -1
  225. data/sig/anthropic/models/tool_text_editor_20250429.rbs +5 -1
  226. data/sig/anthropic/models/tool_text_editor_20250728.rbs +5 -1
  227. data/sig/anthropic/models/tool_union.rbs +1 -0
  228. data/sig/anthropic/models/web_fetch_tool_20250910.rbs +5 -1
  229. data/sig/anthropic/models/web_fetch_tool_20260209.rbs +5 -1
  230. data/sig/anthropic/models/web_fetch_tool_20260309.rbs +5 -1
  231. data/sig/anthropic/models/web_search_tool_20250305.rbs +5 -1
  232. data/sig/anthropic/models/web_search_tool_20260209.rbs +5 -1
  233. data/sig/anthropic/models.rbs +2 -0
  234. data/sig/anthropic/request_options.rbs +4 -1
  235. data/sig/anthropic/resources/beta/messages/batches.rbs +1 -0
  236. data/sig/anthropic/resources/beta/messages.rbs +2 -2
  237. data/sig/anthropic/resources/messages/batches.rbs +1 -0
  238. data/sig/anthropic/resources/messages.rbs +2 -0
  239. metadata +21 -2
@@ -0,0 +1,435 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Anthropic
4
+ # The per-attempt request object a middleware sees.
5
+ #
6
+ # Fields mirror what resource methods pass to `BaseClient#request` (see
7
+ # `RequestComponents`), with `path`/`query` resolved to a `URI::Generic`,
8
+ # headers fully normalized, and `retry_count`/`metadata` added.
9
+ #
10
+ # `body` is the **canonical** Anthropic request body — for JSON endpoints
11
+ # (`POST /v1/messages` etc.) a `Hash` like `{model:, messages:, max_tokens:}`,
12
+ # `nil` for body-less methods. It is *not* a serialized `String`: JSON
13
+ # encoding, 3p-provider rewrite (Bedrock/Vertex), and request signing all
14
+ # happen inside `nxt.call`, so a middleware that edits `body` via
15
+ # `req.with(body: ...)` does not need to re-serialize.
16
+ #
17
+ # Instances are frozen and the `headers`/`body`/`url`/`options` values the
18
+ # SDK supplies are deep-frozen — mutating them or any nested `Hash`/`Array`
19
+ # (e.g. `body[:messages]`) raises. Use {#with} to derive a copy. `metadata`
20
+ # is the one intentionally shared, mutable scratchpad that persists across
21
+ # retry attempts.
22
+ class APIRequest
23
+ # @api private
24
+ MEMBERS =
25
+ [:method, :url, :headers, :body, :stream, :cast_to, :unwrap, :options, :retry_count, :metadata].freeze
26
+
27
+ # @return [Symbol] the HTTP method (`:get`, `:post`, …)
28
+ attr_reader :method
29
+
30
+ # @return [URI::Generic] the resolved request URL (deep-frozen)
31
+ attr_reader :url
32
+
33
+ # @return [Hash{String=>String}] normalized request headers (deep-frozen)
34
+ attr_reader :headers
35
+
36
+ # @return [Object, nil] the canonical request body — usually a
37
+ # `Hash{Symbol=>Object}` for JSON endpoints, `nil` for body-less, but may
38
+ # be a `String`/`IO` for upload paths (see class doc; deep-frozen where
39
+ # structurally copyable)
40
+ attr_reader :body
41
+
42
+ # @return [Class, nil] the SSE stream class to decode into; `nil` for
43
+ # non-streaming
44
+ attr_reader :stream
45
+
46
+ # @return [Anthropic::Internal::Type::Converter::Input, nil] the model
47
+ # class the response body will be coerced to; `nil` for paginated
48
+ # requests
49
+ attr_reader :cast_to
50
+
51
+ # @return [Symbol, Integer, Array<Symbol, Integer>, Proc, nil] the envelope
52
+ # key(s) the SDK digs out of the decoded body before coercing
53
+ attr_reader :unwrap
54
+
55
+ # @return [Hash{Symbol=>Object}] request options (`:timeout`, …;
56
+ # deep-frozen)
57
+ attr_reader :options
58
+
59
+ # @return [Integer] number of prior attempts (`0` on the first)
60
+ attr_reader :retry_count
61
+
62
+ # @return [Hash{Symbol=>Object}] mutable cross-attempt scratchpad shared
63
+ # between retries
64
+ attr_reader :metadata
65
+
66
+ # @param method [Symbol]
67
+ # @param url [URI::Generic]
68
+ # @param headers [Hash{String=>String}]
69
+ # @param body [Object, nil]
70
+ # @param stream [Class, nil]
71
+ # @param cast_to [Anthropic::Internal::Type::Converter::Input, nil]
72
+ # @param unwrap [Symbol, Integer, Array<Symbol, Integer>, Proc, nil]
73
+ # @param options [Hash{Symbol=>Object}]
74
+ # @param retry_count [Integer]
75
+ # @param metadata [Hash{Symbol=>Object}]
76
+ def initialize(
77
+ method:,
78
+ url:,
79
+ headers:,
80
+ body:,
81
+ stream:,
82
+ cast_to:,
83
+ unwrap:,
84
+ options:,
85
+ retry_count:,
86
+ metadata:
87
+ )
88
+ @method = method
89
+ @url = url
90
+ @headers = headers
91
+ @body = body
92
+ @stream = stream
93
+ @cast_to = cast_to
94
+ @unwrap = unwrap
95
+ @options = options
96
+ @retry_count = retry_count
97
+ @metadata = metadata
98
+ freeze
99
+ end
100
+
101
+ # @return [Boolean] whether the SDK call is a streaming/SSE request
102
+ def streaming? = !@stream.nil?
103
+
104
+ # @return [Boolean] whether this is a retry attempt (`retry_count > 0`)
105
+ def retry? = @retry_count.positive?
106
+
107
+ # @return [Float] the request timeout in seconds. Informational only — the
108
+ # transport deadline is fixed when the SDK enters the middleware
109
+ # terminal, so deriving a request via `with(options: {timeout: …})` does
110
+ # not change it. Time spent inside middleware does not count against it.
111
+ def timeout = @options.to_h.fetch(:timeout, 0.0)
112
+
113
+ # Derive a copy with the given members replaced.
114
+ #
115
+ # @param method [Symbol]
116
+ # @param url [URI::Generic]
117
+ # @param headers [Hash{String=>String}]
118
+ # @param body [Object, nil]
119
+ # @param stream [Class, nil]
120
+ # @param cast_to [Anthropic::Internal::Type::Converter::Input, nil]
121
+ # @param unwrap [Symbol, Integer, Array<Symbol, Integer>, Proc, nil]
122
+ # @param options [Hash{Symbol=>Object}]
123
+ # @param retry_count [Integer]
124
+ # @param metadata [Hash{Symbol=>Object}]
125
+ # @return [Anthropic::APIRequest]
126
+ def with(**changes)
127
+ unknown = changes.keys - MEMBERS
128
+ unless unknown.empty?
129
+ raise ArgumentError,
130
+ "unknown keyword#{'s' if unknown.length > 1}: #{unknown.map(&:inspect).join(', ')}"
131
+ end
132
+ self.class.new(**to_h, **changes)
133
+ end
134
+
135
+ # @return [Hash{Symbol=>Object}]
136
+ def to_h = MEMBERS.to_h { [_1, instance_variable_get(:"@#{_1}")] }
137
+ end
138
+
139
+ # The per-attempt response object a middleware sees.
140
+ #
141
+ # `nxt.call(req)` returns an `APIResponse` for **all** HTTP status codes —
142
+ # 4xx and 5xx included. It does **not** raise on error status; the SDK
143
+ # converts to a typed `APIError` only after the chain completes. This lets a
144
+ # middleware inspect `res.status` on a 5xx and choose to substitute, retry
145
+ # differently, or pass through. Connection-level failures
146
+ # ({Anthropic::Errors::APITimeoutError}, {Anthropic::Errors::APIConnectionError})
147
+ # **do** raise from `nxt.call`.
148
+ class APIResponse
149
+ # Raised when a middleware returns an {APIResponse} whose body enumerator was
150
+ # already consumed without first calling {APIResponse#buffer!}. The SDK cannot
151
+ # parse a drained, unbuffered body. Fix by calling `res.buffer!` (or
152
+ # `res.parse`) before reading, or by using `res.wrap_body` to transform the
153
+ # stream without consuming it.
154
+ class ConsumedBodyError < Anthropic::Errors::Error
155
+ end
156
+
157
+ # @return [Integer] HTTP status code
158
+ attr_reader :status
159
+
160
+ # @return [Hash{String=>String}] normalized response headers
161
+ attr_reader :headers
162
+
163
+ # @return [Net::HTTPResponse, nil] the raw response. `nil` for an
164
+ # `APIResponse.new(...)` constructed by a middleware (e.g. a mock).
165
+ attr_reader :raw
166
+
167
+ # @return [Anthropic::APIRequest, nil] the request that produced this
168
+ # response. {#parse} uses it to recover the SDK return type; a fabricated
169
+ # response without one parses to the decoded body only.
170
+ attr_reader :request
171
+
172
+ # @api private
173
+ #
174
+ # Wraps the `[status, Net::HTTPResponse, Enumerable<String>]` tuple the
175
+ # pooled requester returns.
176
+ #
177
+ # @param status [Integer]
178
+ # @param raw [Net::HTTPResponse]
179
+ # @param stream [Enumerable<String>]
180
+ # @param request [Anthropic::APIRequest, nil]
181
+ # @return [Anthropic::APIResponse]
182
+ def self.wrap(status, raw, stream, request: nil)
183
+ # `initialize` normalizes `headers`, so pass the raw header hash straight
184
+ # through rather than normalizing twice on every response.
185
+ new(status: status, headers: raw.each_header.to_h, body: stream, raw: raw, request: request)
186
+ end
187
+
188
+ # @param status [Integer]
189
+ # @param headers [Hash{String=>String}]
190
+ # @param body [Enumerable<String>, String, nil]
191
+ # @param raw [Net::HTTPResponse, nil]
192
+ # @param streaming [Boolean, nil] override `streaming?`; inferred from
193
+ # `request` if `nil`
194
+ # @param request [Anthropic::APIRequest, nil]
195
+ def initialize(status:, headers: {}, body: nil, raw: nil, streaming: nil, request: nil)
196
+ @status = status
197
+ @headers = Anthropic::Internal::Util.normalized_headers(headers)
198
+ @raw = raw
199
+ @request = request
200
+ @streaming = streaming
201
+ @buffered = nil
202
+ @drained = false
203
+ @parsed = Anthropic::Internal::OMIT
204
+
205
+ @body =
206
+ case body
207
+ in nil
208
+ @buffered = [].freeze
209
+ in String
210
+ @buffered = [body].freeze
211
+ in Array
212
+ @buffered = body.dup.freeze
213
+ else
214
+ # Wrap once so the first pull flips `@drained`; `to_tuple`/`buffer!`
215
+ # then detect a body that was iterated without buffering. Fused so
216
+ # `Util.close_fused!` (stream `close`, connection reaping) propagates
217
+ # to the upstream enum without first pulling a chunk off the socket.
218
+ Anthropic::Internal::Util.chain_fused(body) do |y|
219
+ @drained = true
220
+ body.each { y << _1 }
221
+ end
222
+ end
223
+ end
224
+
225
+ # @return [Enumerable<String>] the response body. **Single-consumer**
226
+ # unless {#buffer!} has been called. After `buffer!`, this is a
227
+ # rewindable `Array`.
228
+ def body = @buffered || @body
229
+
230
+ # @return [Boolean] whether the request that produced this response is a
231
+ # streaming/SSE request.
232
+ def streaming?
233
+ return @streaming unless @streaming.nil?
234
+ @request&.streaming? || false
235
+ end
236
+
237
+ # @return [Boolean] whether the SDK would retry this status under its
238
+ # default policy — parity with the Python SDK's `Response.is_retryable`.
239
+ # Useful for middleware that wants to match the SDK's own retry decision.
240
+ def retryable?
241
+ Anthropic::Internal::Transport::BaseClient.should_retry?(@status, headers: @headers)
242
+ end
243
+
244
+ # Drain the body into memory so it can be re-read. Idempotent once
245
+ # buffered.
246
+ #
247
+ # @param force [Boolean] allow buffering a streaming response. By default
248
+ # this raises because buffering an SSE stream defeats streaming; pass
249
+ # `force: true` if you know the stream is bounded.
250
+ # @return [self]
251
+ # @raise [ArgumentError] if `streaming?` and `force` is false.
252
+ # @raise [Anthropic::APIResponse::ConsumedBodyError] if the body was
253
+ # already drained by a raw `body.each` without buffering.
254
+ def buffer!(force: false)
255
+ return self if @buffered
256
+
257
+ if streaming? && !force
258
+ raise ArgumentError,
259
+ "Refusing to buffer a streaming response; pass `force: true` " \
260
+ "or use `wrap_body` to transform the stream without buffering."
261
+ end
262
+
263
+ if @drained
264
+ raise ConsumedBodyError,
265
+ "Response body was already consumed. Call `buffer!` (or " \
266
+ "`parse`) before reading the body, or use `wrap_body` to " \
267
+ "transform the stream without consuming it."
268
+ end
269
+
270
+ @buffered = @body.to_a.freeze
271
+ @drained = true
272
+ self
273
+ end
274
+
275
+ # Replace the body with the block's return value — the composable way to
276
+ # intercept streamed chunks without buffering.
277
+ #
278
+ # @param streaming [Boolean] value for the new response's `streaming?`.
279
+ # Pass `false` if the wrapper collapses the stream to a buffered body.
280
+ # @yieldparam upstream [Enumerable<String>]
281
+ # @yieldreturn [Enumerable<String>]
282
+ # @return [Anthropic::APIResponse]
283
+ def wrap_body(streaming: streaming?)
284
+ raise ArgumentError, "wrap_body requires a block" unless block_given?
285
+ self.class.new(
286
+ status: @status,
287
+ headers: @headers,
288
+ body: yield(body),
289
+ raw: @raw,
290
+ streaming: streaming,
291
+ request: @request
292
+ )
293
+ end
294
+
295
+ # Decode and coerce the body to the SDK-typed result the original caller
296
+ # would have received (e.g. `Anthropic::Message`). Internally `buffer!`s
297
+ # first, so calling `parse` does not steal the body from downstream — the
298
+ # SDK reuses the buffered copy.
299
+ #
300
+ # For non-streaming responses the decoded value is coerced to the request's
301
+ # return type and memoized — repeated calls across the chain cost a single
302
+ # decode. A fabricated response without a `request:` parses to the decoded
303
+ # body (e.g. a `Hash`) instead of an SDK model.
304
+ #
305
+ # For streaming requests, returns a typed stream reading an independent
306
+ # buffered copy of the response body — iterating (or `break`ing out of) it
307
+ # neither consumes nor cancels the events the SDK caller will read. Streams
308
+ # are single-consumer, so each call returns a fresh stream rather than a
309
+ # memoized one.
310
+ #
311
+ # @example
312
+ # usage_logger = lambda do |req, nxt|
313
+ # res = nxt.call(req)
314
+ # LOGGER.info("usage: #{res.parse.usage}") if res.status < 300
315
+ # res
316
+ # end
317
+ #
318
+ # @return [Object]
319
+ def parse
320
+ return parse_stream if streaming?
321
+ return @parsed unless Anthropic::Internal::OMIT.equal?(@parsed)
322
+
323
+ buffer!
324
+ decoded = Anthropic::Internal::Util.decode_content(@headers, stream: body.each)
325
+ unwrapped = Anthropic::Internal::Util.dig(decoded, @request&.unwrap)
326
+ cast_to = @request&.cast_to || Anthropic::Internal::Type::Unknown
327
+ @parsed = Anthropic::Internal::Type::Converter.coerce(cast_to, unwrapped)
328
+ end
329
+
330
+ # @api private
331
+ #
332
+ # Back to the `[Integer, Net::HTTPResponse|nil, Hash, Enumerable<String>]`
333
+ # tuple shape `send_request` works with internally. Headers come from
334
+ # {#headers} — never re-derived from `raw` — so a middleware that returns
335
+ # a modified header set over the original raw response is honored.
336
+ #
337
+ # @return [Array(Integer, Net::HTTPResponse|nil, Hash{String=>String}, Enumerable<String>)]
338
+ def to_tuple
339
+ if @buffered.nil? && @drained
340
+ raise ConsumedBodyError,
341
+ "Middleware consumed the response body without buffering it. " \
342
+ "Call `buffer!` (or `parse`) before reading, or use `wrap_body`."
343
+ end
344
+ [status, @raw, @headers, @buffered || @body]
345
+ end
346
+
347
+ private
348
+
349
+ # A fresh typed stream over a buffered copy of the response body.
350
+ #
351
+ # @return [Anthropic::Internal::Type::BaseStream, Enumerable]
352
+ def parse_stream
353
+ buffer!(force: true)
354
+ decoded = Anthropic::Internal::Util.decode_content(@headers, stream: body.each)
355
+ stream = @request&.stream
356
+ return decoded unless stream
357
+
358
+ stream.new(
359
+ model: @request.cast_to,
360
+ url: @request.url,
361
+ status: status,
362
+ headers: @headers,
363
+ response: @raw,
364
+ unwrap: @request.unwrap,
365
+ stream: decoded
366
+ )
367
+ end
368
+ end
369
+
370
+ # HTTP around-middleware.
371
+ #
372
+ # A middleware is any object that responds to `#call(request, nxt)` and
373
+ # returns an {Anthropic::APIResponse}. `nxt` is itself a `#call(request)`-able
374
+ # that invokes the rest of the chain and, ultimately, a single HTTP attempt.
375
+ # The chain runs **per attempt, inside the SDK's retry loop** — the same
376
+ # placement as Go, TypeScript, Java, and Python.
377
+ #
378
+ # Register middleware at the client level via `Anthropic::Client.new(middleware: [...])`,
379
+ # or per request via `request_options: {middleware: [...]}`. Request-level
380
+ # entries run innermost (below client-level entries), so client-level
381
+ # middleware still wraps every request a per-call middleware fabricates or
382
+ # retries.
383
+ #
384
+ # On provider clients (Bedrock/Vertex/AWS), a provider middleware is
385
+ # appended below all user entries on every dispatch: it rewrites the
386
+ # canonical request into the provider's wire shape and applies provider
387
+ # auth (SigV4/OAuth), so user middleware always sees the canonical
388
+ # Anthropic request and every re-issued or retried leg is re-signed.
389
+ #
390
+ # @example
391
+ # log = ->(req, nxt) { res = nxt.call(req); LOGGER.info(res.status); res }
392
+ # Anthropic::Client.new(middleware: [log])
393
+ module Middleware
394
+ # Optional mixin that names the middleware contract for users who prefer a
395
+ # class to a lambda. `include Anthropic::Middleware` and implement
396
+ # `#call(request, nxt)`. The SDK treats *any* `#call(req, nxt)` object as
397
+ # middleware (lambdas, procs, `Method`s included), so including this is for
398
+ # discovery and type-checking — under Sorbet the method is `abstract`, so a
399
+ # missing or mis-typed `#call` is a static error — not a runtime
400
+ # requirement.
401
+ #
402
+ # @example
403
+ # class AddTeamHeader
404
+ # include Anthropic::Middleware
405
+ #
406
+ # def initialize(team) = @team = team
407
+ #
408
+ # def call(request, nxt)
409
+ # nxt.call(request.with(headers: request.headers.merge("x-team" => @team)))
410
+ # end
411
+ # end
412
+ #
413
+ # @param request [Anthropic::APIRequest] the per-attempt request
414
+ # @param nxt [#call] invokes the rest of the chain; returns an {APIResponse}
415
+ # @return [Anthropic::APIResponse]
416
+ def call(request, nxt)
417
+ raise NotImplementedError, "#{self.class} must implement #{Anthropic::Middleware}#call(request, nxt)"
418
+ end
419
+
420
+ class << self
421
+ # @api private
422
+ #
423
+ # Compose `list` into a single callable. `list[0]` is outermost.
424
+ #
425
+ # @param list [Array<#call>]
426
+ # @param terminal [#call] the innermost callable — the actual HTTP attempt
427
+ # @return [#call]
428
+ def build_chain(list, terminal)
429
+ list.reverse.reduce(terminal) do |inner, mw|
430
+ ->(req) { mw.call(req, inner) }
431
+ end
432
+ end
433
+ end
434
+ end
435
+ end
@@ -31,7 +31,9 @@ module Anthropic
31
31
 
32
32
  # @!attribute mcp_servers
33
33
  # MCP servers this agent connects to. Maximum 20. Names must be unique within the
34
- # array.
34
+ # array. Every server must be referenced by an `mcp_toolset` in `tools`;
35
+ # unreferenced servers are rejected. See the
36
+ # [MCP connector guide](https://platform.claude.com/docs/en/managed-agents/mcp-connector).
35
37
  #
36
38
  # @return [Array<Anthropic::Models::Beta::BetaManagedAgentsURLMCPServerParams>, nil]
37
39
  optional :mcp_servers,
@@ -28,8 +28,11 @@ module Anthropic
28
28
  optional :description, String, nil?: true
29
29
 
30
30
  # @!attribute mcp_servers
31
- # MCP servers. Full replacement. Omit to preserve; send empty array or null to
32
- # clear. Names must be unique. Maximum 20.
31
+ # MCP servers. Full replacement. Omit to preserve; send empty array or `null` to
32
+ # clear. Names must be unique. Maximum 20. Every server must be referenced by an
33
+ # `mcp_toolset` in the agent's resulting `tools`; unreferenced servers are
34
+ # rejected. See the
35
+ # [MCP connector guide](https://platform.claude.com/docs/en/managed-agents/mcp-connector).
33
36
  #
34
37
  # @return [Array<Anthropic::Models::Beta::BetaManagedAgentsURLMCPServerParams>, nil]
35
38
  optional :mcp_servers,
@@ -110,7 +113,7 @@ module Anthropic
110
113
  #
111
114
  # @param description [String, nil] Description. Omit to preserve; send empty string or null to clear.
112
115
  #
113
- # @param mcp_servers [Array<Anthropic::Models::Beta::BetaManagedAgentsURLMCPServerParams>, nil] MCP servers. Full replacement. Omit to preserve; send empty array or null to cle
116
+ # @param mcp_servers [Array<Anthropic::Models::Beta::BetaManagedAgentsURLMCPServerParams>, nil] MCP servers. Full replacement. Omit to preserve; send empty array or `null` to c
114
117
  #
115
118
  # @param metadata [Hash{Symbol=>String, nil}, nil] Metadata patch. Set a key to a string to upsert it, or to null to delete it. Omi
116
119
  #
@@ -106,13 +106,15 @@ module Anthropic
106
106
  # Values: direct: The model can call this tool directly. code_execution_20250825:
107
107
  # The tool can be called from the code execution environment (v1).
108
108
  # code_execution_20260120: The tool can be called from the code execution
109
- # environment (v2 with persistence).
109
+ # environment (v2 with persistence). code_execution_20260521: The tool can be
110
+ # called from the code execution environment (v2 with persistence).
110
111
  module AllowedCaller
111
112
  extend Anthropic::Internal::Type::Enum
112
113
 
113
114
  DIRECT = :direct
114
115
  CODE_EXECUTION_20250825 = :code_execution_20250825
115
116
  CODE_EXECUTION_20260120 = :code_execution_20260120
117
+ CODE_EXECUTION_20260521 = :code_execution_20260521
116
118
 
117
119
  # @!method self.values
118
120
  # @return [Array<Symbol>]
@@ -17,7 +17,9 @@ module Anthropic
17
17
  # - `5m`: 5 minutes
18
18
  # - `1h`: 1 hour
19
19
  #
20
- # Defaults to `5m`.
20
+ # Defaults to `5m`. See
21
+ # [prompt caching pricing](https://docs.claude.com/en/docs/build-with-claude/prompt-caching)
22
+ # for details.
21
23
  #
22
24
  # @return [Symbol, Anthropic::Models::Beta::BetaCacheControlEphemeral::TTL, nil]
23
25
  optional :ttl, enum: -> { Anthropic::Beta::BetaCacheControlEphemeral::TTL }
@@ -37,7 +39,9 @@ module Anthropic
37
39
  # - `5m`: 5 minutes
38
40
  # - `1h`: 1 hour
39
41
  #
40
- # Defaults to `5m`.
42
+ # Defaults to `5m`. See
43
+ # [prompt caching pricing](https://docs.claude.com/en/docs/build-with-claude/prompt-caching)
44
+ # for details.
41
45
  #
42
46
  # @see Anthropic::Models::Beta::BetaCacheControlEphemeral#ttl
43
47
  module TTL
@@ -63,13 +63,15 @@ module Anthropic
63
63
  # Values: direct: The model can call this tool directly. code_execution_20250825:
64
64
  # The tool can be called from the code execution environment (v1).
65
65
  # code_execution_20260120: The tool can be called from the code execution
66
- # environment (v2 with persistence).
66
+ # environment (v2 with persistence). code_execution_20260521: The tool can be
67
+ # called from the code execution environment (v2 with persistence).
67
68
  module AllowedCaller
68
69
  extend Anthropic::Internal::Type::Enum
69
70
 
70
71
  DIRECT = :direct
71
72
  CODE_EXECUTION_20250825 = :code_execution_20250825
72
73
  CODE_EXECUTION_20260120 = :code_execution_20260120
74
+ CODE_EXECUTION_20260521 = :code_execution_20260521
73
75
 
74
76
  # @!method self.values
75
77
  # @return [Array<Symbol>]
@@ -63,13 +63,15 @@ module Anthropic
63
63
  # Values: direct: The model can call this tool directly. code_execution_20250825:
64
64
  # The tool can be called from the code execution environment (v1).
65
65
  # code_execution_20260120: The tool can be called from the code execution
66
- # environment (v2 with persistence).
66
+ # environment (v2 with persistence). code_execution_20260521: The tool can be
67
+ # called from the code execution environment (v2 with persistence).
67
68
  module AllowedCaller
68
69
  extend Anthropic::Internal::Type::Enum
69
70
 
70
71
  DIRECT = :direct
71
72
  CODE_EXECUTION_20250825 = :code_execution_20250825
72
73
  CODE_EXECUTION_20260120 = :code_execution_20260120
74
+ CODE_EXECUTION_20260521 = :code_execution_20260521
73
75
 
74
76
  # @!method self.values
75
77
  # @return [Array<Symbol>]
@@ -66,13 +66,15 @@ module Anthropic
66
66
  # Values: direct: The model can call this tool directly. code_execution_20250825:
67
67
  # The tool can be called from the code execution environment (v1).
68
68
  # code_execution_20260120: The tool can be called from the code execution
69
- # environment (v2 with persistence).
69
+ # environment (v2 with persistence). code_execution_20260521: The tool can be
70
+ # called from the code execution environment (v2 with persistence).
70
71
  module AllowedCaller
71
72
  extend Anthropic::Internal::Type::Enum
72
73
 
73
74
  DIRECT = :direct
74
75
  CODE_EXECUTION_20250825 = :code_execution_20250825
75
76
  CODE_EXECUTION_20260120 = :code_execution_20260120
77
+ CODE_EXECUTION_20260521 = :code_execution_20260521
76
78
 
77
79
  # @!method self.values
78
80
  # @return [Array<Symbol>]
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Anthropic
4
+ module Models
5
+ module Beta
6
+ class BetaCodeExecutionTool20260521 < Anthropic::Internal::Type::BaseModel
7
+ # @!attribute name
8
+ # Name of the tool.
9
+ #
10
+ # This is how the tool will be called by the model and in `tool_use` blocks.
11
+ #
12
+ # @return [Symbol, :code_execution]
13
+ required :name, const: :code_execution
14
+
15
+ # @!attribute type
16
+ #
17
+ # @return [Symbol, :code_execution_20260521]
18
+ required :type, const: :code_execution_20260521
19
+
20
+ # @!attribute allowed_callers
21
+ #
22
+ # @return [Array<Symbol, Anthropic::Models::Beta::BetaCodeExecutionTool20260521::AllowedCaller>, nil]
23
+ optional :allowed_callers,
24
+ -> { Anthropic::Internal::Type::ArrayOf[enum: Anthropic::Beta::BetaCodeExecutionTool20260521::AllowedCaller] }
25
+
26
+ # @!attribute cache_control
27
+ # Create a cache control breakpoint at this content block.
28
+ #
29
+ # @return [Anthropic::Models::Beta::BetaCacheControlEphemeral, nil]
30
+ optional :cache_control, -> { Anthropic::Beta::BetaCacheControlEphemeral }, nil?: true
31
+
32
+ # @!attribute defer_loading
33
+ # If true, tool will not be included in initial system prompt. Only loaded when
34
+ # returned via tool_reference from tool search.
35
+ #
36
+ # @return [Boolean, nil]
37
+ optional :defer_loading, Anthropic::Internal::Type::Boolean
38
+
39
+ # @!attribute strict
40
+ # When true, guarantees schema validation on tool names and inputs
41
+ #
42
+ # @return [Boolean, nil]
43
+ optional :strict, Anthropic::Internal::Type::Boolean
44
+
45
+ # @!method initialize(allowed_callers: nil, cache_control: nil, defer_loading: nil, strict: nil, name: :code_execution, type: :code_execution_20260521)
46
+ # Some parameter documentations has been truncated, see
47
+ # {Anthropic::Models::Beta::BetaCodeExecutionTool20260521} for more details.
48
+ #
49
+ # Code execution tool with REPL state persistence.
50
+ #
51
+ # @param allowed_callers [Array<Symbol, Anthropic::Models::Beta::BetaCodeExecutionTool20260521::AllowedCaller>]
52
+ #
53
+ # @param cache_control [Anthropic::Models::Beta::BetaCacheControlEphemeral, nil] Create a cache control breakpoint at this content block.
54
+ #
55
+ # @param defer_loading [Boolean] If true, tool will not be included in initial system prompt. Only loaded when re
56
+ #
57
+ # @param strict [Boolean] When true, guarantees schema validation on tool names and inputs
58
+ #
59
+ # @param name [Symbol, :code_execution] Name of the tool.
60
+ #
61
+ # @param type [Symbol, :code_execution_20260521]
62
+
63
+ # Specifies who can invoke a tool.
64
+ #
65
+ # Values: direct: The model can call this tool directly. code_execution_20250825:
66
+ # The tool can be called from the code execution environment (v1).
67
+ # code_execution_20260120: The tool can be called from the code execution
68
+ # environment (v2 with persistence). code_execution_20260521: The tool can be
69
+ # called from the code execution environment (v2 with persistence).
70
+ module AllowedCaller
71
+ extend Anthropic::Internal::Type::Enum
72
+
73
+ DIRECT = :direct
74
+ CODE_EXECUTION_20250825 = :code_execution_20250825
75
+ CODE_EXECUTION_20260120 = :code_execution_20260120
76
+ CODE_EXECUTION_20260521 = :code_execution_20260521
77
+
78
+ # @!method self.values
79
+ # @return [Array<Symbol>]
80
+ end
81
+ end
82
+ end
83
+
84
+ BetaCodeExecutionTool20260521 = Beta::BetaCodeExecutionTool20260521
85
+ end
86
+ end
@@ -51,9 +51,9 @@ module Anthropic
51
51
  # Marks the point in `content` where one model's output gives way to the next.
52
52
  #
53
53
  # One block appears per hop where a preceding model actually ran this turn and
54
- # declined. A turn routed directly by the sticky decision has no such boundary
55
- # and carries no block — the signal for whether a fallback model served the
56
- # response is the presence of a `fallback_message` entry in
54
+ # declined. A turn where no preceding model ran and declined has no such
55
+ # boundary and carries no block — the signal for whether a fallback model
56
+ # served the response is the presence of a `fallback_message` entry in
57
57
  # `usage.iterations`, not this block.
58
58
  #
59
59
  # The block is treated like a server-tool content block for streaming: it