anthropic 1.1.1 → 1.2.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 (131) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +45 -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 +6 -0
  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 +5 -5
  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/streaming/events.rbi +85 -0
  64. data/rbi/anthropic/helpers/streaming/message_stream.rbi +59 -0
  65. data/rbi/anthropic/internal/type/base_stream.rbi +8 -1
  66. data/rbi/anthropic/internal/type/boolean.rbi +2 -0
  67. data/rbi/anthropic/internal/type/converter.rbi +15 -15
  68. data/rbi/anthropic/internal/type/union.rbi +5 -0
  69. data/rbi/anthropic/internal/type/unknown.rbi +2 -0
  70. data/rbi/anthropic/internal/util.rbi +2 -0
  71. data/rbi/anthropic/models/beta/beta_base64_pdf_block.rbi +1 -128
  72. data/rbi/anthropic/models/beta/beta_citation_search_result_location.rbi +78 -0
  73. data/rbi/anthropic/models/beta/beta_citation_search_result_location_param.rbi +79 -0
  74. data/rbi/anthropic/models/beta/beta_citations_delta.rbi +4 -2
  75. data/rbi/anthropic/models/beta/beta_content_block.rbi +3 -3
  76. data/rbi/anthropic/models/beta/beta_content_block_param.rbi +8 -7
  77. data/rbi/anthropic/models/beta/beta_message.rbi +11 -3
  78. data/rbi/anthropic/models/beta/beta_raw_content_block_start_event.rbi +6 -6
  79. data/rbi/anthropic/models/beta/beta_request_document_block.rbi +140 -0
  80. data/rbi/anthropic/models/beta/beta_search_result_block_param.rbi +91 -0
  81. data/rbi/anthropic/models/beta/beta_text_block.rbi +2 -1
  82. data/rbi/anthropic/models/beta/beta_text_block_param.rbi +6 -3
  83. data/rbi/anthropic/models/beta/beta_text_citation.rbi +2 -1
  84. data/rbi/anthropic/models/beta/beta_text_citation_param.rbi +2 -1
  85. data/rbi/anthropic/models/beta/beta_tool.rbi +14 -5
  86. data/rbi/anthropic/models/beta/beta_tool_result_block_param.rbi +2 -1
  87. data/rbi/anthropic/models/beta/beta_tool_union.rbi +5 -5
  88. data/rbi/anthropic/models/beta/message_count_tokens_params.rbi +39 -27
  89. data/rbi/anthropic/models/beta/message_create_params.rbi +34 -22
  90. data/rbi/anthropic/models/beta/messages/batch_create_params.rbi +34 -22
  91. data/rbi/anthropic/models/content_block.rbi +3 -3
  92. data/rbi/anthropic/models/content_block_param.rbi +5 -5
  93. data/rbi/anthropic/models/message.rbi +11 -3
  94. data/rbi/anthropic/models/message_count_tokens_params.rbi +18 -2
  95. data/rbi/anthropic/models/message_count_tokens_tool.rbi +61 -0
  96. data/rbi/anthropic/models/message_create_params.rbi +18 -2
  97. data/rbi/anthropic/models/messages/batch_create_params.rbi +18 -2
  98. data/rbi/anthropic/models/raw_content_block_start_event.rbi +6 -6
  99. data/rbi/anthropic/models/tool.rbi +16 -5
  100. data/rbi/anthropic/models/tool_union.rbi +61 -0
  101. data/rbi/anthropic/resources/beta/messages.rbi +36 -18
  102. data/rbi/anthropic/resources/messages.rbi +293 -3
  103. data/rbi/anthropic/streaming.rbi +5 -0
  104. data/sig/anthropic/errors.rbs +9 -0
  105. data/sig/anthropic/helpers/streaming/events.rbs +119 -0
  106. data/sig/anthropic/helpers/streaming/message_stream.rbs +55 -0
  107. data/sig/anthropic/internal/type/base_stream.rbs +4 -0
  108. data/sig/anthropic/internal/type/converter.rbs +7 -1
  109. data/sig/anthropic/models/beta/beta_base64_pdf_block.rbs +1 -58
  110. data/sig/anthropic/models/beta/beta_citation_search_result_location.rbs +54 -0
  111. data/sig/anthropic/models/beta/beta_citation_search_result_location_param.rbs +54 -0
  112. data/sig/anthropic/models/beta/beta_citations_delta.rbs +1 -0
  113. data/sig/anthropic/models/beta/beta_content_block.rbs +2 -2
  114. data/sig/anthropic/models/beta/beta_content_block_param.rbs +9 -8
  115. data/sig/anthropic/models/beta/beta_raw_content_block_start_event.rbs +2 -2
  116. data/sig/anthropic/models/beta/beta_request_document_block.rbs +66 -0
  117. data/sig/anthropic/models/beta/beta_search_result_block_param.rbs +53 -0
  118. data/sig/anthropic/models/beta/beta_text_citation.rbs +1 -0
  119. data/sig/anthropic/models/beta/beta_text_citation_param.rbs +1 -0
  120. data/sig/anthropic/models/beta/beta_tool.rbs +14 -3
  121. data/sig/anthropic/models/beta/beta_tool_result_block_param.rbs +1 -0
  122. data/sig/anthropic/models/beta/beta_tool_union.rbs +4 -4
  123. data/sig/anthropic/models/beta/message_count_tokens_params.rbs +4 -4
  124. data/sig/anthropic/models/content_block.rbs +2 -2
  125. data/sig/anthropic/models/content_block_param.rbs +5 -5
  126. data/sig/anthropic/models/message_count_tokens_tool.rbs +28 -0
  127. data/sig/anthropic/models/raw_content_block_start_event.rbs +2 -2
  128. data/sig/anthropic/models/tool.rbs +14 -3
  129. data/sig/anthropic/models/tool_union.rbs +28 -0
  130. data/sig/anthropic/streaming.rbs +3 -0
  131. metadata +26 -3
@@ -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,275 @@ 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: T::Array[T.any(Anthropic::Models::MessageParam, Anthropic::Internal::AnyHash)],
318
+ model: T.any(Anthropic::Models::Model::OrSymbol, String),
319
+ metadata: T.any(Anthropic::Models::Metadata, Anthropic::Internal::AnyHash),
320
+ stop_sequences: T::Array[String],
321
+ system_: T.any(String, T::Array[T.any(Anthropic::Models::TextBlockParam, Anthropic::Internal::AnyHash)]),
322
+ temperature: Float,
323
+ thinking: T.any(
324
+ Anthropic::Models::ThinkingConfigEnabled,
325
+ Anthropic::Internal::AnyHash,
326
+ Anthropic::Models::ThinkingConfigDisabled
327
+ ),
328
+ tool_choice: T.any(
329
+ Anthropic::Models::ToolChoiceAuto,
330
+ Anthropic::Internal::AnyHash,
331
+ Anthropic::Models::ToolChoiceAny,
332
+ Anthropic::Models::ToolChoiceTool,
333
+ Anthropic::Models::ToolChoiceNone
334
+ ),
335
+ tools: T::Array[
336
+ T.any(
337
+ Anthropic::Models::Tool,
338
+ Anthropic::Internal::AnyHash,
339
+ Anthropic::Models::ToolBash20250124,
340
+ Anthropic::Models::ToolTextEditor20250124
341
+ )
342
+ ],
343
+ top_k: Integer,
344
+ top_p: Float,
345
+ stream: T.noreturn,
346
+ request_options: T.nilable(T.any(Anthropic::RequestOptions, Anthropic::Internal::AnyHash))
347
+ )
348
+ .returns(Anthropic::Helpers::Streaming::MessageStream)
349
+ end
350
+ def stream(
351
+ # The maximum number of tokens to generate before stopping.
352
+ #
353
+ # Note that our models may stop _before_ reaching this maximum. This parameter
354
+ # only specifies the absolute maximum number of tokens to generate.
355
+ #
356
+ # Different models have different maximum values for this parameter. See
357
+ # [models](https://docs.anthropic.com/en/docs/models-overview) for details.
358
+ max_tokens:,
359
+ # Input messages.
360
+ #
361
+ # Our models are trained to operate on alternating `user` and `assistant`
362
+ # conversational turns. When creating a new `Message`, you specify the prior
363
+ # conversational turns with the `messages` parameter, and the model then generates
364
+ # the next `Message` in the conversation. Consecutive `user` or `assistant` turns
365
+ # in your request will be combined into a single turn.
366
+ #
367
+ # Each input message must be an object with a `role` and `content`. You can
368
+ # specify a single `user`-role message, or you can include multiple `user` and
369
+ # `assistant` messages.
370
+ #
371
+ # If the final message uses the `assistant` role, the response content will
372
+ # continue immediately from the content in that message. This can be used to
373
+ # constrain part of the model's response.
374
+ #
375
+ # Example with a single `user` message:
376
+ #
377
+ # ```json
378
+ # [{ "role": "user", "content": "Hello, Claude" }]
379
+ # ```
380
+ #
381
+ # Example with multiple conversational turns:
382
+ #
383
+ # ```json
384
+ # [
385
+ # { "role": "user", "content": "Hello there." },
386
+ # { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
387
+ # { "role": "user", "content": "Can you explain LLMs in plain English?" }
388
+ # ]
389
+ # ```
390
+ #
391
+ # Example with a partially-filled response from Claude:
392
+ #
393
+ # ```json
394
+ # [
395
+ # {
396
+ # "role": "user",
397
+ # "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
398
+ # },
399
+ # { "role": "assistant", "content": "The best answer is (" }
400
+ # ]
401
+ # ```
402
+ #
403
+ # Each input message `content` may be either a single `string` or an array of
404
+ # content blocks, where each block has a specific `type`. Using a `string` for
405
+ # `content` is shorthand for an array of one content block of type `"text"`. The
406
+ # following input messages are equivalent:
407
+ #
408
+ # ```json
409
+ # { "role": "user", "content": "Hello, Claude" }
410
+ # ```
411
+ #
412
+ # ```json
413
+ # { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
414
+ # ```
415
+ #
416
+ # Starting with Claude 3 models, you can also send image content blocks:
417
+ #
418
+ # ```json
419
+ # {
420
+ # "role": "user",
421
+ # "content": [
422
+ # {
423
+ # "type": "image",
424
+ # "source": {
425
+ # "type": "base64",
426
+ # "media_type": "image/jpeg",
427
+ # "data": "/9j/4AAQSkZJRg..."
428
+ # }
429
+ # },
430
+ # { "type": "text", "text": "What is in this image?" }
431
+ # ]
432
+ # }
433
+ # ```
434
+ #
435
+ # We currently support the `base64` source type for images, and the `image/jpeg`,
436
+ # `image/png`, `image/gif`, and `image/webp` media types.
437
+ #
438
+ # See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
439
+ # more input examples.
440
+ #
441
+ # Note that if you want to include a
442
+ # [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
443
+ # the top-level `system` parameter — there is no `"system"` role for input
444
+ # messages in the Messages API.
445
+ messages:,
446
+ # The model that will complete your prompt.\n\nSee
447
+ # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
448
+ # details and options.
449
+ model:,
450
+ # An object describing metadata about the request.
451
+ metadata: nil,
452
+ # Custom text sequences that will cause the model to stop generating.
453
+ #
454
+ # Our models will normally stop when they have naturally completed their turn,
455
+ # which will result in a response `stop_reason` of `"end_turn"`.
456
+ #
457
+ # If you want the model to stop generating when it encounters custom strings of
458
+ # text, you can use the `stop_sequences` parameter. If the model encounters one of
459
+ # the custom sequences, the response `stop_reason` value will be `"stop_sequence"`
460
+ # and the response `stop_sequence` value will contain the matched stop sequence.
461
+ stop_sequences: nil,
462
+ # System prompt.
463
+ #
464
+ # A system prompt is a way of providing context and instructions to Claude, such
465
+ # as specifying a particular goal or role. See our
466
+ # [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
467
+ system_: nil,
468
+ # Amount of randomness injected into the response.
469
+ #
470
+ # Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
471
+ # for analytical / multiple choice, and closer to `1.0` for creative and
472
+ # generative tasks.
473
+ #
474
+ # Note that even with `temperature` of `0.0`, the results will not be fully
475
+ # deterministic.
476
+ temperature: nil,
477
+ # Configuration for enabling Claude's extended thinking.
478
+ #
479
+ # When enabled, responses include `thinking` content blocks showing Claude's
480
+ # thinking process before the final answer. Requires a minimum budget of 1,024
481
+ # tokens and counts towards your `max_tokens` limit.
482
+ #
483
+ # See
484
+ # [extended thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)
485
+ # for details.
486
+ thinking: nil,
487
+ # How the model should use the provided tools. The model can use a specific tool,
488
+ # any available tool, decide by itself, or not use tools at all.
489
+ tool_choice: nil,
490
+ # Definitions of tools that the model may use.
491
+ #
492
+ # If you include `tools` in your API request, the model may return `tool_use`
493
+ # content blocks that represent the model's use of those tools. You can then run
494
+ # those tools using the tool input generated by the model and then optionally
495
+ # return results back to the model using `tool_result` content blocks.
496
+ #
497
+ # Each tool definition includes:
498
+ #
499
+ # - `name`: Name of the tool.
500
+ # - `description`: Optional, but strongly-recommended description of the tool.
501
+ # - `input_schema`: [JSON schema](https://json-schema.org/draft/2020-12) for the
502
+ # tool `input` shape that the model will produce in `tool_use` output content
503
+ # blocks.
504
+ #
505
+ # For example, if you defined `tools` as:
506
+ #
507
+ # ```json
508
+ # [
509
+ # {
510
+ # "name": "get_stock_price",
511
+ # "description": "Get the current stock price for a given ticker symbol.",
512
+ # "input_schema": {
513
+ # "type": "object",
514
+ # "properties": {
515
+ # "ticker": {
516
+ # "type": "string",
517
+ # "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
518
+ # }
519
+ # },
520
+ # "required": ["ticker"]
521
+ # }
522
+ # }
523
+ # ]
524
+ # ```
525
+ #
526
+ # And then asked the model "What's the S&P 500 at today?", the model might produce
527
+ # `tool_use` content blocks in the response like this:
528
+ #
529
+ # ```json
530
+ # [
531
+ # {
532
+ # "type": "tool_use",
533
+ # "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
534
+ # "name": "get_stock_price",
535
+ # "input": { "ticker": "^GSPC" }
536
+ # }
537
+ # ]
538
+ # ```
539
+ #
540
+ # You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
541
+ # input, and return the following back to the model in a subsequent `user`
542
+ # message:
543
+ #
544
+ # ```json
545
+ # [
546
+ # {
547
+ # "type": "tool_result",
548
+ # "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
549
+ # "content": "259.75 USD"
550
+ # }
551
+ # ]
552
+ # ```
553
+ #
554
+ # Tools can be used for workflows that include running client-side tools and
555
+ # functions, or more generally whenever you want the model to produce a particular
556
+ # JSON structure of output.
557
+ #
558
+ # See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
559
+ tools: nil,
560
+ # Only sample from the top K options for each subsequent token.
561
+ #
562
+ # Used to remove "long tail" low probability responses.
563
+ # [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
564
+ #
565
+ # Recommended for advanced use cases only. You usually only need to use
566
+ # `temperature`.
567
+ top_k: nil,
568
+ # Use nucleus sampling.
569
+ #
570
+ # In nucleus sampling, we compute the cumulative distribution over all the options
571
+ # for each subsequent token in decreasing probability order and cut it off once it
572
+ # reaches a particular probability specified by `top_p`. You should either alter
573
+ # `temperature` or `top_p`, but not both.
574
+ #
575
+ # Recommended for advanced use cases only. You usually only need to use
576
+ # `temperature`.
577
+ top_p: nil,
578
+ # There is no need to provide `stream:`. Instead, use `#stream_raw` or `#create`
579
+ # for streaming and non-streaming use cases, respectively.
580
+ stream: true,
581
+ request_options: {}
582
+ ); end
307
583
  sig do
308
584
  params(
309
585
  max_tokens: Integer,
@@ -332,6 +608,7 @@ module Anthropic
332
608
  Anthropic::Tool::OrHash,
333
609
  Anthropic::ToolBash20250124::OrHash,
334
610
  Anthropic::ToolTextEditor20250124::OrHash,
611
+ Anthropic::ToolUnion::TextEditor20250429::OrHash,
335
612
  Anthropic::WebSearchTool20250305::OrHash
336
613
  )
337
614
  ],
@@ -441,7 +718,7 @@ module Anthropic
441
718
  # the top-level `system` parameter — there is no `"system"` role for input
442
719
  # messages in the Messages API.
443
720
  #
444
- # There is a limit of 100000 messages in a single request.
721
+ # There is a limit of 100,000 messages in a single request.
445
722
  messages:,
446
723
  # The model that will complete your prompt.\n\nSee
447
724
  # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
@@ -500,6 +777,12 @@ module Anthropic
500
777
  # those tools using the tool input generated by the model and then optionally
501
778
  # return results back to the model using `tool_result` content blocks.
502
779
  #
780
+ # There are two types of tools: **client tools** and **server tools**. The
781
+ # behavior described below applies to client tools. For
782
+ # [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
783
+ # see their individual documentation as each has its own behavior (e.g., the
784
+ # [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
785
+ #
503
786
  # Each tool definition includes:
504
787
  #
505
788
  # - `name`: Name of the tool.
@@ -618,6 +901,7 @@ module Anthropic
618
901
  Anthropic::Tool::OrHash,
619
902
  Anthropic::ToolBash20250124::OrHash,
620
903
  Anthropic::ToolTextEditor20250124::OrHash,
904
+ Anthropic::MessageCountTokensTool::TextEditor20250429::OrHash,
621
905
  Anthropic::WebSearchTool20250305::OrHash
622
906
  )
623
907
  ],
@@ -712,7 +996,7 @@ module Anthropic
712
996
  # the top-level `system` parameter — there is no `"system"` role for input
713
997
  # messages in the Messages API.
714
998
  #
715
- # There is a limit of 100000 messages in a single request.
999
+ # There is a limit of 100,000 messages in a single request.
716
1000
  messages:,
717
1001
  # The model that will complete your prompt.\n\nSee
718
1002
  # [models](https://docs.anthropic.com/en/docs/models-overview) for additional
@@ -744,6 +1028,12 @@ module Anthropic
744
1028
  # those tools using the tool input generated by the model and then optionally
745
1029
  # return results back to the model using `tool_result` content blocks.
746
1030
  #
1031
+ # There are two types of tools: **client tools** and **server tools**. The
1032
+ # behavior described below applies to client tools. For
1033
+ # [server tools](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview#server-tools),
1034
+ # see their individual documentation as each has its own behavior (e.g., the
1035
+ # [web search tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool)).
1036
+ #
747
1037
  # Each tool definition includes:
748
1038
  #
749
1039
  # - `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,119 @@
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: (
14
+ ?type: :text,
15
+ text: String,
16
+ snapshot: String
17
+ ) -> void
18
+ end
19
+
20
+ type citation_event = {
21
+ type: :citation,
22
+ citation: Anthropic::Models::CitationsDelta::citation,
23
+ snapshot: ::Array[Anthropic::Models::CitationsDelta::citation]
24
+ }
25
+
26
+ class CitationEvent < Anthropic::Internal::Type::BaseModel
27
+ attr_accessor type: :citation
28
+
29
+ attr_accessor citation: Anthropic::Models::CitationsDelta::citation
30
+
31
+ attr_accessor snapshot: ::Array[Anthropic::Models::CitationsDelta::citation]
32
+
33
+ def initialize: (
34
+ ?type: :citation,
35
+ citation: Anthropic::Models::CitationsDelta::citation,
36
+ snapshot: ::Array[Anthropic::Models::CitationsDelta::citation]
37
+ ) -> void
38
+ end
39
+
40
+ type thinking_event = { type: :thinking, thinking: String, snapshot: String }
41
+
42
+ class ThinkingEvent < Anthropic::Internal::Type::BaseModel
43
+ attr_accessor type: :thinking
44
+
45
+ attr_accessor thinking: String
46
+
47
+ attr_accessor snapshot: String
48
+
49
+ def initialize: (
50
+ ?type: :thinking,
51
+ thinking: String,
52
+ snapshot: String
53
+ ) -> void
54
+ end
55
+
56
+ type signature_event = { type: :signature, signature: String }
57
+
58
+ class SignatureEvent < Anthropic::Internal::Type::BaseModel
59
+ attr_accessor type: :signature
60
+
61
+ attr_accessor signature: String
62
+
63
+ def initialize: (
64
+ ?type: :signature,
65
+ signature: String
66
+ ) -> void
67
+ end
68
+
69
+ type input_json_event = { type: :input_json, partial_json: String, snapshot: untyped }
70
+
71
+ class InputJsonEvent < Anthropic::Internal::Type::BaseModel
72
+ attr_accessor type: :input_json
73
+
74
+ attr_accessor partial_json: String
75
+
76
+ attr_accessor snapshot: untyped
77
+
78
+ def initialize: (
79
+ ?type: :input_json,
80
+ partial_json: String,
81
+ snapshot: untyped
82
+ ) -> void
83
+ end
84
+
85
+ type message_stop_event = { type: :message_stop, message: Anthropic::Models::message }
86
+
87
+ class MessageStopEvent < Anthropic::Models::RawMessageStopEvent
88
+ attr_accessor type: :message_stop
89
+
90
+ attr_accessor message: Anthropic::Models::message
91
+
92
+ def initialize: (
93
+ ?type: :message_stop,
94
+ message: Anthropic::Models::message
95
+ ) -> void
96
+ end
97
+
98
+ type content_block_stop_event = {
99
+ type: :content_block_stop,
100
+ index: Integer,
101
+ content_block: Anthropic::Models::content_block
102
+ }
103
+
104
+ class ContentBlockStopEvent < Anthropic::Models::RawContentBlockStopEvent
105
+ attr_accessor type: :content_block_stop
106
+
107
+ attr_accessor index: Integer
108
+
109
+ attr_accessor content_block: Anthropic::Models::content_block
110
+
111
+ def initialize: (
112
+ ?type: :content_block_stop,
113
+ index: Integer,
114
+ content_block: Anthropic::Models::content_block
115
+ ) -> void
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,55 @@
1
+ module Anthropic
2
+ module Helpers
3
+ module Streaming
4
+ type raw_message_event =
5
+ Anthropic::Models::raw_message_start_event
6
+ | Anthropic::Models::raw_message_delta_event
7
+ | Anthropic::Models::raw_message_stop_event
8
+ | Anthropic::Models::raw_content_block_start_event
9
+ | Anthropic::Models::raw_content_block_delta_event
10
+ | Anthropic::Models::raw_content_block_stop_event
11
+
12
+ type stream_event =
13
+ raw_message_event
14
+ | text_event
15
+ | citation_event
16
+ | thinking_event
17
+ | signature_event
18
+ | input_json_event
19
+ | message_stop_event
20
+ | content_block_stop_event
21
+
22
+ class MessageStream
23
+ include Anthropic::Internal::Type::BaseStream[raw_message_event, stream_event]
24
+
25
+ @raw_stream: Anthropic::Internal::Stream[raw_message_event]
26
+ @accumated_message_snapshot: Anthropic::Models::message?
27
+ @iterator: Enumerable[stream_event]?
28
+
29
+ def initialize: (raw_stream: Anthropic::Internal::Stream[raw_message_event]) -> void
30
+
31
+ def until_done: -> void
32
+
33
+ def text: -> Enumerator[String]
34
+
35
+ def accumulated_message: -> Anthropic::Models::message
36
+
37
+ def accumulated_text: -> String
38
+
39
+ private
40
+
41
+ def iterator: -> Enumerable[stream_event]
42
+
43
+ def accumulate_event: (
44
+ event: raw_message_event,
45
+ current_snapshot: Anthropic::Models::message?
46
+ ) -> Anthropic::Models::message
47
+
48
+ def build_events: (
49
+ event: raw_message_event,
50
+ message_snapshot: Anthropic::Models::message
51
+ ) -> ::Array[stream_event]
52
+ end
53
+ end
54
+ end
55
+ end
@@ -23,6 +23,10 @@ module Anthropic
23
23
  url: URI::Generic,
24
24
  status: Integer,
25
25
  response: top,
26
+ unwrap: Symbol
27
+ | Integer
28
+ | ::Array[Symbol | Integer]
29
+ | ^(top arg0) -> top,
26
30
  stream: Enumerable[Message]
27
31
  ) -> void
28
32
 
@@ -8,8 +8,10 @@ module Anthropic
8
8
 
9
9
  type coerce_state =
10
10
  {
11
- strictness: bool | :strong,
11
+ translate_names: bool,
12
+ strictness: bool,
12
13
  exactness: { yes: Integer, no: Integer, maybe: Integer },
14
+ error: Class,
13
15
  branched: Integer
14
16
  }
15
17
 
@@ -37,6 +39,10 @@ module Anthropic
37
39
  | Anthropic::Internal::Type::Converter::input spec
38
40
  ) -> (^-> top)
39
41
 
42
+ def self.new_coerce_state: (
43
+ ?translate_names: bool
44
+ ) -> Anthropic::Internal::Type::Converter::coerce_state
45
+
40
46
  def self.coerce: (
41
47
  Anthropic::Internal::Type::Converter::input target,
42
48
  top value,
@@ -3,64 +3,7 @@ module Anthropic
3
3
  class BetaBase64PDFBlock = Beta::BetaBase64PDFBlock
4
4
 
5
5
  module Beta
6
- type beta_base64_pdf_block =
7
- {
8
- source: Anthropic::Models::Beta::BetaBase64PDFBlock::source,
9
- type: :document,
10
- cache_control: Anthropic::Beta::BetaCacheControlEphemeral?,
11
- citations: Anthropic::Beta::BetaCitationsConfigParam,
12
- context: String?,
13
- title: String?
14
- }
15
-
16
- class BetaBase64PDFBlock < Anthropic::Internal::Type::BaseModel
17
- attr_accessor source: Anthropic::Models::Beta::BetaBase64PDFBlock::source
18
-
19
- attr_accessor type: :document
20
-
21
- attr_accessor cache_control: Anthropic::Beta::BetaCacheControlEphemeral?
22
-
23
- attr_reader citations: Anthropic::Beta::BetaCitationsConfigParam?
24
-
25
- def citations=: (
26
- Anthropic::Beta::BetaCitationsConfigParam
27
- ) -> Anthropic::Beta::BetaCitationsConfigParam
28
-
29
- attr_accessor context: String?
30
-
31
- attr_accessor title: String?
32
-
33
- def initialize: (
34
- source: Anthropic::Models::Beta::BetaBase64PDFBlock::source,
35
- ?cache_control: Anthropic::Beta::BetaCacheControlEphemeral?,
36
- ?citations: Anthropic::Beta::BetaCitationsConfigParam,
37
- ?context: String?,
38
- ?title: String?,
39
- ?type: :document
40
- ) -> void
41
-
42
- def to_hash: -> {
43
- source: Anthropic::Models::Beta::BetaBase64PDFBlock::source,
44
- type: :document,
45
- cache_control: Anthropic::Beta::BetaCacheControlEphemeral?,
46
- citations: Anthropic::Beta::BetaCitationsConfigParam,
47
- context: String?,
48
- title: String?
49
- }
50
-
51
- type source =
52
- Anthropic::Beta::BetaBase64PDFSource
53
- | Anthropic::Beta::BetaPlainTextSource
54
- | Anthropic::Beta::BetaContentBlockSource
55
- | Anthropic::Beta::BetaURLPDFSource
56
- | Anthropic::Beta::BetaFileDocumentSource
57
-
58
- module Source
59
- extend Anthropic::Internal::Type::Union
60
-
61
- def self?.variants: -> ::Array[Anthropic::Models::Beta::BetaBase64PDFBlock::source]
62
- end
63
- end
6
+ class BetaBase64PDFBlock = Anthropic::Models::Beta::BetaRequestDocumentBlock
64
7
  end
65
8
  end
66
9
  end