anthropic 1.13.0 → 1.15.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 (95) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -0
  3. data/README.md +31 -1
  4. data/lib/anthropic/helpers/input_schema/base_model.rb +6 -3
  5. data/lib/anthropic/helpers/input_schema/json_schema_converter.rb +9 -3
  6. data/lib/anthropic/helpers/input_schema/supported_schemas.rb +106 -0
  7. data/lib/anthropic/helpers/input_schema/union_of.rb +3 -1
  8. data/lib/anthropic/helpers/messages.rb +107 -0
  9. data/lib/anthropic/helpers/streaming/message_stream.rb +54 -43
  10. data/lib/anthropic/helpers/tools/base_tool.rb +82 -0
  11. data/lib/anthropic/helpers/tools/runner.rb +156 -0
  12. data/lib/anthropic/helpers/tools.rb +5 -0
  13. data/lib/anthropic/internal/transport/base_client.rb +7 -1
  14. data/lib/anthropic/internal/transport/pooled_net_requester.rb +6 -2
  15. data/lib/anthropic/models/beta/beta_code_execution_tool_20250522.rb +8 -1
  16. data/lib/anthropic/models/beta/beta_code_execution_tool_20250825.rb +8 -1
  17. data/lib/anthropic/models/beta/beta_json_output_format.rb +27 -0
  18. data/lib/anthropic/models/beta/beta_memory_tool_20250818.rb +8 -1
  19. data/lib/anthropic/models/beta/beta_tool.rb +8 -1
  20. data/lib/anthropic/models/beta/beta_tool_bash_20241022.rb +8 -1
  21. data/lib/anthropic/models/beta/beta_tool_bash_20250124.rb +8 -1
  22. data/lib/anthropic/models/beta/beta_tool_computer_use_20241022.rb +8 -1
  23. data/lib/anthropic/models/beta/beta_tool_computer_use_20250124.rb +8 -1
  24. data/lib/anthropic/models/beta/beta_tool_text_editor_20241022.rb +8 -1
  25. data/lib/anthropic/models/beta/beta_tool_text_editor_20250124.rb +8 -1
  26. data/lib/anthropic/models/beta/beta_tool_text_editor_20250429.rb +8 -1
  27. data/lib/anthropic/models/beta/beta_tool_text_editor_20250728.rb +8 -1
  28. data/lib/anthropic/models/beta/beta_tool_use_block.rb +14 -0
  29. data/lib/anthropic/models/beta/beta_web_fetch_tool_20250910.rb +8 -1
  30. data/lib/anthropic/models/beta/beta_web_search_tool_20250305.rb +8 -1
  31. data/lib/anthropic/models/beta/message_count_tokens_params.rb +9 -1
  32. data/lib/anthropic/models/beta/message_create_params.rb +9 -1
  33. data/lib/anthropic/models/beta/messages/batch_create_params.rb +9 -1
  34. data/lib/anthropic/models/tool_use_block.rb +6 -6
  35. data/lib/anthropic/resources/beta/messages/batches.rb +6 -6
  36. data/lib/anthropic/resources/beta/messages.rb +37 -11
  37. data/lib/anthropic/resources/messages/batches.rb +6 -6
  38. data/lib/anthropic/resources/messages.rb +12 -84
  39. data/lib/anthropic/version.rb +1 -1
  40. data/lib/anthropic.rb +16 -10
  41. data/manifest.yaml +1 -0
  42. data/rbi/anthropic/helpers/input_schema/base_model.rbi +7 -2
  43. data/rbi/anthropic/helpers/tools/base_tool.rbi +51 -0
  44. data/rbi/anthropic/helpers/tools/runner.rbi +40 -0
  45. data/rbi/anthropic/helpers/tools.rbi +5 -0
  46. data/rbi/anthropic/internal/transport/base_client.rbi +5 -0
  47. data/rbi/anthropic/internal/transport/pooled_net_requester.rbi +6 -2
  48. data/rbi/anthropic/internal/type/base_model.rbi +8 -4
  49. data/rbi/anthropic/models/beta/beta_code_execution_tool_20250522.rbi +10 -1
  50. data/rbi/anthropic/models/beta/beta_code_execution_tool_20250825.rbi +10 -1
  51. data/rbi/anthropic/models/beta/beta_json_output_format.rbi +46 -0
  52. data/rbi/anthropic/models/beta/beta_memory_tool_20250818.rbi +10 -1
  53. data/rbi/anthropic/models/beta/beta_tool.rbi +9 -0
  54. data/rbi/anthropic/models/beta/beta_tool_bash_20241022.rbi +10 -1
  55. data/rbi/anthropic/models/beta/beta_tool_bash_20250124.rbi +10 -1
  56. data/rbi/anthropic/models/beta/beta_tool_computer_use_20241022.rbi +10 -1
  57. data/rbi/anthropic/models/beta/beta_tool_computer_use_20250124.rbi +10 -1
  58. data/rbi/anthropic/models/beta/beta_tool_text_editor_20241022.rbi +10 -1
  59. data/rbi/anthropic/models/beta/beta_tool_text_editor_20250124.rbi +10 -1
  60. data/rbi/anthropic/models/beta/beta_tool_text_editor_20250429.rbi +10 -1
  61. data/rbi/anthropic/models/beta/beta_tool_text_editor_20250728.rbi +10 -1
  62. data/rbi/anthropic/models/beta/beta_web_fetch_tool_20250910.rbi +10 -1
  63. data/rbi/anthropic/models/beta/beta_web_search_tool_20250305.rbi +9 -0
  64. data/rbi/anthropic/models/beta/message_count_tokens_params.rbi +17 -0
  65. data/rbi/anthropic/models/beta/message_create_params.rbi +17 -0
  66. data/rbi/anthropic/models/beta/messages/batch_create_params.rbi +18 -0
  67. data/rbi/anthropic/models/tool_use_block.rbi +3 -0
  68. data/rbi/anthropic/resources/beta/messages/batches.rbi +6 -6
  69. data/rbi/anthropic/resources/beta/messages.rbi +313 -3
  70. data/rbi/anthropic/resources/messages/batches.rbi +6 -6
  71. data/rbi/anthropic/resources/messages.rbi +5 -3
  72. data/sig/anthropic/internal/transport/base_client.rbs +2 -0
  73. data/sig/anthropic/internal/transport/pooled_net_requester.rbs +4 -1
  74. data/sig/anthropic/models/beta/beta_code_execution_tool_20250522.rbs +9 -2
  75. data/sig/anthropic/models/beta/beta_code_execution_tool_20250825.rbs +9 -2
  76. data/sig/anthropic/models/beta/beta_json_output_format.rbs +23 -0
  77. data/sig/anthropic/models/beta/beta_memory_tool_20250818.rbs +9 -2
  78. data/sig/anthropic/models/beta/beta_tool.rbs +7 -0
  79. data/sig/anthropic/models/beta/beta_tool_bash_20241022.rbs +9 -2
  80. data/sig/anthropic/models/beta/beta_tool_bash_20250124.rbs +9 -2
  81. data/sig/anthropic/models/beta/beta_tool_computer_use_20241022.rbs +9 -2
  82. data/sig/anthropic/models/beta/beta_tool_computer_use_20250124.rbs +9 -2
  83. data/sig/anthropic/models/beta/beta_tool_text_editor_20241022.rbs +9 -2
  84. data/sig/anthropic/models/beta/beta_tool_text_editor_20250124.rbs +9 -2
  85. data/sig/anthropic/models/beta/beta_tool_text_editor_20250429.rbs +9 -2
  86. data/sig/anthropic/models/beta/beta_tool_text_editor_20250728.rbs +9 -2
  87. data/sig/anthropic/models/beta/beta_web_fetch_tool_20250910.rbs +9 -2
  88. data/sig/anthropic/models/beta/beta_web_search_tool_20250305.rbs +7 -0
  89. data/sig/anthropic/models/beta/message_count_tokens_params.rbs +5 -0
  90. data/sig/anthropic/models/beta/message_create_params.rbs +5 -0
  91. data/sig/anthropic/models/beta/messages/batch_create_params.rbs +5 -0
  92. data/sig/anthropic/resources/beta/messages.rbs +3 -0
  93. metadata +14 -4
  94. data/lib/anthropic/helpers/input_schema/property_mapping.rb +0 -47
  95. /data/rbi/anthropic/helpers/{structured_output.rbi → input_schema.rbi} +0 -0
@@ -296,6 +296,18 @@ module Anthropic
296
296
  end
297
297
  attr_writer :metadata
298
298
 
299
+ # A schema to specify Claude's output format in responses.
300
+ sig { returns(T.nilable(Anthropic::Beta::BetaJSONOutputFormat)) }
301
+ attr_reader :output_format
302
+
303
+ sig do
304
+ params(
305
+ output_format:
306
+ T.nilable(Anthropic::Beta::BetaJSONOutputFormat::OrHash)
307
+ ).void
308
+ end
309
+ attr_writer :output_format
310
+
299
311
  # Determines whether to use priority capacity (if available) or standard capacity
300
312
  # for this request.
301
313
  #
@@ -618,6 +630,8 @@ module Anthropic
618
630
  Anthropic::Beta::BetaRequestMCPServerURLDefinition::OrHash
619
631
  ],
620
632
  metadata: Anthropic::Beta::BetaMetadata::OrHash,
633
+ output_format:
634
+ T.nilable(Anthropic::Beta::BetaJSONOutputFormat::OrHash),
621
635
  service_tier:
622
636
  Anthropic::Beta::Messages::BatchCreateParams::Request::Params::ServiceTier::OrSymbol,
623
637
  stop_sequences: T::Array[String],
@@ -750,6 +764,8 @@ module Anthropic
750
764
  mcp_servers: nil,
751
765
  # An object describing metadata about the request.
752
766
  metadata: nil,
767
+ # A schema to specify Claude's output format in responses.
768
+ output_format: nil,
753
769
  # Determines whether to use priority capacity (if available) or standard capacity
754
770
  # for this request.
755
771
  #
@@ -912,6 +928,8 @@ module Anthropic
912
928
  Anthropic::Beta::BetaRequestMCPServerURLDefinition
913
929
  ],
914
930
  metadata: Anthropic::Beta::BetaMetadata,
931
+ output_format:
932
+ T.nilable(Anthropic::Beta::BetaJSONOutputFormat),
915
933
  service_tier:
916
934
  Anthropic::Beta::Messages::BatchCreateParams::Request::Params::ServiceTier::OrSymbol,
917
935
  stop_sequences: T::Array[String],
@@ -20,6 +20,9 @@ module Anthropic
20
20
  sig { returns(Symbol) }
21
21
  attr_accessor :type
22
22
 
23
+ sig { returns(T.nilable(T.anything)) }
24
+ attr_accessor :parsed
25
+
23
26
  sig do
24
27
  params(
25
28
  id: String,
@@ -12,7 +12,7 @@ module Anthropic
12
12
  # can take up to 24 hours to complete.
13
13
  #
14
14
  # Learn more about the Message Batches API in our
15
- # [user guide](/en/docs/build-with-claude/batch-processing)
15
+ # [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
16
16
  sig do
17
17
  params(
18
18
  requests:
@@ -39,7 +39,7 @@ module Anthropic
39
39
  # `results_url` field in the response.
40
40
  #
41
41
  # Learn more about the Message Batches API in our
42
- # [user guide](/en/docs/build-with-claude/batch-processing)
42
+ # [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
43
43
  sig do
44
44
  params(
45
45
  message_batch_id: String,
@@ -61,7 +61,7 @@ module Anthropic
61
61
  # returned first.
62
62
  #
63
63
  # Learn more about the Message Batches API in our
64
- # [user guide](/en/docs/build-with-claude/batch-processing)
64
+ # [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
65
65
  sig do
66
66
  params(
67
67
  after_id: String,
@@ -99,7 +99,7 @@ module Anthropic
99
99
  # like to delete an in-progress batch, you must first cancel it.
100
100
  #
101
101
  # Learn more about the Message Batches API in our
102
- # [user guide](/en/docs/build-with-claude/batch-processing)
102
+ # [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
103
103
  sig do
104
104
  params(
105
105
  message_batch_id: String,
@@ -128,7 +128,7 @@ module Anthropic
128
128
  # non-interruptible.
129
129
  #
130
130
  # Learn more about the Message Batches API in our
131
- # [user guide](/en/docs/build-with-claude/batch-processing)
131
+ # [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
132
132
  sig do
133
133
  params(
134
134
  message_batch_id: String,
@@ -153,7 +153,7 @@ module Anthropic
153
153
  # requests. Use the `custom_id` field to match results to requests.
154
154
  #
155
155
  # Learn more about the Message Batches API in our
156
- # [user guide](/en/docs/build-with-claude/batch-processing)
156
+ # [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
157
157
  sig do
158
158
  params(
159
159
  message_batch_id: String,
@@ -7,6 +7,302 @@ module Anthropic
7
7
  sig { returns(Anthropic::Resources::Beta::Messages::Batches) }
8
8
  attr_reader :batches
9
9
 
10
+ sig do
11
+ params(
12
+ max_tokens: Integer,
13
+ messages: T::Array[Anthropic::Beta::BetaMessageParam::OrHash],
14
+ model: T.any(Anthropic::Model::OrSymbol, String),
15
+ container:
16
+ T.nilable(
17
+ T.any(Anthropic::Beta::BetaContainerParams::OrHash, String)
18
+ ),
19
+ context_management:
20
+ T.nilable(Anthropic::Beta::BetaContextManagementConfig::OrHash),
21
+ mcp_servers:
22
+ T::Array[
23
+ Anthropic::Beta::BetaRequestMCPServerURLDefinition::OrHash
24
+ ],
25
+ metadata: Anthropic::Beta::BetaMetadata::OrHash,
26
+ service_tier:
27
+ Anthropic::Beta::MessageCreateParams::ServiceTier::OrSymbol,
28
+ stop_sequences: T::Array[String],
29
+ system_: Anthropic::Beta::MessageCreateParams::System::Variants,
30
+ temperature: Float,
31
+ thinking:
32
+ T.any(
33
+ Anthropic::Beta::BetaThinkingConfigEnabled::OrHash,
34
+ Anthropic::Beta::BetaThinkingConfigDisabled::OrHash
35
+ ),
36
+ tool_choice:
37
+ T.any(
38
+ Anthropic::Beta::BetaToolChoiceAuto::OrHash,
39
+ Anthropic::Beta::BetaToolChoiceAny::OrHash,
40
+ Anthropic::Beta::BetaToolChoiceTool::OrHash,
41
+ Anthropic::Beta::BetaToolChoiceNone::OrHash
42
+ ),
43
+ tools:
44
+ T::Array[
45
+ T.any(
46
+ Anthropic::Beta::BetaTool::OrHash,
47
+ Anthropic::Beta::BetaToolBash20241022::OrHash,
48
+ Anthropic::Beta::BetaToolBash20250124::OrHash,
49
+ Anthropic::Beta::BetaCodeExecutionTool20250522::OrHash,
50
+ Anthropic::Beta::BetaCodeExecutionTool20250825::OrHash,
51
+ Anthropic::Beta::BetaToolComputerUse20241022::OrHash,
52
+ Anthropic::Beta::BetaMemoryTool20250818::OrHash,
53
+ Anthropic::Beta::BetaToolComputerUse20250124::OrHash,
54
+ Anthropic::Beta::BetaToolTextEditor20241022::OrHash,
55
+ Anthropic::Beta::BetaToolTextEditor20250124::OrHash,
56
+ Anthropic::Beta::BetaToolTextEditor20250429::OrHash,
57
+ Anthropic::Beta::BetaToolTextEditor20250728::OrHash,
58
+ Anthropic::Beta::BetaWebSearchTool20250305::OrHash,
59
+ Anthropic::Beta::BetaWebFetchTool20250910::OrHash
60
+ )
61
+ ],
62
+ top_k: Integer,
63
+ top_p: Float,
64
+ betas: T::Array[T.any(String, Anthropic::AnthropicBeta::OrSymbol)],
65
+ stream: T.noreturn,
66
+ request_options: Anthropic::RequestOptions::OrHash
67
+ ).returns(Anthropic::Helpers::Tools::Runner)
68
+ end
69
+ def tool_runner(
70
+ # Body param: The maximum number of tokens to generate before stopping.
71
+ #
72
+ # Note that our models may stop _before_ reaching this maximum. This parameter
73
+ # only specifies the absolute maximum number of tokens to generate.
74
+ #
75
+ # Different models have different maximum values for this parameter. See
76
+ # [models](https://docs.claude.com/en/docs/models-overview) for details.
77
+ max_tokens:,
78
+ # Body param: Input messages.
79
+ #
80
+ # Our models are trained to operate on alternating `user` and `assistant`
81
+ # conversational turns. When creating a new `Message`, you specify the prior
82
+ # conversational turns with the `messages` parameter, and the model then generates
83
+ # the next `Message` in the conversation. Consecutive `user` or `assistant` turns
84
+ # in your request will be combined into a single turn.
85
+ #
86
+ # Each input message must be an object with a `role` and `content`. You can
87
+ # specify a single `user`-role message, or you can include multiple `user` and
88
+ # `assistant` messages.
89
+ #
90
+ # If the final message uses the `assistant` role, the response content will
91
+ # continue immediately from the content in that message. This can be used to
92
+ # constrain part of the model's response.
93
+ #
94
+ # Example with a single `user` message:
95
+ #
96
+ # ```json
97
+ # [{ "role": "user", "content": "Hello, Claude" }]
98
+ # ```
99
+ #
100
+ # Example with multiple conversational turns:
101
+ #
102
+ # ```json
103
+ # [
104
+ # { "role": "user", "content": "Hello there." },
105
+ # { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
106
+ # { "role": "user", "content": "Can you explain LLMs in plain English?" }
107
+ # ]
108
+ # ```
109
+ #
110
+ # Example with a partially-filled response from Claude:
111
+ #
112
+ # ```json
113
+ # [
114
+ # {
115
+ # "role": "user",
116
+ # "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
117
+ # },
118
+ # { "role": "assistant", "content": "The best answer is (" }
119
+ # ]
120
+ # ```
121
+ #
122
+ # Each input message `content` may be either a single `string` or an array of
123
+ # content blocks, where each block has a specific `type`. Using a `string` for
124
+ # `content` is shorthand for an array of one content block of type `"text"`. The
125
+ # following input messages are equivalent:
126
+ #
127
+ # ```json
128
+ # { "role": "user", "content": "Hello, Claude" }
129
+ # ```
130
+ #
131
+ # ```json
132
+ # { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
133
+ # ```
134
+ #
135
+ # See [input examples](https://docs.claude.com/en/api/messages-examples).
136
+ #
137
+ # Note that if you want to include a
138
+ # [system prompt](https://docs.claude.com/en/docs/system-prompts), you can use the
139
+ # top-level `system` parameter — there is no `"system"` role for input messages in
140
+ # the Messages API.
141
+ #
142
+ # There is a limit of 100,000 messages in a single request.
143
+ messages:,
144
+ # Body param: The model that will complete your prompt.\n\nSee
145
+ # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
146
+ # details and options.
147
+ model:,
148
+ # Body param: Container identifier for reuse across requests.
149
+ container: nil,
150
+ # Body param: Context management configuration.
151
+ #
152
+ # This allows you to control how Claude manages context across multiple requests,
153
+ # such as whether to clear function results or not.
154
+ context_management: nil,
155
+ # Body param: MCP servers to be utilized in this request
156
+ mcp_servers: nil,
157
+ # Body param: An object describing metadata about the request.
158
+ metadata: nil,
159
+ # Body param: Determines whether to use priority capacity (if available) or
160
+ # standard capacity for this request.
161
+ #
162
+ # Anthropic offers different levels of service for your API requests. See
163
+ # [service-tiers](https://docs.claude.com/en/api/service-tiers) for details.
164
+ service_tier: nil,
165
+ # Body param: Custom text sequences that will cause the model to stop generating.
166
+ #
167
+ # Our models will normally stop when they have naturally completed their turn,
168
+ # which will result in a response `stop_reason` of `"end_turn"`.
169
+ #
170
+ # If you want the model to stop generating when it encounters custom strings of
171
+ # text, you can use the `stop_sequences` parameter. If the model encounters one of
172
+ # the custom sequences, the response `stop_reason` value will be `"stop_sequence"`
173
+ # and the response `stop_sequence` value will contain the matched stop sequence.
174
+ stop_sequences: nil,
175
+ # Body param: System prompt.
176
+ #
177
+ # A system prompt is a way of providing context and instructions to Claude, such
178
+ # as specifying a particular goal or role. See our
179
+ # [guide to system prompts](https://docs.claude.com/en/docs/system-prompts).
180
+ system_: nil,
181
+ # Body param: Amount of randomness injected into the response.
182
+ #
183
+ # Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
184
+ # for analytical / multiple choice, and closer to `1.0` for creative and
185
+ # generative tasks.
186
+ #
187
+ # Note that even with `temperature` of `0.0`, the results will not be fully
188
+ # deterministic.
189
+ temperature: nil,
190
+ # Body param: Configuration for enabling Claude's extended thinking.
191
+ #
192
+ # When enabled, responses include `thinking` content blocks showing Claude's
193
+ # thinking process before the final answer. Requires a minimum budget of 1,024
194
+ # tokens and counts towards your `max_tokens` limit.
195
+ #
196
+ # See
197
+ # [extended thinking](https://docs.claude.com/en/docs/build-with-claude/extended-thinking)
198
+ # for details.
199
+ thinking: nil,
200
+ # Body param: How the model should use the provided tools. The model can use a
201
+ # specific tool, any available tool, decide by itself, or not use tools at all.
202
+ tool_choice: nil,
203
+ # Body param: Definitions of tools that the model may use.
204
+ #
205
+ # If you include `tools` in your API request, the model may return `tool_use`
206
+ # content blocks that represent the model's use of those tools. You can then run
207
+ # those tools using the tool input generated by the model and then optionally
208
+ # return results back to the model using `tool_result` content blocks.
209
+ #
210
+ # There are two types of tools: **client tools** and **server tools**. The
211
+ # behavior described below applies to client tools. For
212
+ # [server tools](https://docs.claude.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
213
+ # see their individual documentation as each has its own behavior (e.g., the
214
+ # [web search tool](https://docs.claude.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
215
+ #
216
+ # Each tool definition includes:
217
+ #
218
+ # - `name`: Name of the tool.
219
+ # - `description`: Optional, but strongly-recommended description of the tool.
220
+ # - `input_schema`: [JSON schema](https://json-schema.org/draft/2020-12) for the
221
+ # tool `input` shape that the model will produce in `tool_use` output content
222
+ # blocks.
223
+ #
224
+ # For example, if you defined `tools` as:
225
+ #
226
+ # ```json
227
+ # [
228
+ # {
229
+ # "name": "get_stock_price",
230
+ # "description": "Get the current stock price for a given ticker symbol.",
231
+ # "input_schema": {
232
+ # "type": "object",
233
+ # "properties": {
234
+ # "ticker": {
235
+ # "type": "string",
236
+ # "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
237
+ # }
238
+ # },
239
+ # "required": ["ticker"]
240
+ # }
241
+ # }
242
+ # ]
243
+ # ```
244
+ #
245
+ # And then asked the model "What's the S&P 500 at today?", the model might produce
246
+ # `tool_use` content blocks in the response like this:
247
+ #
248
+ # ```json
249
+ # [
250
+ # {
251
+ # "type": "tool_use",
252
+ # "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
253
+ # "name": "get_stock_price",
254
+ # "input": { "ticker": "^GSPC" }
255
+ # }
256
+ # ]
257
+ # ```
258
+ #
259
+ # You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
260
+ # input, and return the following back to the model in a subsequent `user`
261
+ # message:
262
+ #
263
+ # ```json
264
+ # [
265
+ # {
266
+ # "type": "tool_result",
267
+ # "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
268
+ # "content": "259.75 USD"
269
+ # }
270
+ # ]
271
+ # ```
272
+ #
273
+ # Tools can be used for workflows that include running client-side tools and
274
+ # functions, or more generally whenever you want the model to produce a particular
275
+ # JSON structure of output.
276
+ #
277
+ # See our [guide](https://docs.claude.com/en/docs/tool-use) for more details.
278
+ tools: nil,
279
+ # Body param: Only sample from the top K options for each subsequent token.
280
+ #
281
+ # Used to remove "long tail" low probability responses.
282
+ # [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
283
+ #
284
+ # Recommended for advanced use cases only. You usually only need to use
285
+ # `temperature`.
286
+ top_k: nil,
287
+ # Body param: Use nucleus sampling.
288
+ #
289
+ # In nucleus sampling, we compute the cumulative distribution over all the options
290
+ # for each subsequent token in decreasing probability order and cut it off once it
291
+ # reaches a particular probability specified by `top_p`. You should either alter
292
+ # `temperature` or `top_p`, but not both.
293
+ #
294
+ # Recommended for advanced use cases only. You usually only need to use
295
+ # `temperature`.
296
+ top_p: nil,
297
+ # Header param: Optional header to specify the beta version(s) you want to use.
298
+ betas: nil,
299
+ # There is no need to provide `stream:`. Instead, use `#stream_raw` or `#create`
300
+ # for streaming and non-streaming use cases, respectively.
301
+ stream: false,
302
+ request_options: {}
303
+ )
304
+ end
305
+
10
306
  # See {Anthropic::Resources::Beta::Messages#stream_raw} for streaming counterpart.
11
307
  #
12
308
  # Send a structured list of input messages with text and/or image content, and the
@@ -15,7 +311,8 @@ module Anthropic
15
311
  # The Messages API can be used for either single queries or stateless multi-turn
16
312
  # conversations.
17
313
  #
18
- # Learn more about the Messages API in our [user guide](/en/docs/initial-setup)
314
+ # Learn more about the Messages API in our
315
+ # [user guide](https://docs.claude.com/en/docs/initial-setup)
19
316
  sig do
20
317
  params(
21
318
  max_tokens: Integer,
@@ -32,6 +329,8 @@ module Anthropic
32
329
  Anthropic::Beta::BetaRequestMCPServerURLDefinition::OrHash
33
330
  ],
34
331
  metadata: Anthropic::Beta::BetaMetadata::OrHash,
332
+ output_format:
333
+ T.nilable(Anthropic::Beta::BetaJSONOutputFormat::OrHash),
35
334
  service_tier:
36
335
  Anthropic::Beta::MessageCreateParams::ServiceTier::OrSymbol,
37
336
  stop_sequences: T::Array[String],
@@ -165,6 +464,8 @@ module Anthropic
165
464
  mcp_servers: nil,
166
465
  # Body param: An object describing metadata about the request.
167
466
  metadata: nil,
467
+ # Body param: A schema to specify Claude's output format in responses.
468
+ output_format: nil,
168
469
  # Body param: Determines whether to use priority capacity (if available) or
169
470
  # standard capacity for this request.
170
471
  #
@@ -320,7 +621,8 @@ module Anthropic
320
621
  # The Messages API can be used for either single queries or stateless multi-turn
321
622
  # conversations.
322
623
  #
323
- # Learn more about the Messages API in our [user guide](/en/docs/initial-setup)
624
+ # Learn more about the Messages API in our
625
+ # [user guide](https://docs.claude.com/en/docs/initial-setup)
324
626
  sig do
325
627
  params(
326
628
  max_tokens: Integer,
@@ -337,6 +639,8 @@ module Anthropic
337
639
  Anthropic::Beta::BetaRequestMCPServerURLDefinition::OrHash
338
640
  ],
339
641
  metadata: Anthropic::Beta::BetaMetadata::OrHash,
642
+ output_format:
643
+ T.nilable(Anthropic::Beta::BetaJSONOutputFormat::OrHash),
340
644
  service_tier:
341
645
  Anthropic::Beta::MessageCreateParams::ServiceTier::OrSymbol,
342
646
  stop_sequences: T::Array[String],
@@ -474,6 +778,8 @@ module Anthropic
474
778
  mcp_servers: nil,
475
779
  # Body param: An object describing metadata about the request.
476
780
  metadata: nil,
781
+ # Body param: A schema to specify Claude's output format in responses.
782
+ output_format: nil,
477
783
  # Body param: Determines whether to use priority capacity (if available) or
478
784
  # standard capacity for this request.
479
785
  #
@@ -627,7 +933,7 @@ module Anthropic
627
933
  # including tools, images, and documents, without creating it.
628
934
  #
629
935
  # Learn more about token counting in our
630
- # [user guide](/en/docs/build-with-claude/token-counting)
936
+ # [user guide](https://docs.claude.com/en/docs/build-with-claude/token-counting)
631
937
  sig do
632
938
  params(
633
939
  messages: T::Array[Anthropic::Beta::BetaMessageParam::OrHash],
@@ -638,6 +944,8 @@ module Anthropic
638
944
  T::Array[
639
945
  Anthropic::Beta::BetaRequestMCPServerURLDefinition::OrHash
640
946
  ],
947
+ output_format:
948
+ T.nilable(Anthropic::Beta::BetaJSONOutputFormat::OrHash),
641
949
  system_:
642
950
  Anthropic::Beta::MessageCountTokensParams::System::Variants,
643
951
  thinking:
@@ -753,6 +1061,8 @@ module Anthropic
753
1061
  context_management: nil,
754
1062
  # Body param: MCP servers to be utilized in this request
755
1063
  mcp_servers: nil,
1064
+ # Body param: A schema to specify Claude's output format in responses.
1065
+ output_format: nil,
756
1066
  # Body param: System prompt.
757
1067
  #
758
1068
  # A system prompt is a way of providing context and instructions to Claude, such
@@ -11,7 +11,7 @@ module Anthropic
11
11
  # can take up to 24 hours to complete.
12
12
  #
13
13
  # Learn more about the Message Batches API in our
14
- # [user guide](/en/docs/build-with-claude/batch-processing)
14
+ # [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
15
15
  sig do
16
16
  params(
17
17
  requests:
@@ -32,7 +32,7 @@ module Anthropic
32
32
  # `results_url` field in the response.
33
33
  #
34
34
  # Learn more about the Message Batches API in our
35
- # [user guide](/en/docs/build-with-claude/batch-processing)
35
+ # [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
36
36
  sig do
37
37
  params(
38
38
  message_batch_id: String,
@@ -50,7 +50,7 @@ module Anthropic
50
50
  # returned first.
51
51
  #
52
52
  # Learn more about the Message Batches API in our
53
- # [user guide](/en/docs/build-with-claude/batch-processing)
53
+ # [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
54
54
  sig do
55
55
  params(
56
56
  after_id: String,
@@ -82,7 +82,7 @@ module Anthropic
82
82
  # like to delete an in-progress batch, you must first cancel it.
83
83
  #
84
84
  # Learn more about the Message Batches API in our
85
- # [user guide](/en/docs/build-with-claude/batch-processing)
85
+ # [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
86
86
  sig do
87
87
  params(
88
88
  message_batch_id: String,
@@ -107,7 +107,7 @@ module Anthropic
107
107
  # non-interruptible.
108
108
  #
109
109
  # Learn more about the Message Batches API in our
110
- # [user guide](/en/docs/build-with-claude/batch-processing)
110
+ # [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
111
111
  sig do
112
112
  params(
113
113
  message_batch_id: String,
@@ -128,7 +128,7 @@ module Anthropic
128
128
  # requests. Use the `custom_id` field to match results to requests.
129
129
  #
130
130
  # Learn more about the Message Batches API in our
131
- # [user guide](/en/docs/build-with-claude/batch-processing)
131
+ # [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
132
132
  sig do
133
133
  params(
134
134
  message_batch_id: String,
@@ -14,7 +14,8 @@ module Anthropic
14
14
  # The Messages API can be used for either single queries or stateless multi-turn
15
15
  # conversations.
16
16
  #
17
- # Learn more about the Messages API in our [user guide](/en/docs/initial-setup)
17
+ # Learn more about the Messages API in our
18
+ # [user guide](https://docs.claude.com/en/docs/initial-setup)
18
19
  sig do
19
20
  params(
20
21
  max_tokens: Integer,
@@ -288,7 +289,8 @@ module Anthropic
288
289
  # The Messages API can be used for either single queries or stateless multi-turn
289
290
  # conversations.
290
291
  #
291
- # Learn more about the Messages API in our [user guide](/en/docs/initial-setup)
292
+ # Learn more about the Messages API in our
293
+ # [user guide](https://docs.claude.com/en/docs/initial-setup)
292
294
  sig do
293
295
  params(
294
296
  max_tokens: Integer,
@@ -855,7 +857,7 @@ module Anthropic
855
857
  # including tools, images, and documents, without creating it.
856
858
  #
857
859
  # Learn more about token counting in our
858
- # [user guide](/en/docs/build-with-claude/token-counting)
860
+ # [user guide](https://docs.claude.com/en/docs/build-with-claude/token-counting)
859
861
  sig do
860
862
  params(
861
863
  messages: T::Array[Anthropic::MessageParam::OrHash],
@@ -87,6 +87,8 @@ module Anthropic
87
87
 
88
88
  private def auth_headers: -> ::Hash[String, String]
89
89
 
90
+ private def user_agent: -> String
91
+
90
92
  private def generate_idempotency_key: -> String
91
93
 
92
94
  private def build_request: (
@@ -17,7 +17,10 @@ module Anthropic
17
17
 
18
18
  DEFAULT_MAX_CONNECTIONS: Integer
19
19
 
20
- def self.connect: (URI::Generic url) -> top
20
+ def self.connect: (
21
+ cert_store: OpenSSL::X509::Store,
22
+ url: URI::Generic
23
+ ) -> top
21
24
 
22
25
  def self.calibrate_socket_timeout: (top conn, Float deadline) -> void
23
26
 
@@ -7,7 +7,8 @@ module Anthropic
7
7
  {
8
8
  name: :code_execution,
9
9
  type: :code_execution_20250522,
10
- cache_control: Anthropic::Beta::BetaCacheControlEphemeral?
10
+ cache_control: Anthropic::Beta::BetaCacheControlEphemeral?,
11
+ strict: bool
11
12
  }
12
13
 
13
14
  class BetaCodeExecutionTool20250522 < Anthropic::Internal::Type::BaseModel
@@ -17,8 +18,13 @@ module Anthropic
17
18
 
18
19
  attr_accessor cache_control: Anthropic::Beta::BetaCacheControlEphemeral?
19
20
 
21
+ attr_reader strict: bool?
22
+
23
+ def strict=: (bool) -> bool
24
+
20
25
  def initialize: (
21
26
  ?cache_control: Anthropic::Beta::BetaCacheControlEphemeral?,
27
+ ?strict: bool,
22
28
  ?name: :code_execution,
23
29
  ?type: :code_execution_20250522
24
30
  ) -> void
@@ -26,7 +32,8 @@ module Anthropic
26
32
  def to_hash: -> {
27
33
  name: :code_execution,
28
34
  type: :code_execution_20250522,
29
- cache_control: Anthropic::Beta::BetaCacheControlEphemeral?
35
+ cache_control: Anthropic::Beta::BetaCacheControlEphemeral?,
36
+ strict: bool
30
37
  }
31
38
  end
32
39
  end
@@ -7,7 +7,8 @@ module Anthropic
7
7
  {
8
8
  name: :code_execution,
9
9
  type: :code_execution_20250825,
10
- cache_control: Anthropic::Beta::BetaCacheControlEphemeral?
10
+ cache_control: Anthropic::Beta::BetaCacheControlEphemeral?,
11
+ strict: bool
11
12
  }
12
13
 
13
14
  class BetaCodeExecutionTool20250825 < Anthropic::Internal::Type::BaseModel
@@ -17,8 +18,13 @@ module Anthropic
17
18
 
18
19
  attr_accessor cache_control: Anthropic::Beta::BetaCacheControlEphemeral?
19
20
 
21
+ attr_reader strict: bool?
22
+
23
+ def strict=: (bool) -> bool
24
+
20
25
  def initialize: (
21
26
  ?cache_control: Anthropic::Beta::BetaCacheControlEphemeral?,
27
+ ?strict: bool,
22
28
  ?name: :code_execution,
23
29
  ?type: :code_execution_20250825
24
30
  ) -> void
@@ -26,7 +32,8 @@ module Anthropic
26
32
  def to_hash: -> {
27
33
  name: :code_execution,
28
34
  type: :code_execution_20250825,
29
- cache_control: Anthropic::Beta::BetaCacheControlEphemeral?
35
+ cache_control: Anthropic::Beta::BetaCacheControlEphemeral?,
36
+ strict: bool
30
37
  }
31
38
  end
32
39
  end