anthropic 1.1.1 → 1.3.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 (135) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +69 -0
  3. data/README.md +32 -16
  4. data/lib/anthropic/errors.rb +22 -0
  5. data/lib/anthropic/helpers/streaming/events.rb +141 -0
  6. data/lib/anthropic/helpers/streaming/message_stream.rb +238 -0
  7. data/lib/anthropic/helpers/streaming.rb +37 -0
  8. data/lib/anthropic/helpers/vertex/client.rb +4 -1
  9. data/lib/anthropic/internal/stream.rb +4 -2
  10. data/lib/anthropic/internal/transport/base_client.rb +10 -2
  11. data/lib/anthropic/internal/type/array_of.rb +6 -1
  12. data/lib/anthropic/internal/type/base_model.rb +77 -23
  13. data/lib/anthropic/internal/type/base_stream.rb +3 -1
  14. data/lib/anthropic/internal/type/boolean.rb +7 -1
  15. data/lib/anthropic/internal/type/converter.rb +42 -34
  16. data/lib/anthropic/internal/type/enum.rb +16 -5
  17. data/lib/anthropic/internal/type/file_input.rb +6 -1
  18. data/lib/anthropic/internal/type/hash_of.rb +6 -1
  19. data/lib/anthropic/internal/type/union.rb +17 -9
  20. data/lib/anthropic/internal/type/unknown.rb +7 -1
  21. data/lib/anthropic/internal/util.rb +8 -9
  22. data/lib/anthropic/models/beta/beta_base64_pdf_block.rb +1 -65
  23. data/lib/anthropic/models/beta/beta_citation_search_result_location.rb +55 -0
  24. data/lib/anthropic/models/beta/beta_citation_search_result_location_param.rb +55 -0
  25. data/lib/anthropic/models/beta/beta_citations_delta.rb +5 -3
  26. data/lib/anthropic/models/beta/beta_content_block.rb +5 -5
  27. data/lib/anthropic/models/beta/beta_content_block_param.rb +20 -17
  28. data/lib/anthropic/models/beta/beta_message.rb +6 -2
  29. data/lib/anthropic/models/beta/beta_message_param.rb +3 -3
  30. data/lib/anthropic/models/beta/beta_raw_content_block_start_event.rb +7 -7
  31. data/lib/anthropic/models/beta/beta_request_document_block.rb +75 -0
  32. data/lib/anthropic/models/beta/beta_search_result_block_param.rb +55 -0
  33. data/lib/anthropic/models/beta/beta_text_block.rb +2 -2
  34. data/lib/anthropic/models/beta/beta_text_block_param.rb +2 -2
  35. data/lib/anthropic/models/beta/beta_text_citation.rb +3 -1
  36. data/lib/anthropic/models/beta/beta_text_citation_param.rb +3 -1
  37. data/lib/anthropic/models/beta/beta_tool.rb +7 -1
  38. data/lib/anthropic/models/beta/beta_tool_result_block_param.rb +6 -4
  39. data/lib/anthropic/models/beta/beta_tool_union.rb +7 -7
  40. data/lib/anthropic/models/beta/message_count_tokens_params.rb +16 -10
  41. data/lib/anthropic/models/beta/message_create_params.rb +9 -3
  42. data/lib/anthropic/models/beta/messages/batch_create_params.rb +9 -3
  43. data/lib/anthropic/models/content_block.rb +5 -5
  44. data/lib/anthropic/models/content_block_param.rb +11 -11
  45. data/lib/anthropic/models/message.rb +6 -2
  46. data/lib/anthropic/models/message_count_tokens_params.rb +9 -3
  47. data/lib/anthropic/models/message_count_tokens_tool.rb +35 -1
  48. data/lib/anthropic/models/message_create_params.rb +9 -3
  49. data/lib/anthropic/models/message_param.rb +3 -3
  50. data/lib/anthropic/models/messages/batch_create_params.rb +9 -3
  51. data/lib/anthropic/models/model.rb +5 -21
  52. data/lib/anthropic/models/raw_content_block_start_event.rb +7 -7
  53. data/lib/anthropic/models/tool.rb +7 -1
  54. data/lib/anthropic/models/tool_union.rb +34 -1
  55. data/lib/anthropic/models/tool_use_block.rb +6 -0
  56. data/lib/anthropic/models.rb +4 -4
  57. data/lib/anthropic/resources/beta/messages.rb +73 -6
  58. data/lib/anthropic/resources/messages.rb +68 -7
  59. data/lib/anthropic/streaming.rb +5 -0
  60. data/lib/anthropic/version.rb +1 -1
  61. data/lib/anthropic.rb +8 -0
  62. data/rbi/anthropic/errors.rbi +16 -0
  63. data/rbi/anthropic/helpers/bedrock/client.rbi +17 -6
  64. data/rbi/anthropic/helpers/streaming/events.rbi +95 -0
  65. data/rbi/anthropic/helpers/streaming/message_stream.rbi +73 -0
  66. data/rbi/anthropic/helpers/vertex/client.rbi +17 -6
  67. data/rbi/anthropic/internal/type/base_stream.rbi +8 -1
  68. data/rbi/anthropic/internal/type/boolean.rbi +2 -0
  69. data/rbi/anthropic/internal/type/converter.rbi +15 -15
  70. data/rbi/anthropic/internal/type/union.rbi +5 -0
  71. data/rbi/anthropic/internal/type/unknown.rbi +2 -0
  72. data/rbi/anthropic/internal/util.rbi +2 -0
  73. data/rbi/anthropic/models/beta/beta_base64_pdf_block.rbi +1 -128
  74. data/rbi/anthropic/models/beta/beta_citation_search_result_location.rbi +78 -0
  75. data/rbi/anthropic/models/beta/beta_citation_search_result_location_param.rbi +79 -0
  76. data/rbi/anthropic/models/beta/beta_citations_delta.rbi +4 -2
  77. data/rbi/anthropic/models/beta/beta_content_block.rbi +3 -3
  78. data/rbi/anthropic/models/beta/beta_content_block_param.rbi +8 -7
  79. data/rbi/anthropic/models/beta/beta_message.rbi +11 -3
  80. data/rbi/anthropic/models/beta/beta_raw_content_block_start_event.rbi +6 -6
  81. data/rbi/anthropic/models/beta/beta_request_document_block.rbi +140 -0
  82. data/rbi/anthropic/models/beta/beta_search_result_block_param.rbi +91 -0
  83. data/rbi/anthropic/models/beta/beta_text_block.rbi +2 -1
  84. data/rbi/anthropic/models/beta/beta_text_block_param.rbi +6 -3
  85. data/rbi/anthropic/models/beta/beta_text_citation.rbi +2 -1
  86. data/rbi/anthropic/models/beta/beta_text_citation_param.rbi +2 -1
  87. data/rbi/anthropic/models/beta/beta_tool.rbi +14 -5
  88. data/rbi/anthropic/models/beta/beta_tool_result_block_param.rbi +2 -1
  89. data/rbi/anthropic/models/beta/beta_tool_union.rbi +5 -5
  90. data/rbi/anthropic/models/beta/message_count_tokens_params.rbi +39 -27
  91. data/rbi/anthropic/models/beta/message_create_params.rbi +34 -22
  92. data/rbi/anthropic/models/beta/messages/batch_create_params.rbi +34 -22
  93. data/rbi/anthropic/models/content_block.rbi +3 -3
  94. data/rbi/anthropic/models/content_block_param.rbi +5 -5
  95. data/rbi/anthropic/models/message.rbi +11 -3
  96. data/rbi/anthropic/models/message_count_tokens_params.rbi +18 -2
  97. data/rbi/anthropic/models/message_count_tokens_tool.rbi +61 -0
  98. data/rbi/anthropic/models/message_create_params.rbi +18 -2
  99. data/rbi/anthropic/models/messages/batch_create_params.rbi +18 -2
  100. data/rbi/anthropic/models/model.rbi +0 -8
  101. data/rbi/anthropic/models/raw_content_block_start_event.rbi +6 -6
  102. data/rbi/anthropic/models/tool.rbi +16 -5
  103. data/rbi/anthropic/models/tool_union.rbi +61 -0
  104. data/rbi/anthropic/resources/beta/messages.rbi +36 -18
  105. data/rbi/anthropic/resources/messages.rbi +315 -3
  106. data/rbi/anthropic/streaming.rbi +5 -0
  107. data/sig/anthropic/errors.rbs +9 -0
  108. data/sig/anthropic/helpers/streaming/events.rbs +117 -0
  109. data/sig/anthropic/helpers/streaming/message_stream.rbs +57 -0
  110. data/sig/anthropic/internal/type/base_stream.rbs +4 -0
  111. data/sig/anthropic/internal/type/converter.rbs +7 -1
  112. data/sig/anthropic/models/beta/beta_base64_pdf_block.rbs +1 -58
  113. data/sig/anthropic/models/beta/beta_citation_search_result_location.rbs +54 -0
  114. data/sig/anthropic/models/beta/beta_citation_search_result_location_param.rbs +54 -0
  115. data/sig/anthropic/models/beta/beta_citations_delta.rbs +1 -0
  116. data/sig/anthropic/models/beta/beta_content_block.rbs +2 -2
  117. data/sig/anthropic/models/beta/beta_content_block_param.rbs +9 -8
  118. data/sig/anthropic/models/beta/beta_raw_content_block_start_event.rbs +2 -2
  119. data/sig/anthropic/models/beta/beta_request_document_block.rbs +66 -0
  120. data/sig/anthropic/models/beta/beta_search_result_block_param.rbs +53 -0
  121. data/sig/anthropic/models/beta/beta_text_citation.rbs +1 -0
  122. data/sig/anthropic/models/beta/beta_text_citation_param.rbs +1 -0
  123. data/sig/anthropic/models/beta/beta_tool.rbs +14 -3
  124. data/sig/anthropic/models/beta/beta_tool_result_block_param.rbs +1 -0
  125. data/sig/anthropic/models/beta/beta_tool_union.rbs +4 -4
  126. data/sig/anthropic/models/beta/message_count_tokens_params.rbs +4 -4
  127. data/sig/anthropic/models/content_block.rbs +2 -2
  128. data/sig/anthropic/models/content_block_param.rbs +5 -5
  129. data/sig/anthropic/models/message_count_tokens_tool.rbs +28 -0
  130. data/sig/anthropic/models/model.rbs +0 -10
  131. data/sig/anthropic/models/raw_content_block_start_event.rbs +2 -2
  132. data/sig/anthropic/models/tool.rbs +14 -3
  133. data/sig/anthropic/models/tool_union.rbs +28 -0
  134. data/sig/anthropic/streaming.rbs +3 -0
  135. metadata +26 -3
@@ -48,15 +48,15 @@ module Anthropic
48
48
  T::Array[
49
49
  T.any(
50
50
  Anthropic::Beta::BetaTool::OrHash,
51
- Anthropic::Beta::BetaToolComputerUse20241022::OrHash,
52
51
  Anthropic::Beta::BetaToolBash20241022::OrHash,
53
- Anthropic::Beta::BetaToolTextEditor20241022::OrHash,
54
- Anthropic::Beta::BetaToolComputerUse20250124::OrHash,
55
52
  Anthropic::Beta::BetaToolBash20250124::OrHash,
53
+ Anthropic::Beta::BetaCodeExecutionTool20250522::OrHash,
54
+ Anthropic::Beta::BetaToolComputerUse20241022::OrHash,
55
+ Anthropic::Beta::BetaToolComputerUse20250124::OrHash,
56
+ Anthropic::Beta::BetaToolTextEditor20241022::OrHash,
56
57
  Anthropic::Beta::BetaToolTextEditor20250124::OrHash,
57
58
  Anthropic::Beta::BetaToolTextEditor20250429::OrHash,
58
- Anthropic::Beta::BetaWebSearchTool20250305::OrHash,
59
- Anthropic::Beta::BetaCodeExecutionTool20250522::OrHash
59
+ Anthropic::Beta::BetaWebSearchTool20250305::OrHash
60
60
  )
61
61
  ],
62
62
  top_k: Integer,
@@ -162,7 +162,7 @@ module Anthropic
162
162
  # the top-level `system` parameter — there is no `"system"` role for input
163
163
  # messages in the Messages API.
164
164
  #
165
- # There is a limit of 100000 messages in a single request.
165
+ # There is a limit of 100,000 messages in a single request.
166
166
  messages:,
167
167
  # Body param: The model that will complete your prompt.\n\nSee
168
168
  # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
@@ -225,6 +225,12 @@ module Anthropic
225
225
  # those tools using the tool input generated by the model and then optionally
226
226
  # return results back to the model using `tool_result` content blocks.
227
227
  #
228
+ # There are two types of tools: **client tools** and **server tools**. The
229
+ # behavior described below applies to client tools. For
230
+ # [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
231
+ # see their individual documentation as each has its own behavior (e.g., the
232
+ # [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
233
+ #
228
234
  # Each tool definition includes:
229
235
  #
230
236
  # - `name`: Name of the tool.
@@ -356,15 +362,15 @@ module Anthropic
356
362
  T::Array[
357
363
  T.any(
358
364
  Anthropic::Beta::BetaTool::OrHash,
359
- Anthropic::Beta::BetaToolComputerUse20241022::OrHash,
360
365
  Anthropic::Beta::BetaToolBash20241022::OrHash,
361
- Anthropic::Beta::BetaToolTextEditor20241022::OrHash,
362
- Anthropic::Beta::BetaToolComputerUse20250124::OrHash,
363
366
  Anthropic::Beta::BetaToolBash20250124::OrHash,
367
+ Anthropic::Beta::BetaCodeExecutionTool20250522::OrHash,
368
+ Anthropic::Beta::BetaToolComputerUse20241022::OrHash,
369
+ Anthropic::Beta::BetaToolComputerUse20250124::OrHash,
370
+ Anthropic::Beta::BetaToolTextEditor20241022::OrHash,
364
371
  Anthropic::Beta::BetaToolTextEditor20250124::OrHash,
365
372
  Anthropic::Beta::BetaToolTextEditor20250429::OrHash,
366
- Anthropic::Beta::BetaWebSearchTool20250305::OrHash,
367
- Anthropic::Beta::BetaCodeExecutionTool20250522::OrHash
373
+ Anthropic::Beta::BetaWebSearchTool20250305::OrHash
368
374
  )
369
375
  ],
370
376
  top_k: Integer,
@@ -474,7 +480,7 @@ module Anthropic
474
480
  # the top-level `system` parameter — there is no `"system"` role for input
475
481
  # messages in the Messages API.
476
482
  #
477
- # There is a limit of 100000 messages in a single request.
483
+ # There is a limit of 100,000 messages in a single request.
478
484
  messages:,
479
485
  # Body param: The model that will complete your prompt.\n\nSee
480
486
  # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
@@ -537,6 +543,12 @@ module Anthropic
537
543
  # those tools using the tool input generated by the model and then optionally
538
544
  # return results back to the model using `tool_result` content blocks.
539
545
  #
546
+ # There are two types of tools: **client tools** and **server tools**. The
547
+ # behavior described below applies to client tools. For
548
+ # [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
549
+ # see their individual documentation as each has its own behavior (e.g., the
550
+ # [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
551
+ #
540
552
  # Each tool definition includes:
541
553
  #
542
554
  # - `name`: Name of the tool.
@@ -660,15 +672,15 @@ module Anthropic
660
672
  T::Array[
661
673
  T.any(
662
674
  Anthropic::Beta::BetaTool::OrHash,
663
- Anthropic::Beta::BetaToolComputerUse20241022::OrHash,
664
675
  Anthropic::Beta::BetaToolBash20241022::OrHash,
665
- Anthropic::Beta::BetaToolTextEditor20241022::OrHash,
666
- Anthropic::Beta::BetaToolComputerUse20250124::OrHash,
667
676
  Anthropic::Beta::BetaToolBash20250124::OrHash,
677
+ Anthropic::Beta::BetaCodeExecutionTool20250522::OrHash,
678
+ Anthropic::Beta::BetaToolComputerUse20241022::OrHash,
679
+ Anthropic::Beta::BetaToolComputerUse20250124::OrHash,
680
+ Anthropic::Beta::BetaToolTextEditor20241022::OrHash,
668
681
  Anthropic::Beta::BetaToolTextEditor20250124::OrHash,
669
682
  Anthropic::Beta::BetaToolTextEditor20250429::OrHash,
670
- Anthropic::Beta::BetaWebSearchTool20250305::OrHash,
671
- Anthropic::Beta::BetaCodeExecutionTool20250522::OrHash
683
+ Anthropic::Beta::BetaWebSearchTool20250305::OrHash
672
684
  )
673
685
  ],
674
686
  betas: T::Array[T.any(String, Anthropic::AnthropicBeta::OrSymbol)],
@@ -763,7 +775,7 @@ module Anthropic
763
775
  # the top-level `system` parameter — there is no `"system"` role for input
764
776
  # messages in the Messages API.
765
777
  #
766
- # There is a limit of 100000 messages in a single request.
778
+ # There is a limit of 100,000 messages in a single request.
767
779
  messages:,
768
780
  # Body param: The model that will complete your prompt.\n\nSee
769
781
  # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
@@ -797,6 +809,12 @@ module Anthropic
797
809
  # those tools using the tool input generated by the model and then optionally
798
810
  # return results back to the model using `tool_result` content blocks.
799
811
  #
812
+ # There are two types of tools: **client tools** and **server tools**. The
813
+ # behavior described below applies to client tools. For
814
+ # [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
815
+ # see their individual documentation as each has its own behavior (e.g., the
816
+ # [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
817
+ #
800
818
  # Each tool definition includes:
801
819
  #
802
820
  # - `name`: Name of the tool.
@@ -43,6 +43,7 @@ module Anthropic
43
43
  Anthropic::Tool::OrHash,
44
44
  Anthropic::ToolBash20250124::OrHash,
45
45
  Anthropic::ToolTextEditor20250124::OrHash,
46
+ Anthropic::ToolUnion::TextEditor20250429::OrHash,
46
47
  Anthropic::WebSearchTool20250305::OrHash
47
48
  )
48
49
  ],
@@ -148,7 +149,7 @@ module Anthropic
148
149
  # the top-level `system` parameter — there is no `"system"` role for input
149
150
  # messages in the Messages API.
150
151
  #
151
- # There is a limit of 100000 messages in a single request.
152
+ # There is a limit of 100,000 messages in a single request.
152
153
  messages:,
153
154
  # The model that will complete your prompt.\n\nSee
154
155
  # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
@@ -207,6 +208,12 @@ module Anthropic
207
208
  # those tools using the tool input generated by the model and then optionally
208
209
  # return results back to the model using `tool_result` content blocks.
209
210
  #
211
+ # There are two types of tools: **client tools** and **server tools**. The
212
+ # behavior described below applies to client tools. For
213
+ # [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
214
+ # see their individual documentation as each has its own behavior (e.g., the
215
+ # [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
216
+ #
210
217
  # Each tool definition includes:
211
218
  #
212
219
  # - `name`: Name of the tool.
@@ -304,6 +311,297 @@ module Anthropic
304
311
  # conversations.
305
312
  #
306
313
  # Learn more about the Messages API in our [user guide](/en/docs/initial-setup)
314
+ sig do
315
+ params(
316
+ max_tokens: Integer,
317
+ messages:
318
+ T::Array[
319
+ T.any(
320
+ Anthropic::Models::MessageParam,
321
+ Anthropic::Internal::AnyHash
322
+ )
323
+ ],
324
+ model: T.any(Anthropic::Models::Model::OrSymbol, String),
325
+ metadata:
326
+ T.any(Anthropic::Models::Metadata, Anthropic::Internal::AnyHash),
327
+ stop_sequences: T::Array[String],
328
+ system_:
329
+ T.any(
330
+ String,
331
+ T::Array[
332
+ T.any(
333
+ Anthropic::Models::TextBlockParam,
334
+ Anthropic::Internal::AnyHash
335
+ )
336
+ ]
337
+ ),
338
+ temperature: Float,
339
+ thinking:
340
+ T.any(
341
+ Anthropic::Models::ThinkingConfigEnabled,
342
+ Anthropic::Internal::AnyHash,
343
+ Anthropic::Models::ThinkingConfigDisabled
344
+ ),
345
+ tool_choice:
346
+ T.any(
347
+ Anthropic::Models::ToolChoiceAuto,
348
+ Anthropic::Internal::AnyHash,
349
+ Anthropic::Models::ToolChoiceAny,
350
+ Anthropic::Models::ToolChoiceTool,
351
+ Anthropic::Models::ToolChoiceNone
352
+ ),
353
+ tools:
354
+ T::Array[
355
+ T.any(
356
+ Anthropic::Models::Tool,
357
+ Anthropic::Internal::AnyHash,
358
+ Anthropic::Models::ToolBash20250124,
359
+ Anthropic::Models::ToolTextEditor20250124
360
+ )
361
+ ],
362
+ top_k: Integer,
363
+ top_p: Float,
364
+ stream: T.noreturn,
365
+ request_options:
366
+ T.nilable(
367
+ T.any(Anthropic::RequestOptions, Anthropic::Internal::AnyHash)
368
+ )
369
+ ).returns(Anthropic::Helpers::Streaming::MessageStream)
370
+ end
371
+ def stream(
372
+ # The maximum number of tokens to generate before stopping.
373
+ #
374
+ # Note that our models may stop _before_ reaching this maximum. This parameter
375
+ # only specifies the absolute maximum number of tokens to generate.
376
+ #
377
+ # Different models have different maximum values for this parameter. See
378
+ # [models](https://docs.anthropic.com/en/docs/models-overview) for details.
379
+ max_tokens:,
380
+ # Input messages.
381
+ #
382
+ # Our models are trained to operate on alternating `user` and `assistant`
383
+ # conversational turns. When creating a new `Message`, you specify the prior
384
+ # conversational turns with the `messages` parameter, and the model then generates
385
+ # the next `Message` in the conversation. Consecutive `user` or `assistant` turns
386
+ # in your request will be combined into a single turn.
387
+ #
388
+ # Each input message must be an object with a `role` and `content`. You can
389
+ # specify a single `user`-role message, or you can include multiple `user` and
390
+ # `assistant` messages.
391
+ #
392
+ # If the final message uses the `assistant` role, the response content will
393
+ # continue immediately from the content in that message. This can be used to
394
+ # constrain part of the model's response.
395
+ #
396
+ # Example with a single `user` message:
397
+ #
398
+ # ```json
399
+ # [{ "role": "user", "content": "Hello, Claude" }]
400
+ # ```
401
+ #
402
+ # Example with multiple conversational turns:
403
+ #
404
+ # ```json
405
+ # [
406
+ # { "role": "user", "content": "Hello there." },
407
+ # { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
408
+ # { "role": "user", "content": "Can you explain LLMs in plain English?" }
409
+ # ]
410
+ # ```
411
+ #
412
+ # Example with a partially-filled response from Claude:
413
+ #
414
+ # ```json
415
+ # [
416
+ # {
417
+ # "role": "user",
418
+ # "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
419
+ # },
420
+ # { "role": "assistant", "content": "The best answer is (" }
421
+ # ]
422
+ # ```
423
+ #
424
+ # Each input message `content` may be either a single `string` or an array of
425
+ # content blocks, where each block has a specific `type`. Using a `string` for
426
+ # `content` is shorthand for an array of one content block of type `"text"`. The
427
+ # following input messages are equivalent:
428
+ #
429
+ # ```json
430
+ # { "role": "user", "content": "Hello, Claude" }
431
+ # ```
432
+ #
433
+ # ```json
434
+ # { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
435
+ # ```
436
+ #
437
+ # Starting with Claude 3 models, you can also send image content blocks:
438
+ #
439
+ # ```json
440
+ # {
441
+ # "role": "user",
442
+ # "content": [
443
+ # {
444
+ # "type": "image",
445
+ # "source": {
446
+ # "type": "base64",
447
+ # "media_type": "image/jpeg",
448
+ # "data": "/9j/4AAQSkZJRg..."
449
+ # }
450
+ # },
451
+ # { "type": "text", "text": "What is in this image?" }
452
+ # ]
453
+ # }
454
+ # ```
455
+ #
456
+ # We currently support the `base64` source type for images, and the `image/jpeg`,
457
+ # `image/png`, `image/gif`, and `image/webp` media types.
458
+ #
459
+ # See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
460
+ # more input examples.
461
+ #
462
+ # Note that if you want to include a
463
+ # [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
464
+ # the top-level `system` parameter — there is no `"system"` role for input
465
+ # messages in the Messages API.
466
+ messages:,
467
+ # The model that will complete your prompt.\n\nSee
468
+ # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
469
+ # details and options.
470
+ model:,
471
+ # An object describing metadata about the request.
472
+ metadata: nil,
473
+ # Custom text sequences that will cause the model to stop generating.
474
+ #
475
+ # Our models will normally stop when they have naturally completed their turn,
476
+ # which will result in a response `stop_reason` of `"end_turn"`.
477
+ #
478
+ # If you want the model to stop generating when it encounters custom strings of
479
+ # text, you can use the `stop_sequences` parameter. If the model encounters one of
480
+ # the custom sequences, the response `stop_reason` value will be `"stop_sequence"`
481
+ # and the response `stop_sequence` value will contain the matched stop sequence.
482
+ stop_sequences: nil,
483
+ # System prompt.
484
+ #
485
+ # A system prompt is a way of providing context and instructions to Claude, such
486
+ # as specifying a particular goal or role. See our
487
+ # [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
488
+ system_: nil,
489
+ # Amount of randomness injected into the response.
490
+ #
491
+ # Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
492
+ # for analytical / multiple choice, and closer to `1.0` for creative and
493
+ # generative tasks.
494
+ #
495
+ # Note that even with `temperature` of `0.0`, the results will not be fully
496
+ # deterministic.
497
+ temperature: nil,
498
+ # Configuration for enabling Claude's extended thinking.
499
+ #
500
+ # When enabled, responses include `thinking` content blocks showing Claude's
501
+ # thinking process before the final answer. Requires a minimum budget of 1,024
502
+ # tokens and counts towards your `max_tokens` limit.
503
+ #
504
+ # See
505
+ # [extended thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)
506
+ # for details.
507
+ thinking: nil,
508
+ # How the model should use the provided tools. The model can use a specific tool,
509
+ # any available tool, decide by itself, or not use tools at all.
510
+ tool_choice: nil,
511
+ # Definitions of tools that the model may use.
512
+ #
513
+ # If you include `tools` in your API request, the model may return `tool_use`
514
+ # content blocks that represent the model's use of those tools. You can then run
515
+ # those tools using the tool input generated by the model and then optionally
516
+ # return results back to the model using `tool_result` content blocks.
517
+ #
518
+ # Each tool definition includes:
519
+ #
520
+ # - `name`: Name of the tool.
521
+ # - `description`: Optional, but strongly-recommended description of the tool.
522
+ # - `input_schema`: [JSON schema](https://json-schema.org/draft/2020-12) for the
523
+ # tool `input` shape that the model will produce in `tool_use` output content
524
+ # blocks.
525
+ #
526
+ # For example, if you defined `tools` as:
527
+ #
528
+ # ```json
529
+ # [
530
+ # {
531
+ # "name": "get_stock_price",
532
+ # "description": "Get the current stock price for a given ticker symbol.",
533
+ # "input_schema": {
534
+ # "type": "object",
535
+ # "properties": {
536
+ # "ticker": {
537
+ # "type": "string",
538
+ # "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
539
+ # }
540
+ # },
541
+ # "required": ["ticker"]
542
+ # }
543
+ # }
544
+ # ]
545
+ # ```
546
+ #
547
+ # And then asked the model "What's the S&P 500 at today?", the model might produce
548
+ # `tool_use` content blocks in the response like this:
549
+ #
550
+ # ```json
551
+ # [
552
+ # {
553
+ # "type": "tool_use",
554
+ # "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
555
+ # "name": "get_stock_price",
556
+ # "input": { "ticker": "^GSPC" }
557
+ # }
558
+ # ]
559
+ # ```
560
+ #
561
+ # You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
562
+ # input, and return the following back to the model in a subsequent `user`
563
+ # message:
564
+ #
565
+ # ```json
566
+ # [
567
+ # {
568
+ # "type": "tool_result",
569
+ # "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
570
+ # "content": "259.75 USD"
571
+ # }
572
+ # ]
573
+ # ```
574
+ #
575
+ # Tools can be used for workflows that include running client-side tools and
576
+ # functions, or more generally whenever you want the model to produce a particular
577
+ # JSON structure of output.
578
+ #
579
+ # See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
580
+ tools: nil,
581
+ # Only sample from the top K options for each subsequent token.
582
+ #
583
+ # Used to remove "long tail" low probability responses.
584
+ # [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
585
+ #
586
+ # Recommended for advanced use cases only. You usually only need to use
587
+ # `temperature`.
588
+ top_k: nil,
589
+ # Use nucleus sampling.
590
+ #
591
+ # In nucleus sampling, we compute the cumulative distribution over all the options
592
+ # for each subsequent token in decreasing probability order and cut it off once it
593
+ # reaches a particular probability specified by `top_p`. You should either alter
594
+ # `temperature` or `top_p`, but not both.
595
+ #
596
+ # Recommended for advanced use cases only. You usually only need to use
597
+ # `temperature`.
598
+ top_p: nil,
599
+ # There is no need to provide `stream:`. Instead, use `#stream_raw` or `#create`
600
+ # for streaming and non-streaming use cases, respectively.
601
+ stream: true,
602
+ request_options: {}
603
+ )
604
+ end
307
605
  sig do
308
606
  params(
309
607
  max_tokens: Integer,
@@ -332,6 +630,7 @@ module Anthropic
332
630
  Anthropic::Tool::OrHash,
333
631
  Anthropic::ToolBash20250124::OrHash,
334
632
  Anthropic::ToolTextEditor20250124::OrHash,
633
+ Anthropic::ToolUnion::TextEditor20250429::OrHash,
335
634
  Anthropic::WebSearchTool20250305::OrHash
336
635
  )
337
636
  ],
@@ -441,7 +740,7 @@ module Anthropic
441
740
  # the top-level `system` parameter — there is no `"system"` role for input
442
741
  # messages in the Messages API.
443
742
  #
444
- # There is a limit of 100000 messages in a single request.
743
+ # There is a limit of 100,000 messages in a single request.
445
744
  messages:,
446
745
  # The model that will complete your prompt.\n\nSee
447
746
  # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
@@ -500,6 +799,12 @@ module Anthropic
500
799
  # those tools using the tool input generated by the model and then optionally
501
800
  # return results back to the model using `tool_result` content blocks.
502
801
  #
802
+ # There are two types of tools: **client tools** and **server tools**. The
803
+ # behavior described below applies to client tools. For
804
+ # [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
805
+ # see their individual documentation as each has its own behavior (e.g., the
806
+ # [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
807
+ #
503
808
  # Each tool definition includes:
504
809
  #
505
810
  # - `name`: Name of the tool.
@@ -618,6 +923,7 @@ module Anthropic
618
923
  Anthropic::Tool::OrHash,
619
924
  Anthropic::ToolBash20250124::OrHash,
620
925
  Anthropic::ToolTextEditor20250124::OrHash,
926
+ Anthropic::MessageCountTokensTool::TextEditor20250429::OrHash,
621
927
  Anthropic::WebSearchTool20250305::OrHash
622
928
  )
623
929
  ],
@@ -712,7 +1018,7 @@ module Anthropic
712
1018
  # the top-level `system` parameter — there is no `"system"` role for input
713
1019
  # messages in the Messages API.
714
1020
  #
715
- # There is a limit of 100000 messages in a single request.
1021
+ # There is a limit of 100,000 messages in a single request.
716
1022
  messages:,
717
1023
  # The model that will complete your prompt.\n\nSee
718
1024
  # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
@@ -744,6 +1050,12 @@ module Anthropic
744
1050
  # those tools using the tool input generated by the model and then optionally
745
1051
  # return results back to the model using `tool_result` content blocks.
746
1052
  #
1053
+ # There are two types of tools: **client tools** and **server tools**. The
1054
+ # behavior described below applies to client tools. For
1055
+ # [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
1056
+ # see their individual documentation as each has its own behavior (e.g., the
1057
+ # [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
1058
+ #
747
1059
  # Each tool definition includes:
748
1060
  #
749
1061
  # - `name`: Name of the tool.
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Anthropic
4
+ Streaming = Anthropic::Helpers::Streaming
5
+ end
@@ -5,6 +5,15 @@ module Anthropic
5
5
  end
6
6
 
7
7
  class ConversionError < Anthropic::Errors::Error
8
+ def cause: -> StandardError?
9
+
10
+ def initialize: (
11
+ on: Class,
12
+ method: Symbol,
13
+ target: top,
14
+ value: top,
15
+ ?cause: StandardError?
16
+ ) -> void
8
17
  end
9
18
 
10
19
  class APIError < Anthropic::Errors::Error
@@ -0,0 +1,117 @@
1
+ module Anthropic
2
+ module Helpers
3
+ module Streaming
4
+ type text_event = { type: :text, text: String, snapshot: String }
5
+
6
+ class TextEvent < Anthropic::Internal::Type::BaseModel
7
+ attr_accessor type: :text
8
+
9
+ attr_accessor text: String
10
+
11
+ attr_accessor snapshot: String
12
+
13
+ def initialize: (text: String, snapshot: String, ?type: :text) -> void
14
+ end
15
+
16
+ type citation_event =
17
+ {
18
+ type: :citation,
19
+ citation: Anthropic::Models::CitationsDelta::citation,
20
+ snapshot: ::Array[Anthropic::Models::CitationsDelta::citation]
21
+ }
22
+
23
+ class CitationEvent < Anthropic::Internal::Type::BaseModel
24
+ attr_accessor type: :citation
25
+
26
+ attr_accessor citation: Anthropic::Models::CitationsDelta::citation
27
+
28
+ attr_accessor snapshot: ::Array[Anthropic::Models::CitationsDelta::citation]
29
+
30
+ def initialize: (
31
+ citation: Anthropic::Models::CitationsDelta::citation,
32
+ snapshot: ::Array[Anthropic::Models::CitationsDelta::citation],
33
+ ?type: :citation
34
+ ) -> void
35
+ end
36
+
37
+ type thinking_event =
38
+ { type: :thinking, thinking: String, snapshot: String }
39
+
40
+ class ThinkingEvent < Anthropic::Internal::Type::BaseModel
41
+ attr_accessor type: :thinking
42
+
43
+ attr_accessor thinking: String
44
+
45
+ attr_accessor snapshot: String
46
+
47
+ def initialize: (
48
+ thinking: String,
49
+ snapshot: String,
50
+ ?type: :thinking
51
+ ) -> void
52
+ end
53
+
54
+ type signature_event = { type: :signature, signature: String }
55
+
56
+ class SignatureEvent < Anthropic::Internal::Type::BaseModel
57
+ attr_accessor type: :signature
58
+
59
+ attr_accessor signature: String
60
+
61
+ def initialize: (signature: String, ?type: :signature) -> void
62
+ end
63
+
64
+ type input_json_event =
65
+ { type: :input_json, partial_json: String, snapshot: untyped }
66
+
67
+ class InputJsonEvent < Anthropic::Internal::Type::BaseModel
68
+ attr_accessor type: :input_json
69
+
70
+ attr_accessor partial_json: String
71
+
72
+ attr_accessor snapshot: untyped
73
+
74
+ def initialize: (
75
+ partial_json: String,
76
+ snapshot: untyped,
77
+ ?type: :input_json
78
+ ) -> void
79
+ end
80
+
81
+ type message_stop_event =
82
+ { type: :message_stop, message: Anthropic::Models::message }
83
+
84
+ class MessageStopEvent < Anthropic::Models::RawMessageStopEvent
85
+ attr_accessor type: :message_stop
86
+
87
+ attr_accessor message: Anthropic::Models::message
88
+
89
+ def initialize: (
90
+ message: Anthropic::Models::message,
91
+ ?type: :message_stop
92
+ ) -> void
93
+ end
94
+
95
+ type content_block_stop_event =
96
+ {
97
+ type: :content_block_stop,
98
+ index: Integer,
99
+ content_block: Anthropic::Models::content_block
100
+ }
101
+
102
+ class ContentBlockStopEvent < Anthropic::Models::RawContentBlockStopEvent
103
+ attr_accessor type: :content_block_stop
104
+
105
+ attr_accessor index: Integer
106
+
107
+ attr_accessor content_block: Anthropic::Models::content_block
108
+
109
+ def initialize: (
110
+ index: Integer,
111
+ content_block: Anthropic::Models::content_block,
112
+ ?type: :content_block_stop
113
+ ) -> void
114
+ end
115
+ end
116
+ end
117
+ end