Method: Anthropic::Resources::Messages#create
- Defined in:
- lib/anthropic/resources/messages.rb
#create(max_tokens:, messages:, model:, cache_control: nil, container: nil, inference_geo: nil, metadata: nil, output_config: nil, service_tier: nil, stop_sequences: nil, system_: nil, temperature: nil, thinking: nil, tool_choice: nil, tools: nil, top_k: nil, top_p: nil, request_options: {}) ⇒ Anthropic::Models::Message Also known as: parse
See #stream for streaming counterpart.
Some parameter documentations has been truncated, see Models::MessageCreateParams for more details.
Send a structured list of input messages with text and/or image content, and the model will generate the next message in the conversation.
The Messages API can be used for either single queries or stateless multi-turn conversations.
Learn more about the Messages API in our user guide
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/anthropic/resources/messages.rb', line 66 def create(params) parsed, = Anthropic::MessageCreateParams.dump_request(params) if parsed[:stream] = "Please use `#stream` for the streaming use case." raise ArgumentError.new() end warn_thinking_enabled(parsed) tools, models = Anthropic::Helpers::Messages.distill_input_schema_models!(parsed, strict: nil) unwrap = ->(raw) { Anthropic::Helpers::Messages.parse_input_schemas!(raw, tools:, models:) } if .empty? && @client.timeout == Anthropic::Client::DEFAULT_TIMEOUT_IN_SECONDS model = parsed[:model]&.to_sym max_tokens = parsed[:max_tokens].to_i timeout = @client.calculate_nonstreaming_timeout( max_tokens, Anthropic::Client::MODEL_NONSTREAMING_TOKENS[model] ) = {timeout: timeout} else = {timeout: 600, **} end @client.request( method: :post, path: "v1/messages", body: parsed, model: Anthropic::Message, unwrap: unwrap, options: ) end |