anthropic 1.48.2 → 1.49.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 (212) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -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/vertex/client.rb +99 -55
  12. data/lib/anthropic/internal/transport/base_client.rb +196 -33
  13. data/lib/anthropic/internal/util.rb +37 -1
  14. data/lib/anthropic/middleware.rb +435 -0
  15. data/lib/anthropic/models/beta/beta_advisor_tool_20260301.rb +3 -1
  16. data/lib/anthropic/models/beta/beta_code_execution_tool_20250522.rb +3 -1
  17. data/lib/anthropic/models/beta/beta_code_execution_tool_20250825.rb +3 -1
  18. data/lib/anthropic/models/beta/beta_code_execution_tool_20260120.rb +3 -1
  19. data/lib/anthropic/models/beta/beta_code_execution_tool_20260521.rb +86 -0
  20. data/lib/anthropic/models/beta/beta_content_block.rb +3 -3
  21. data/lib/anthropic/models/beta/beta_content_block_param.rb +10 -12
  22. data/lib/anthropic/models/beta/beta_fallback_block.rb +13 -5
  23. data/lib/anthropic/models/beta/beta_fallback_block_param.rb +22 -13
  24. data/lib/anthropic/models/beta/beta_fallback_refusal_trigger.rb +44 -0
  25. data/lib/anthropic/models/beta/beta_memory_tool_20250818.rb +3 -1
  26. data/lib/anthropic/models/beta/beta_raw_content_block_start_event.rb +3 -3
  27. data/lib/anthropic/models/beta/beta_refusal_stop_details.rb +3 -7
  28. data/lib/anthropic/models/beta/beta_tool.rb +3 -1
  29. data/lib/anthropic/models/beta/beta_tool_bash_20241022.rb +3 -1
  30. data/lib/anthropic/models/beta/beta_tool_bash_20250124.rb +3 -1
  31. data/lib/anthropic/models/beta/beta_tool_computer_use_20241022.rb +3 -1
  32. data/lib/anthropic/models/beta/beta_tool_computer_use_20250124.rb +3 -1
  33. data/lib/anthropic/models/beta/beta_tool_computer_use_20251124.rb +3 -1
  34. data/lib/anthropic/models/beta/beta_tool_search_tool_bm25_20251119.rb +3 -1
  35. data/lib/anthropic/models/beta/beta_tool_search_tool_regex_20251119.rb +3 -1
  36. data/lib/anthropic/models/beta/beta_tool_text_editor_20241022.rb +3 -1
  37. data/lib/anthropic/models/beta/beta_tool_text_editor_20250124.rb +3 -1
  38. data/lib/anthropic/models/beta/beta_tool_text_editor_20250429.rb +3 -1
  39. data/lib/anthropic/models/beta/beta_tool_text_editor_20250728.rb +3 -1
  40. data/lib/anthropic/models/beta/beta_tool_union.rb +4 -1
  41. data/lib/anthropic/models/beta/beta_web_fetch_tool_20250910.rb +3 -1
  42. data/lib/anthropic/models/beta/beta_web_fetch_tool_20260209.rb +3 -1
  43. data/lib/anthropic/models/beta/beta_web_fetch_tool_20260309.rb +3 -1
  44. data/lib/anthropic/models/beta/beta_web_search_tool_20250305.rb +3 -1
  45. data/lib/anthropic/models/beta/beta_web_search_tool_20260209.rb +3 -1
  46. data/lib/anthropic/models/beta/beta_webhook_event.rb +2 -2
  47. data/lib/anthropic/models/beta/beta_webhook_event_data.rb +3 -1
  48. data/lib/anthropic/models/beta/beta_webhook_session_updated_event_data.rb +41 -0
  49. data/lib/anthropic/models/beta/message_count_tokens_params.rb +6 -3
  50. data/lib/anthropic/models/beta/message_create_params.rb +2 -2
  51. data/lib/anthropic/models/beta/messages/batch_create_params.rb +2 -2
  52. data/lib/anthropic/models/beta/unwrap_webhook_event.rb +2 -2
  53. data/lib/anthropic/models/code_execution_tool_20250522.rb +3 -1
  54. data/lib/anthropic/models/code_execution_tool_20250825.rb +3 -1
  55. data/lib/anthropic/models/code_execution_tool_20260120.rb +3 -1
  56. data/lib/anthropic/models/code_execution_tool_20260521.rb +82 -0
  57. data/lib/anthropic/models/memory_tool_20250818.rb +3 -1
  58. data/lib/anthropic/models/message_count_tokens_params.rb +2 -2
  59. data/lib/anthropic/models/message_count_tokens_tool.rb +4 -1
  60. data/lib/anthropic/models/message_create_params.rb +2 -2
  61. data/lib/anthropic/models/messages/batch_create_params.rb +2 -2
  62. data/lib/anthropic/models/refusal_stop_details.rb +3 -7
  63. data/lib/anthropic/models/tool.rb +3 -1
  64. data/lib/anthropic/models/tool_bash_20250124.rb +3 -1
  65. data/lib/anthropic/models/tool_search_tool_bm25_20251119.rb +3 -1
  66. data/lib/anthropic/models/tool_search_tool_regex_20251119.rb +3 -1
  67. data/lib/anthropic/models/tool_text_editor_20250124.rb +3 -1
  68. data/lib/anthropic/models/tool_text_editor_20250429.rb +3 -1
  69. data/lib/anthropic/models/tool_text_editor_20250728.rb +3 -1
  70. data/lib/anthropic/models/tool_union.rb +4 -1
  71. data/lib/anthropic/models/web_fetch_tool_20250910.rb +3 -1
  72. data/lib/anthropic/models/web_fetch_tool_20260209.rb +3 -1
  73. data/lib/anthropic/models/web_fetch_tool_20260309.rb +3 -1
  74. data/lib/anthropic/models/web_search_tool_20250305.rb +3 -1
  75. data/lib/anthropic/models/web_search_tool_20260209.rb +3 -1
  76. data/lib/anthropic/models.rb +2 -0
  77. data/lib/anthropic/request_options.rb +9 -0
  78. data/lib/anthropic/resources/beta/messages.rb +3 -3
  79. data/lib/anthropic/resources/messages.rb +3 -3
  80. data/lib/anthropic/version.rb +1 -1
  81. data/lib/anthropic.rb +6 -0
  82. data/rbi/anthropic/client.rbi +7 -2
  83. data/rbi/anthropic/errors.rbi +5 -0
  84. data/rbi/anthropic/helpers/aws/client.rbi +3 -6
  85. data/rbi/anthropic/helpers/bedrock/client.rbi +24 -13
  86. data/rbi/anthropic/helpers/bedrock/event_stream.rbi +25 -0
  87. data/rbi/anthropic/helpers/bedrock/mantle_client.rbi +3 -6
  88. data/rbi/anthropic/helpers/vertex/client.rbi +28 -8
  89. data/rbi/anthropic/internal/transport/base_client.rbi +39 -4
  90. data/rbi/anthropic/internal/util.rbi +5 -0
  91. data/rbi/anthropic/middleware.rbi +338 -0
  92. data/rbi/anthropic/models/beta/beta_advisor_tool_20260301.rbi +7 -1
  93. data/rbi/anthropic/models/beta/beta_code_execution_tool_20250522.rbi +7 -1
  94. data/rbi/anthropic/models/beta/beta_code_execution_tool_20250825.rbi +7 -1
  95. data/rbi/anthropic/models/beta/beta_code_execution_tool_20260120.rbi +7 -1
  96. data/rbi/anthropic/models/beta/beta_code_execution_tool_20260521.rbi +178 -0
  97. data/rbi/anthropic/models/beta/beta_fallback_block.rbi +19 -4
  98. data/rbi/anthropic/models/beta/beta_fallback_block_param.rbi +23 -13
  99. data/rbi/anthropic/models/beta/beta_fallback_refusal_trigger.rbi +108 -0
  100. data/rbi/anthropic/models/beta/beta_memory_tool_20250818.rbi +7 -1
  101. data/rbi/anthropic/models/beta/beta_refusal_stop_details.rbi +3 -9
  102. data/rbi/anthropic/models/beta/beta_tool.rbi +7 -1
  103. data/rbi/anthropic/models/beta/beta_tool_bash_20241022.rbi +7 -1
  104. data/rbi/anthropic/models/beta/beta_tool_bash_20250124.rbi +7 -1
  105. data/rbi/anthropic/models/beta/beta_tool_computer_use_20241022.rbi +7 -1
  106. data/rbi/anthropic/models/beta/beta_tool_computer_use_20250124.rbi +7 -1
  107. data/rbi/anthropic/models/beta/beta_tool_computer_use_20251124.rbi +7 -1
  108. data/rbi/anthropic/models/beta/beta_tool_search_tool_bm25_20251119.rbi +7 -1
  109. data/rbi/anthropic/models/beta/beta_tool_search_tool_regex_20251119.rbi +7 -1
  110. data/rbi/anthropic/models/beta/beta_tool_text_editor_20241022.rbi +7 -1
  111. data/rbi/anthropic/models/beta/beta_tool_text_editor_20250124.rbi +7 -1
  112. data/rbi/anthropic/models/beta/beta_tool_text_editor_20250429.rbi +7 -1
  113. data/rbi/anthropic/models/beta/beta_tool_text_editor_20250728.rbi +7 -1
  114. data/rbi/anthropic/models/beta/beta_tool_union.rbi +1 -0
  115. data/rbi/anthropic/models/beta/beta_web_fetch_tool_20250910.rbi +7 -1
  116. data/rbi/anthropic/models/beta/beta_web_fetch_tool_20260209.rbi +7 -1
  117. data/rbi/anthropic/models/beta/beta_web_fetch_tool_20260309.rbi +7 -1
  118. data/rbi/anthropic/models/beta/beta_web_search_tool_20250305.rbi +7 -1
  119. data/rbi/anthropic/models/beta/beta_web_search_tool_20260209.rbi +7 -1
  120. data/rbi/anthropic/models/beta/beta_webhook_event.rbi +6 -3
  121. data/rbi/anthropic/models/beta/beta_webhook_event_data.rbi +2 -1
  122. data/rbi/anthropic/models/beta/beta_webhook_session_updated_event_data.rbi +63 -0
  123. data/rbi/anthropic/models/beta/message_count_tokens_params.rbi +5 -0
  124. data/rbi/anthropic/models/beta/message_create_params.rbi +4 -0
  125. data/rbi/anthropic/models/beta/messages/batch_create_params.rbi +4 -0
  126. data/rbi/anthropic/models/beta/unwrap_webhook_event.rbi +2 -1
  127. data/rbi/anthropic/models/code_execution_tool_20250522.rbi +7 -1
  128. data/rbi/anthropic/models/code_execution_tool_20250825.rbi +7 -1
  129. data/rbi/anthropic/models/code_execution_tool_20260120.rbi +7 -1
  130. data/rbi/anthropic/models/code_execution_tool_20260521.rbi +168 -0
  131. data/rbi/anthropic/models/memory_tool_20250818.rbi +7 -1
  132. data/rbi/anthropic/models/message_count_tokens_params.rbi +4 -0
  133. data/rbi/anthropic/models/message_count_tokens_tool.rbi +1 -0
  134. data/rbi/anthropic/models/message_create_params.rbi +4 -0
  135. data/rbi/anthropic/models/messages/batch_create_params.rbi +4 -0
  136. data/rbi/anthropic/models/refusal_stop_details.rbi +3 -9
  137. data/rbi/anthropic/models/tool.rbi +7 -1
  138. data/rbi/anthropic/models/tool_bash_20250124.rbi +7 -1
  139. data/rbi/anthropic/models/tool_search_tool_bm25_20251119.rbi +7 -1
  140. data/rbi/anthropic/models/tool_search_tool_regex_20251119.rbi +7 -1
  141. data/rbi/anthropic/models/tool_text_editor_20250124.rbi +7 -1
  142. data/rbi/anthropic/models/tool_text_editor_20250429.rbi +7 -1
  143. data/rbi/anthropic/models/tool_text_editor_20250728.rbi +7 -1
  144. data/rbi/anthropic/models/tool_union.rbi +1 -0
  145. data/rbi/anthropic/models/web_fetch_tool_20250910.rbi +7 -1
  146. data/rbi/anthropic/models/web_fetch_tool_20260209.rbi +7 -1
  147. data/rbi/anthropic/models/web_fetch_tool_20260309.rbi +7 -1
  148. data/rbi/anthropic/models/web_search_tool_20250305.rbi +7 -1
  149. data/rbi/anthropic/models/web_search_tool_20260209.rbi +7 -1
  150. data/rbi/anthropic/models.rbi +2 -0
  151. data/rbi/anthropic/request_options.rbi +5 -0
  152. data/rbi/anthropic/resources/beta/messages.rbi +3 -0
  153. data/rbi/anthropic/resources/messages.rbi +3 -0
  154. data/sig/anthropic/client.rbs +2 -1
  155. data/sig/anthropic/errors.rbs +3 -0
  156. data/sig/anthropic/helpers/bedrock/client.rbs +12 -4
  157. data/sig/anthropic/helpers/vertex/client.rbs +17 -4
  158. data/sig/anthropic/internal/transport/base_client.rbs +18 -3
  159. data/sig/anthropic/internal/util.rbs +2 -0
  160. data/sig/anthropic/middleware.rbs +117 -0
  161. data/sig/anthropic/models/beta/beta_advisor_tool_20260301.rbs +5 -1
  162. data/sig/anthropic/models/beta/beta_code_execution_tool_20250522.rbs +5 -1
  163. data/sig/anthropic/models/beta/beta_code_execution_tool_20250825.rbs +5 -1
  164. data/sig/anthropic/models/beta/beta_code_execution_tool_20260120.rbs +5 -1
  165. data/sig/anthropic/models/beta/beta_code_execution_tool_20260521.rbs +74 -0
  166. data/sig/anthropic/models/beta/beta_fallback_block.rbs +5 -0
  167. data/sig/anthropic/models/beta/beta_fallback_block_param.rbs +9 -2
  168. data/sig/anthropic/models/beta/beta_fallback_refusal_trigger.rbs +42 -0
  169. data/sig/anthropic/models/beta/beta_memory_tool_20250818.rbs +5 -1
  170. data/sig/anthropic/models/beta/beta_tool.rbs +5 -1
  171. data/sig/anthropic/models/beta/beta_tool_bash_20241022.rbs +5 -1
  172. data/sig/anthropic/models/beta/beta_tool_bash_20250124.rbs +5 -1
  173. data/sig/anthropic/models/beta/beta_tool_computer_use_20241022.rbs +5 -1
  174. data/sig/anthropic/models/beta/beta_tool_computer_use_20250124.rbs +5 -1
  175. data/sig/anthropic/models/beta/beta_tool_computer_use_20251124.rbs +5 -1
  176. data/sig/anthropic/models/beta/beta_tool_search_tool_bm25_20251119.rbs +5 -1
  177. data/sig/anthropic/models/beta/beta_tool_search_tool_regex_20251119.rbs +5 -1
  178. data/sig/anthropic/models/beta/beta_tool_text_editor_20241022.rbs +5 -1
  179. data/sig/anthropic/models/beta/beta_tool_text_editor_20250124.rbs +5 -1
  180. data/sig/anthropic/models/beta/beta_tool_text_editor_20250429.rbs +5 -1
  181. data/sig/anthropic/models/beta/beta_tool_text_editor_20250728.rbs +5 -1
  182. data/sig/anthropic/models/beta/beta_tool_union.rbs +1 -0
  183. data/sig/anthropic/models/beta/beta_web_fetch_tool_20250910.rbs +5 -1
  184. data/sig/anthropic/models/beta/beta_web_fetch_tool_20260209.rbs +5 -1
  185. data/sig/anthropic/models/beta/beta_web_fetch_tool_20260309.rbs +5 -1
  186. data/sig/anthropic/models/beta/beta_web_search_tool_20250305.rbs +5 -1
  187. data/sig/anthropic/models/beta/beta_web_search_tool_20260209.rbs +5 -1
  188. data/sig/anthropic/models/beta/beta_webhook_event_data.rbs +1 -0
  189. data/sig/anthropic/models/beta/beta_webhook_session_updated_event_data.rbs +39 -0
  190. data/sig/anthropic/models/beta/message_count_tokens_params.rbs +1 -0
  191. data/sig/anthropic/models/code_execution_tool_20250522.rbs +5 -1
  192. data/sig/anthropic/models/code_execution_tool_20250825.rbs +5 -1
  193. data/sig/anthropic/models/code_execution_tool_20260120.rbs +5 -1
  194. data/sig/anthropic/models/code_execution_tool_20260521.rbs +70 -0
  195. data/sig/anthropic/models/memory_tool_20250818.rbs +5 -1
  196. data/sig/anthropic/models/message_count_tokens_tool.rbs +1 -0
  197. data/sig/anthropic/models/tool.rbs +5 -1
  198. data/sig/anthropic/models/tool_bash_20250124.rbs +5 -1
  199. data/sig/anthropic/models/tool_search_tool_bm25_20251119.rbs +5 -1
  200. data/sig/anthropic/models/tool_search_tool_regex_20251119.rbs +5 -1
  201. data/sig/anthropic/models/tool_text_editor_20250124.rbs +5 -1
  202. data/sig/anthropic/models/tool_text_editor_20250429.rbs +5 -1
  203. data/sig/anthropic/models/tool_text_editor_20250728.rbs +5 -1
  204. data/sig/anthropic/models/tool_union.rbs +1 -0
  205. data/sig/anthropic/models/web_fetch_tool_20250910.rbs +5 -1
  206. data/sig/anthropic/models/web_fetch_tool_20260209.rbs +5 -1
  207. data/sig/anthropic/models/web_fetch_tool_20260309.rbs +5 -1
  208. data/sig/anthropic/models/web_search_tool_20250305.rbs +5 -1
  209. data/sig/anthropic/models/web_search_tool_20260209.rbs +5 -1
  210. data/sig/anthropic/models.rbs +2 -0
  211. data/sig/anthropic/request_options.rbs +4 -1
  212. metadata +19 -2
@@ -0,0 +1,338 @@
1
+ # typed: strong
2
+
3
+ module Anthropic
4
+ # The per-attempt request object a middleware sees.
5
+ class APIRequest
6
+ MEMBERS = T.let(T.unsafe(nil), T::Array[Symbol])
7
+
8
+ sig { returns(Symbol) }
9
+ attr_reader :method
10
+
11
+ sig { returns(URI::Generic) }
12
+ attr_reader :url
13
+
14
+ sig { returns(T::Hash[String, String]) }
15
+ attr_reader :headers
16
+
17
+ sig { returns(T.nilable(T.anything)) }
18
+ attr_reader :body
19
+
20
+ sig do
21
+ returns(
22
+ T.nilable(
23
+ T::Class[
24
+ Anthropic::Internal::Type::BaseStream[
25
+ T.anything,
26
+ Anthropic::Internal::Type::BaseModel
27
+ ]
28
+ ]
29
+ )
30
+ )
31
+ end
32
+ attr_reader :stream
33
+
34
+ sig { returns(T.nilable(Anthropic::Internal::Type::Converter::Input)) }
35
+ attr_reader :cast_to
36
+
37
+ sig do
38
+ returns(
39
+ T.nilable(
40
+ T.any(
41
+ Symbol,
42
+ Integer,
43
+ T::Array[T.any(Symbol, Integer)],
44
+ T.proc.params(arg0: T.anything).returns(T.anything)
45
+ )
46
+ )
47
+ )
48
+ end
49
+ attr_reader :unwrap
50
+
51
+ sig { returns(T::Hash[Symbol, T.anything]) }
52
+ attr_reader :options
53
+
54
+ sig { returns(Integer) }
55
+ attr_reader :retry_count
56
+
57
+ sig { returns(T::Hash[Symbol, T.anything]) }
58
+ attr_reader :metadata
59
+
60
+ sig { returns(T::Boolean) }
61
+ def streaming?
62
+ end
63
+
64
+ sig { returns(T::Boolean) }
65
+ def retry?
66
+ end
67
+
68
+ sig { returns(Float) }
69
+ def timeout
70
+ end
71
+
72
+ sig do
73
+ params(
74
+ method: Symbol,
75
+ url: URI::Generic,
76
+ headers: T::Hash[String, String],
77
+ body: T.nilable(T.anything),
78
+ stream:
79
+ T.nilable(
80
+ T::Class[
81
+ Anthropic::Internal::Type::BaseStream[
82
+ T.anything,
83
+ Anthropic::Internal::Type::BaseModel
84
+ ]
85
+ ]
86
+ ),
87
+ cast_to: T.nilable(Anthropic::Internal::Type::Converter::Input),
88
+ unwrap:
89
+ T.nilable(
90
+ T.any(
91
+ Symbol,
92
+ Integer,
93
+ T::Array[T.any(Symbol, Integer)],
94
+ T.proc.params(arg0: T.anything).returns(T.anything)
95
+ )
96
+ ),
97
+ options: T::Hash[Symbol, T.anything],
98
+ retry_count: Integer,
99
+ metadata: T::Hash[Symbol, T.anything]
100
+ ).returns(T.attached_class)
101
+ end
102
+ def self.new(
103
+ method:,
104
+ url:,
105
+ headers:,
106
+ body:,
107
+ stream:,
108
+ cast_to:,
109
+ unwrap:,
110
+ options:,
111
+ retry_count:,
112
+ metadata:
113
+ )
114
+ end
115
+
116
+ sig do
117
+ params(
118
+ method: Symbol,
119
+ url: URI::Generic,
120
+ headers: T::Hash[String, String],
121
+ body: T.nilable(T.anything),
122
+ stream:
123
+ T.nilable(
124
+ T::Class[
125
+ Anthropic::Internal::Type::BaseStream[
126
+ T.anything,
127
+ Anthropic::Internal::Type::BaseModel
128
+ ]
129
+ ]
130
+ ),
131
+ cast_to: T.nilable(Anthropic::Internal::Type::Converter::Input),
132
+ unwrap:
133
+ T.nilable(
134
+ T.any(
135
+ Symbol,
136
+ Integer,
137
+ T::Array[T.any(Symbol, Integer)],
138
+ T.proc.params(arg0: T.anything).returns(T.anything)
139
+ )
140
+ ),
141
+ options: T::Hash[Symbol, T.anything],
142
+ retry_count: Integer,
143
+ metadata: T::Hash[Symbol, T.anything]
144
+ ).returns(T.self_type)
145
+ end
146
+ def with(
147
+ method: self.method,
148
+ url: self.url,
149
+ headers: self.headers,
150
+ body: self.body,
151
+ stream: self.stream,
152
+ cast_to: self.cast_to,
153
+ unwrap: self.unwrap,
154
+ options: self.options,
155
+ retry_count: self.retry_count,
156
+ metadata: self.metadata
157
+ )
158
+ end
159
+
160
+ sig { returns(T::Hash[Symbol, T.anything]) }
161
+ def to_h
162
+ end
163
+ end
164
+
165
+ class APIResponse
166
+ class ConsumedBodyError < Anthropic::Errors::Error
167
+ end
168
+
169
+ sig { returns(Integer) }
170
+ attr_reader :status
171
+
172
+ sig { returns(T::Hash[String, String]) }
173
+ attr_reader :headers
174
+
175
+ sig { returns(T.nilable(Net::HTTPResponse)) }
176
+ attr_reader :raw
177
+
178
+ sig { returns(T.nilable(Anthropic::APIRequest)) }
179
+ attr_reader :request
180
+
181
+ # @api private
182
+ sig do
183
+ params(
184
+ status: Integer,
185
+ raw: Net::HTTPResponse,
186
+ stream: T::Enumerable[String],
187
+ request: T.nilable(Anthropic::APIRequest)
188
+ ).returns(T.attached_class)
189
+ end
190
+ def self.wrap(status, raw, stream, request: nil)
191
+ end
192
+
193
+ sig do
194
+ params(
195
+ status: Integer,
196
+ headers: T::Hash[String, String],
197
+ body: T.nilable(T.any(T::Enumerable[String], String)),
198
+ raw: T.nilable(Net::HTTPResponse),
199
+ streaming: T.nilable(T::Boolean),
200
+ request: T.nilable(Anthropic::APIRequest)
201
+ ).returns(T.attached_class)
202
+ end
203
+ def self.new(
204
+ status:,
205
+ headers: {},
206
+ body: nil,
207
+ raw: nil,
208
+ streaming: nil,
209
+ request: nil
210
+ )
211
+ end
212
+
213
+ sig { returns(T::Enumerable[String]) }
214
+ def body
215
+ end
216
+
217
+ sig { returns(T::Boolean) }
218
+ def streaming?
219
+ end
220
+
221
+ sig { returns(T::Boolean) }
222
+ def retryable?
223
+ end
224
+
225
+ sig { params(force: T::Boolean).returns(T.self_type) }
226
+ def buffer!(force: false)
227
+ end
228
+
229
+ sig do
230
+ params(
231
+ streaming: T::Boolean,
232
+ blk:
233
+ T
234
+ .proc
235
+ .params(upstream: T::Enumerable[String])
236
+ .returns(T::Enumerable[String])
237
+ ).returns(Anthropic::APIResponse)
238
+ end
239
+ def wrap_body(streaming: streaming?, &blk)
240
+ end
241
+
242
+ sig { returns(T.anything) }
243
+ def parse
244
+ end
245
+
246
+ # @api private
247
+ sig do
248
+ returns(
249
+ [
250
+ Integer,
251
+ T.nilable(Net::HTTPResponse),
252
+ T::Hash[String, String],
253
+ T::Enumerable[String]
254
+ ]
255
+ )
256
+ end
257
+ def to_tuple
258
+ end
259
+ end
260
+
261
+ module Middleware
262
+ extend T::Helpers
263
+
264
+ abstract!
265
+
266
+ # Optional mixin naming the middleware contract — `include` it in a
267
+ # middleware class and implement `#call`. The SDK accepts any
268
+ # `#call(req, nxt)` object, so this is for discovery and type-checking.
269
+ sig do
270
+ abstract
271
+ .params(
272
+ request: Anthropic::APIRequest,
273
+ nxt:
274
+ T
275
+ .proc
276
+ .params(request: Anthropic::APIRequest)
277
+ .returns(Anthropic::APIResponse)
278
+ )
279
+ .returns(Anthropic::APIResponse)
280
+ end
281
+ def call(request, nxt)
282
+ end
283
+
284
+ # `(req, nxt) -> APIResponse` callable. `nxt` is itself `(req) -> APIResponse`.
285
+ Callable =
286
+ T.type_alias do
287
+ T
288
+ .proc
289
+ .params(
290
+ req: Anthropic::APIRequest,
291
+ nxt:
292
+ T
293
+ .proc
294
+ .params(req: Anthropic::APIRequest)
295
+ .returns(Anthropic::APIResponse)
296
+ )
297
+ .returns(Anthropic::APIResponse)
298
+ end
299
+
300
+ # A single chain entry — a {Callable} lambda, an object including
301
+ # {Anthropic::Middleware}, or any other object responding to
302
+ # `#call(req, nxt)`.
303
+ Entry =
304
+ T.type_alias do
305
+ T.any(Anthropic::Middleware, Anthropic::Middleware::Callable)
306
+ end
307
+
308
+ # The `middleware:` constructor option — a single entry or an array of them.
309
+ EntryOrArray =
310
+ T.type_alias do
311
+ T.any(
312
+ Anthropic::Middleware::Entry,
313
+ T::Array[Anthropic::Middleware::Entry]
314
+ )
315
+ end
316
+
317
+ class << self
318
+ # @api private
319
+ sig do
320
+ params(
321
+ list: T::Array[T.anything],
322
+ terminal:
323
+ T
324
+ .proc
325
+ .params(req: Anthropic::APIRequest)
326
+ .returns(Anthropic::APIResponse)
327
+ ).returns(
328
+ T
329
+ .proc
330
+ .params(req: Anthropic::APIRequest)
331
+ .returns(Anthropic::APIResponse)
332
+ )
333
+ end
334
+ def build_chain(list, terminal)
335
+ end
336
+ end
337
+ end
338
+ end
@@ -189,7 +189,8 @@ module Anthropic
189
189
  # Values: direct: The model can call this tool directly. code_execution_20250825:
190
190
  # The tool can be called from the code execution environment (v1).
191
191
  # code_execution_20260120: The tool can be called from the code execution
192
- # environment (v2 with persistence).
192
+ # environment (v2 with persistence). code_execution_20260521: The tool can be
193
+ # called from the code execution environment (v2 with persistence).
193
194
  module AllowedCaller
194
195
  extend Anthropic::Internal::Type::Enum
195
196
 
@@ -217,6 +218,11 @@ module Anthropic
217
218
  :code_execution_20260120,
218
219
  Anthropic::Beta::BetaAdvisorTool20260301::AllowedCaller::TaggedSymbol
219
220
  )
221
+ CODE_EXECUTION_20260521 =
222
+ T.let(
223
+ :code_execution_20260521,
224
+ Anthropic::Beta::BetaAdvisorTool20260301::AllowedCaller::TaggedSymbol
225
+ )
220
226
 
221
227
  sig do
222
228
  override.returns(
@@ -126,7 +126,8 @@ module Anthropic
126
126
  # Values: direct: The model can call this tool directly. code_execution_20250825:
127
127
  # The tool can be called from the code execution environment (v1).
128
128
  # code_execution_20260120: The tool can be called from the code execution
129
- # environment (v2 with persistence).
129
+ # environment (v2 with persistence). code_execution_20260521: The tool can be
130
+ # called from the code execution environment (v2 with persistence).
130
131
  module AllowedCaller
131
132
  extend Anthropic::Internal::Type::Enum
132
133
 
@@ -154,6 +155,11 @@ module Anthropic
154
155
  :code_execution_20260120,
155
156
  Anthropic::Beta::BetaCodeExecutionTool20250522::AllowedCaller::TaggedSymbol
156
157
  )
158
+ CODE_EXECUTION_20260521 =
159
+ T.let(
160
+ :code_execution_20260521,
161
+ Anthropic::Beta::BetaCodeExecutionTool20250522::AllowedCaller::TaggedSymbol
162
+ )
157
163
 
158
164
  sig do
159
165
  override.returns(
@@ -126,7 +126,8 @@ module Anthropic
126
126
  # Values: direct: The model can call this tool directly. code_execution_20250825:
127
127
  # The tool can be called from the code execution environment (v1).
128
128
  # code_execution_20260120: The tool can be called from the code execution
129
- # environment (v2 with persistence).
129
+ # environment (v2 with persistence). code_execution_20260521: The tool can be
130
+ # called from the code execution environment (v2 with persistence).
130
131
  module AllowedCaller
131
132
  extend Anthropic::Internal::Type::Enum
132
133
 
@@ -154,6 +155,11 @@ module Anthropic
154
155
  :code_execution_20260120,
155
156
  Anthropic::Beta::BetaCodeExecutionTool20250825::AllowedCaller::TaggedSymbol
156
157
  )
158
+ CODE_EXECUTION_20260521 =
159
+ T.let(
160
+ :code_execution_20260521,
161
+ Anthropic::Beta::BetaCodeExecutionTool20250825::AllowedCaller::TaggedSymbol
162
+ )
157
163
 
158
164
  sig do
159
165
  override.returns(
@@ -128,7 +128,8 @@ module Anthropic
128
128
  # Values: direct: The model can call this tool directly. code_execution_20250825:
129
129
  # The tool can be called from the code execution environment (v1).
130
130
  # code_execution_20260120: The tool can be called from the code execution
131
- # environment (v2 with persistence).
131
+ # environment (v2 with persistence). code_execution_20260521: The tool can be
132
+ # called from the code execution environment (v2 with persistence).
132
133
  module AllowedCaller
133
134
  extend Anthropic::Internal::Type::Enum
134
135
 
@@ -156,6 +157,11 @@ module Anthropic
156
157
  :code_execution_20260120,
157
158
  Anthropic::Beta::BetaCodeExecutionTool20260120::AllowedCaller::TaggedSymbol
158
159
  )
160
+ CODE_EXECUTION_20260521 =
161
+ T.let(
162
+ :code_execution_20260521,
163
+ Anthropic::Beta::BetaCodeExecutionTool20260120::AllowedCaller::TaggedSymbol
164
+ )
159
165
 
160
166
  sig do
161
167
  override.returns(
@@ -0,0 +1,178 @@
1
+ # typed: strong
2
+
3
+ module Anthropic
4
+ module Models
5
+ BetaCodeExecutionTool20260521 = Beta::BetaCodeExecutionTool20260521
6
+
7
+ module Beta
8
+ class BetaCodeExecutionTool20260521 < Anthropic::Internal::Type::BaseModel
9
+ OrHash =
10
+ T.type_alias do
11
+ T.any(
12
+ Anthropic::Beta::BetaCodeExecutionTool20260521,
13
+ Anthropic::Internal::AnyHash
14
+ )
15
+ end
16
+
17
+ # Name of the tool.
18
+ #
19
+ # This is how the tool will be called by the model and in `tool_use` blocks.
20
+ sig { returns(Symbol) }
21
+ attr_accessor :name
22
+
23
+ sig { returns(Symbol) }
24
+ attr_accessor :type
25
+
26
+ sig do
27
+ returns(
28
+ T.nilable(
29
+ T::Array[
30
+ Anthropic::Beta::BetaCodeExecutionTool20260521::AllowedCaller::OrSymbol
31
+ ]
32
+ )
33
+ )
34
+ end
35
+ attr_reader :allowed_callers
36
+
37
+ sig do
38
+ params(
39
+ allowed_callers:
40
+ T::Array[
41
+ Anthropic::Beta::BetaCodeExecutionTool20260521::AllowedCaller::OrSymbol
42
+ ]
43
+ ).void
44
+ end
45
+ attr_writer :allowed_callers
46
+
47
+ # Create a cache control breakpoint at this content block.
48
+ sig { returns(T.nilable(Anthropic::Beta::BetaCacheControlEphemeral)) }
49
+ attr_reader :cache_control
50
+
51
+ sig do
52
+ params(
53
+ cache_control:
54
+ T.nilable(Anthropic::Beta::BetaCacheControlEphemeral::OrHash)
55
+ ).void
56
+ end
57
+ attr_writer :cache_control
58
+
59
+ # If true, tool will not be included in initial system prompt. Only loaded when
60
+ # returned via tool_reference from tool search.
61
+ sig { returns(T.nilable(T::Boolean)) }
62
+ attr_reader :defer_loading
63
+
64
+ sig { params(defer_loading: T::Boolean).void }
65
+ attr_writer :defer_loading
66
+
67
+ # When true, guarantees schema validation on tool names and inputs
68
+ sig { returns(T.nilable(T::Boolean)) }
69
+ attr_reader :strict
70
+
71
+ sig { params(strict: T::Boolean).void }
72
+ attr_writer :strict
73
+
74
+ # Code execution tool with REPL state persistence.
75
+ sig do
76
+ params(
77
+ allowed_callers:
78
+ T::Array[
79
+ Anthropic::Beta::BetaCodeExecutionTool20260521::AllowedCaller::OrSymbol
80
+ ],
81
+ cache_control:
82
+ T.nilable(Anthropic::Beta::BetaCacheControlEphemeral::OrHash),
83
+ defer_loading: T::Boolean,
84
+ strict: T::Boolean,
85
+ name: Symbol,
86
+ type: Symbol
87
+ ).returns(T.attached_class)
88
+ end
89
+ def self.new(
90
+ allowed_callers: nil,
91
+ # Create a cache control breakpoint at this content block.
92
+ cache_control: nil,
93
+ # If true, tool will not be included in initial system prompt. Only loaded when
94
+ # returned via tool_reference from tool search.
95
+ defer_loading: nil,
96
+ # When true, guarantees schema validation on tool names and inputs
97
+ strict: nil,
98
+ # Name of the tool.
99
+ #
100
+ # This is how the tool will be called by the model and in `tool_use` blocks.
101
+ name: :code_execution,
102
+ type: :code_execution_20260521
103
+ )
104
+ end
105
+
106
+ sig do
107
+ override.returns(
108
+ {
109
+ name: Symbol,
110
+ type: Symbol,
111
+ allowed_callers:
112
+ T::Array[
113
+ Anthropic::Beta::BetaCodeExecutionTool20260521::AllowedCaller::OrSymbol
114
+ ],
115
+ cache_control:
116
+ T.nilable(Anthropic::Beta::BetaCacheControlEphemeral),
117
+ defer_loading: T::Boolean,
118
+ strict: T::Boolean
119
+ }
120
+ )
121
+ end
122
+ def to_hash
123
+ end
124
+
125
+ # Specifies who can invoke a tool.
126
+ #
127
+ # Values: direct: The model can call this tool directly. code_execution_20250825:
128
+ # The tool can be called from the code execution environment (v1).
129
+ # code_execution_20260120: The tool can be called from the code execution
130
+ # environment (v2 with persistence). code_execution_20260521: The tool can be
131
+ # called from the code execution environment (v2 with persistence).
132
+ module AllowedCaller
133
+ extend Anthropic::Internal::Type::Enum
134
+
135
+ TaggedSymbol =
136
+ T.type_alias do
137
+ T.all(
138
+ Symbol,
139
+ Anthropic::Beta::BetaCodeExecutionTool20260521::AllowedCaller
140
+ )
141
+ end
142
+ OrSymbol = T.type_alias { T.any(Symbol, String) }
143
+
144
+ DIRECT =
145
+ T.let(
146
+ :direct,
147
+ Anthropic::Beta::BetaCodeExecutionTool20260521::AllowedCaller::TaggedSymbol
148
+ )
149
+ CODE_EXECUTION_20250825 =
150
+ T.let(
151
+ :code_execution_20250825,
152
+ Anthropic::Beta::BetaCodeExecutionTool20260521::AllowedCaller::TaggedSymbol
153
+ )
154
+ CODE_EXECUTION_20260120 =
155
+ T.let(
156
+ :code_execution_20260120,
157
+ Anthropic::Beta::BetaCodeExecutionTool20260521::AllowedCaller::TaggedSymbol
158
+ )
159
+ CODE_EXECUTION_20260521 =
160
+ T.let(
161
+ :code_execution_20260521,
162
+ Anthropic::Beta::BetaCodeExecutionTool20260521::AllowedCaller::TaggedSymbol
163
+ )
164
+
165
+ sig do
166
+ override.returns(
167
+ T::Array[
168
+ Anthropic::Beta::BetaCodeExecutionTool20260521::AllowedCaller::TaggedSymbol
169
+ ]
170
+ )
171
+ end
172
+ def self.values
173
+ end
174
+ end
175
+ end
176
+ end
177
+ end
178
+ end
@@ -32,16 +32,27 @@ module Anthropic
32
32
  sig { params(to: Anthropic::Beta::BetaFallbackInfo::OrHash).void }
33
33
  attr_writer :to
34
34
 
35
+ # What caused the `from` model to hand over at this hop.
36
+ sig { returns(Anthropic::Beta::BetaFallbackRefusalTrigger) }
37
+ attr_reader :trigger
38
+
39
+ sig do
40
+ params(
41
+ trigger: Anthropic::Beta::BetaFallbackRefusalTrigger::OrHash
42
+ ).void
43
+ end
44
+ attr_writer :trigger
45
+
35
46
  sig { returns(Symbol) }
36
47
  attr_accessor :type
37
48
 
38
49
  # Marks the point in `content` where one model's output gives way to the next.
39
50
  #
40
51
  # One block appears per hop where a preceding model actually ran this turn and
41
- # declined. A turn routed directly by the sticky decision has no such boundary and
42
- # carries no block — the signal for whether a fallback model served the response
43
- # is the presence of a `fallback_message` entry in `usage.iterations`, not this
44
- # block.
52
+ # declined. A turn where no preceding model ran and declined has no such boundary
53
+ # and carries no block — the signal for whether a fallback model served the
54
+ # response is the presence of a `fallback_message` entry in `usage.iterations`,
55
+ # not this block.
45
56
  #
46
57
  # The block is treated like a server-tool content block for streaming: it arrives
47
58
  # via the standard `content_block_start` / `content_block_stop` pair and carries
@@ -50,6 +61,7 @@ module Anthropic
50
61
  params(
51
62
  from: Anthropic::Beta::BetaFallbackInfo::OrHash,
52
63
  to: Anthropic::Beta::BetaFallbackInfo::OrHash,
64
+ trigger: Anthropic::Beta::BetaFallbackRefusalTrigger::OrHash,
53
65
  type: Symbol
54
66
  ).returns(T.attached_class)
55
67
  end
@@ -62,6 +74,8 @@ module Anthropic
62
74
  # The fallback model producing the content that follows this block. Its `model` is
63
75
  # always the canonical id.
64
76
  to:,
77
+ # What caused the `from` model to hand over at this hop.
78
+ trigger:,
65
79
  type: :fallback
66
80
  )
67
81
  end
@@ -71,6 +85,7 @@ module Anthropic
71
85
  {
72
86
  from: Anthropic::Beta::BetaFallbackInfo,
73
87
  to: Anthropic::Beta::BetaFallbackInfo,
88
+ trigger: Anthropic::Beta::BetaFallbackRefusalTrigger,
74
89
  type: Symbol
75
90
  }
76
91
  )