anthropic 0.4.1 → 1.0.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/.ignore +2 -0
- data/CHANGELOG.md +636 -29
- data/README.md +251 -285
- data/SECURITY.md +27 -0
- data/lib/anthropic/bedrock.rb +5 -0
- data/lib/anthropic/client.rb +90 -97
- data/lib/anthropic/errors.rb +192 -0
- data/lib/anthropic/file_part.rb +55 -0
- data/lib/anthropic/helpers/bedrock/client.rb +259 -0
- data/lib/anthropic/helpers/vertex/client.rb +218 -0
- data/lib/anthropic/internal/jsonl_stream.rb +26 -0
- data/lib/anthropic/internal/page.rb +99 -0
- data/lib/anthropic/internal/stream.rb +58 -0
- data/lib/anthropic/internal/transport/base_client.rb +558 -0
- data/lib/anthropic/internal/transport/pooled_net_requester.rb +209 -0
- data/lib/anthropic/internal/type/array_of.rb +162 -0
- data/lib/anthropic/internal/type/base_model.rb +481 -0
- data/lib/anthropic/internal/type/base_page.rb +55 -0
- data/lib/anthropic/internal/type/base_stream.rb +90 -0
- data/lib/anthropic/internal/type/boolean.rb +71 -0
- data/lib/anthropic/internal/type/converter.rb +292 -0
- data/lib/anthropic/internal/type/enum.rb +145 -0
- data/lib/anthropic/internal/type/file_input.rb +103 -0
- data/lib/anthropic/internal/type/hash_of.rb +182 -0
- data/lib/anthropic/internal/type/request_parameters.rb +42 -0
- data/lib/anthropic/internal/type/union.rb +252 -0
- data/lib/anthropic/internal/type/unknown.rb +75 -0
- data/lib/anthropic/internal/util.rb +907 -0
- data/lib/anthropic/internal.rb +20 -0
- data/lib/anthropic/models/anthropic_beta.rb +47 -0
- data/lib/anthropic/models/api_error_object.rb +21 -0
- data/lib/anthropic/models/authentication_error.rb +21 -0
- data/lib/anthropic/models/base64_image_source.rb +40 -0
- data/lib/anthropic/models/base64_pdf_source.rb +27 -0
- data/lib/anthropic/models/beta/beta_base64_image_source.rb +44 -0
- data/lib/anthropic/models/beta/beta_base64_pdf_block.rb +73 -0
- data/lib/anthropic/models/beta/beta_base64_pdf_source.rb +31 -0
- data/lib/anthropic/models/beta/beta_cache_control_ephemeral.rb +19 -0
- data/lib/anthropic/models/beta/beta_citation_char_location.rb +49 -0
- data/lib/anthropic/models/beta/beta_citation_char_location_param.rb +49 -0
- data/lib/anthropic/models/beta/beta_citation_content_block_location.rb +49 -0
- data/lib/anthropic/models/beta/beta_citation_content_block_location_param.rb +49 -0
- data/lib/anthropic/models/beta/beta_citation_page_location.rb +49 -0
- data/lib/anthropic/models/beta/beta_citation_page_location_param.rb +49 -0
- data/lib/anthropic/models/beta/beta_citation_web_search_result_location_param.rb +43 -0
- data/lib/anthropic/models/beta/beta_citations_config_param.rb +19 -0
- data/lib/anthropic/models/beta/beta_citations_delta.rb +43 -0
- data/lib/anthropic/models/beta/beta_citations_web_search_result_location.rb +43 -0
- data/lib/anthropic/models/beta/beta_content_block.rb +30 -0
- data/lib/anthropic/models/beta/beta_content_block_param.rb +36 -0
- data/lib/anthropic/models/beta/beta_content_block_source.rb +41 -0
- data/lib/anthropic/models/beta/beta_content_block_source_content.rb +22 -0
- data/lib/anthropic/models/beta/beta_image_block_param.rb +48 -0
- data/lib/anthropic/models/beta/beta_input_json_delta.rb +25 -0
- data/lib/anthropic/models/beta/beta_message.rb +148 -0
- data/lib/anthropic/models/beta/beta_message_delta_usage.rb +52 -0
- data/lib/anthropic/models/beta/beta_message_param.rb +52 -0
- data/lib/anthropic/models/beta/beta_message_tokens_count.rb +25 -0
- data/lib/anthropic/models/beta/beta_metadata.rb +27 -0
- data/lib/anthropic/models/beta/beta_model_info.rb +51 -0
- data/lib/anthropic/models/beta/beta_plain_text_source.rb +31 -0
- data/lib/anthropic/models/beta/beta_raw_content_block_delta.rb +28 -0
- data/lib/anthropic/models/beta/beta_raw_content_block_delta_event.rb +31 -0
- data/lib/anthropic/models/beta/beta_raw_content_block_start_event.rb +53 -0
- data/lib/anthropic/models/beta/beta_raw_content_block_stop_event.rb +25 -0
- data/lib/anthropic/models/beta/beta_raw_message_delta_event.rb +68 -0
- data/lib/anthropic/models/beta/beta_raw_message_start_event.rb +25 -0
- data/lib/anthropic/models/beta/beta_raw_message_stop_event.rb +19 -0
- data/lib/anthropic/models/beta/beta_raw_message_stream_event.rb +30 -0
- data/lib/anthropic/models/beta/beta_redacted_thinking_block.rb +25 -0
- data/lib/anthropic/models/beta/beta_redacted_thinking_block_param.rb +25 -0
- data/lib/anthropic/models/beta/beta_server_tool_usage.rb +20 -0
- data/lib/anthropic/models/beta/beta_server_tool_use_block.rb +37 -0
- data/lib/anthropic/models/beta/beta_server_tool_use_block_param.rb +48 -0
- data/lib/anthropic/models/beta/beta_signature_delta.rb +25 -0
- data/lib/anthropic/models/beta/beta_stop_reason.rb +23 -0
- data/lib/anthropic/models/beta/beta_text_block.rb +43 -0
- data/lib/anthropic/models/beta/beta_text_block_param.rb +43 -0
- data/lib/anthropic/models/beta/beta_text_citation.rb +26 -0
- data/lib/anthropic/models/beta/beta_text_citation_param.rb +26 -0
- data/lib/anthropic/models/beta/beta_text_delta.rb +25 -0
- data/lib/anthropic/models/beta/beta_thinking_block.rb +31 -0
- data/lib/anthropic/models/beta/beta_thinking_block_param.rb +31 -0
- data/lib/anthropic/models/beta/beta_thinking_config_disabled.rb +19 -0
- data/lib/anthropic/models/beta/beta_thinking_config_enabled.rb +38 -0
- data/lib/anthropic/models/beta/beta_thinking_config_param.rb +31 -0
- data/lib/anthropic/models/beta/beta_thinking_delta.rb +25 -0
- data/lib/anthropic/models/beta/beta_tool.rb +96 -0
- data/lib/anthropic/models/beta/beta_tool_bash_20241022.rb +40 -0
- data/lib/anthropic/models/beta/beta_tool_bash_20250124.rb +40 -0
- data/lib/anthropic/models/beta/beta_tool_choice.rb +32 -0
- data/lib/anthropic/models/beta/beta_tool_choice_any.rb +35 -0
- data/lib/anthropic/models/beta/beta_tool_choice_auto.rb +35 -0
- data/lib/anthropic/models/beta/beta_tool_choice_none.rb +21 -0
- data/lib/anthropic/models/beta/beta_tool_choice_tool.rb +43 -0
- data/lib/anthropic/models/beta/beta_tool_computer_use_20241022.rb +64 -0
- data/lib/anthropic/models/beta/beta_tool_computer_use_20250124.rb +64 -0
- data/lib/anthropic/models/beta/beta_tool_result_block_param.rb +79 -0
- data/lib/anthropic/models/beta/beta_tool_text_editor_20241022.rb +40 -0
- data/lib/anthropic/models/beta/beta_tool_text_editor_20250124.rb +40 -0
- data/lib/anthropic/models/beta/beta_tool_union.rb +32 -0
- data/lib/anthropic/models/beta/beta_tool_use_block.rb +37 -0
- data/lib/anthropic/models/beta/beta_tool_use_block_param.rb +48 -0
- data/lib/anthropic/models/beta/beta_url_image_source.rb +25 -0
- data/lib/anthropic/models/beta/beta_url_pdf_source.rb +25 -0
- data/lib/anthropic/models/beta/beta_usage.rb +52 -0
- data/lib/anthropic/models/beta/beta_web_search_result_block.rb +43 -0
- data/lib/anthropic/models/beta/beta_web_search_result_block_param.rb +43 -0
- data/lib/anthropic/models/beta/beta_web_search_tool_20250305.rb +126 -0
- data/lib/anthropic/models/beta/beta_web_search_tool_request_error.rb +39 -0
- data/lib/anthropic/models/beta/beta_web_search_tool_result_block.rb +31 -0
- data/lib/anthropic/models/beta/beta_web_search_tool_result_block_content.rb +24 -0
- data/lib/anthropic/models/beta/beta_web_search_tool_result_block_param.rb +41 -0
- data/lib/anthropic/models/beta/beta_web_search_tool_result_block_param_content.rb +26 -0
- data/lib/anthropic/models/beta/beta_web_search_tool_result_error.rb +39 -0
- data/lib/anthropic/models/beta/message_count_tokens_params.rb +292 -0
- data/lib/anthropic/models/beta/message_create_params.rb +351 -0
- data/lib/anthropic/models/beta/messages/batch_cancel_params.rb +26 -0
- data/lib/anthropic/models/beta/messages/batch_create_params.rb +424 -0
- data/lib/anthropic/models/beta/messages/batch_delete_params.rb +26 -0
- data/lib/anthropic/models/beta/messages/batch_list_params.rb +57 -0
- data/lib/anthropic/models/beta/messages/batch_results_params.rb +26 -0
- data/lib/anthropic/models/beta/messages/batch_retrieve_params.rb +26 -0
- data/lib/anthropic/models/beta/messages/beta_deleted_message_batch.rb +34 -0
- data/lib/anthropic/models/beta/messages/beta_message_batch.rb +133 -0
- data/lib/anthropic/models/beta/messages/beta_message_batch_canceled_result.rb +19 -0
- data/lib/anthropic/models/beta/messages/beta_message_batch_errored_result.rb +25 -0
- data/lib/anthropic/models/beta/messages/beta_message_batch_expired_result.rb +19 -0
- data/lib/anthropic/models/beta/messages/beta_message_batch_individual_response.rb +43 -0
- data/lib/anthropic/models/beta/messages/beta_message_batch_request_counts.rb +63 -0
- data/lib/anthropic/models/beta/messages/beta_message_batch_result.rb +31 -0
- data/lib/anthropic/models/beta/messages/beta_message_batch_succeeded_result.rb +25 -0
- data/lib/anthropic/models/beta/model_list_params.rb +55 -0
- data/lib/anthropic/models/beta/model_retrieve_params.rb +24 -0
- data/lib/anthropic/models/beta_api_error.rb +21 -0
- data/lib/anthropic/models/beta_authentication_error.rb +21 -0
- data/lib/anthropic/models/beta_billing_error.rb +21 -0
- data/lib/anthropic/models/beta_error.rb +32 -0
- data/lib/anthropic/models/beta_error_response.rb +21 -0
- data/lib/anthropic/models/beta_gateway_timeout_error.rb +21 -0
- data/lib/anthropic/models/beta_invalid_request_error.rb +21 -0
- data/lib/anthropic/models/beta_not_found_error.rb +21 -0
- data/lib/anthropic/models/beta_overloaded_error.rb +21 -0
- data/lib/anthropic/models/beta_permission_error.rb +21 -0
- data/lib/anthropic/models/beta_rate_limit_error.rb +21 -0
- data/lib/anthropic/models/billing_error.rb +21 -0
- data/lib/anthropic/models/cache_control_ephemeral.rb +15 -0
- data/lib/anthropic/models/citation_char_location.rb +45 -0
- data/lib/anthropic/models/citation_char_location_param.rb +45 -0
- data/lib/anthropic/models/citation_content_block_location.rb +45 -0
- data/lib/anthropic/models/citation_content_block_location_param.rb +45 -0
- data/lib/anthropic/models/citation_page_location.rb +45 -0
- data/lib/anthropic/models/citation_page_location_param.rb +45 -0
- data/lib/anthropic/models/citation_web_search_result_location_param.rb +39 -0
- data/lib/anthropic/models/citations_config_param.rb +15 -0
- data/lib/anthropic/models/citations_delta.rb +39 -0
- data/lib/anthropic/models/citations_web_search_result_location.rb +39 -0
- data/lib/anthropic/models/completion.rb +66 -0
- data/lib/anthropic/models/completion_create_params.rb +133 -0
- data/lib/anthropic/models/content_block.rb +26 -0
- data/lib/anthropic/models/content_block_param.rb +32 -0
- data/lib/anthropic/models/content_block_source.rb +37 -0
- data/lib/anthropic/models/content_block_source_content.rb +18 -0
- data/lib/anthropic/models/document_block_param.rb +69 -0
- data/lib/anthropic/models/error_object.rb +32 -0
- data/lib/anthropic/models/error_response.rb +21 -0
- data/lib/anthropic/models/gateway_timeout_error.rb +21 -0
- data/lib/anthropic/models/image_block_param.rb +44 -0
- data/lib/anthropic/models/input_json_delta.rb +21 -0
- data/lib/anthropic/models/invalid_request_error.rb +21 -0
- data/lib/anthropic/models/message.rb +144 -0
- data/lib/anthropic/models/message_count_tokens_params.rb +254 -0
- data/lib/anthropic/models/message_count_tokens_tool.rb +20 -0
- data/lib/anthropic/models/message_create_params.rb +339 -0
- data/lib/anthropic/models/message_delta_usage.rb +48 -0
- data/lib/anthropic/models/message_param.rb +49 -0
- data/lib/anthropic/models/message_tokens_count.rb +21 -0
- data/lib/anthropic/models/messages/batch_cancel_params.rb +16 -0
- data/lib/anthropic/models/messages/batch_create_params.rb +406 -0
- data/lib/anthropic/models/messages/batch_delete_params.rb +16 -0
- data/lib/anthropic/models/messages/batch_list_params.rb +47 -0
- data/lib/anthropic/models/messages/batch_results_params.rb +16 -0
- data/lib/anthropic/models/messages/batch_retrieve_params.rb +16 -0
- data/lib/anthropic/models/messages/deleted_message_batch.rb +32 -0
- data/lib/anthropic/models/messages/message_batch.rb +130 -0
- data/lib/anthropic/models/messages/message_batch_canceled_result.rb +19 -0
- data/lib/anthropic/models/messages/message_batch_errored_result.rb +25 -0
- data/lib/anthropic/models/messages/message_batch_expired_result.rb +19 -0
- data/lib/anthropic/models/messages/message_batch_individual_response.rb +42 -0
- data/lib/anthropic/models/messages/message_batch_request_counts.rb +63 -0
- data/lib/anthropic/models/messages/message_batch_result.rb +31 -0
- data/lib/anthropic/models/messages/message_batch_succeeded_result.rb +25 -0
- data/lib/anthropic/models/metadata.rb +23 -0
- data/lib/anthropic/models/model.rb +96 -0
- data/lib/anthropic/models/model_info.rb +47 -0
- data/lib/anthropic/models/model_list_params.rb +53 -0
- data/lib/anthropic/models/model_retrieve_params.rb +22 -0
- data/lib/anthropic/models/not_found_error.rb +21 -0
- data/lib/anthropic/models/overloaded_error.rb +21 -0
- data/lib/anthropic/models/permission_error.rb +21 -0
- data/lib/anthropic/models/plain_text_source.rb +27 -0
- data/lib/anthropic/models/rate_limit_error.rb +21 -0
- data/lib/anthropic/models/raw_content_block_delta.rb +24 -0
- data/lib/anthropic/models/raw_content_block_delta_event.rb +27 -0
- data/lib/anthropic/models/raw_content_block_start_event.rb +49 -0
- data/lib/anthropic/models/raw_content_block_stop_event.rb +21 -0
- data/lib/anthropic/models/raw_message_delta_event.rb +64 -0
- data/lib/anthropic/models/raw_message_start_event.rb +21 -0
- data/lib/anthropic/models/raw_message_stop_event.rb +15 -0
- data/lib/anthropic/models/raw_message_stream_event.rb +26 -0
- data/lib/anthropic/models/redacted_thinking_block.rb +21 -0
- data/lib/anthropic/models/redacted_thinking_block_param.rb +21 -0
- data/lib/anthropic/models/server_tool_usage.rb +16 -0
- data/lib/anthropic/models/server_tool_use_block.rb +33 -0
- data/lib/anthropic/models/server_tool_use_block_param.rb +44 -0
- data/lib/anthropic/models/signature_delta.rb +21 -0
- data/lib/anthropic/models/stop_reason.rb +19 -0
- data/lib/anthropic/models/text_block.rb +41 -0
- data/lib/anthropic/models/text_block_param.rb +39 -0
- data/lib/anthropic/models/text_citation.rb +22 -0
- data/lib/anthropic/models/text_citation_param.rb +22 -0
- data/lib/anthropic/models/text_delta.rb +21 -0
- data/lib/anthropic/models/thinking_block.rb +27 -0
- data/lib/anthropic/models/thinking_block_param.rb +27 -0
- data/lib/anthropic/models/thinking_config_disabled.rb +15 -0
- data/lib/anthropic/models/thinking_config_enabled.rb +34 -0
- data/lib/anthropic/models/thinking_config_param.rb +27 -0
- data/lib/anthropic/models/thinking_delta.rb +21 -0
- data/lib/anthropic/models/tool.rb +92 -0
- data/lib/anthropic/models/tool_bash_20250124.rb +36 -0
- data/lib/anthropic/models/tool_choice.rb +28 -0
- data/lib/anthropic/models/tool_choice_any.rb +31 -0
- data/lib/anthropic/models/tool_choice_auto.rb +31 -0
- data/lib/anthropic/models/tool_choice_none.rb +17 -0
- data/lib/anthropic/models/tool_choice_tool.rb +39 -0
- data/lib/anthropic/models/tool_result_block_param.rb +73 -0
- data/lib/anthropic/models/tool_text_editor_20250124.rb +36 -0
- data/lib/anthropic/models/tool_union.rb +20 -0
- data/lib/anthropic/models/tool_use_block.rb +33 -0
- data/lib/anthropic/models/tool_use_block_param.rb +44 -0
- data/lib/anthropic/models/url_image_source.rb +21 -0
- data/lib/anthropic/models/url_pdf_source.rb +21 -0
- data/lib/anthropic/models/usage.rb +48 -0
- data/lib/anthropic/models/web_search_result_block.rb +39 -0
- data/lib/anthropic/models/web_search_result_block_param.rb +39 -0
- data/lib/anthropic/models/web_search_tool_20250305.rb +122 -0
- data/lib/anthropic/models/web_search_tool_request_error.rb +35 -0
- data/lib/anthropic/models/web_search_tool_result_block.rb +27 -0
- data/lib/anthropic/models/web_search_tool_result_block_content.rb +19 -0
- data/lib/anthropic/models/web_search_tool_result_block_param.rb +37 -0
- data/lib/anthropic/models/web_search_tool_result_block_param_content.rb +20 -0
- data/lib/anthropic/models/web_search_tool_result_error.rb +35 -0
- data/lib/anthropic/models.rb +261 -0
- data/lib/anthropic/request_options.rb +77 -0
- data/lib/anthropic/resources/beta/messages/batches.rb +218 -0
- data/lib/anthropic/resources/beta/messages.rb +200 -0
- data/lib/anthropic/resources/beta/models.rb +80 -0
- data/lib/anthropic/resources/beta.rb +22 -0
- data/lib/anthropic/resources/completions.rb +132 -0
- data/lib/anthropic/resources/messages/batches.rb +193 -0
- data/lib/anthropic/resources/messages.rb +184 -0
- data/lib/anthropic/resources/models.rb +78 -0
- data/lib/anthropic/version.rb +3 -1
- data/lib/anthropic/vertex.rb +5 -0
- data/lib/anthropic.rb +286 -68
- data/manifest.yaml +15 -0
- data/rbi/anthropic/bedrock.rbi +5 -0
- data/rbi/anthropic/client.rbi +74 -0
- data/rbi/anthropic/errors.rbi +162 -0
- data/rbi/anthropic/file_part.rbi +37 -0
- data/rbi/anthropic/helpers/bedrock/client.rbi +82 -0
- data/rbi/anthropic/helpers/vertex/client.rbi +58 -0
- data/rbi/anthropic/internal/jsonl_stream.rbi +17 -0
- data/rbi/anthropic/internal/page.rbi +28 -0
- data/rbi/anthropic/internal/stream.rbi +20 -0
- data/rbi/anthropic/internal/transport/base_client.rbi +310 -0
- data/rbi/anthropic/internal/transport/pooled_net_requester.rbi +79 -0
- data/rbi/anthropic/internal/type/array_of.rbi +104 -0
- data/rbi/anthropic/internal/type/base_model.rbi +304 -0
- data/rbi/anthropic/internal/type/base_page.rbi +42 -0
- data/rbi/anthropic/internal/type/base_stream.rbi +68 -0
- data/rbi/anthropic/internal/type/boolean.rbi +56 -0
- data/rbi/anthropic/internal/type/converter.rbi +162 -0
- data/rbi/anthropic/internal/type/enum.rbi +82 -0
- data/rbi/anthropic/internal/type/file_input.rbi +59 -0
- data/rbi/anthropic/internal/type/hash_of.rbi +104 -0
- data/rbi/anthropic/internal/type/request_parameters.rbi +29 -0
- data/rbi/anthropic/internal/type/union.rbi +116 -0
- data/rbi/anthropic/internal/type/unknown.rbi +56 -0
- data/rbi/anthropic/internal/util.rbi +485 -0
- data/rbi/anthropic/internal.rbi +18 -0
- data/rbi/anthropic/models/anthropic_beta.rbi +54 -0
- data/rbi/anthropic/models/api_error_object.rbi +26 -0
- data/rbi/anthropic/models/authentication_error.rbi +26 -0
- data/rbi/anthropic/models/base64_image_source.rbi +82 -0
- data/rbi/anthropic/models/base64_pdf_source.rbi +35 -0
- data/rbi/anthropic/models/beta/beta_base64_image_source.rbi +95 -0
- data/rbi/anthropic/models/beta/beta_base64_pdf_block.rbi +134 -0
- data/rbi/anthropic/models/beta/beta_base64_pdf_source.rbi +42 -0
- data/rbi/anthropic/models/beta/beta_cache_control_ephemeral.rbi +30 -0
- data/rbi/anthropic/models/beta/beta_citation_char_location.rbi +72 -0
- data/rbi/anthropic/models/beta/beta_citation_char_location_param.rbi +72 -0
- data/rbi/anthropic/models/beta/beta_citation_content_block_location.rbi +72 -0
- data/rbi/anthropic/models/beta/beta_citation_content_block_location_param.rbi +73 -0
- data/rbi/anthropic/models/beta/beta_citation_page_location.rbi +72 -0
- data/rbi/anthropic/models/beta/beta_citation_page_location_param.rbi +72 -0
- data/rbi/anthropic/models/beta/beta_citation_web_search_result_location_param.rbi +67 -0
- data/rbi/anthropic/models/beta/beta_citations_config_param.rbi +33 -0
- data/rbi/anthropic/models/beta/beta_citations_delta.rbi +73 -0
- data/rbi/anthropic/models/beta/beta_citations_web_search_result_location.rbi +67 -0
- data/rbi/anthropic/models/beta/beta_content_block.rbi +33 -0
- data/rbi/anthropic/models/beta/beta_content_block_param.rbi +36 -0
- data/rbi/anthropic/models/beta/beta_content_block_source.rbi +80 -0
- data/rbi/anthropic/models/beta/beta_content_block_source_content.rbi +29 -0
- data/rbi/anthropic/models/beta/beta_image_block_param.rbi +101 -0
- data/rbi/anthropic/models/beta/beta_input_json_delta.rbi +35 -0
- data/rbi/anthropic/models/beta/beta_message.rbi +245 -0
- data/rbi/anthropic/models/beta/beta_message_delta_usage.rbi +85 -0
- data/rbi/anthropic/models/beta/beta_message_param.rbi +99 -0
- data/rbi/anthropic/models/beta/beta_message_tokens_count.rbi +36 -0
- data/rbi/anthropic/models/beta/beta_metadata.rbi +39 -0
- data/rbi/anthropic/models/beta/beta_model_info.rbi +66 -0
- data/rbi/anthropic/models/beta/beta_plain_text_source.rbi +42 -0
- data/rbi/anthropic/models/beta/beta_raw_content_block_delta.rbi +32 -0
- data/rbi/anthropic/models/beta/beta_raw_content_block_delta_event.rbi +57 -0
- data/rbi/anthropic/models/beta/beta_raw_content_block_start_event.rbi +89 -0
- data/rbi/anthropic/models/beta/beta_raw_content_block_stop_event.rbi +33 -0
- data/rbi/anthropic/models/beta/beta_raw_message_delta_event.rbi +135 -0
- data/rbi/anthropic/models/beta/beta_raw_message_start_event.rbi +45 -0
- data/rbi/anthropic/models/beta/beta_raw_message_stop_event.rbi +30 -0
- data/rbi/anthropic/models/beta/beta_raw_message_stream_event.rbi +33 -0
- data/rbi/anthropic/models/beta/beta_redacted_thinking_block.rbi +33 -0
- data/rbi/anthropic/models/beta/beta_redacted_thinking_block_param.rbi +33 -0
- data/rbi/anthropic/models/beta/beta_server_tool_usage.rbi +34 -0
- data/rbi/anthropic/models/beta/beta_server_tool_use_block.rbi +50 -0
- data/rbi/anthropic/models/beta/beta_server_tool_use_block_param.rbi +78 -0
- data/rbi/anthropic/models/beta/beta_signature_delta.rbi +35 -0
- data/rbi/anthropic/models/beta/beta_stop_reason.rbi +37 -0
- data/rbi/anthropic/models/beta/beta_text_block.rbi +78 -0
- data/rbi/anthropic/models/beta/beta_text_block_param.rbi +105 -0
- data/rbi/anthropic/models/beta/beta_text_citation.rbi +31 -0
- data/rbi/anthropic/models/beta/beta_text_citation_param.rbi +31 -0
- data/rbi/anthropic/models/beta/beta_text_delta.rbi +30 -0
- data/rbi/anthropic/models/beta/beta_thinking_block.rbi +44 -0
- data/rbi/anthropic/models/beta/beta_thinking_block_param.rbi +44 -0
- data/rbi/anthropic/models/beta/beta_thinking_config_disabled.rbi +30 -0
- data/rbi/anthropic/models/beta/beta_thinking_config_enabled.rbi +56 -0
- data/rbi/anthropic/models/beta/beta_thinking_config_param.rbi +38 -0
- data/rbi/anthropic/models/beta/beta_thinking_delta.rbi +33 -0
- data/rbi/anthropic/models/beta/beta_tool.rbi +165 -0
- data/rbi/anthropic/models/beta/beta_tool_bash_20241022.rbi +72 -0
- data/rbi/anthropic/models/beta/beta_tool_bash_20250124.rbi +72 -0
- data/rbi/anthropic/models/beta/beta_tool_choice.rbi +31 -0
- data/rbi/anthropic/models/beta/beta_tool_choice_any.rbi +56 -0
- data/rbi/anthropic/models/beta/beta_tool_choice_auto.rbi +56 -0
- data/rbi/anthropic/models/beta/beta_tool_choice_none.rbi +31 -0
- data/rbi/anthropic/models/beta/beta_tool_choice_tool.rbi +68 -0
- data/rbi/anthropic/models/beta/beta_tool_computer_use_20241022.rbi +96 -0
- data/rbi/anthropic/models/beta/beta_tool_computer_use_20250124.rbi +96 -0
- data/rbi/anthropic/models/beta/beta_tool_result_block_param.rbi +152 -0
- data/rbi/anthropic/models/beta/beta_tool_text_editor_20241022.rbi +72 -0
- data/rbi/anthropic/models/beta/beta_tool_text_editor_20250124.rbi +72 -0
- data/rbi/anthropic/models/beta/beta_tool_union.rbi +33 -0
- data/rbi/anthropic/models/beta/beta_tool_use_block.rbi +50 -0
- data/rbi/anthropic/models/beta/beta_tool_use_block_param.rbi +78 -0
- data/rbi/anthropic/models/beta/beta_url_image_source.rbi +33 -0
- data/rbi/anthropic/models/beta/beta_url_pdf_source.rbi +33 -0
- data/rbi/anthropic/models/beta/beta_usage.rbi +82 -0
- data/rbi/anthropic/models/beta/beta_web_search_result_block.rbi +66 -0
- data/rbi/anthropic/models/beta/beta_web_search_result_block_param.rbi +66 -0
- data/rbi/anthropic/models/beta/beta_web_search_tool_20250305.rbi +201 -0
- data/rbi/anthropic/models/beta/beta_web_search_tool_request_error.rbi +100 -0
- data/rbi/anthropic/models/beta/beta_web_search_tool_result_block.rbi +59 -0
- data/rbi/anthropic/models/beta/beta_web_search_tool_result_block_content.rbi +40 -0
- data/rbi/anthropic/models/beta/beta_web_search_tool_result_block_param.rbi +89 -0
- data/rbi/anthropic/models/beta/beta_web_search_tool_result_block_param_content.rbi +40 -0
- data/rbi/anthropic/models/beta/beta_web_search_tool_result_error.rbi +100 -0
- data/rbi/anthropic/models/beta/message_count_tokens_params.rbi +649 -0
- data/rbi/anthropic/models/beta/message_create_params.rbi +748 -0
- data/rbi/anthropic/models/beta/messages/batch_cancel_params.rbi +65 -0
- data/rbi/anthropic/models/beta/messages/batch_create_params.rbi +897 -0
- data/rbi/anthropic/models/beta/messages/batch_delete_params.rbi +65 -0
- data/rbi/anthropic/models/beta/messages/batch_list_params.rbi +106 -0
- data/rbi/anthropic/models/beta/messages/batch_results_params.rbi +65 -0
- data/rbi/anthropic/models/beta/messages/batch_retrieve_params.rbi +65 -0
- data/rbi/anthropic/models/beta/messages/beta_deleted_message_batch.rbi +44 -0
- data/rbi/anthropic/models/beta/messages/beta_message_batch.rbi +214 -0
- data/rbi/anthropic/models/beta/messages/beta_message_batch_canceled_result.rbi +30 -0
- data/rbi/anthropic/models/beta/messages/beta_message_batch_errored_result.rbi +45 -0
- data/rbi/anthropic/models/beta/messages/beta_message_batch_expired_result.rbi +30 -0
- data/rbi/anthropic/models/beta/messages/beta_message_batch_individual_response.rbi +77 -0
- data/rbi/anthropic/models/beta/messages/beta_message_batch_request_counts.rbi +92 -0
- data/rbi/anthropic/models/beta/messages/beta_message_batch_result.rbi +38 -0
- data/rbi/anthropic/models/beta/messages/beta_message_batch_succeeded_result.rbi +45 -0
- data/rbi/anthropic/models/beta/model_list_params.rbi +103 -0
- data/rbi/anthropic/models/beta/model_retrieve_params.rbi +62 -0
- data/rbi/anthropic/models/beta_api_error.rbi +26 -0
- data/rbi/anthropic/models/beta_authentication_error.rbi +29 -0
- data/rbi/anthropic/models/beta_billing_error.rbi +26 -0
- data/rbi/anthropic/models/beta_error.rbi +28 -0
- data/rbi/anthropic/models/beta_error_response.rbi +46 -0
- data/rbi/anthropic/models/beta_gateway_timeout_error.rbi +29 -0
- data/rbi/anthropic/models/beta_invalid_request_error.rbi +29 -0
- data/rbi/anthropic/models/beta_not_found_error.rbi +26 -0
- data/rbi/anthropic/models/beta_overloaded_error.rbi +26 -0
- data/rbi/anthropic/models/beta_permission_error.rbi +26 -0
- data/rbi/anthropic/models/beta_rate_limit_error.rbi +26 -0
- data/rbi/anthropic/models/billing_error.rbi +26 -0
- data/rbi/anthropic/models/cache_control_ephemeral.rbi +23 -0
- data/rbi/anthropic/models/citation_char_location.rbi +65 -0
- data/rbi/anthropic/models/citation_char_location_param.rbi +68 -0
- data/rbi/anthropic/models/citation_content_block_location.rbi +68 -0
- data/rbi/anthropic/models/citation_content_block_location_param.rbi +68 -0
- data/rbi/anthropic/models/citation_page_location.rbi +65 -0
- data/rbi/anthropic/models/citation_page_location_param.rbi +68 -0
- data/rbi/anthropic/models/citation_web_search_result_location_param.rbi +62 -0
- data/rbi/anthropic/models/citations_config_param.rbi +26 -0
- data/rbi/anthropic/models/citations_delta.rbi +66 -0
- data/rbi/anthropic/models/citations_web_search_result_location.rbi +62 -0
- data/rbi/anthropic/models/completion.rbi +93 -0
- data/rbi/anthropic/models/completion_create_params.rbi +217 -0
- data/rbi/anthropic/models/content_block.rbi +25 -0
- data/rbi/anthropic/models/content_block_param.rbi +28 -0
- data/rbi/anthropic/models/content_block_source.rbi +66 -0
- data/rbi/anthropic/models/content_block_source_content.rbi +22 -0
- data/rbi/anthropic/models/document_block_param.rbi +120 -0
- data/rbi/anthropic/models/error_object.rbi +28 -0
- data/rbi/anthropic/models/error_response.rbi +46 -0
- data/rbi/anthropic/models/gateway_timeout_error.rbi +26 -0
- data/rbi/anthropic/models/image_block_param.rbi +80 -0
- data/rbi/anthropic/models/input_json_delta.rbi +28 -0
- data/rbi/anthropic/models/invalid_request_error.rbi +26 -0
- data/rbi/anthropic/models/message.rbi +236 -0
- data/rbi/anthropic/models/message_count_tokens_params.rbi +571 -0
- data/rbi/anthropic/models/message_count_tokens_tool.rbi +25 -0
- data/rbi/anthropic/models/message_create_params.rbi +697 -0
- data/rbi/anthropic/models/message_delta_usage.rbi +76 -0
- data/rbi/anthropic/models/message_param.rbi +81 -0
- data/rbi/anthropic/models/message_tokens_count.rbi +29 -0
- data/rbi/anthropic/models/messages/batch_cancel_params.rbi +32 -0
- data/rbi/anthropic/models/messages/batch_create_params.rbi +843 -0
- data/rbi/anthropic/models/messages/batch_delete_params.rbi +32 -0
- data/rbi/anthropic/models/messages/batch_list_params.rbi +81 -0
- data/rbi/anthropic/models/messages/batch_results_params.rbi +32 -0
- data/rbi/anthropic/models/messages/batch_retrieve_params.rbi +32 -0
- data/rbi/anthropic/models/messages/deleted_message_batch.rbi +42 -0
- data/rbi/anthropic/models/messages/message_batch.rbi +208 -0
- data/rbi/anthropic/models/messages/message_batch_canceled_result.rbi +30 -0
- data/rbi/anthropic/models/messages/message_batch_errored_result.rbi +42 -0
- data/rbi/anthropic/models/messages/message_batch_expired_result.rbi +30 -0
- data/rbi/anthropic/models/messages/message_batch_individual_response.rbi +74 -0
- data/rbi/anthropic/models/messages/message_batch_request_counts.rbi +92 -0
- data/rbi/anthropic/models/messages/message_batch_result.rbi +36 -0
- data/rbi/anthropic/models/messages/message_batch_succeeded_result.rbi +40 -0
- data/rbi/anthropic/models/metadata.rbi +35 -0
- data/rbi/anthropic/models/model.rbi +68 -0
- data/rbi/anthropic/models/model_info.rbi +62 -0
- data/rbi/anthropic/models/model_list_params.rbi +95 -0
- data/rbi/anthropic/models/model_retrieve_params.rbi +54 -0
- data/rbi/anthropic/models/not_found_error.rbi +26 -0
- data/rbi/anthropic/models/overloaded_error.rbi +26 -0
- data/rbi/anthropic/models/permission_error.rbi +26 -0
- data/rbi/anthropic/models/plain_text_source.rbi +35 -0
- data/rbi/anthropic/models/rate_limit_error.rbi +26 -0
- data/rbi/anthropic/models/raw_content_block_delta.rbi +26 -0
- data/rbi/anthropic/models/raw_content_block_delta_event.rbi +53 -0
- data/rbi/anthropic/models/raw_content_block_start_event.rbi +83 -0
- data/rbi/anthropic/models/raw_content_block_stop_event.rbi +29 -0
- data/rbi/anthropic/models/raw_message_delta_event.rbi +119 -0
- data/rbi/anthropic/models/raw_message_start_event.rbi +33 -0
- data/rbi/anthropic/models/raw_message_stop_event.rbi +23 -0
- data/rbi/anthropic/models/raw_message_stream_event.rbi +27 -0
- data/rbi/anthropic/models/redacted_thinking_block.rbi +26 -0
- data/rbi/anthropic/models/redacted_thinking_block_param.rbi +29 -0
- data/rbi/anthropic/models/server_tool_usage.rbi +27 -0
- data/rbi/anthropic/models/server_tool_use_block.rbi +43 -0
- data/rbi/anthropic/models/server_tool_use_block_param.rbi +71 -0
- data/rbi/anthropic/models/signature_delta.rbi +26 -0
- data/rbi/anthropic/models/stop_reason.rbi +23 -0
- data/rbi/anthropic/models/text_block.rbi +67 -0
- data/rbi/anthropic/models/text_block_param.rbi +95 -0
- data/rbi/anthropic/models/text_citation.rbi +23 -0
- data/rbi/anthropic/models/text_citation_param.rbi +23 -0
- data/rbi/anthropic/models/text_delta.rbi +26 -0
- data/rbi/anthropic/models/thinking_block.rbi +35 -0
- data/rbi/anthropic/models/thinking_block_param.rbi +35 -0
- data/rbi/anthropic/models/thinking_config_disabled.rbi +23 -0
- data/rbi/anthropic/models/thinking_config_enabled.rbi +49 -0
- data/rbi/anthropic/models/thinking_config_param.rbi +32 -0
- data/rbi/anthropic/models/thinking_delta.rbi +26 -0
- data/rbi/anthropic/models/tool.rbi +142 -0
- data/rbi/anthropic/models/tool_bash_20250124.rbi +62 -0
- data/rbi/anthropic/models/tool_choice.rbi +25 -0
- data/rbi/anthropic/models/tool_choice_any.rbi +49 -0
- data/rbi/anthropic/models/tool_choice_auto.rbi +49 -0
- data/rbi/anthropic/models/tool_choice_none.rbi +24 -0
- data/rbi/anthropic/models/tool_choice_tool.rbi +57 -0
- data/rbi/anthropic/models/tool_result_block_param.rbi +127 -0
- data/rbi/anthropic/models/tool_text_editor_20250124.rbi +62 -0
- data/rbi/anthropic/models/tool_union.rbi +23 -0
- data/rbi/anthropic/models/tool_use_block.rbi +43 -0
- data/rbi/anthropic/models/tool_use_block_param.rbi +68 -0
- data/rbi/anthropic/models/url_image_source.rbi +26 -0
- data/rbi/anthropic/models/url_pdf_source.rbi +26 -0
- data/rbi/anthropic/models/usage.rbi +74 -0
- data/rbi/anthropic/models/web_search_result_block.rbi +59 -0
- data/rbi/anthropic/models/web_search_result_block_param.rbi +62 -0
- data/rbi/anthropic/models/web_search_tool_20250305.rbi +181 -0
- data/rbi/anthropic/models/web_search_tool_request_error.rbi +88 -0
- data/rbi/anthropic/models/web_search_tool_result_block.rbi +50 -0
- data/rbi/anthropic/models/web_search_tool_result_block_content.rbi +31 -0
- data/rbi/anthropic/models/web_search_tool_result_block_param.rbi +80 -0
- data/rbi/anthropic/models/web_search_tool_result_block_param_content.rbi +33 -0
- data/rbi/anthropic/models/web_search_tool_result_error.rbi +90 -0
- data/rbi/anthropic/models.rbi +229 -0
- data/rbi/anthropic/request_options.rbi +59 -0
- data/rbi/anthropic/resources/beta/messages/batches.rbi +186 -0
- data/rbi/anthropic/resources/beta/messages.rbi +830 -0
- data/rbi/anthropic/resources/beta/models.rbi +64 -0
- data/rbi/anthropic/resources/beta.rbi +18 -0
- data/rbi/anthropic/resources/completions.rbi +199 -0
- data/rbi/anthropic/resources/messages/batches.rbi +156 -0
- data/rbi/anthropic/resources/messages.rbi +806 -0
- data/rbi/anthropic/resources/models.rbi +62 -0
- data/rbi/anthropic/version.rbi +5 -0
- data/rbi/anthropic/vertex.rbi +5 -0
- data/sig/anthropic/bedrock.rbs +3 -0
- data/sig/anthropic/client.rbs +39 -0
- data/sig/anthropic/errors.rbs +101 -0
- data/sig/anthropic/file_part.rbs +21 -0
- data/sig/anthropic/helpers/bedrock/client.rbs +43 -0
- data/sig/anthropic/helpers/vertex/client.rbs +36 -0
- data/sig/anthropic/internal/jsonl_stream.rbs +9 -0
- data/sig/anthropic/internal/page.rbs +17 -0
- data/sig/anthropic/internal/stream.rbs +9 -0
- data/sig/anthropic/internal/transport/base_client.rbs +131 -0
- data/sig/anthropic/internal/transport/pooled_net_requester.rbs +45 -0
- data/sig/anthropic/internal/type/array_of.rbs +48 -0
- data/sig/anthropic/internal/type/base_model.rbs +102 -0
- data/sig/anthropic/internal/type/base_page.rbs +24 -0
- data/sig/anthropic/internal/type/base_stream.rbs +33 -0
- data/sig/anthropic/internal/type/boolean.rbs +26 -0
- data/sig/anthropic/internal/type/converter.rbs +56 -0
- data/sig/anthropic/internal/type/enum.rbs +32 -0
- data/sig/anthropic/internal/type/file_input.rbs +25 -0
- data/sig/anthropic/internal/type/hash_of.rbs +48 -0
- data/sig/anthropic/internal/type/request_parameters.rbs +19 -0
- data/sig/anthropic/internal/type/union.rbs +52 -0
- data/sig/anthropic/internal/type/unknown.rbs +26 -0
- data/sig/anthropic/internal/util.rbs +185 -0
- data/sig/anthropic/internal.rbs +9 -0
- data/sig/anthropic/models/anthropic_beta.rbs +29 -0
- data/sig/anthropic/models/api_error_object.rbs +13 -0
- data/sig/anthropic/models/authentication_error.rbs +13 -0
- data/sig/anthropic/models/base64_image_source.rbs +38 -0
- data/sig/anthropic/models/base64_pdf_source.rbs +20 -0
- data/sig/anthropic/models/beta/beta_base64_image_source.rbs +42 -0
- data/sig/anthropic/models/beta/beta_base64_pdf_block.rbs +56 -0
- data/sig/anthropic/models/beta/beta_base64_pdf_source.rbs +24 -0
- data/sig/anthropic/models/beta/beta_cache_control_ephemeral.rbs +15 -0
- data/sig/anthropic/models/beta/beta_citation_char_location.rbs +40 -0
- data/sig/anthropic/models/beta/beta_citation_char_location_param.rbs +40 -0
- data/sig/anthropic/models/beta/beta_citation_content_block_location.rbs +40 -0
- data/sig/anthropic/models/beta/beta_citation_content_block_location_param.rbs +40 -0
- data/sig/anthropic/models/beta/beta_citation_page_location.rbs +40 -0
- data/sig/anthropic/models/beta/beta_citation_page_location_param.rbs +40 -0
- data/sig/anthropic/models/beta/beta_citation_web_search_result_location_param.rbs +36 -0
- data/sig/anthropic/models/beta/beta_citations_config_param.rbs +17 -0
- data/sig/anthropic/models/beta/beta_citations_delta.rbs +36 -0
- data/sig/anthropic/models/beta/beta_citations_web_search_result_location.rbs +36 -0
- data/sig/anthropic/models/beta/beta_content_block.rbs +21 -0
- data/sig/anthropic/models/beta/beta_content_block_param.rbs +24 -0
- data/sig/anthropic/models/beta/beta_content_block_source.rbs +36 -0
- data/sig/anthropic/models/beta/beta_content_block_source_content.rbs +17 -0
- data/sig/anthropic/models/beta/beta_image_block_param.rbs +38 -0
- data/sig/anthropic/models/beta/beta_input_json_delta.rbs +18 -0
- data/sig/anthropic/models/beta/beta_message.rbs +48 -0
- data/sig/anthropic/models/beta/beta_message_delta_usage.rbs +36 -0
- data/sig/anthropic/models/beta/beta_message_param.rbs +46 -0
- data/sig/anthropic/models/beta/beta_message_tokens_count.rbs +15 -0
- data/sig/anthropic/models/beta/beta_metadata.rbs +15 -0
- data/sig/anthropic/models/beta/beta_model_info.rbs +27 -0
- data/sig/anthropic/models/beta/beta_plain_text_source.rbs +24 -0
- data/sig/anthropic/models/beta/beta_raw_content_block_delta.rbs +20 -0
- data/sig/anthropic/models/beta/beta_raw_content_block_delta_event.rbs +28 -0
- data/sig/anthropic/models/beta/beta_raw_content_block_start_event.rbs +42 -0
- data/sig/anthropic/models/beta/beta_raw_content_block_stop_event.rbs +18 -0
- data/sig/anthropic/models/beta/beta_raw_message_delta_event.rbs +45 -0
- data/sig/anthropic/models/beta/beta_raw_message_start_event.rbs +21 -0
- data/sig/anthropic/models/beta/beta_raw_message_stop_event.rbs +15 -0
- data/sig/anthropic/models/beta/beta_raw_message_stream_event.rbs +21 -0
- data/sig/anthropic/models/beta/beta_redacted_thinking_block.rbs +18 -0
- data/sig/anthropic/models/beta/beta_redacted_thinking_block_param.rbs +18 -0
- data/sig/anthropic/models/beta/beta_server_tool_usage.rbs +15 -0
- data/sig/anthropic/models/beta/beta_server_tool_use_block.rbs +27 -0
- data/sig/anthropic/models/beta/beta_server_tool_use_block_param.rbs +36 -0
- data/sig/anthropic/models/beta/beta_signature_delta.rbs +17 -0
- data/sig/anthropic/models/beta/beta_stop_reason.rbs +28 -0
- data/sig/anthropic/models/beta/beta_text_block.rbs +28 -0
- data/sig/anthropic/models/beta/beta_text_block_param.rbs +32 -0
- data/sig/anthropic/models/beta/beta_text_citation.rbs +19 -0
- data/sig/anthropic/models/beta/beta_text_citation_param.rbs +19 -0
- data/sig/anthropic/models/beta/beta_text_delta.rbs +17 -0
- data/sig/anthropic/models/beta/beta_thinking_block.rbs +24 -0
- data/sig/anthropic/models/beta/beta_thinking_block_param.rbs +24 -0
- data/sig/anthropic/models/beta/beta_thinking_config_disabled.rbs +15 -0
- data/sig/anthropic/models/beta/beta_thinking_config_enabled.rbs +18 -0
- data/sig/anthropic/models/beta/beta_thinking_config_param.rbs +17 -0
- data/sig/anthropic/models/beta/beta_thinking_delta.rbs +17 -0
- data/sig/anthropic/models/beta/beta_tool.rbs +58 -0
- data/sig/anthropic/models/beta/beta_tool_bash_20241022.rbs +28 -0
- data/sig/anthropic/models/beta/beta_tool_bash_20250124.rbs +28 -0
- data/sig/anthropic/models/beta/beta_tool_choice.rbs +19 -0
- data/sig/anthropic/models/beta/beta_tool_choice_any.rbs +20 -0
- data/sig/anthropic/models/beta/beta_tool_choice_auto.rbs +20 -0
- data/sig/anthropic/models/beta/beta_tool_choice_none.rbs +15 -0
- data/sig/anthropic/models/beta/beta_tool_choice_tool.rbs +26 -0
- data/sig/anthropic/models/beta/beta_tool_computer_use_20241022.rbs +40 -0
- data/sig/anthropic/models/beta/beta_tool_computer_use_20250124.rbs +40 -0
- data/sig/anthropic/models/beta/beta_tool_result_block_param.rbs +64 -0
- data/sig/anthropic/models/beta/beta_tool_text_editor_20241022.rbs +28 -0
- data/sig/anthropic/models/beta/beta_tool_text_editor_20250124.rbs +28 -0
- data/sig/anthropic/models/beta/beta_tool_union.rbs +23 -0
- data/sig/anthropic/models/beta/beta_tool_use_block.rbs +27 -0
- data/sig/anthropic/models/beta/beta_tool_use_block_param.rbs +36 -0
- data/sig/anthropic/models/beta/beta_url_image_source.rbs +17 -0
- data/sig/anthropic/models/beta/beta_url_pdf_source.rbs +17 -0
- data/sig/anthropic/models/beta/beta_usage.rbs +36 -0
- data/sig/anthropic/models/beta/beta_web_search_result_block.rbs +36 -0
- data/sig/anthropic/models/beta/beta_web_search_result_block_param.rbs +36 -0
- data/sig/anthropic/models/beta/beta_web_search_tool_20250305.rbs +73 -0
- data/sig/anthropic/models/beta/beta_web_search_tool_request_error.rbs +43 -0
- data/sig/anthropic/models/beta/beta_web_search_tool_result_block.rbs +28 -0
- data/sig/anthropic/models/beta/beta_web_search_tool_result_block_content.rbs +19 -0
- data/sig/anthropic/models/beta/beta_web_search_tool_result_block_param.rbs +32 -0
- data/sig/anthropic/models/beta/beta_web_search_tool_result_block_param_content.rbs +19 -0
- data/sig/anthropic/models/beta/beta_web_search_tool_result_error.rbs +43 -0
- data/sig/anthropic/models/beta/message_count_tokens_params.rbs +93 -0
- data/sig/anthropic/models/beta/message_create_params.rbs +113 -0
- data/sig/anthropic/models/beta/messages/batch_cancel_params.rbs +27 -0
- data/sig/anthropic/models/beta/messages/batch_create_params.rbs +152 -0
- data/sig/anthropic/models/beta/messages/batch_delete_params.rbs +27 -0
- data/sig/anthropic/models/beta/messages/batch_list_params.rbs +47 -0
- data/sig/anthropic/models/beta/messages/batch_results_params.rbs +27 -0
- data/sig/anthropic/models/beta/messages/batch_retrieve_params.rbs +27 -0
- data/sig/anthropic/models/beta/messages/beta_deleted_message_batch.rbs +18 -0
- data/sig/anthropic/models/beta/messages/beta_message_batch.rbs +68 -0
- data/sig/anthropic/models/beta/messages/beta_message_batch_canceled_result.rbs +15 -0
- data/sig/anthropic/models/beta/messages/beta_message_batch_errored_result.rbs +21 -0
- data/sig/anthropic/models/beta/messages/beta_message_batch_expired_result.rbs +15 -0
- data/sig/anthropic/models/beta/messages/beta_message_batch_individual_response.rbs +24 -0
- data/sig/anthropic/models/beta/messages/beta_message_batch_request_counts.rbs +36 -0
- data/sig/anthropic/models/beta/messages/beta_message_batch_result.rbs +19 -0
- data/sig/anthropic/models/beta/messages/beta_message_batch_succeeded_result.rbs +21 -0
- data/sig/anthropic/models/beta/model_list_params.rbs +45 -0
- data/sig/anthropic/models/beta/model_retrieve_params.rbs +25 -0
- data/sig/anthropic/models/beta_api_error.rbs +13 -0
- data/sig/anthropic/models/beta_authentication_error.rbs +14 -0
- data/sig/anthropic/models/beta_billing_error.rbs +13 -0
- data/sig/anthropic/models/beta_error.rbs +20 -0
- data/sig/anthropic/models/beta_error_response.rbs +17 -0
- data/sig/anthropic/models/beta_gateway_timeout_error.rbs +13 -0
- data/sig/anthropic/models/beta_invalid_request_error.rbs +14 -0
- data/sig/anthropic/models/beta_not_found_error.rbs +13 -0
- data/sig/anthropic/models/beta_overloaded_error.rbs +13 -0
- data/sig/anthropic/models/beta_permission_error.rbs +13 -0
- data/sig/anthropic/models/beta_rate_limit_error.rbs +13 -0
- data/sig/anthropic/models/billing_error.rbs +13 -0
- data/sig/anthropic/models/cache_control_ephemeral.rbs +11 -0
- data/sig/anthropic/models/citation_char_location.rbs +36 -0
- data/sig/anthropic/models/citation_char_location_param.rbs +36 -0
- data/sig/anthropic/models/citation_content_block_location.rbs +36 -0
- data/sig/anthropic/models/citation_content_block_location_param.rbs +36 -0
- data/sig/anthropic/models/citation_page_location.rbs +36 -0
- data/sig/anthropic/models/citation_page_location_param.rbs +36 -0
- data/sig/anthropic/models/citation_web_search_result_location_param.rbs +32 -0
- data/sig/anthropic/models/citations_config_param.rbs +13 -0
- data/sig/anthropic/models/citations_delta.rbs +29 -0
- data/sig/anthropic/models/citations_web_search_result_location.rbs +32 -0
- data/sig/anthropic/models/completion.rbs +32 -0
- data/sig/anthropic/models/completion_create_params.rbs +67 -0
- data/sig/anthropic/models/content_block.rbs +17 -0
- data/sig/anthropic/models/content_block_param.rbs +20 -0
- data/sig/anthropic/models/content_block_source.rbs +28 -0
- data/sig/anthropic/models/content_block_source_content.rbs +12 -0
- data/sig/anthropic/models/document_block_param.rbs +52 -0
- data/sig/anthropic/models/error_object.rbs +20 -0
- data/sig/anthropic/models/error_response.rbs +17 -0
- data/sig/anthropic/models/gateway_timeout_error.rbs +13 -0
- data/sig/anthropic/models/image_block_param.rbs +32 -0
- data/sig/anthropic/models/input_json_delta.rbs +13 -0
- data/sig/anthropic/models/invalid_request_error.rbs +14 -0
- data/sig/anthropic/models/message.rbs +44 -0
- data/sig/anthropic/models/message_count_tokens_params.rbs +67 -0
- data/sig/anthropic/models/message_count_tokens_tool.rbs +15 -0
- data/sig/anthropic/models/message_create_params.rbs +101 -0
- data/sig/anthropic/models/message_delta_usage.rbs +32 -0
- data/sig/anthropic/models/message_param.rbs +41 -0
- data/sig/anthropic/models/message_tokens_count.rbs +11 -0
- data/sig/anthropic/models/messages/batch_cancel_params.rbs +15 -0
- data/sig/anthropic/models/messages/batch_create_params.rbs +137 -0
- data/sig/anthropic/models/messages/batch_delete_params.rbs +15 -0
- data/sig/anthropic/models/messages/batch_list_params.rbs +33 -0
- data/sig/anthropic/models/messages/batch_results_params.rbs +15 -0
- data/sig/anthropic/models/messages/batch_retrieve_params.rbs +15 -0
- data/sig/anthropic/models/messages/deleted_message_batch.rbs +15 -0
- data/sig/anthropic/models/messages/message_batch.rbs +68 -0
- data/sig/anthropic/models/messages/message_batch_canceled_result.rbs +15 -0
- data/sig/anthropic/models/messages/message_batch_errored_result.rbs +21 -0
- data/sig/anthropic/models/messages/message_batch_expired_result.rbs +15 -0
- data/sig/anthropic/models/messages/message_batch_individual_response.rbs +24 -0
- data/sig/anthropic/models/messages/message_batch_request_counts.rbs +36 -0
- data/sig/anthropic/models/messages/message_batch_result.rbs +19 -0
- data/sig/anthropic/models/messages/message_batch_succeeded_result.rbs +18 -0
- data/sig/anthropic/models/metadata.rbs +11 -0
- data/sig/anthropic/models/model.rbs +61 -0
- data/sig/anthropic/models/model_info.rbs +23 -0
- data/sig/anthropic/models/model_list_params.rbs +43 -0
- data/sig/anthropic/models/model_retrieve_params.rbs +23 -0
- data/sig/anthropic/models/not_found_error.rbs +13 -0
- data/sig/anthropic/models/overloaded_error.rbs +13 -0
- data/sig/anthropic/models/permission_error.rbs +13 -0
- data/sig/anthropic/models/plain_text_source.rbs +20 -0
- data/sig/anthropic/models/rate_limit_error.rbs +13 -0
- data/sig/anthropic/models/raw_content_block_delta.rbs +16 -0
- data/sig/anthropic/models/raw_content_block_delta_event.rbs +24 -0
- data/sig/anthropic/models/raw_content_block_start_event.rbs +38 -0
- data/sig/anthropic/models/raw_content_block_stop_event.rbs +14 -0
- data/sig/anthropic/models/raw_message_delta_event.rbs +38 -0
- data/sig/anthropic/models/raw_message_start_event.rbs +17 -0
- data/sig/anthropic/models/raw_message_stop_event.rbs +11 -0
- data/sig/anthropic/models/raw_message_stream_event.rbs +17 -0
- data/sig/anthropic/models/redacted_thinking_block.rbs +13 -0
- data/sig/anthropic/models/redacted_thinking_block_param.rbs +14 -0
- data/sig/anthropic/models/server_tool_usage.rbs +11 -0
- data/sig/anthropic/models/server_tool_use_block.rbs +23 -0
- data/sig/anthropic/models/server_tool_use_block_param.rbs +32 -0
- data/sig/anthropic/models/signature_delta.rbs +13 -0
- data/sig/anthropic/models/stop_reason.rbs +24 -0
- data/sig/anthropic/models/text_block.rbs +24 -0
- data/sig/anthropic/models/text_block_param.rbs +28 -0
- data/sig/anthropic/models/text_citation.rbs +15 -0
- data/sig/anthropic/models/text_citation_param.rbs +15 -0
- data/sig/anthropic/models/text_delta.rbs +13 -0
- data/sig/anthropic/models/thinking_block.rbs +20 -0
- data/sig/anthropic/models/thinking_block_param.rbs +20 -0
- data/sig/anthropic/models/thinking_config_disabled.rbs +11 -0
- data/sig/anthropic/models/thinking_config_enabled.rbs +13 -0
- data/sig/anthropic/models/thinking_config_param.rbs +12 -0
- data/sig/anthropic/models/thinking_delta.rbs +13 -0
- data/sig/anthropic/models/tool.rbs +54 -0
- data/sig/anthropic/models/tool_bash_20250124.rbs +24 -0
- data/sig/anthropic/models/tool_choice.rbs +15 -0
- data/sig/anthropic/models/tool_choice_any.rbs +15 -0
- data/sig/anthropic/models/tool_choice_auto.rbs +15 -0
- data/sig/anthropic/models/tool_choice_none.rbs +11 -0
- data/sig/anthropic/models/tool_choice_tool.rbs +22 -0
- data/sig/anthropic/models/tool_result_block_param.rbs +57 -0
- data/sig/anthropic/models/tool_text_editor_20250124.rbs +24 -0
- data/sig/anthropic/models/tool_union.rbs +15 -0
- data/sig/anthropic/models/tool_use_block.rbs +23 -0
- data/sig/anthropic/models/tool_use_block_param.rbs +32 -0
- data/sig/anthropic/models/url_image_source.rbs +13 -0
- data/sig/anthropic/models/url_pdf_source.rbs +13 -0
- data/sig/anthropic/models/usage.rbs +32 -0
- data/sig/anthropic/models/web_search_result_block.rbs +32 -0
- data/sig/anthropic/models/web_search_result_block_param.rbs +32 -0
- data/sig/anthropic/models/web_search_tool_20250305.rbs +69 -0
- data/sig/anthropic/models/web_search_tool_request_error.rbs +39 -0
- data/sig/anthropic/models/web_search_tool_result_block.rbs +24 -0
- data/sig/anthropic/models/web_search_tool_result_block_content.rbs +15 -0
- data/sig/anthropic/models/web_search_tool_result_block_param.rbs +28 -0
- data/sig/anthropic/models/web_search_tool_result_block_param_content.rbs +15 -0
- data/sig/anthropic/models/web_search_tool_result_error.rbs +39 -0
- data/sig/anthropic/models.rbs +221 -0
- data/sig/anthropic/request_options.rbs +34 -0
- data/sig/anthropic/resources/beta/messages/batches.rbs +49 -0
- data/sig/anthropic/resources/beta/messages.rbs +56 -0
- data/sig/anthropic/resources/beta/models.rbs +23 -0
- data/sig/anthropic/resources/beta.rbs +11 -0
- data/sig/anthropic/resources/completions.rbs +33 -0
- data/sig/anthropic/resources/messages/batches.rbs +41 -0
- data/sig/anthropic/resources/messages.rbs +51 -0
- data/sig/anthropic/resources/models.rbs +21 -0
- data/sig/anthropic/version.rbs +3 -0
- data/sig/anthropic/vertex.rbs +3 -0
- metadata +799 -77
- data/.circleci/config.yml +0 -45
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- data/.github/dependabot.yml +0 -15
- data/.gitignore +0 -16
- data/.rspec +0 -3
- data/.rubocop.yml +0 -30
- data/CODE_OF_CONDUCT.md +0 -74
- data/CONTRIBUTING.md +0 -3
- data/Gemfile +0 -13
- data/Gemfile.lock +0 -88
- data/LICENSE.txt +0 -21
- data/Rakefile +0 -19
- data/anthropic.gemspec +0 -31
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/lib/anthropic/compatibility.rb +0 -10
- data/lib/anthropic/http.rb +0 -200
- data/lib/anthropic/http_headers.rb +0 -38
- data/lib/anthropic/messages/batches.rb +0 -112
- data/lib/anthropic/messages/client.rb +0 -13
- data/lib/ruby/anthropic.rb +0 -2
- data/pull_request_template.md +0 -5
@@ -0,0 +1,558 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Anthropic
|
4
|
+
module Internal
|
5
|
+
module Transport
|
6
|
+
# @api private
|
7
|
+
#
|
8
|
+
# @abstract
|
9
|
+
class BaseClient
|
10
|
+
extend Anthropic::Internal::Util::SorbetRuntimeSupport
|
11
|
+
|
12
|
+
# from whatwg fetch spec
|
13
|
+
MAX_REDIRECTS = 20
|
14
|
+
|
15
|
+
# rubocop:disable Style/MutableConstant
|
16
|
+
PLATFORM_HEADERS =
|
17
|
+
{
|
18
|
+
"x-stainless-arch" => Anthropic::Internal::Util.arch,
|
19
|
+
"x-stainless-lang" => "ruby",
|
20
|
+
"x-stainless-os" => Anthropic::Internal::Util.os,
|
21
|
+
"x-stainless-package-version" => Anthropic::VERSION,
|
22
|
+
"x-stainless-runtime" => ::RUBY_ENGINE,
|
23
|
+
"x-stainless-runtime-version" => ::RUBY_ENGINE_VERSION
|
24
|
+
}
|
25
|
+
# rubocop:enable Style/MutableConstant
|
26
|
+
|
27
|
+
class << self
|
28
|
+
# @api private
|
29
|
+
#
|
30
|
+
# @param req [Hash{Symbol=>Object}]
|
31
|
+
#
|
32
|
+
# @raise [ArgumentError]
|
33
|
+
def validate!(req)
|
34
|
+
keys = [:method, :path, :query, :headers, :body, :unwrap, :page, :stream, :model, :options]
|
35
|
+
case req
|
36
|
+
in Hash
|
37
|
+
req.each_key do |k|
|
38
|
+
unless keys.include?(k)
|
39
|
+
raise ArgumentError.new("Request `req` keys must be one of #{keys}, got #{k.inspect}")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
else
|
43
|
+
raise ArgumentError.new("Request `req` must be a Hash or RequestOptions, got #{req.inspect}")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# @api private
|
48
|
+
#
|
49
|
+
# @param status [Integer]
|
50
|
+
# @param headers [Hash{String=>String}, Net::HTTPHeader]
|
51
|
+
#
|
52
|
+
# @return [Boolean]
|
53
|
+
def should_retry?(status, headers:)
|
54
|
+
coerced = Anthropic::Internal::Util.coerce_boolean(headers["x-should-retry"])
|
55
|
+
case [coerced, status]
|
56
|
+
in [true | false, _]
|
57
|
+
coerced
|
58
|
+
in [_, 408 | 409 | 429 | (500..)]
|
59
|
+
# retry on:
|
60
|
+
# 408: timeouts
|
61
|
+
# 409: locks
|
62
|
+
# 429: rate limits
|
63
|
+
# 500+: unknown errors
|
64
|
+
true
|
65
|
+
else
|
66
|
+
false
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# @api private
|
71
|
+
#
|
72
|
+
# @param request [Hash{Symbol=>Object}] .
|
73
|
+
#
|
74
|
+
# @option request [Symbol] :method
|
75
|
+
#
|
76
|
+
# @option request [URI::Generic] :url
|
77
|
+
#
|
78
|
+
# @option request [Hash{String=>String}] :headers
|
79
|
+
#
|
80
|
+
# @option request [Object] :body
|
81
|
+
#
|
82
|
+
# @option request [Integer] :max_retries
|
83
|
+
#
|
84
|
+
# @option request [Float] :timeout
|
85
|
+
#
|
86
|
+
# @param status [Integer]
|
87
|
+
#
|
88
|
+
# @param response_headers [Hash{String=>String}, Net::HTTPHeader]
|
89
|
+
#
|
90
|
+
# @return [Hash{Symbol=>Object}]
|
91
|
+
def follow_redirect(request, status:, response_headers:)
|
92
|
+
method, url, headers = request.fetch_values(:method, :url, :headers)
|
93
|
+
location =
|
94
|
+
Kernel.then do
|
95
|
+
URI.join(url, response_headers["location"])
|
96
|
+
rescue ArgumentError
|
97
|
+
message = "Server responded with status #{status} but no valid location header."
|
98
|
+
raise Anthropic::Errors::APIConnectionError.new(
|
99
|
+
url: url,
|
100
|
+
response: response_headers,
|
101
|
+
message: message
|
102
|
+
)
|
103
|
+
end
|
104
|
+
|
105
|
+
request = {**request, url: location}
|
106
|
+
|
107
|
+
case [url.scheme, location.scheme]
|
108
|
+
in ["https", "http"]
|
109
|
+
message = "Tried to redirect to a insecure URL"
|
110
|
+
raise Anthropic::Errors::APIConnectionError.new(
|
111
|
+
url: url,
|
112
|
+
response: response_headers,
|
113
|
+
message: message
|
114
|
+
)
|
115
|
+
else
|
116
|
+
nil
|
117
|
+
end
|
118
|
+
|
119
|
+
# from whatwg fetch spec
|
120
|
+
case [status, method]
|
121
|
+
in [301 | 302, :post] | [303, _]
|
122
|
+
drop = %w[content-encoding content-language content-length content-location content-type]
|
123
|
+
request = {
|
124
|
+
**request,
|
125
|
+
method: method == :head ? :head : :get,
|
126
|
+
headers: headers.except(*drop),
|
127
|
+
body: nil
|
128
|
+
}
|
129
|
+
else
|
130
|
+
end
|
131
|
+
|
132
|
+
# from undici
|
133
|
+
if Anthropic::Internal::Util.uri_origin(url) != Anthropic::Internal::Util.uri_origin(location)
|
134
|
+
drop = %w[authorization cookie host proxy-authorization]
|
135
|
+
request = {**request, headers: request.fetch(:headers).except(*drop)}
|
136
|
+
end
|
137
|
+
|
138
|
+
request
|
139
|
+
end
|
140
|
+
|
141
|
+
# @api private
|
142
|
+
#
|
143
|
+
# @param status [Integer, Anthropic::Errors::APIConnectionError]
|
144
|
+
# @param stream [Enumerable<String>, nil]
|
145
|
+
def reap_connection!(status, stream:)
|
146
|
+
case status
|
147
|
+
in (..199) | (300..499)
|
148
|
+
stream&.each { next }
|
149
|
+
in Anthropic::Errors::APIConnectionError | (500..)
|
150
|
+
Anthropic::Internal::Util.close_fused!(stream)
|
151
|
+
else
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# @return [URI::Generic]
|
157
|
+
attr_reader :base_url
|
158
|
+
|
159
|
+
# @return [Float]
|
160
|
+
attr_reader :timeout
|
161
|
+
|
162
|
+
# @return [Integer]
|
163
|
+
attr_reader :max_retries
|
164
|
+
|
165
|
+
# @return [Float]
|
166
|
+
attr_reader :initial_retry_delay
|
167
|
+
|
168
|
+
# @return [Float]
|
169
|
+
attr_reader :max_retry_delay
|
170
|
+
|
171
|
+
# @return [Hash{String=>String}]
|
172
|
+
attr_reader :headers
|
173
|
+
|
174
|
+
# @return [String, nil]
|
175
|
+
attr_reader :idempotency_header
|
176
|
+
|
177
|
+
# @api private
|
178
|
+
# @return [Anthropic::Internal::Transport::PooledNetRequester]
|
179
|
+
attr_reader :requester
|
180
|
+
|
181
|
+
# @api private
|
182
|
+
#
|
183
|
+
# @param base_url [String]
|
184
|
+
# @param timeout [Float]
|
185
|
+
# @param max_retries [Integer]
|
186
|
+
# @param initial_retry_delay [Float]
|
187
|
+
# @param max_retry_delay [Float]
|
188
|
+
# @param headers [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}]
|
189
|
+
# @param idempotency_header [String, nil]
|
190
|
+
def initialize(
|
191
|
+
base_url:,
|
192
|
+
timeout: 0.0,
|
193
|
+
max_retries: 0,
|
194
|
+
initial_retry_delay: 0.0,
|
195
|
+
max_retry_delay: 0.0,
|
196
|
+
headers: {},
|
197
|
+
idempotency_header: nil
|
198
|
+
)
|
199
|
+
@requester = Anthropic::Internal::Transport::PooledNetRequester.new
|
200
|
+
@headers = Anthropic::Internal::Util.normalized_headers(
|
201
|
+
self.class::PLATFORM_HEADERS,
|
202
|
+
{
|
203
|
+
"accept" => "application/json",
|
204
|
+
"content-type" => "application/json"
|
205
|
+
},
|
206
|
+
headers
|
207
|
+
)
|
208
|
+
@base_url_components = Anthropic::Internal::Util.parse_uri(base_url)
|
209
|
+
@base_url = Anthropic::Internal::Util.unparse_uri(@base_url_components)
|
210
|
+
@idempotency_header = idempotency_header&.to_s&.downcase
|
211
|
+
@timeout = timeout
|
212
|
+
@max_retries = max_retries
|
213
|
+
@initial_retry_delay = initial_retry_delay
|
214
|
+
@max_retry_delay = max_retry_delay
|
215
|
+
end
|
216
|
+
|
217
|
+
# @api private
|
218
|
+
#
|
219
|
+
# @return [Hash{String=>String}]
|
220
|
+
private def auth_headers = {}
|
221
|
+
|
222
|
+
# @api private
|
223
|
+
#
|
224
|
+
# @return [String]
|
225
|
+
private def generate_idempotency_key = "stainless-ruby-retry-#{SecureRandom.uuid}"
|
226
|
+
|
227
|
+
# @api private
|
228
|
+
#
|
229
|
+
# @param req [Hash{Symbol=>Object}] .
|
230
|
+
#
|
231
|
+
# @option req [Symbol] :method
|
232
|
+
#
|
233
|
+
# @option req [String, Array<String>] :path
|
234
|
+
#
|
235
|
+
# @option req [Hash{String=>Array<String>, String, nil}, nil] :query
|
236
|
+
#
|
237
|
+
# @option req [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}, nil] :headers
|
238
|
+
#
|
239
|
+
# @option req [Object, nil] :body
|
240
|
+
#
|
241
|
+
# @option req [Symbol, Integer, Array<Symbol, Integer>, Proc, nil] :unwrap
|
242
|
+
#
|
243
|
+
# @option req [Class<Anthropic::Internal::Type::BasePage>, nil] :page
|
244
|
+
#
|
245
|
+
# @option req [Class<Anthropic::Internal::Type::BaseStream>, nil] :stream
|
246
|
+
#
|
247
|
+
# @option req [Anthropic::Internal::Type::Converter, Class, nil] :model
|
248
|
+
#
|
249
|
+
# @param opts [Hash{Symbol=>Object}] .
|
250
|
+
#
|
251
|
+
# @option opts [String, nil] :idempotency_key
|
252
|
+
#
|
253
|
+
# @option opts [Hash{String=>Array<String>, String, nil}, nil] :extra_query
|
254
|
+
#
|
255
|
+
# @option opts [Hash{String=>String, nil}, nil] :extra_headers
|
256
|
+
#
|
257
|
+
# @option opts [Object, nil] :extra_body
|
258
|
+
#
|
259
|
+
# @option opts [Integer, nil] :max_retries
|
260
|
+
#
|
261
|
+
# @option opts [Float, nil] :timeout
|
262
|
+
#
|
263
|
+
# @return [Hash{Symbol=>Object}]
|
264
|
+
private def build_request(req, opts)
|
265
|
+
method, uninterpolated_path = req.fetch_values(:method, :path)
|
266
|
+
|
267
|
+
path = Anthropic::Internal::Util.interpolate_path(uninterpolated_path)
|
268
|
+
|
269
|
+
query = Anthropic::Internal::Util.deep_merge(req[:query].to_h, opts[:extra_query].to_h)
|
270
|
+
|
271
|
+
headers = Anthropic::Internal::Util.normalized_headers(
|
272
|
+
@headers,
|
273
|
+
auth_headers,
|
274
|
+
req[:headers].to_h,
|
275
|
+
opts[:extra_headers].to_h
|
276
|
+
)
|
277
|
+
|
278
|
+
if @idempotency_header &&
|
279
|
+
!headers.key?(@idempotency_header) &&
|
280
|
+
(!Net::HTTP::IDEMPOTENT_METHODS_.include?(method.to_s.upcase) || opts.key?(:idempotency_key))
|
281
|
+
headers[@idempotency_header] = opts.fetch(:idempotency_key) { generate_idempotency_key }
|
282
|
+
end
|
283
|
+
|
284
|
+
unless headers.key?("x-stainless-retry-count")
|
285
|
+
headers["x-stainless-retry-count"] = "0"
|
286
|
+
end
|
287
|
+
|
288
|
+
timeout = opts.fetch(:timeout, @timeout).to_f.clamp(0..)
|
289
|
+
unless headers.key?("x-stainless-timeout") || timeout.zero?
|
290
|
+
headers["x-stainless-timeout"] = timeout.to_s
|
291
|
+
end
|
292
|
+
|
293
|
+
headers.reject! { |_, v| v.to_s.empty? }
|
294
|
+
|
295
|
+
body =
|
296
|
+
case method
|
297
|
+
in :get | :head | :options | :trace
|
298
|
+
nil
|
299
|
+
else
|
300
|
+
Anthropic::Internal::Util.deep_merge(*[req[:body], opts[:extra_body]].compact)
|
301
|
+
end
|
302
|
+
|
303
|
+
url = Anthropic::Internal::Util.join_parsed_uri(
|
304
|
+
@base_url_components,
|
305
|
+
{**req, path: path, query: query}
|
306
|
+
)
|
307
|
+
headers, encoded = Anthropic::Internal::Util.encode_content(headers, body)
|
308
|
+
{
|
309
|
+
method: method,
|
310
|
+
url: url,
|
311
|
+
headers: headers,
|
312
|
+
body: encoded,
|
313
|
+
max_retries: opts.fetch(:max_retries, @max_retries),
|
314
|
+
timeout: timeout
|
315
|
+
}
|
316
|
+
end
|
317
|
+
|
318
|
+
# @api private
|
319
|
+
#
|
320
|
+
# @param headers [Hash{String=>String}]
|
321
|
+
# @param retry_count [Integer]
|
322
|
+
#
|
323
|
+
# @return [Float]
|
324
|
+
private def retry_delay(headers, retry_count:)
|
325
|
+
# Non-standard extension
|
326
|
+
span = Float(headers["retry-after-ms"], exception: false)&.then { _1 / 1000 }
|
327
|
+
return span if span
|
328
|
+
|
329
|
+
retry_header = headers["retry-after"]
|
330
|
+
return span if (span = Float(retry_header, exception: false))
|
331
|
+
|
332
|
+
span = retry_header&.then do
|
333
|
+
Time.httpdate(_1) - Time.now
|
334
|
+
rescue ArgumentError
|
335
|
+
nil
|
336
|
+
end
|
337
|
+
return span if span
|
338
|
+
|
339
|
+
scale = retry_count**2
|
340
|
+
jitter = 1 - (0.25 * rand)
|
341
|
+
(@initial_retry_delay * scale * jitter).clamp(0, @max_retry_delay)
|
342
|
+
end
|
343
|
+
|
344
|
+
# @api private
|
345
|
+
#
|
346
|
+
# @param request [Hash{Symbol=>Object}] .
|
347
|
+
#
|
348
|
+
# @option request [Symbol] :method
|
349
|
+
#
|
350
|
+
# @option request [URI::Generic] :url
|
351
|
+
#
|
352
|
+
# @option request [Hash{String=>String}] :headers
|
353
|
+
#
|
354
|
+
# @option request [Object] :body
|
355
|
+
#
|
356
|
+
# @option request [Integer] :max_retries
|
357
|
+
#
|
358
|
+
# @option request [Float] :timeout
|
359
|
+
#
|
360
|
+
# @param redirect_count [Integer]
|
361
|
+
#
|
362
|
+
# @param retry_count [Integer]
|
363
|
+
#
|
364
|
+
# @param send_retry_header [Boolean]
|
365
|
+
#
|
366
|
+
# @raise [Anthropic::Errors::APIError]
|
367
|
+
# @return [Array(Integer, Net::HTTPResponse, Enumerable<String>)]
|
368
|
+
private def send_request(request, redirect_count:, retry_count:, send_retry_header:)
|
369
|
+
url, headers, max_retries, timeout = request.fetch_values(:url, :headers, :max_retries, :timeout)
|
370
|
+
input = {**request.except(:timeout), deadline: Anthropic::Internal::Util.monotonic_secs + timeout}
|
371
|
+
|
372
|
+
if send_retry_header
|
373
|
+
headers["x-stainless-retry-count"] = retry_count.to_s
|
374
|
+
end
|
375
|
+
|
376
|
+
begin
|
377
|
+
status, response, stream = @requester.execute(input)
|
378
|
+
rescue Anthropic::Errors::APIConnectionError => e
|
379
|
+
status = e
|
380
|
+
end
|
381
|
+
|
382
|
+
case status
|
383
|
+
in ..299
|
384
|
+
[status, response, stream]
|
385
|
+
in 300..399 if redirect_count >= self.class::MAX_REDIRECTS
|
386
|
+
self.class.reap_connection!(status, stream: stream)
|
387
|
+
|
388
|
+
message = "Failed to complete the request within #{self.class::MAX_REDIRECTS} redirects."
|
389
|
+
raise Anthropic::Errors::APIConnectionError.new(url: url, response: response, message: message)
|
390
|
+
in 300..399
|
391
|
+
self.class.reap_connection!(status, stream: stream)
|
392
|
+
|
393
|
+
request = self.class.follow_redirect(request, status: status, response_headers: response)
|
394
|
+
send_request(
|
395
|
+
request,
|
396
|
+
redirect_count: redirect_count + 1,
|
397
|
+
retry_count: retry_count,
|
398
|
+
send_retry_header: send_retry_header
|
399
|
+
)
|
400
|
+
in Anthropic::Errors::APIConnectionError if retry_count >= max_retries
|
401
|
+
raise status
|
402
|
+
in (400..) if retry_count >= max_retries || !self.class.should_retry?(status, headers: response)
|
403
|
+
decoded = Kernel.then do
|
404
|
+
Anthropic::Internal::Util.decode_content(response, stream: stream, suppress_error: true)
|
405
|
+
ensure
|
406
|
+
self.class.reap_connection!(status, stream: stream)
|
407
|
+
end
|
408
|
+
|
409
|
+
raise Anthropic::Errors::APIStatusError.for(
|
410
|
+
url: url,
|
411
|
+
status: status,
|
412
|
+
body: decoded,
|
413
|
+
request: nil,
|
414
|
+
response: response
|
415
|
+
)
|
416
|
+
in (400..) | Anthropic::Errors::APIConnectionError
|
417
|
+
self.class.reap_connection!(status, stream: stream)
|
418
|
+
|
419
|
+
delay = retry_delay(response || {}, retry_count: retry_count)
|
420
|
+
sleep(delay)
|
421
|
+
|
422
|
+
send_request(
|
423
|
+
request,
|
424
|
+
redirect_count: redirect_count,
|
425
|
+
retry_count: retry_count + 1,
|
426
|
+
send_retry_header: send_retry_header
|
427
|
+
)
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
# Execute the request specified by `req`. This is the method that all resource
|
432
|
+
# methods call into.
|
433
|
+
#
|
434
|
+
# @overload request(method, path, query: {}, headers: {}, body: nil, unwrap: nil, page: nil, stream: nil, model: Anthropic::Internal::Type::Unknown, options: {})
|
435
|
+
#
|
436
|
+
# @param method [Symbol]
|
437
|
+
#
|
438
|
+
# @param path [String, Array<String>]
|
439
|
+
#
|
440
|
+
# @param query [Hash{String=>Array<String>, String, nil}, nil]
|
441
|
+
#
|
442
|
+
# @param headers [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}, nil]
|
443
|
+
#
|
444
|
+
# @param body [Object, nil]
|
445
|
+
#
|
446
|
+
# @param unwrap [Symbol, Integer, Array<Symbol, Integer>, Proc, nil]
|
447
|
+
#
|
448
|
+
# @param page [Class<Anthropic::Internal::Type::BasePage>, nil]
|
449
|
+
#
|
450
|
+
# @param stream [Class<Anthropic::Internal::Type::BaseStream>, nil]
|
451
|
+
#
|
452
|
+
# @param model [Anthropic::Internal::Type::Converter, Class, nil]
|
453
|
+
#
|
454
|
+
# @param options [Anthropic::RequestOptions, Hash{Symbol=>Object}, nil] .
|
455
|
+
#
|
456
|
+
# @option options [String, nil] :idempotency_key
|
457
|
+
#
|
458
|
+
# @option options [Hash{String=>Array<String>, String, nil}, nil] :extra_query
|
459
|
+
#
|
460
|
+
# @option options [Hash{String=>String, nil}, nil] :extra_headers
|
461
|
+
#
|
462
|
+
# @option options [Object, nil] :extra_body
|
463
|
+
#
|
464
|
+
# @option options [Integer, nil] :max_retries
|
465
|
+
#
|
466
|
+
# @option options [Float, nil] :timeout
|
467
|
+
#
|
468
|
+
# @raise [Anthropic::Errors::APIError]
|
469
|
+
# @return [Object]
|
470
|
+
def request(req)
|
471
|
+
self.class.validate!(req)
|
472
|
+
model = req.fetch(:model) { Anthropic::Internal::Type::Unknown }
|
473
|
+
opts = req[:options].to_h
|
474
|
+
Anthropic::RequestOptions.validate!(opts)
|
475
|
+
request = build_request(req.except(:options), opts)
|
476
|
+
url = request.fetch(:url)
|
477
|
+
|
478
|
+
# Don't send the current retry count in the headers if the caller modified the header defaults.
|
479
|
+
send_retry_header = request.fetch(:headers)["x-stainless-retry-count"] == "0"
|
480
|
+
status, response, stream = send_request(
|
481
|
+
request,
|
482
|
+
redirect_count: 0,
|
483
|
+
retry_count: 0,
|
484
|
+
send_retry_header: send_retry_header
|
485
|
+
)
|
486
|
+
|
487
|
+
decoded = Anthropic::Internal::Util.decode_content(response, stream: stream)
|
488
|
+
case req
|
489
|
+
in {stream: Class => st}
|
490
|
+
st.new(model: model, url: url, status: status, response: response, stream: decoded)
|
491
|
+
in {page: Class => page}
|
492
|
+
page.new(client: self, req: req, headers: response, page_data: decoded)
|
493
|
+
else
|
494
|
+
unwrapped = Anthropic::Internal::Util.dig(decoded, req[:unwrap])
|
495
|
+
Anthropic::Internal::Type::Converter.coerce(model, unwrapped)
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
# @api private
|
500
|
+
#
|
501
|
+
# @return [String]
|
502
|
+
def inspect
|
503
|
+
# rubocop:disable Layout/LineLength
|
504
|
+
"#<#{self.class.name}:0x#{object_id.to_s(16)} base_url=#{@base_url} max_retries=#{@max_retries} timeout=#{@timeout}>"
|
505
|
+
# rubocop:enable Layout/LineLength
|
506
|
+
end
|
507
|
+
|
508
|
+
define_sorbet_constant!(:RequestComponents) do
|
509
|
+
T.type_alias do
|
510
|
+
{
|
511
|
+
method: Symbol,
|
512
|
+
path: T.any(String, T::Array[String]),
|
513
|
+
query: T.nilable(T::Hash[String, T.nilable(T.any(T::Array[String], String))]),
|
514
|
+
headers: T.nilable(
|
515
|
+
T::Hash[String,
|
516
|
+
T.nilable(
|
517
|
+
T.any(
|
518
|
+
String,
|
519
|
+
Integer,
|
520
|
+
T::Array[T.nilable(T.any(String, Integer))]
|
521
|
+
)
|
522
|
+
)]
|
523
|
+
),
|
524
|
+
body: T.nilable(T.anything),
|
525
|
+
unwrap: T.nilable(
|
526
|
+
T.any(
|
527
|
+
Symbol,
|
528
|
+
Integer,
|
529
|
+
T::Array[T.any(Symbol, Integer)],
|
530
|
+
T.proc.params(arg0: T.anything).returns(T.anything)
|
531
|
+
)
|
532
|
+
),
|
533
|
+
page: T.nilable(T::Class[Anthropic::Internal::Type::BasePage[Anthropic::Internal::Type::BaseModel]]),
|
534
|
+
stream: T.nilable(
|
535
|
+
T::Class[Anthropic::Internal::Type::BaseStream[T.anything,
|
536
|
+
Anthropic::Internal::Type::BaseModel]]
|
537
|
+
),
|
538
|
+
model: T.nilable(Anthropic::Internal::Type::Converter::Input),
|
539
|
+
options: T.nilable(Anthropic::RequestOptions::OrHash)
|
540
|
+
}
|
541
|
+
end
|
542
|
+
end
|
543
|
+
define_sorbet_constant!(:RequestInput) do
|
544
|
+
T.type_alias do
|
545
|
+
{
|
546
|
+
method: Symbol,
|
547
|
+
url: URI::Generic,
|
548
|
+
headers: T::Hash[String, String],
|
549
|
+
body: T.anything,
|
550
|
+
max_retries: Integer,
|
551
|
+
timeout: Float
|
552
|
+
}
|
553
|
+
end
|
554
|
+
end
|
555
|
+
end
|
556
|
+
end
|
557
|
+
end
|
558
|
+
end
|