anthropic 1.1.1 → 1.9.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +170 -0
- data/README.md +32 -16
- data/lib/anthropic/client.rb +5 -2
- data/lib/anthropic/errors.rb +22 -0
- data/lib/anthropic/helpers/bedrock/client.rb +34 -4
- data/lib/anthropic/helpers/input_schema/array_of.rb +41 -0
- data/lib/anthropic/helpers/input_schema/base_model.rb +86 -0
- data/lib/anthropic/helpers/input_schema/boolean.rb +29 -0
- data/lib/anthropic/helpers/input_schema/enum_of.rb +63 -0
- data/lib/anthropic/helpers/input_schema/json_schema_converter.rb +199 -0
- data/lib/anthropic/helpers/input_schema/parsed_json.rb +39 -0
- data/lib/anthropic/helpers/input_schema/property_mapping.rb +47 -0
- data/lib/anthropic/helpers/input_schema/union_of.rb +56 -0
- data/lib/anthropic/helpers/input_schema.rb +16 -0
- data/lib/anthropic/helpers/streaming/events.rb +141 -0
- data/lib/anthropic/helpers/streaming/message_stream.rb +278 -0
- data/lib/anthropic/helpers/streaming.rb +37 -0
- data/lib/anthropic/helpers/vertex/client.rb +4 -1
- data/lib/anthropic/input_schema.rb +10 -0
- data/lib/anthropic/internal/stream.rb +6 -3
- data/lib/anthropic/internal/transport/base_client.rb +30 -5
- data/lib/anthropic/internal/transport/pooled_net_requester.rb +1 -9
- data/lib/anthropic/internal/type/array_of.rb +7 -1
- data/lib/anthropic/internal/type/base_model.rb +81 -32
- data/lib/anthropic/internal/type/base_stream.rb +3 -1
- data/lib/anthropic/internal/type/boolean.rb +7 -1
- data/lib/anthropic/internal/type/converter.rb +69 -34
- data/lib/anthropic/internal/type/enum.rb +16 -5
- data/lib/anthropic/internal/type/file_input.rb +6 -1
- data/lib/anthropic/internal/type/hash_of.rb +7 -1
- data/lib/anthropic/internal/type/union.rb +26 -16
- data/lib/anthropic/internal/type/unknown.rb +7 -1
- data/lib/anthropic/internal/util.rb +10 -11
- data/lib/anthropic/models/anthropic_beta.rb +3 -0
- data/lib/anthropic/models/beta/beta_base64_pdf_block.rb +1 -65
- data/lib/anthropic/models/beta/beta_bash_code_execution_output_block.rb +25 -0
- data/lib/anthropic/models/beta/beta_bash_code_execution_output_block_param.rb +25 -0
- data/lib/anthropic/models/beta/beta_bash_code_execution_result_block.rb +44 -0
- data/lib/anthropic/models/beta/beta_bash_code_execution_result_block_param.rb +44 -0
- data/lib/anthropic/models/beta/beta_bash_code_execution_tool_result_block.rb +43 -0
- data/lib/anthropic/models/beta/beta_bash_code_execution_tool_result_block_param.rb +53 -0
- data/lib/anthropic/models/beta/beta_bash_code_execution_tool_result_error.rb +39 -0
- data/lib/anthropic/models/beta/beta_bash_code_execution_tool_result_error_param.rb +39 -0
- data/lib/anthropic/models/beta/beta_citation_char_location.rb +7 -1
- data/lib/anthropic/models/beta/beta_citation_config.rb +19 -0
- data/lib/anthropic/models/beta/beta_citation_content_block_location.rb +7 -1
- data/lib/anthropic/models/beta/beta_citation_page_location.rb +7 -1
- data/lib/anthropic/models/beta/beta_citation_search_result_location.rb +55 -0
- data/lib/anthropic/models/beta/beta_citation_search_result_location_param.rb +55 -0
- data/lib/anthropic/models/beta/beta_citations_delta.rb +5 -3
- data/lib/anthropic/models/beta/beta_code_execution_tool_20250825.rb +40 -0
- data/lib/anthropic/models/beta/beta_content_block.rb +12 -5
- data/lib/anthropic/models/beta/beta_content_block_param.rb +28 -17
- data/lib/anthropic/models/beta/beta_document_block.rb +56 -0
- data/lib/anthropic/models/beta/beta_message.rb +6 -2
- data/lib/anthropic/models/beta/beta_message_param.rb +3 -3
- data/lib/anthropic/models/beta/beta_raw_content_block_start_event.rb +14 -7
- data/lib/anthropic/models/beta/beta_request_document_block.rb +75 -0
- data/lib/anthropic/models/beta/beta_search_result_block_param.rb +55 -0
- data/lib/anthropic/models/beta/beta_server_tool_usage.rb +9 -1
- data/lib/anthropic/models/beta/beta_server_tool_use_block.rb +3 -0
- data/lib/anthropic/models/beta/beta_server_tool_use_block_param.rb +3 -0
- data/lib/anthropic/models/beta/beta_text_block.rb +2 -2
- data/lib/anthropic/models/beta/beta_text_block_param.rb +2 -2
- data/lib/anthropic/models/beta/beta_text_citation.rb +3 -1
- data/lib/anthropic/models/beta/beta_text_citation_param.rb +3 -1
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_create_result_block.rb +25 -0
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_create_result_block_param.rb +26 -0
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block.rb +49 -0
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block_param.rb +50 -0
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_tool_result_block.rb +47 -0
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_tool_result_block_param.rb +57 -0
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_tool_result_error.rb +45 -0
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_tool_result_error_param.rb +46 -0
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_view_result_block.rb +61 -0
- data/lib/anthropic/models/beta/beta_text_editor_code_execution_view_result_block_param.rb +62 -0
- data/lib/anthropic/models/beta/beta_tool.rb +7 -1
- data/lib/anthropic/models/beta/beta_tool_result_block_param.rb +8 -4
- data/lib/anthropic/models/beta/beta_tool_text_editor_20250728.rb +49 -0
- data/lib/anthropic/models/beta/beta_tool_union.rb +12 -6
- data/lib/anthropic/models/beta/beta_web_fetch_block.rb +42 -0
- data/lib/anthropic/models/beta/beta_web_fetch_block_param.rb +42 -0
- data/lib/anthropic/models/beta/beta_web_fetch_tool_20250910.rb +82 -0
- data/lib/anthropic/models/beta/beta_web_fetch_tool_result_block.rb +43 -0
- data/lib/anthropic/models/beta/beta_web_fetch_tool_result_block_param.rb +53 -0
- data/lib/anthropic/models/beta/beta_web_fetch_tool_result_error_block.rb +25 -0
- data/lib/anthropic/models/beta/beta_web_fetch_tool_result_error_block_param.rb +25 -0
- data/lib/anthropic/models/beta/beta_web_fetch_tool_result_error_code.rb +25 -0
- data/lib/anthropic/models/beta/message_count_tokens_params.rb +23 -36
- data/lib/anthropic/models/beta/message_create_params.rb +10 -27
- data/lib/anthropic/models/beta/messages/batch_create_params.rb +13 -37
- data/lib/anthropic/models/beta/messages/beta_message_batch.rb +1 -4
- data/lib/anthropic/models/beta_error_response.rb +7 -1
- data/lib/anthropic/models/cache_control_ephemeral.rb +39 -1
- data/lib/anthropic/models/cache_creation.rb +24 -0
- data/lib/anthropic/models/citation_char_location.rb +7 -1
- data/lib/anthropic/models/citation_content_block_location.rb +7 -1
- data/lib/anthropic/models/citation_page_location.rb +7 -1
- data/lib/anthropic/models/citation_search_result_location_param.rb +51 -0
- data/lib/anthropic/models/citations_delta.rb +5 -3
- data/lib/anthropic/models/citations_search_result_location.rb +51 -0
- data/lib/anthropic/models/content_block.rb +5 -5
- data/lib/anthropic/models/content_block_param.rb +14 -11
- data/lib/anthropic/models/document_block_param.rb +2 -2
- data/lib/anthropic/models/error_response.rb +7 -1
- data/lib/anthropic/models/message.rb +6 -2
- data/lib/anthropic/models/message_count_tokens_params.rb +10 -27
- data/lib/anthropic/models/message_count_tokens_tool.rb +5 -1
- data/lib/anthropic/models/message_create_params.rb +10 -27
- data/lib/anthropic/models/message_param.rb +3 -3
- data/lib/anthropic/models/messages/batch_create_params.rb +11 -31
- data/lib/anthropic/models/model.rb +16 -21
- data/lib/anthropic/models/raw_content_block_start_event.rb +7 -7
- data/lib/anthropic/models/search_result_block_param.rb +51 -0
- data/lib/anthropic/models/text_block.rb +2 -2
- data/lib/anthropic/models/text_block_param.rb +2 -2
- data/lib/anthropic/models/text_citation.rb +3 -1
- data/lib/anthropic/models/text_citation_param.rb +3 -1
- data/lib/anthropic/models/tool.rb +7 -1
- data/lib/anthropic/models/tool_result_block_param.rb +8 -4
- data/lib/anthropic/models/tool_text_editor_20250429.rb +36 -0
- data/lib/anthropic/models/tool_text_editor_20250728.rb +45 -0
- data/lib/anthropic/models/tool_union.rb +5 -1
- data/lib/anthropic/models/tool_use_block.rb +14 -0
- data/lib/anthropic/models/usage.rb +9 -1
- data/lib/anthropic/models.rb +16 -4
- data/lib/anthropic/resources/beta/messages.rb +73 -6
- data/lib/anthropic/resources/messages.rb +152 -7
- data/lib/anthropic/streaming.rb +5 -0
- data/lib/anthropic/version.rb +1 -1
- data/lib/anthropic.rb +54 -0
- data/rbi/anthropic/errors.rbi +18 -2
- data/rbi/anthropic/helpers/bedrock/client.rbi +17 -6
- data/rbi/anthropic/helpers/input_schema/array_of.rbi +16 -0
- data/rbi/anthropic/helpers/input_schema/base_model.rbi +21 -0
- data/rbi/anthropic/helpers/input_schema/boolean.rbi +11 -0
- data/rbi/anthropic/helpers/input_schema/enum_of.rbi +30 -0
- data/rbi/anthropic/helpers/input_schema/json_schema_converter.rbi +89 -0
- data/rbi/anthropic/helpers/input_schema/union_of.rbi +23 -0
- data/rbi/anthropic/helpers/streaming/events.rbi +95 -0
- data/rbi/anthropic/helpers/streaming/message_stream.rbi +73 -0
- data/rbi/anthropic/helpers/structured_output.rbi +16 -0
- data/rbi/anthropic/helpers/vertex/client.rbi +17 -6
- data/rbi/anthropic/input_schema.rbi +12 -0
- data/rbi/anthropic/internal/transport/base_client.rbi +1 -1
- data/rbi/anthropic/internal/type/base_stream.rbi +8 -1
- data/rbi/anthropic/internal/type/boolean.rbi +2 -0
- data/rbi/anthropic/internal/type/converter.rbi +69 -15
- data/rbi/anthropic/internal/type/union.rbi +14 -2
- data/rbi/anthropic/internal/type/unknown.rbi +2 -0
- data/rbi/anthropic/internal/util.rbi +2 -0
- data/rbi/anthropic/models/anthropic_beta.rbi +2 -0
- data/rbi/anthropic/models/beta/beta_base64_pdf_block.rbi +1 -128
- data/rbi/anthropic/models/beta/beta_bash_code_execution_output_block.rbi +33 -0
- data/rbi/anthropic/models/beta/beta_bash_code_execution_output_block_param.rbi +34 -0
- data/rbi/anthropic/models/beta/beta_bash_code_execution_result_block.rbi +72 -0
- data/rbi/anthropic/models/beta/beta_bash_code_execution_result_block_param.rbi +77 -0
- data/rbi/anthropic/models/beta/beta_bash_code_execution_tool_result_block.rbi +86 -0
- data/rbi/anthropic/models/beta/beta_bash_code_execution_tool_result_block_param.rbi +110 -0
- data/rbi/anthropic/models/beta/beta_bash_code_execution_tool_result_error.rbi +101 -0
- data/rbi/anthropic/models/beta/beta_bash_code_execution_tool_result_error_param.rbi +101 -0
- data/rbi/anthropic/models/beta/beta_citation_char_location.rbi +6 -0
- data/rbi/anthropic/models/beta/beta_citation_config.rbi +30 -0
- data/rbi/anthropic/models/beta/beta_citation_content_block_location.rbi +6 -0
- data/rbi/anthropic/models/beta/beta_citation_page_location.rbi +6 -0
- data/rbi/anthropic/models/beta/beta_citation_search_result_location.rbi +78 -0
- data/rbi/anthropic/models/beta/beta_citation_search_result_location_param.rbi +79 -0
- data/rbi/anthropic/models/beta/beta_citations_delta.rbi +4 -2
- data/rbi/anthropic/models/beta/beta_code_execution_tool_20250825.rbi +72 -0
- data/rbi/anthropic/models/beta/beta_content_block.rbi +6 -3
- data/rbi/anthropic/models/beta/beta_content_block_param.rbi +11 -7
- data/rbi/anthropic/models/beta/beta_document_block.rbi +95 -0
- data/rbi/anthropic/models/beta/beta_message.rbi +14 -3
- data/rbi/anthropic/models/beta/beta_raw_content_block_start_event.rbi +12 -6
- data/rbi/anthropic/models/beta/beta_request_document_block.rbi +142 -0
- data/rbi/anthropic/models/beta/beta_search_result_block_param.rbi +91 -0
- data/rbi/anthropic/models/beta/beta_server_tool_usage.rbi +17 -2
- data/rbi/anthropic/models/beta/beta_server_tool_use_block.rbi +15 -0
- data/rbi/anthropic/models/beta/beta_server_tool_use_block_param.rbi +15 -0
- data/rbi/anthropic/models/beta/beta_text_block.rbi +2 -1
- data/rbi/anthropic/models/beta/beta_text_block_param.rbi +6 -3
- data/rbi/anthropic/models/beta/beta_text_citation.rbi +2 -1
- data/rbi/anthropic/models/beta/beta_text_citation_param.rbi +2 -1
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_create_result_block.rbi +41 -0
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_create_result_block_param.rbi +41 -0
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block.rbi +73 -0
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block_param.rbi +73 -0
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_tool_result_block.rbi +90 -0
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_tool_result_block_param.rbi +118 -0
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_tool_result_error.rbi +110 -0
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_tool_result_error_param.rbi +110 -0
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_view_result_block.rbi +118 -0
- data/rbi/anthropic/models/beta/beta_text_editor_code_execution_view_result_block_param.rbi +118 -0
- data/rbi/anthropic/models/beta/beta_tool.rbi +14 -5
- data/rbi/anthropic/models/beta/beta_tool_result_block_param.rbi +3 -1
- data/rbi/anthropic/models/beta/beta_tool_text_editor_20250728.rbi +82 -0
- data/rbi/anthropic/models/beta/beta_tool_union.rbi +7 -4
- data/rbi/anthropic/models/beta/beta_web_fetch_block.rbi +67 -0
- data/rbi/anthropic/models/beta/beta_web_fetch_block_param.rbi +71 -0
- data/rbi/anthropic/models/beta/beta_web_fetch_tool_20250910.rbi +125 -0
- data/rbi/anthropic/models/beta/beta_web_fetch_tool_result_block.rbi +81 -0
- data/rbi/anthropic/models/beta/beta_web_fetch_tool_result_block_param.rbi +109 -0
- data/rbi/anthropic/models/beta/beta_web_fetch_tool_result_error_block.rbi +51 -0
- data/rbi/anthropic/models/beta/beta_web_fetch_tool_result_error_block_param.rbi +50 -0
- data/rbi/anthropic/models/beta/beta_web_fetch_tool_result_error_code.rbi +70 -0
- data/rbi/anthropic/models/beta/message_count_tokens_params.rbi +51 -70
- data/rbi/anthropic/models/beta/message_create_params.rbi +44 -66
- data/rbi/anthropic/models/beta/messages/batch_create_params.rbi +44 -66
- data/rbi/anthropic/models/beta_error_response.rbi +10 -2
- data/rbi/anthropic/models/cache_control_ephemeral.rbi +68 -3
- data/rbi/anthropic/models/cache_creation.rbi +45 -0
- data/rbi/anthropic/models/citation_char_location.rbi +6 -0
- data/rbi/anthropic/models/citation_content_block_location.rbi +6 -0
- data/rbi/anthropic/models/citation_page_location.rbi +6 -0
- data/rbi/anthropic/models/citation_search_result_location_param.rbi +74 -0
- data/rbi/anthropic/models/citations_delta.rbi +4 -2
- data/rbi/anthropic/models/citations_search_result_location.rbi +74 -0
- data/rbi/anthropic/models/content_block.rbi +3 -3
- data/rbi/anthropic/models/content_block_param.rbi +6 -5
- data/rbi/anthropic/models/document_block_param.rbi +7 -3
- data/rbi/anthropic/models/error_response.rbi +10 -2
- data/rbi/anthropic/models/message.rbi +11 -3
- data/rbi/anthropic/models/message_count_tokens_params.rbi +24 -50
- data/rbi/anthropic/models/message_count_tokens_tool.rbi +2 -0
- data/rbi/anthropic/models/message_create_params.rbi +24 -50
- data/rbi/anthropic/models/messages/batch_create_params.rbi +24 -50
- data/rbi/anthropic/models/model.rbi +4 -8
- data/rbi/anthropic/models/raw_content_block_start_event.rbi +6 -6
- data/rbi/anthropic/models/search_result_block_param.rbi +77 -0
- data/rbi/anthropic/models/text_block.rbi +2 -1
- data/rbi/anthropic/models/text_block_param.rbi +6 -3
- data/rbi/anthropic/models/text_citation.rbi +2 -1
- data/rbi/anthropic/models/text_citation_param.rbi +2 -1
- data/rbi/anthropic/models/tool.rbi +16 -5
- data/rbi/anthropic/models/tool_result_block_param.rbi +6 -1
- data/rbi/anthropic/models/tool_text_editor_20250429.rbi +62 -0
- data/rbi/anthropic/models/tool_text_editor_20250728.rbi +72 -0
- data/rbi/anthropic/models/tool_union.rbi +2 -0
- data/rbi/anthropic/models/usage.rbi +13 -0
- data/rbi/anthropic/models.rbi +14 -0
- data/rbi/anthropic/resources/beta/messages.rbi +45 -87
- data/rbi/anthropic/resources/messages.rbi +315 -69
- data/rbi/anthropic/streaming.rbi +5 -0
- data/sig/anthropic/errors.rbs +9 -0
- data/sig/anthropic/helpers/streaming/events.rbs +117 -0
- data/sig/anthropic/helpers/streaming/message_stream.rbs +57 -0
- data/sig/anthropic/internal/transport/base_client.rbs +1 -1
- data/sig/anthropic/internal/type/base_stream.rbs +4 -0
- data/sig/anthropic/internal/type/converter.rbs +24 -1
- data/sig/anthropic/internal/type/union.rbs +2 -2
- data/sig/anthropic/models/anthropic_beta.rbs +2 -0
- data/sig/anthropic/models/beta/beta_base64_pdf_block.rbs +1 -58
- data/sig/anthropic/models/beta/beta_bash_code_execution_output_block.rbs +23 -0
- data/sig/anthropic/models/beta/beta_bash_code_execution_output_block_param.rbs +23 -0
- data/sig/anthropic/models/beta/beta_bash_code_execution_result_block.rbs +44 -0
- data/sig/anthropic/models/beta/beta_bash_code_execution_result_block_param.rbs +44 -0
- data/sig/anthropic/models/beta/beta_bash_code_execution_tool_result_block.rbs +44 -0
- data/sig/anthropic/models/beta/beta_bash_code_execution_tool_result_block_param.rbs +49 -0
- data/sig/anthropic/models/beta/beta_bash_code_execution_tool_result_error.rbs +48 -0
- data/sig/anthropic/models/beta/beta_bash_code_execution_tool_result_error_param.rbs +48 -0
- data/sig/anthropic/models/beta/beta_citation_char_location.rbs +5 -0
- data/sig/anthropic/models/beta/beta_citation_config.rbs +17 -0
- data/sig/anthropic/models/beta/beta_citation_content_block_location.rbs +5 -0
- data/sig/anthropic/models/beta/beta_citation_page_location.rbs +5 -0
- data/sig/anthropic/models/beta/beta_citation_search_result_location.rbs +54 -0
- data/sig/anthropic/models/beta/beta_citation_search_result_location_param.rbs +54 -0
- data/sig/anthropic/models/beta/beta_citations_delta.rbs +1 -0
- data/sig/anthropic/models/beta/beta_code_execution_tool_20250825.rbs +34 -0
- data/sig/anthropic/models/beta/beta_content_block.rbs +5 -2
- data/sig/anthropic/models/beta/beta_content_block_param.rbs +12 -8
- data/sig/anthropic/models/beta/beta_document_block.rbs +49 -0
- data/sig/anthropic/models/beta/beta_raw_content_block_start_event.rbs +5 -2
- data/sig/anthropic/models/beta/beta_request_document_block.rbs +62 -0
- data/sig/anthropic/models/beta/beta_search_result_block_param.rbs +53 -0
- data/sig/anthropic/models/beta/beta_server_tool_usage.rbs +12 -3
- data/sig/anthropic/models/beta/beta_server_tool_use_block.rbs +9 -1
- data/sig/anthropic/models/beta/beta_server_tool_use_block_param.rbs +9 -1
- data/sig/anthropic/models/beta/beta_text_citation.rbs +1 -0
- data/sig/anthropic/models/beta/beta_text_citation_param.rbs +1 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_create_result_block.rbs +29 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_create_result_block_param.rbs +29 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block.rbs +49 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_str_replace_result_block_param.rbs +49 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_tool_result_block.rbs +46 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_tool_result_block_param.rbs +51 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_tool_result_error.rbs +53 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_tool_result_error_param.rbs +53 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_view_result_block.rbs +61 -0
- data/sig/anthropic/models/beta/beta_text_editor_code_execution_view_result_block_param.rbs +61 -0
- data/sig/anthropic/models/beta/beta_tool.rbs +14 -3
- data/sig/anthropic/models/beta/beta_tool_result_block_param.rbs +2 -0
- data/sig/anthropic/models/beta/beta_tool_text_editor_20250728.rbs +39 -0
- data/sig/anthropic/models/beta/beta_tool_union.rbs +7 -4
- data/sig/anthropic/models/beta/beta_web_fetch_block.rbs +39 -0
- data/sig/anthropic/models/beta/beta_web_fetch_block_param.rbs +39 -0
- data/sig/anthropic/models/beta/beta_web_fetch_tool_20250910.rbs +59 -0
- data/sig/anthropic/models/beta/beta_web_fetch_tool_result_block.rbs +44 -0
- data/sig/anthropic/models/beta/beta_web_fetch_tool_result_block_param.rbs +49 -0
- data/sig/anthropic/models/beta/beta_web_fetch_tool_result_error_block.rbs +29 -0
- data/sig/anthropic/models/beta/beta_web_fetch_tool_result_error_block_param.rbs +29 -0
- data/sig/anthropic/models/beta/beta_web_fetch_tool_result_error_code.rbs +32 -0
- data/sig/anthropic/models/beta/message_count_tokens_params.rbs +7 -4
- data/sig/anthropic/models/beta_error_response.rbs +13 -2
- data/sig/anthropic/models/cache_control_ephemeral.rbs +27 -3
- data/sig/anthropic/models/cache_creation.rbs +25 -0
- data/sig/anthropic/models/citation_char_location.rbs +5 -0
- data/sig/anthropic/models/citation_content_block_location.rbs +5 -0
- data/sig/anthropic/models/citation_page_location.rbs +5 -0
- data/sig/anthropic/models/citation_search_result_location_param.rbs +50 -0
- data/sig/anthropic/models/citations_delta.rbs +1 -0
- data/sig/anthropic/models/citations_search_result_location.rbs +50 -0
- data/sig/anthropic/models/content_block.rbs +2 -2
- data/sig/anthropic/models/content_block_param.rbs +6 -5
- data/sig/anthropic/models/document_block_param.rbs +4 -8
- data/sig/anthropic/models/error_response.rbs +13 -2
- data/sig/anthropic/models/message_count_tokens_tool.rbs +2 -0
- data/sig/anthropic/models/model.rbs +4 -10
- data/sig/anthropic/models/raw_content_block_start_event.rbs +2 -2
- data/sig/anthropic/models/search_result_block_param.rbs +49 -0
- data/sig/anthropic/models/text_citation.rbs +1 -0
- data/sig/anthropic/models/text_citation_param.rbs +1 -0
- data/sig/anthropic/models/tool.rbs +14 -3
- data/sig/anthropic/models/tool_result_block_param.rbs +5 -1
- data/sig/anthropic/models/tool_text_editor_20250429.rbs +30 -0
- data/sig/anthropic/models/tool_text_editor_20250728.rbs +35 -0
- data/sig/anthropic/models/tool_union.rbs +2 -0
- data/sig/anthropic/models/usage.rbs +5 -0
- data/sig/anthropic/models.rbs +12 -0
- data/sig/anthropic/streaming.rbs +3 -0
- metadata +152 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9508f2174591353cfaa66f66d1ec7d72fbd3dced9f88e64aae101ad0b370ec51
|
4
|
+
data.tar.gz: 4e10f3b7dcdfe9e1fc2bf5efec9bb8578d63f2d49a0ed36b08db2153109a0ada
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5eeb2c0701c8ab45b86c58f28c4fd49344ae4b9ac1539486ba282ce3b9154cd3b7e8466fb933b61206f18ef2024f50de8366d5aa89336e86307e2ab22a8f1c2
|
7
|
+
data.tar.gz: c6f369c9cd95b5501e4416dd8c46ba936f2b09134ccb1a7fec65e7a7948b0e734db46bc3836dee43deac948c4fd216162a5395301c71b837e6277cdbabbbc7a9
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,175 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.9.0 (2025-09-10)
|
4
|
+
|
5
|
+
Full Changelog: [v1.8.0...v1.9.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.8.0...v1.9.0)
|
6
|
+
|
7
|
+
### Features
|
8
|
+
|
9
|
+
* **api:** adds support for Documents in tool results ([91e23c1](https://github.com/anthropics/anthropic-sdk-ruby/commit/91e23c14525ba91fa63eab1ab901c7d8782aa6b3))
|
10
|
+
* **api:** adds support for web_fetch_20250910 tool ([631783d](https://github.com/anthropics/anthropic-sdk-ruby/commit/631783ddbbcc0aab95172b3dd4d6cbd29e0ec507))
|
11
|
+
|
12
|
+
|
13
|
+
### Bug Fixes
|
14
|
+
|
15
|
+
* unnecessarily long multipart boundary length ([#124](https://github.com/anthropics/anthropic-sdk-ruby/issues/124)) ([69aa4c8](https://github.com/anthropics/anthropic-sdk-ruby/commit/69aa4c8c918b3d401933efaba6440164c6eb6962))
|
16
|
+
|
17
|
+
## 1.8.0 (2025-09-02)
|
18
|
+
|
19
|
+
Full Changelog: [v1.7.0...v1.8.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.7.0...v1.8.0)
|
20
|
+
|
21
|
+
### Features
|
22
|
+
|
23
|
+
* **client:** adds support for code-execution-2025-08-26 tool ([28e554e](https://github.com/anthropics/anthropic-sdk-ruby/commit/28e554ec75e8c34d20ef1e021672f9a02d5be3ec))
|
24
|
+
* input schemas ([#660](https://github.com/anthropics/anthropic-sdk-ruby/issues/660)) ([3e062c0](https://github.com/anthropics/anthropic-sdk-ruby/commit/3e062c03b0fc964877095a34cb69de9ba63dfa19))
|
25
|
+
|
26
|
+
|
27
|
+
### Bug Fixes
|
28
|
+
|
29
|
+
* bump sorbet version and fix new type errors from the breaking change ([3c4f15d](https://github.com/anthropics/anthropic-sdk-ruby/commit/3c4f15d8f4115d6da6d8589856e7654162f91110))
|
30
|
+
* correctly raise errors encountered during streaming ([be9bc45](https://github.com/anthropics/anthropic-sdk-ruby/commit/be9bc45d96ac227fd5648281199a7c8dd234897d))
|
31
|
+
|
32
|
+
|
33
|
+
### Chores
|
34
|
+
|
35
|
+
* add json schema comment for rubocop.yml ([3fce402](https://github.com/anthropics/anthropic-sdk-ruby/commit/3fce4021da72749b127adacee9436327d4b03f60))
|
36
|
+
|
37
|
+
## 1.7.0 (2025-08-13)
|
38
|
+
|
39
|
+
Full Changelog: [v1.6.0...v1.7.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.6.0...v1.7.0)
|
40
|
+
|
41
|
+
### Features
|
42
|
+
|
43
|
+
* **api:** makes 1 hour TTL Cache Control generally available ([c2dbf3b](https://github.com/anthropics/anthropic-sdk-ruby/commit/c2dbf3bcc3137b53db4d0a5779a014d4c59609bc))
|
44
|
+
|
45
|
+
|
46
|
+
### Chores
|
47
|
+
|
48
|
+
* deprecate older claude-3-5 sonnet models ([#679](https://github.com/anthropics/anthropic-sdk-ruby/issues/679)) ([4a3fb20](https://github.com/anthropics/anthropic-sdk-ruby/commit/4a3fb2042b20ca34346e2fa914c77713e664b922))
|
49
|
+
|
50
|
+
## 1.6.0 (2025-08-12)
|
51
|
+
|
52
|
+
Full Changelog: [v1.5.0...v1.6.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.5.0...v1.6.0)
|
53
|
+
|
54
|
+
### Features
|
55
|
+
|
56
|
+
* **betas:** add context-1m-2025-08-07 ([5bb5064](https://github.com/anthropics/anthropic-sdk-ruby/commit/5bb506416852bcd0c893c643831ec6e52a2cc79d))
|
57
|
+
|
58
|
+
|
59
|
+
### Chores
|
60
|
+
|
61
|
+
* collect metadata from type DSL ([69114b1](https://github.com/anthropics/anthropic-sdk-ruby/commit/69114b159e3710c467cbb7c55b8b7526cb5ea8e7))
|
62
|
+
* **internal:** update comment in script ([c5bd3b1](https://github.com/anthropics/anthropic-sdk-ruby/commit/c5bd3b144ad399c114e644437820a8785e7399f0))
|
63
|
+
* **internal:** update test skipping reason ([6d7c586](https://github.com/anthropics/anthropic-sdk-ruby/commit/6d7c58606a88e6a34b16f19006e44dbf17d657c0))
|
64
|
+
* update @stainless-api/prism-cli to v5.15.0 ([356427c](https://github.com/anthropics/anthropic-sdk-ruby/commit/356427c4ec83d134dbcccdf27915eee65e5e8daa))
|
65
|
+
|
66
|
+
## 1.5.0 (2025-08-08)
|
67
|
+
|
68
|
+
Full Changelog: [v1.4.1...v1.5.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.4.1...v1.5.0)
|
69
|
+
|
70
|
+
### Features
|
71
|
+
|
72
|
+
* **api:** search result content blocks ([9a94866](https://github.com/anthropics/anthropic-sdk-ruby/commit/9a9486664e10ce0d02967ab1d5360357ffb72a66))
|
73
|
+
|
74
|
+
|
75
|
+
### Bug Fixes
|
76
|
+
|
77
|
+
* aws bedrock base url ([#673](https://github.com/anthropics/anthropic-sdk-ruby/issues/673)) ([b2996b9](https://github.com/anthropics/anthropic-sdk-ruby/commit/b2996b9349b047c53232ecd63823110ad90c71c3))
|
78
|
+
|
79
|
+
## 1.4.1 (2025-08-07)
|
80
|
+
|
81
|
+
Full Changelog: [v1.4.0...v1.4.1](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.4.0...v1.4.1)
|
82
|
+
|
83
|
+
### Bug Fixes
|
84
|
+
|
85
|
+
* aws bedrock should sign each request follow retries ([#672](https://github.com/anthropics/anthropic-sdk-ruby/issues/672)) ([df9f4e1](https://github.com/anthropics/anthropic-sdk-ruby/commit/df9f4e1aa7e7211dab3d36dd9093092d20649359))
|
86
|
+
|
87
|
+
## 1.4.0 (2025-08-05)
|
88
|
+
|
89
|
+
Full Changelog: [v1.3.0...v1.4.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.3.0...v1.4.0)
|
90
|
+
|
91
|
+
### Features
|
92
|
+
|
93
|
+
* **api:** add claude-opus-4-1-20250805 ([2477a05](https://github.com/anthropics/anthropic-sdk-ruby/commit/2477a05b8b26b047df178264db7d0764ca954954))
|
94
|
+
* **api:** adds support for text_editor_20250728 tool ([dff36db](https://github.com/anthropics/anthropic-sdk-ruby/commit/dff36db0eb8b7077ba311f3815eb0065422c2fd4))
|
95
|
+
* update streaming error message to say 'required' not 'recommended' ([6272ddd](https://github.com/anthropics/anthropic-sdk-ruby/commit/6272ddd9cd3ae0110afee98159516c3232c65832))
|
96
|
+
|
97
|
+
|
98
|
+
### Chores
|
99
|
+
|
100
|
+
* **ci:** setup Ruby on release job ([#111](https://github.com/anthropics/anthropic-sdk-ruby/issues/111)) ([bb5d08f](https://github.com/anthropics/anthropic-sdk-ruby/commit/bb5d08f052b3e65f70d345c45ce59e3e8fe282f3))
|
101
|
+
* **client:** add TextEditor_20250429 tool ([3b344dc](https://github.com/anthropics/anthropic-sdk-ruby/commit/3b344dcf2dc759a0a01a1061573115c7a6c8a449))
|
102
|
+
* **internal:** increase visibility of internal helper method ([72fb96c](https://github.com/anthropics/anthropic-sdk-ruby/commit/72fb96cdcdb2a6436aaf6d908f010ae16c08bd33))
|
103
|
+
|
104
|
+
## 1.3.0 (2025-07-28)
|
105
|
+
|
106
|
+
Full Changelog: [v1.2.0...v1.3.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.2.0...v1.3.0)
|
107
|
+
|
108
|
+
### Features
|
109
|
+
|
110
|
+
* **api:** removed older deprecated models ([47de6c2](https://github.com/anthropics/anthropic-sdk-ruby/commit/47de6c2860fabd344374aed733df1bcb17988454))
|
111
|
+
* **client:** add beta stream implementation and fine grained tool streaming example ([2856b81](https://github.com/anthropics/anthropic-sdk-ruby/commit/2856b8119b99e6487093df3f49216ecc8d1bd3e3))
|
112
|
+
* **client:** add beta stream implementation and fine grained tool streaming example ([bc87fd4](https://github.com/anthropics/anthropic-sdk-ruby/commit/bc87fd4afd94a48301fec548a0e7b21f44a24a59))
|
113
|
+
|
114
|
+
|
115
|
+
### Bug Fixes
|
116
|
+
|
117
|
+
* **internal:** ensure sorbet test always runs serially ([0b39a19](https://github.com/anthropics/anthropic-sdk-ruby/commit/0b39a1908587597ca5836872333541307f24bdf2))
|
118
|
+
* **internal:** ensure vertex client test ordering ([#667](https://github.com/anthropics/anthropic-sdk-ruby/issues/667)) ([d7439fa](https://github.com/anthropics/anthropic-sdk-ruby/commit/d7439fa58664d9a533cacca6a299b3dbbe43ec7f))
|
119
|
+
|
120
|
+
|
121
|
+
### Chores
|
122
|
+
|
123
|
+
* add basic tool use example ([#107](https://github.com/anthropics/anthropic-sdk-ruby/issues/107)) ([4452119](https://github.com/anthropics/anthropic-sdk-ruby/commit/445211929b09ff0be9406aad1b3f3604d8bf3794))
|
124
|
+
* add Darwin to PLATFORMS in Gemfile.lock ([#104](https://github.com/anthropics/anthropic-sdk-ruby/issues/104)) ([aa5bcbe](https://github.com/anthropics/anthropic-sdk-ruby/commit/aa5bcbedc48cc9a49ba14050fa3ad934a6f95c99))
|
125
|
+
* **internal:** run formatter ([87ce979](https://github.com/anthropics/anthropic-sdk-ruby/commit/87ce979a06108f980e8c867d43166fbeeff02ec3))
|
126
|
+
* update contribute.md ([aa928a0](https://github.com/anthropics/anthropic-sdk-ruby/commit/aa928a09f08250c9e6e93b884761eb35a9d5b6b4))
|
127
|
+
|
128
|
+
## 1.2.0 (2025-07-18)
|
129
|
+
|
130
|
+
Full Changelog: [v1.1.1...v1.2.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.1.1...v1.2.0)
|
131
|
+
|
132
|
+
### Features
|
133
|
+
|
134
|
+
* **api:** add support for Search Result Content Blocks ([158a7ce](https://github.com/anthropics/anthropic-sdk-ruby/commit/158a7ced1013c3af956554caf41ee08ec5d1db3c))
|
135
|
+
* **api:** api update ([cd22765](https://github.com/anthropics/anthropic-sdk-ruby/commit/cd2276536c7960a4f7276ceb9baba8ba5aec196e))
|
136
|
+
* **api:** manual updates ([7f51b33](https://github.com/anthropics/anthropic-sdk-ruby/commit/7f51b336943422d230d8704583f42dc6f8a3ac62))
|
137
|
+
* **client:** add breaking change detection to CI ([52e342f](https://github.com/anthropics/anthropic-sdk-ruby/commit/52e342fe8c8231ad6b6b6ff68ed522033cd503c7))
|
138
|
+
* **client:** add support for new text_editor_20250429 tool ([9049af2](https://github.com/anthropics/anthropic-sdk-ruby/commit/9049af2f634f88d867104f2dc0ddc6396f5f8031))
|
139
|
+
* streaming helpers ([#627](https://github.com/anthropics/anthropic-sdk-ruby/issues/627)) ([43fbbf8](https://github.com/anthropics/anthropic-sdk-ruby/commit/43fbbf8a39ac1d99920845ba19da43d7419a5e73))
|
140
|
+
* **vertex:** support global region endpoint ([da8c452](https://github.com/anthropics/anthropic-sdk-ruby/commit/da8c452a22c56780f311f4f1ab3477a48ac46891))
|
141
|
+
|
142
|
+
|
143
|
+
### Bug Fixes
|
144
|
+
|
145
|
+
* `to_sorbet_type` should not return branded types ([2658903](https://github.com/anthropics/anthropic-sdk-ruby/commit/2658903f13178a133ca679f4b87615e9cddcd813))
|
146
|
+
* **ci:** release-doctor — report correct token name ([e30183e](https://github.com/anthropics/anthropic-sdk-ruby/commit/e30183e5561070dfd3dfe041f48e76765975cb3b))
|
147
|
+
* **client:** deprecate BetaBase64PDFBlock in favor of BetaRequestDocumentBlock ([f75705b](https://github.com/anthropics/anthropic-sdk-ruby/commit/f75705bfb4af3160b2fa7208adfad10719cd17a7))
|
148
|
+
* default content-type for text in multi-part formdata uploads should be text/plain ([0a91592](https://github.com/anthropics/anthropic-sdk-ruby/commit/0a915925fc93ca7ad191bab33dba8c72b6c48a2a))
|
149
|
+
* **internal:** fix: should publish to ruby gems when a release is created ([cc88c6c](https://github.com/anthropics/anthropic-sdk-ruby/commit/cc88c6c7c164c5bb1937e12cefb4d91f05fec157))
|
150
|
+
* issue where we cannot mutate arrays on base model derivatives ([446c8be](https://github.com/anthropics/anthropic-sdk-ruby/commit/446c8be0eb77a29641d472ea36cbaf6f786f7e3a))
|
151
|
+
|
152
|
+
|
153
|
+
### Chores
|
154
|
+
|
155
|
+
* add `license` to the gemspec ([#101](https://github.com/anthropics/anthropic-sdk-ruby/issues/101)) ([af509a7](https://github.com/anthropics/anthropic-sdk-ruby/commit/af509a735c0e985e615f9279bc070dc090874df8))
|
156
|
+
* add RBS types for helpers/streaming ([#631](https://github.com/anthropics/anthropic-sdk-ruby/issues/631)) ([0d7941d](https://github.com/anthropics/anthropic-sdk-ruby/commit/0d7941df6628b1500f7e7e8def88f613d7bcf2fa))
|
157
|
+
* **api:** mark claude-3-opus-20240229 as deprecated ([1edd9bd](https://github.com/anthropics/anthropic-sdk-ruby/commit/1edd9bdf0bf508f5467daf92c4b1db11128d70ea))
|
158
|
+
* **api:** update BetaCitationSearchResultLocation ([b294f7e](https://github.com/anthropics/anthropic-sdk-ruby/commit/b294f7e2bfd44d01504eeb7e30b37926ca7200e2))
|
159
|
+
* **ci:** enable for pull requests ([31bbb43](https://github.com/anthropics/anthropic-sdk-ruby/commit/31bbb43d02cc56505ad5ec8d737801b73f9f5fd8))
|
160
|
+
* **ci:** link to correct github repo ([37b5902](https://github.com/anthropics/anthropic-sdk-ruby/commit/37b59027a26268ad5bb20ee6530c7f0c630bc5b5))
|
161
|
+
* **ci:** only run for pushes and fork pull requests ([8d3c942](https://github.com/anthropics/anthropic-sdk-ruby/commit/8d3c9425afe873a49e403c7a8a36f14642191a89))
|
162
|
+
* **internal:** allow streams to also be unwrapped on a per-row basis ([a271d21](https://github.com/anthropics/anthropic-sdk-ruby/commit/a271d21d2f01a9f7c9c2d126b1f3d9b0611dd8cd))
|
163
|
+
* **internal:** codegen related update ([8b12fd6](https://github.com/anthropics/anthropic-sdk-ruby/commit/8b12fd6e8ec1c06d3cbf7d20c63c6933538d0983))
|
164
|
+
* remove workaround for updating arrays in place in streaming ([#643](https://github.com/anthropics/anthropic-sdk-ruby/issues/643)) ([e0a30b8](https://github.com/anthropics/anthropic-sdk-ruby/commit/e0a30b8128624566f673ac77f97c305953b11c63))
|
165
|
+
|
166
|
+
|
167
|
+
### Documentation
|
168
|
+
|
169
|
+
* model in examples ([18ba0b6](https://github.com/anthropics/anthropic-sdk-ruby/commit/18ba0b62bd8f87b84766265726090ca2265a64b7))
|
170
|
+
* update documentation in MessageStream ([#630](https://github.com/anthropics/anthropic-sdk-ruby/issues/630)) ([4795c73](https://github.com/anthropics/anthropic-sdk-ruby/commit/4795c73f0628d2bc710f77bd0868be18c53ec31a))
|
171
|
+
* update models and non-beta ([a4ea04e](https://github.com/anthropics/anthropic-sdk-ruby/commit/a4ea04eaf88e608612512d39d07051842beaf500))
|
172
|
+
|
3
173
|
## 1.1.1 (2025-05-28)
|
4
174
|
|
5
175
|
Full Changelog: [v1.1.0...v1.1.1](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.1.0...v1.1.1)
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@ To use this gem, install via Bundler by adding the following to your application
|
|
15
15
|
<!-- x-release-please-start-version -->
|
16
16
|
|
17
17
|
```ruby
|
18
|
-
gem "anthropic", "~> 1.
|
18
|
+
gem "anthropic", "~> 1.9.0"
|
19
19
|
```
|
20
20
|
|
21
21
|
<!-- x-release-please-end -->
|
@@ -39,7 +39,7 @@ anthropic = Anthropic::Client.new(
|
|
39
39
|
message = anthropic.messages.create(
|
40
40
|
max_tokens: 1024,
|
41
41
|
messages: [{role: "user", content: "Hello, Claude"}],
|
42
|
-
model: :"claude-
|
42
|
+
model: :"claude-sonnet-4-20250514"
|
43
43
|
)
|
44
44
|
|
45
45
|
puts(message.content)
|
@@ -49,13 +49,11 @@ puts(message.content)
|
|
49
49
|
|
50
50
|
We provide support for streaming responses using Server-Sent Events (SSE).
|
51
51
|
|
52
|
-
**coming soon**: `anthropic.messages.stream` will have [Python SDK](https://github.com/anthropics/anthropic-sdk-python?tab=readme-ov-file#streaming-helpers) style streaming response helpers.
|
53
|
-
|
54
52
|
```ruby
|
55
|
-
stream = anthropic.messages.
|
53
|
+
stream = anthropic.messages.stream(
|
56
54
|
max_tokens: 1024,
|
57
55
|
messages: [{role: "user", content: "Hello, Claude"}],
|
58
|
-
model: :"claude-
|
56
|
+
model: :"claude-sonnet-4-20250514"
|
59
57
|
)
|
60
58
|
|
61
59
|
stream.each do |message|
|
@@ -63,6 +61,24 @@ stream.each do |message|
|
|
63
61
|
end
|
64
62
|
```
|
65
63
|
|
64
|
+
### Streaming Helpers
|
65
|
+
|
66
|
+
This library provides several conveniences for streaming messages, for example:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
stream = anthropic.messages.stream(
|
70
|
+
max_tokens: 1024,
|
71
|
+
messages: [{role: :user, content: "Say hello there!"}],
|
72
|
+
model: :"claude-sonnet-4-20250514"
|
73
|
+
)
|
74
|
+
|
75
|
+
stream.text.each do |text|
|
76
|
+
print(text)
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
80
|
+
Streaming with `anthropic.messages.stream(...)` exposes [various helpers for your convenience](helpers.md) including accumulation & SDK-specific events.
|
81
|
+
|
66
82
|
### Pagination
|
67
83
|
|
68
84
|
List methods in the Anthropic API are paginated.
|
@@ -70,7 +86,7 @@ List methods in the Anthropic API are paginated.
|
|
70
86
|
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
|
71
87
|
|
72
88
|
```ruby
|
73
|
-
page = anthropic.
|
89
|
+
page = anthropic.messages.batches.list(limit: 20)
|
74
90
|
|
75
91
|
# Fetch single item from page.
|
76
92
|
batch = page.data[0]
|
@@ -122,7 +138,7 @@ begin
|
|
122
138
|
message = anthropic.messages.create(
|
123
139
|
max_tokens: 1024,
|
124
140
|
messages: [{role: "user", content: "Hello, Claude"}],
|
125
|
-
model: :"claude-
|
141
|
+
model: :"claude-sonnet-4-20250514"
|
126
142
|
)
|
127
143
|
rescue Anthropic::Errors::APIConnectionError => e
|
128
144
|
puts("The server could not be reached")
|
@@ -169,7 +185,7 @@ anthropic = Anthropic::Client.new(
|
|
169
185
|
anthropic.messages.create(
|
170
186
|
max_tokens: 1024,
|
171
187
|
messages: [{role: "user", content: "Hello, Claude"}],
|
172
|
-
model: :"claude-
|
188
|
+
model: :"claude-sonnet-4-20250514",
|
173
189
|
request_options: {max_retries: 5}
|
174
190
|
)
|
175
191
|
```
|
@@ -188,7 +204,7 @@ anthropic = Anthropic::Client.new(
|
|
188
204
|
anthropic.messages.create(
|
189
205
|
max_tokens: 1024,
|
190
206
|
messages: [{role: "user", content: "Hello, Claude"}],
|
191
|
-
model: :"claude-
|
207
|
+
model: :"claude-sonnet-4-20250514",
|
192
208
|
request_options: {timeout: 5}
|
193
209
|
)
|
194
210
|
```
|
@@ -219,7 +235,7 @@ message = anthropic.messages.create(
|
|
219
235
|
content: "Hello, Claude"
|
220
236
|
}
|
221
237
|
],
|
222
|
-
model: "anthropic.claude-
|
238
|
+
model: "anthropic.claude-sonnet-4-20250514-v2:0"
|
223
239
|
)
|
224
240
|
|
225
241
|
puts(message)
|
@@ -247,7 +263,7 @@ message = anthropic.messages.create(
|
|
247
263
|
content: "Hello, Claude"
|
248
264
|
}
|
249
265
|
],
|
250
|
-
model: "claude-
|
266
|
+
model: "claude-sonnet-4@20250514"
|
251
267
|
)
|
252
268
|
|
253
269
|
puts(message)
|
@@ -284,7 +300,7 @@ message =
|
|
284
300
|
anthropic.messages.create(
|
285
301
|
max_tokens: 1024,
|
286
302
|
messages: [{role: "user", content: "Hello, Claude"}],
|
287
|
-
model: :"claude-
|
303
|
+
model: :"claude-sonnet-4-20250514",
|
288
304
|
request_options: {
|
289
305
|
extra_query: {my_query_parameter: value},
|
290
306
|
extra_body: {my_body_parameter: value},
|
@@ -333,7 +349,7 @@ You can provide typesafe request parameters like so:
|
|
333
349
|
anthropic.messages.create(
|
334
350
|
max_tokens: 1024,
|
335
351
|
messages: [Anthropic::MessageParam.new(role: "user", content: "Hello, Claude")],
|
336
|
-
model: :"claude-
|
352
|
+
model: :"claude-sonnet-4-20250514"
|
337
353
|
)
|
338
354
|
```
|
339
355
|
|
@@ -344,14 +360,14 @@ Or, equivalently:
|
|
344
360
|
anthropic.messages.create(
|
345
361
|
max_tokens: 1024,
|
346
362
|
messages: [{role: "user", content: "Hello, Claude"}],
|
347
|
-
model: :"claude-
|
363
|
+
model: :"claude-sonnet-4-20250514"
|
348
364
|
)
|
349
365
|
|
350
366
|
# You can also splat a full Params class:
|
351
367
|
params = Anthropic::MessageCreateParams.new(
|
352
368
|
max_tokens: 1024,
|
353
369
|
messages: [Anthropic::MessageParam.new(role: "user", content: "Hello, Claude")],
|
354
|
-
model: :"claude-
|
370
|
+
model: :"claude-sonnet-4-20250514"
|
355
371
|
)
|
356
372
|
anthropic.messages.create(**params)
|
357
373
|
```
|
data/lib/anthropic/client.rb
CHANGED
@@ -21,7 +21,10 @@ module Anthropic
|
|
21
21
|
"claude-opus-4-0": 8_192,
|
22
22
|
"claude-4-opus-20250514": 8_192,
|
23
23
|
"anthropic.claude-opus-4-20250514-v1:0": 8_192,
|
24
|
-
"claude-opus-4@20250514": 8_192
|
24
|
+
"claude-opus-4@20250514": 8_192,
|
25
|
+
"claude-opus-4-1-20250805": 8192,
|
26
|
+
"anthropic.claude-opus-4-1-20250805-v1:0": 8192,
|
27
|
+
"claude-opus-4-1@20250805": 8192
|
25
28
|
}.freeze
|
26
29
|
|
27
30
|
# @return [String, nil]
|
@@ -78,7 +81,7 @@ module Anthropic
|
|
78
81
|
expected_time = maximum_time * max_tokens / 128_000.0
|
79
82
|
if expected_time > default_time || (max_nonstreaming_tokens && max_tokens > max_nonstreaming_tokens)
|
80
83
|
raise ArgumentError.new(
|
81
|
-
"Streaming is
|
84
|
+
"Streaming is required for operations that may take longer than 10 minutes. " \
|
82
85
|
"See https://github.com/anthropics/anthropic-sdk-ruby#long-requests for more details"
|
83
86
|
)
|
84
87
|
end
|
data/lib/anthropic/errors.rb
CHANGED
@@ -9,6 +9,28 @@ module Anthropic
|
|
9
9
|
end
|
10
10
|
|
11
11
|
class ConversionError < Anthropic::Errors::Error
|
12
|
+
# @return [StandardError, nil]
|
13
|
+
def cause = @cause.nil? ? super : @cause
|
14
|
+
|
15
|
+
# @api private
|
16
|
+
#
|
17
|
+
# @param on [Class<StandardError>]
|
18
|
+
# @param method [Symbol]
|
19
|
+
# @param target [Object]
|
20
|
+
# @param value [Object]
|
21
|
+
# @param cause [StandardError, nil]
|
22
|
+
def initialize(on:, method:, target:, value:, cause: nil)
|
23
|
+
cls = on.name.split("::").last
|
24
|
+
|
25
|
+
message = [
|
26
|
+
"Failed to parse #{cls}.#{method} from #{value.class} to #{target.inspect}.",
|
27
|
+
"To get the unparsed API response, use #{cls}[#{method.inspect}].",
|
28
|
+
cause && "Cause: #{cause.message}"
|
29
|
+
].filter(&:itself).join(" ")
|
30
|
+
|
31
|
+
@cause = cause
|
32
|
+
super(message)
|
33
|
+
end
|
12
34
|
end
|
13
35
|
|
14
36
|
class APIError < Anthropic::Errors::Error
|
@@ -50,10 +50,10 @@ module Anthropic
|
|
50
50
|
def initialize(
|
51
51
|
aws_region: nil,
|
52
52
|
base_url: nil,
|
53
|
-
max_retries: DEFAULT_MAX_RETRIES,
|
54
|
-
timeout: DEFAULT_TIMEOUT_IN_SECONDS,
|
55
|
-
initial_retry_delay: DEFAULT_INITIAL_RETRY_DELAY,
|
56
|
-
max_retry_delay: DEFAULT_MAX_RETRY_DELAY,
|
53
|
+
max_retries: self.class::DEFAULT_MAX_RETRIES,
|
54
|
+
timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
|
55
|
+
initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
|
56
|
+
max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY,
|
57
57
|
aws_access_key: nil,
|
58
58
|
aws_secret_key: nil,
|
59
59
|
aws_session_token: nil,
|
@@ -165,6 +165,36 @@ module Anthropic
|
|
165
165
|
request_input
|
166
166
|
end
|
167
167
|
|
168
|
+
# @api private
|
169
|
+
#
|
170
|
+
# Very private API, do not use
|
171
|
+
#
|
172
|
+
# @param request [Hash{Symbol=>Object}] .
|
173
|
+
#
|
174
|
+
# @option request [Symbol] :method
|
175
|
+
#
|
176
|
+
# @option request [URI::Generic] :url
|
177
|
+
#
|
178
|
+
# @option request [Hash{String=>String}] :headers
|
179
|
+
#
|
180
|
+
# @option request [Object] :body
|
181
|
+
#
|
182
|
+
# @return [Hash{Symbol, Object}]
|
183
|
+
private def transform_request(request)
|
184
|
+
sliced = super.slice(
|
185
|
+
:method,
|
186
|
+
:url,
|
187
|
+
:headers,
|
188
|
+
:body
|
189
|
+
).transform_keys(method: :http_method)
|
190
|
+
body = StringIO.new(body.to_a.join) if (body = sliced.fetch(:body)).is_a?(Enumerator)
|
191
|
+
|
192
|
+
signed = @signer.sign_request({**sliced, body: body})
|
193
|
+
|
194
|
+
headers = Anthropic::Internal::Util.normalized_headers(request.fetch(:headers), signed.headers)
|
195
|
+
{**request, headers: headers}
|
196
|
+
end
|
197
|
+
|
168
198
|
# @param aws_region [String, nil]
|
169
199
|
#
|
170
200
|
# @param aws_secret_key [String, nil]
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Anthropic
|
4
|
+
module Helpers
|
5
|
+
module InputSchema
|
6
|
+
# @generic Elem
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# example = Anthropic::ArrayOf[Integer]
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# example = Anthropic::ArrayOf[Integer, nil?: true, doc: "hi there!"]
|
13
|
+
class ArrayOf < Anthropic::Internal::Type::ArrayOf
|
14
|
+
include Anthropic::Helpers::InputSchema::JsonSchemaConverter
|
15
|
+
|
16
|
+
# @api private
|
17
|
+
#
|
18
|
+
# @param state [Hash{Symbol=>Object}]
|
19
|
+
#
|
20
|
+
# @option state [Hash{Object=>String}] :defs
|
21
|
+
#
|
22
|
+
# @option state [Array<String>] :path
|
23
|
+
#
|
24
|
+
# @return [Hash{Symbol=>Object}]
|
25
|
+
def to_json_schema_inner(state:)
|
26
|
+
Anthropic::Helpers::InputSchema::JsonSchemaConverter.cache_def!(state, type: self) do
|
27
|
+
state.fetch(:path) << "[]"
|
28
|
+
items = Anthropic::Helpers::InputSchema::JsonSchemaConverter.to_json_schema_inner(
|
29
|
+
item_type,
|
30
|
+
state: state
|
31
|
+
)
|
32
|
+
items = Anthropic::Helpers::InputSchema::JsonSchemaConverter.to_nilable(items) if nilable?
|
33
|
+
Anthropic::Helpers::InputSchema::JsonSchemaConverter.assoc_meta!(items, meta: @meta)
|
34
|
+
|
35
|
+
{type: "array", items: items}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Anthropic
|
4
|
+
module Helpers
|
5
|
+
module InputSchema
|
6
|
+
# Represents a response from Anthropic's API where the model's output has been structured according to a schema predefined by the user.
|
7
|
+
#
|
8
|
+
# This class is specifically used when making requests with the `input_schema` parameter.
|
9
|
+
#
|
10
|
+
# See {examples/input_schemas.rb} for a complete example of use
|
11
|
+
class BaseModel < Anthropic::Internal::Type::BaseModel
|
12
|
+
extend Anthropic::Helpers::InputSchema::JsonSchemaConverter
|
13
|
+
|
14
|
+
class << self
|
15
|
+
# @return [Hash{Symbol=>Object}]
|
16
|
+
def to_json_schema = Anthropic::Helpers::InputSchema::JsonSchemaConverter.to_json_schema(self)
|
17
|
+
|
18
|
+
# @api private
|
19
|
+
#
|
20
|
+
# @param state [Hash{Symbol=>Object}]
|
21
|
+
#
|
22
|
+
# @option state [Hash{Object=>String}] :defs
|
23
|
+
#
|
24
|
+
# @option state [Array<String>] :path
|
25
|
+
#
|
26
|
+
# @return [Hash{Symbol=>Object}]
|
27
|
+
def to_json_schema_inner(state:)
|
28
|
+
Anthropic::Helpers::InputSchema::JsonSchemaConverter.cache_def!(state, type: self) do
|
29
|
+
path = state.fetch(:path)
|
30
|
+
properties = fields.to_h do |name, field|
|
31
|
+
type, nilable, meta = field.fetch_values(:type, :nilable, :meta)
|
32
|
+
new_state = {**state, path: [*path, ".#{name}"]}
|
33
|
+
|
34
|
+
schema =
|
35
|
+
case type
|
36
|
+
in Anthropic::Helpers::InputSchema::JsonSchemaConverter
|
37
|
+
type.to_json_schema_inner(state: new_state)
|
38
|
+
else
|
39
|
+
Anthropic::Helpers::InputSchema::JsonSchemaConverter.to_json_schema_inner(
|
40
|
+
type,
|
41
|
+
state: new_state
|
42
|
+
)
|
43
|
+
end
|
44
|
+
Anthropic::Helpers::InputSchema::JsonSchemaConverter.assoc_meta!(schema, meta: meta)
|
45
|
+
schema = Anthropic::Helpers::InputSchema::JsonSchemaConverter.to_nilable(schema) if nilable
|
46
|
+
|
47
|
+
[name, schema]
|
48
|
+
end
|
49
|
+
|
50
|
+
{
|
51
|
+
type: "object",
|
52
|
+
properties: properties,
|
53
|
+
required: fields.select { _2.fetch(:required) }.keys.map(&:to_s),
|
54
|
+
additionalProperties: false
|
55
|
+
}.tap { _1.store(:description, @doc_string) unless @doc_string.nil? }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class << self
|
61
|
+
def required(name_sym, type_info, *args)
|
62
|
+
spec = process_field_args(args)
|
63
|
+
super(name_sym, type_info, spec)
|
64
|
+
end
|
65
|
+
|
66
|
+
def optional(name_sym, type_info, *args)
|
67
|
+
spec = process_field_args(args)
|
68
|
+
super(name_sym, type_info, spec)
|
69
|
+
end
|
70
|
+
|
71
|
+
attr_reader :doc_string
|
72
|
+
|
73
|
+
# @param description [String]
|
74
|
+
def doc(description)
|
75
|
+
@doc_string = description
|
76
|
+
end
|
77
|
+
|
78
|
+
private def process_field_args(args)
|
79
|
+
# Only accept hash format for descriptions.
|
80
|
+
args.grep(Hash).first.to_h
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Anthropic
|
4
|
+
module Helpers
|
5
|
+
module InputSchema
|
6
|
+
# @abstract
|
7
|
+
#
|
8
|
+
# Ruby does not have a "boolean" Class, this is something for models to refer to.
|
9
|
+
class Boolean < Anthropic::Internal::Type::Boolean
|
10
|
+
extend Anthropic::Helpers::InputSchema::JsonSchemaConverter
|
11
|
+
|
12
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
13
|
+
|
14
|
+
# @api private
|
15
|
+
#
|
16
|
+
# @param state [Hash{Symbol=>Object}]
|
17
|
+
#
|
18
|
+
# @option state [Hash{Object=>String}] :defs
|
19
|
+
#
|
20
|
+
# @option state [Array<String>] :path
|
21
|
+
#
|
22
|
+
# @return [Hash{Symbol=>Object}]
|
23
|
+
def self.to_json_schema_inner(state:) = {type: "boolean"}
|
24
|
+
|
25
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Anthropic
|
4
|
+
module Helpers
|
5
|
+
module InputSchema
|
6
|
+
# @generic Value
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# example = Anthropic::EnumOf[:foo, :bar, :zoo]
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# example = Anthropic::EnumOf[1, 2, 3]
|
13
|
+
class EnumOf
|
14
|
+
include Anthropic::Internal::Type::Enum
|
15
|
+
include Anthropic::Helpers::InputSchema::JsonSchemaConverter
|
16
|
+
|
17
|
+
# @api private
|
18
|
+
#
|
19
|
+
# @param state [Hash{Symbol=>Object}]
|
20
|
+
#
|
21
|
+
# @option state [Hash{Object=>String}] :defs
|
22
|
+
#
|
23
|
+
# @option state [Array<String>] :path
|
24
|
+
#
|
25
|
+
# @return [Hash{Symbol=>Object}]
|
26
|
+
def to_json_schema_inner(state:)
|
27
|
+
Anthropic::Helpers::InputSchema::JsonSchemaConverter.cache_def!(state, type: self) do
|
28
|
+
types = values.map do
|
29
|
+
case _1
|
30
|
+
in NilClass
|
31
|
+
"null"
|
32
|
+
in true | false
|
33
|
+
"boolean"
|
34
|
+
in Integer
|
35
|
+
"integer"
|
36
|
+
in Float
|
37
|
+
"number"
|
38
|
+
in Symbol
|
39
|
+
"string"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
.uniq
|
43
|
+
|
44
|
+
{
|
45
|
+
type: types.length == 1 ? types.first : types,
|
46
|
+
enum: values.map { _1.is_a?(Symbol) ? _1.to_s : _1 }
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private_class_method :new
|
52
|
+
|
53
|
+
def self.[](...) = new(...)
|
54
|
+
|
55
|
+
# @return [Array<generic<Value>>]
|
56
|
+
attr_reader :values
|
57
|
+
|
58
|
+
# @param values [Array<generic<Value>>]
|
59
|
+
def initialize(*values) = (@values = values.map { _1.is_a?(String) ? _1.to_sym : _1 })
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|