Class: Anthropic::Models::MessageCreateParams
- Inherits:
-
Internal::Type::BaseModel
- Object
- Internal::Type::BaseModel
- Anthropic::Models::MessageCreateParams
- Extended by:
- Internal::Type::RequestParameters::Converter
- Includes:
- Internal::Type::RequestParameters
- Defined in:
- lib/anthropic/models/message_create_params.rb,
sig/anthropic/models/message_create_params.rbs
Overview
Defined Under Namespace
Modules: ServiceTier, Speed, System
Instance Attribute Summary collapse
-
#cache_control ⇒ Anthropic::Models::CacheControlEphemeral?
Top-level cache control automatically applies a cache_control marker to the last cacheable block in the request.
-
#container ⇒ Anthropic::Models::ContainerParams, ...
Container identifier for reuse across requests.
-
#diagnostics ⇒ Anthropic::Models::DiagnosticsParam?
Request-level diagnostics.
-
#inference_geo ⇒ String?
Specifies the geographic region for inference processing.
-
#max_tokens ⇒ Integer
The maximum number of tokens to generate before stopping.
-
#messages ⇒ Array<Anthropic::Models::UserMessageParam, Anthropic::Models::AssistantMessageParam, Anthropic::Models::SystemMessageParam>
Input messages.
-
#metadata ⇒ Anthropic::Models::Metadata?
An object describing metadata about the request.
-
#model ⇒ Symbol, ...
The model that will complete your prompt.
-
#output_config ⇒ Anthropic::Models::OutputConfig?
Configuration options for the model's output, such as the output format.
-
#service_tier ⇒ Symbol, ...
Determines whether to use priority capacity (if available) or standard capacity for this request.
-
#speed ⇒ Symbol, ...
The inference speed mode for this request.
-
#stop_sequences ⇒ Array<String>?
Custom text sequences that will cause the model to stop generating.
-
#system_ ⇒ String, ...
System prompt.
-
#thinking ⇒ Anthropic::Models::ThinkingConfigEnabled, ...
Configuration for Claude's thinking.
-
#tool_choice ⇒ Anthropic::Models::ToolChoiceAuto, ...
How the model should use the provided tools.
-
#tools ⇒ Array<Anthropic::Models::Tool, Anthropic::Models::ToolBash20250124, Anthropic::Models::CodeExecutionTool20250522, Anthropic::Models::CodeExecutionTool20250825, Anthropic::Models::CodeExecutionTool20260120, Anthropic::Models::CodeExecutionTool20260521, Anthropic::Models::BrowserToolset20260801, Anthropic::Models::MemoryTool20250818, Anthropic::Models::ComputerToolset20260801, Anthropic::Models::ToolTextEditor20250124, Anthropic::Models::ToolTextEditor20250429, Anthropic::Models::ToolTextEditor20250728, Anthropic::Models::WebSearchTool20250305, Anthropic::Models::WebFetchTool20250910, Anthropic::Models::WebSearchTool20260209, Anthropic::Models::WebFetchTool20260209, Anthropic::Models::WebFetchTool20260309, Anthropic::Models::WebSearchTool20260318, Anthropic::Models::WebFetchTool20260318, Anthropic::Models::ToolSearchToolBm25_20251119, Anthropic::Models::ToolSearchToolRegex20251119>?
Definitions of tools that the model may use.
-
#user_profile_id ⇒ String?
The user profile ID to attribute this request to.
-
#workspace_id ⇒ String?
Optional header to select the Workspace for this request.
Attributes included from Internal::Type::RequestParameters
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(max_tokens:, messages:, model:, cache_control: nil, container: nil, diagnostics: nil, inference_geo: nil, metadata: nil, output_config: nil, service_tier: nil, speed: nil, stop_sequences: nil, system_: nil, thinking: nil, tool_choice: nil, tools: nil, user_profile_id: nil, workspace_id: nil, request_options: {}) ⇒ MessageCreateParams
constructor
Some parameter documentations has been truncated, see MessageCreateParams for more details.
- #to_hash ⇒ { max_tokens: Integer, messages: ::Array[Anthropic::Models::message_param], model: Anthropic::Models::model, cache_control: Anthropic::CacheControlEphemeral?, container: Anthropic::Models::message_create_params_container?, diagnostics: Anthropic::DiagnosticsParam?, inference_geo: String?, metadata: Anthropic::Metadata, output_config: Anthropic::OutputConfig, service_tier: Anthropic::Models::MessageCreateParams::service_tier, speed: Anthropic::Models::MessageCreateParams::speed?, stop_sequences: ::Array[String], system_: Anthropic::Models::MessageCreateParams::system_, thinking: Anthropic::Models::thinking_config_param, tool_choice: Anthropic::Models::tool_choice, tools: ::Array[Anthropic::Models::tool_union], user_profile_id: String, workspace_id: String, request_options: Anthropic::RequestOptions }
Methods included from Internal::Type::RequestParameters::Converter
Methods included from Internal::Type::RequestParameters
Methods inherited from Internal::Type::BaseModel
==, #==, #[], coerce, #deconstruct_keys, #deep_to_h, dump, fields, hash, #hash, inherited, inspect, #inspect, known_fields, optional, recursively_to_h, required, #to_h, #to_json, #to_s, to_sorbet_type, #to_yaml
Methods included from Internal::Type::Converter
#coerce, coerce, #dump, dump, inspect, #inspect, meta_info, new_coerce_state, type_info
Methods included from Internal::Util::SorbetRuntimeSupport
#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type
Constructor Details
#initialize(max_tokens:, messages:, model:, cache_control: nil, container: nil, diagnostics: nil, inference_geo: nil, metadata: nil, output_config: nil, service_tier: nil, speed: nil, stop_sequences: nil, system_: nil, thinking: nil, tool_choice: nil, tools: nil, user_profile_id: nil, workspace_id: nil, request_options: {}) ⇒ MessageCreateParams
Some parameter documentations has been truncated, see Anthropic::Models::MessageCreateParams for more details.
|
|
# File 'lib/anthropic/models/message_create_params.rb', line 321
|
Instance Attribute Details
#cache_control ⇒ Anthropic::Models::CacheControlEphemeral?
Top-level cache control automatically applies a cache_control marker to the last cacheable block in the request.
117 |
# File 'lib/anthropic/models/message_create_params.rb', line 117 optional :cache_control, -> { Anthropic::CacheControlEphemeral }, nil?: true |
#container ⇒ Anthropic::Models::ContainerParams, ...
Container identifier for reuse across requests.
123 |
# File 'lib/anthropic/models/message_create_params.rb', line 123 optional :container, union: -> { Anthropic::MessageCreateParamsContainer }, nil?: true |
#diagnostics ⇒ Anthropic::Models::DiagnosticsParam?
Request-level diagnostics. Supply previous_message_id to have the response
include diagnostics.cache_miss_reason explaining any prompt-cache divergence
from that prior request.
131 |
# File 'lib/anthropic/models/message_create_params.rb', line 131 optional :diagnostics, -> { Anthropic::DiagnosticsParam }, nil?: true |
#inference_geo ⇒ String?
Specifies the geographic region for inference processing. If not specified, the
workspace's default_inference_geo is used.
138 |
# File 'lib/anthropic/models/message_create_params.rb', line 138 optional :inference_geo, String, nil?: true |
#max_tokens ⇒ Integer
The maximum number of tokens to generate before stopping.
Note that our models may stop before reaching this maximum. This parameter only specifies the absolute maximum number of tokens to generate.
Set to 0 to populate the
prompt cache
without generating a response.
Different models have different maximum values for this parameter. See models for details.
27 |
# File 'lib/anthropic/models/message_create_params.rb', line 27 required :max_tokens, Integer |
#messages ⇒ Array<Anthropic::Models::UserMessageParam, Anthropic::Models::AssistantMessageParam, Anthropic::Models::SystemMessageParam>
Input messages.
Our models are trained to operate on alternating user and assistant
conversational turns. When creating a new Message, you specify the prior
conversational turns with the messages parameter, and the model then generates
the next Message in the conversation. Consecutive user or assistant turns
in your request will be combined into a single turn.
Each input message must be an object with a role and content. You can
specify a single user-role message, or you can include multiple user and
assistant messages.
If the final message uses the assistant role, the response content will
continue immediately from the content in that message. This can be used to
constrain part of the model's response. This is called prefill. On models that
don't support prefill, creating a message that ends with a partial assistant
response returns a 400 error. See
Prefill not supported.
Example with a single user message:
[{ "role": "user", "content": "Hello, Claude" }]
Example with multiple conversational turns:
[
{ "role": "user", "content": "Hello there." },
{ "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
{ "role": "user", "content": "Can you explain LLMs in plain English?" }
]
Example with a partially-filled response from Claude, for models that support prefill:
[
{
"role": "user",
"content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
},
{ "role": "assistant", "content": "The best answer is (" }
]
Each input message content may be either a single string or an array of
content blocks, where each block has a specific type. Using a string for
content is shorthand for an array of one content block of type "text". The
following input messages are equivalent:
{ "role": "user", "content": "Hello, Claude" }
{ "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
See input examples.
Note that if you want to include a
system prompt,
you can use the top-level system parameter.
There is a limit of 100,000 messages in a single request.
101 |
# File 'lib/anthropic/models/message_create_params.rb', line 101 required :messages, -> { Anthropic::Internal::Type::ArrayOf[union: Anthropic::MessageParam] } |
#metadata ⇒ Anthropic::Models::Metadata?
An object describing metadata about the request.
144 |
# File 'lib/anthropic/models/message_create_params.rb', line 144 optional :metadata, -> { Anthropic::Metadata } |
#model ⇒ Symbol, ...
The model that will complete your prompt.
See models for additional details and options.
110 |
# File 'lib/anthropic/models/message_create_params.rb', line 110 required :model, union: -> { Anthropic::Model } |
#output_config ⇒ Anthropic::Models::OutputConfig?
Configuration options for the model's output, such as the output format.
150 |
# File 'lib/anthropic/models/message_create_params.rb', line 150 optional :output_config, -> { Anthropic::OutputConfig } |
#service_tier ⇒ Symbol, ...
Determines whether to use priority capacity (if available) or standard capacity for this request.
Anthropic offers different levels of service for your API requests. See service-tiers for details.
161 |
# File 'lib/anthropic/models/message_create_params.rb', line 161 optional :service_tier, enum: -> { Anthropic::MessageCreateParams::ServiceTier } |
#speed ⇒ Symbol, ...
The inference speed mode for this request. "fast" enables high
output-tokens-per-second inference.
Some models require the fast-mode-2026-02-01 beta header for any speed
value. See
fast mode for
which models.
173 |
# File 'lib/anthropic/models/message_create_params.rb', line 173 optional :speed, enum: -> { Anthropic::MessageCreateParams::Speed }, nil?: true |
#stop_sequences ⇒ Array<String>?
Custom text sequences that will cause the model to stop generating.
Our models will normally stop when they have naturally completed their turn,
which will result in a response stop_reason of "end_turn".
If you want the model to stop generating when it encounters custom strings of
text, you can use the stop_sequences parameter. If the model encounters one of
the custom sequences, the response stop_reason value will be "stop_sequence"
and the response stop_sequence value will contain the matched stop sequence.
187 |
# File 'lib/anthropic/models/message_create_params.rb', line 187 optional :stop_sequences, Anthropic::Internal::Type::ArrayOf[String] |
#system_ ⇒ String, ...
System prompt.
A system prompt is a way of providing context and instructions to Claude, such as specifying a particular goal or role. See our guide to system prompts.
197 |
# File 'lib/anthropic/models/message_create_params.rb', line 197 optional :system_, union: -> { Anthropic::MessageCreateParams::System }, api_name: :system |
#thinking ⇒ Anthropic::Models::ThinkingConfigEnabled, ...
Configuration for Claude's thinking.
With {"type": "adaptive"}, Claude decides when and how much to think. With
{"type": "enabled"} (manual extended thinking), you set a budget_tokens of
at least 1,024. Thinking tokens count toward your max_tokens limit.
Which type values are accepted, and what happens when you omit thinking,
depend on the model. See
thinking
for each model's behavior.
212 |
# File 'lib/anthropic/models/message_create_params.rb', line 212 optional :thinking, union: -> { Anthropic::ThinkingConfigParam } |
#tool_choice ⇒ Anthropic::Models::ToolChoiceAuto, ...
How the model should use the provided tools. The model can use a specific tool, any available tool, decide by itself, or not use tools at all.
219 |
# File 'lib/anthropic/models/message_create_params.rb', line 219 optional :tool_choice, union: -> { Anthropic::ToolChoice } |
#tools ⇒ Array<Anthropic::Models::Tool, Anthropic::Models::ToolBash20250124, Anthropic::Models::CodeExecutionTool20250522, Anthropic::Models::CodeExecutionTool20250825, Anthropic::Models::CodeExecutionTool20260120, Anthropic::Models::CodeExecutionTool20260521, Anthropic::Models::BrowserToolset20260801, Anthropic::Models::MemoryTool20250818, Anthropic::Models::ComputerToolset20260801, Anthropic::Models::ToolTextEditor20250124, Anthropic::Models::ToolTextEditor20250429, Anthropic::Models::ToolTextEditor20250728, Anthropic::Models::WebSearchTool20250305, Anthropic::Models::WebFetchTool20250910, Anthropic::Models::WebSearchTool20260209, Anthropic::Models::WebFetchTool20260209, Anthropic::Models::WebFetchTool20260309, Anthropic::Models::WebSearchTool20260318, Anthropic::Models::WebFetchTool20260318, Anthropic::Models::ToolSearchToolBm25_20251119, Anthropic::Models::ToolSearchToolRegex20251119>?
Definitions of tools that the model may use.
If you include tools in your API request, the model may return tool_use
content blocks that represent the model's use of those tools. You can then run
those tools using the tool input generated by the model and then optionally
return results back to the model using tool_result content blocks.
There are two types of tools: client tools and server tools. The behavior described below applies to client tools. For server tools, see their individual documentation as each has its own behavior (e.g., the web search tool).
Each tool definition includes:
name: Name of the tool.description: Optional, but strongly-recommended description of the tool.input_schema: JSON schema for the toolinputshape that the model will produce intool_useoutput content blocks.
For example, if you defined tools as:
[
{
"name": "get_stock_price",
"description": "Get the current stock price for a given ticker symbol.",
"input_schema": {
"type": "object",
"properties": {
"ticker": {
"type": "string",
"description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
}
},
"required": ["ticker"]
}
}
]
And then asked the model "What's the S&P 500 at today?", the model might produce
tool_use content blocks in the response like this:
[
{
"type": "tool_use",
"id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
"name": "get_stock_price",
"input": { "ticker": "^GSPC" }
}
]
You might then run your get_stock_price tool with {"ticker": "^GSPC"} as an
input, and return the following back to the model in a subsequent user
message:
[
{
"type": "tool_result",
"tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
"content": "259.75 USD"
}
]
Tools can be used for workflows that include running client-side tools and functions, or more generally whenever you want the model to produce a particular JSON structure of output.
See our guide for more details.
301 |
# File 'lib/anthropic/models/message_create_params.rb', line 301 optional :tools, -> { Anthropic::Internal::Type::ArrayOf[union: Anthropic::ToolUnion] } |
#user_profile_id ⇒ String?
The user profile ID to attribute this request to. Use when acting on behalf of a party other than your organization.
308 |
# File 'lib/anthropic/models/message_create_params.rb', line 308 optional :user_profile_id, String |
#workspace_id ⇒ String?
Optional header to select the Workspace for this request. The value is a
Workspace ID (for example, wrkspc_011CZkZaBF1tNoB5wlCeusgy).
Only needed for credentials that can act on more than one Workspace. A credential that belongs to a specific Workspace may omit it; if sent, it must match that Workspace.
319 |
# File 'lib/anthropic/models/message_create_params.rb', line 319 optional :workspace_id, String |
Class Method Details
.values ⇒ Array<Symbol>
|
|
# File 'lib/anthropic/models/message_create_params.rb', line 375
|
Instance Method Details
#to_hash ⇒ { max_tokens: Integer, messages: ::Array[Anthropic::Models::message_param], model: Anthropic::Models::model, cache_control: Anthropic::CacheControlEphemeral?, container: Anthropic::Models::message_create_params_container?, diagnostics: Anthropic::DiagnosticsParam?, inference_geo: String?, metadata: Anthropic::Metadata, output_config: Anthropic::OutputConfig, service_tier: Anthropic::Models::MessageCreateParams::service_tier, speed: Anthropic::Models::MessageCreateParams::speed?, stop_sequences: ::Array[String], system_: Anthropic::Models::MessageCreateParams::system_, thinking: Anthropic::Models::thinking_config_param, tool_choice: Anthropic::Models::tool_choice, tools: ::Array[Anthropic::Models::tool_union], user_profile_id: String, workspace_id: String, request_options: Anthropic::RequestOptions }
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'sig/anthropic/models/message_create_params.rbs', line 118
def to_hash: -> {
max_tokens: Integer,
messages: ::Array[Anthropic::Models::message_param],
model: Anthropic::Models::model,
cache_control: Anthropic::CacheControlEphemeral?,
container: Anthropic::Models::message_create_params_container?,
diagnostics: Anthropic::DiagnosticsParam?,
inference_geo: String?,
metadata: Anthropic::Metadata,
output_config: Anthropic::OutputConfig,
service_tier: Anthropic::Models::MessageCreateParams::service_tier,
speed: Anthropic::Models::MessageCreateParams::speed?,
stop_sequences: ::Array[String],
system_: Anthropic::Models::MessageCreateParams::system_,
thinking: Anthropic::Models::thinking_config_param,
tool_choice: Anthropic::Models::tool_choice,
tools: ::Array[Anthropic::Models::tool_union],
user_profile_id: String,
workspace_id: String,
request_options: Anthropic::RequestOptions
}
|