Class MessageCreateParams.Body
-
- All Implemented Interfaces:
public final class MessageCreateParams.Body
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classMessageCreateParams.Body.BuilderA builder for Body.
-
Method Summary
Modifier and Type Method Description final LongmaxTokens()The maximum number of tokens to generate before stopping. final List<BetaMessageParam>messages()Input messages. final Modelmodel()The model that will complete your prompt. final Optional<BetaCacheControlEphemeral>cacheControl()Top-level cache control automatically applies a cache_control marker to the last cacheable block in the request. final Optional<MessageCreateParams.Container>container()Container identifier for reuse across requests. final Optional<BetaContextManagementConfig>contextManagement()Context management configuration. final Optional<BetaDiagnosticsParam>diagnostics()Request-level diagnostics. final Optional<String>fallbackCreditToken()The fallback_credit_tokenfrom a prior refusal'sstop_details.final Optional<List<BetaFallbackParam>>fallbacks()Opt-in server-side retry on one or more substitute models when the requested model declines for policy reasons. final Optional<String>inferenceGeo()Specifies the geographic region for inference processing. final Optional<List<BetaRequestMcpServerUrlDefinition>>mcpServers()MCP servers to be utilized in this request final Optional<BetaMetadata>metadata()An object describing metadata about the request. final Optional<BetaOutputConfig>outputConfig()Configuration options for the model's output, such as the output format. final Optional<BetaJsonOutputFormat>outputFormat()Deprecated: Use output_config.formatinstead.final Optional<MessageCreateParams.ServiceTier>serviceTier()Determines whether to use priority capacity (if available) or standard capacity for this request. final Optional<MessageCreateParams.Speed>speed()The inference speed mode for this request. final Optional<List<String>>stopSequences()Custom text sequences that will cause the model to stop generating. final Optional<MessageCreateParams.System>system()System prompt. final Optional<Double>temperature()Amount of randomness injected into the response. final Optional<BetaThinkingConfigParam>thinking()Configuration for enabling Claude's extended thinking. final Optional<BetaToolChoice>toolChoice()How the model should use the provided tools. final Optional<List<BetaToolUnion>>tools()Definitions of tools that the model may use. final Optional<Long>topK()Only sample from the top K options for each subsequent token. final Optional<Double>topP()Use nucleus sampling. final Optional<String>userProfileId()The user profile ID to attribute this request to. final JsonField<Long>_maxTokens()Returns the raw JSON value of maxTokens. final JsonField<List<BetaMessageParam>>_messages()Returns the raw JSON value of messages. final JsonField<Model>_model()Returns the raw JSON value of model. final JsonField<BetaCacheControlEphemeral>_cacheControl()Returns the raw JSON value of cacheControl. final JsonField<MessageCreateParams.Container>_container()Returns the raw JSON value of container. final JsonField<BetaContextManagementConfig>_contextManagement()Returns the raw JSON value of contextManagement. final JsonField<BetaDiagnosticsParam>_diagnostics()Returns the raw JSON value of diagnostics. final JsonField<String>_fallbackCreditToken()Returns the raw JSON value of fallbackCreditToken. final JsonField<List<BetaFallbackParam>>_fallbacks()Returns the raw JSON value of fallbacks. final JsonField<String>_inferenceGeo()Returns the raw JSON value of inferenceGeo. final JsonField<List<BetaRequestMcpServerUrlDefinition>>_mcpServers()Returns the raw JSON value of mcpServers. final JsonField<BetaMetadata>_metadata()Returns the raw JSON value of metadata. final JsonField<BetaOutputConfig>_outputConfig()Returns the raw JSON value of outputConfig. final JsonField<BetaJsonOutputFormat>_outputFormat()Returns the raw JSON value of outputFormat. final JsonField<MessageCreateParams.ServiceTier>_serviceTier()Returns the raw JSON value of serviceTier. final JsonField<MessageCreateParams.Speed>_speed()Returns the raw JSON value of speed. final JsonField<List<String>>_stopSequences()Returns the raw JSON value of stopSequences. final JsonField<MessageCreateParams.System>_system()Returns the raw JSON value of system. final JsonField<Double>_temperature()Returns the raw JSON value of temperature. final JsonField<BetaThinkingConfigParam>_thinking()Returns the raw JSON value of thinking. final JsonField<BetaToolChoice>_toolChoice()Returns the raw JSON value of toolChoice. final JsonField<List<BetaToolUnion>>_tools()Returns the raw JSON value of tools. final JsonField<Long>_topK()Returns the raw JSON value of topK. final JsonField<Double>_topP()Returns the raw JSON value of topP. final JsonField<String>_userProfileId()Returns the raw JSON value of userProfileId. final Map<String, JsonValue>_additionalProperties()final MessageCreateParams.Body.BuildertoBuilder()final MessageCreateParams.Bodyvalidate()Validates that the types of all values in this object match their expected types recursively. final BooleanisValid()Booleanequals(Object other)IntegerhashCode()StringtoString()final static MessageCreateParams.Body.Builderbuilder()Returns a mutable builder for constructing an instance of Body. -
-
Method Detail
-
maxTokens
final Long maxTokens()
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
0to populate the prompt cache without generating a response.Different models have different maximum values for this parameter. See models for details.
-
messages
final List<BetaMessageParam> messages()
Input messages.
Our models are trained to operate on alternating
userandassistantconversational turns. When creating a newMessage, you specify the prior conversational turns with themessagesparameter, and the model then generates the nextMessagein the conversation. Consecutiveuserorassistantturns in your request will be combined into a single turn.Each input message must be an object with a
roleandcontent. You can specify a singleuser-role message, or you can include multipleuserandassistantmessages.If the final message uses the
assistantrole, the response content will continue immediately from the content in that message. This can be used to constrain part of the model's response.Example with a single
usermessage:[{"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:
[ {"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
contentmay be either a singlestringor an array of content blocks, where each block has a specifictype. Using astringforcontentis 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
systemparameter — there is no"system"role for input messages in the Messages API.There is a limit of 100,000 messages in a single request.
-
model
final Model model()
The model that will complete your prompt.
See models for additional details and options.
-
cacheControl
final Optional<BetaCacheControlEphemeral> cacheControl()
Top-level cache control automatically applies a cache_control marker to the last cacheable block in the request.
-
container
final Optional<MessageCreateParams.Container> container()
Container identifier for reuse across requests.
-
contextManagement
final Optional<BetaContextManagementConfig> contextManagement()
Context management configuration.
This allows you to control how Claude manages context across multiple requests, such as whether to clear function results or not.
-
diagnostics
final Optional<BetaDiagnosticsParam> diagnostics()
Request-level diagnostics. Currently carries the previous response id for prompt-cache divergence reporting.
-
fallbackCreditToken
final Optional<String> fallbackCreditToken()
The
fallback_credit_tokenfrom a prior refusal'sstop_details.When a preceding request was refused and returned a
fallback_credit_token, pass that code here on the retry to have the retry's cache-creation tokens for the prefix that was warm on the refused model billed at the cache-read rate. Must be redeemed by the same organization and workspace, with the same request body (optionally extended by one appendedassistantmessage whose content is the partial text — with any trailing whitespace stripped from the final text block — and paired server-tool blocks streamed before the refusal; the appended-assistant form is not available for requests withoutput_formatset or forcedtool_choice), on an eligible fallback model, on the same platform, and within 5 minutes of the refusal; a mismatch is a 400. A token minted mid-server-tool-loop whose partial content was continuable may only be redeemed with the appended-assistant form — if an exact-body retry is rejected with a 400 saying the token must be redeemed by continuing the partial response, retry with the appended-assistant form instead.When the appended-assistant form is used on a model that otherwise disallows assistant-turn prefill, this token also authorizes that one prefill.
-
fallbacks
final Optional<List<BetaFallbackParam>> fallbacks()
Opt-in server-side retry on one or more substitute models when the requested model declines for policy reasons. Tried in order: if the first entry also declines, the second is tried, and so on.
-
inferenceGeo
final Optional<String> inferenceGeo()
Specifies the geographic region for inference processing. If not specified, the workspace's
default_inference_geois used.
-
mcpServers
final Optional<List<BetaRequestMcpServerUrlDefinition>> mcpServers()
MCP servers to be utilized in this request
-
metadata
final Optional<BetaMetadata> metadata()
An object describing metadata about the request.
-
outputConfig
final Optional<BetaOutputConfig> outputConfig()
Configuration options for the model's output, such as the output format.
-
outputFormat
@Deprecated(message = "deprecated") final Optional<BetaJsonOutputFormat> outputFormat()
Deprecated: Use
output_config.formatinstead. See structured outputsA schema to specify Claude's output format in responses. This parameter will be removed in a future release.
-
serviceTier
final Optional<MessageCreateParams.ServiceTier> serviceTier()
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.
-
speed
final Optional<MessageCreateParams.Speed> speed()
The inference speed mode for this request.
"fast"enables high output-tokens-per-second inference.
-
stopSequences
final Optional<List<String>> stopSequences()
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_reasonof"end_turn".If you want the model to stop generating when it encounters custom strings of text, you can use the
stop_sequencesparameter. If the model encounters one of the custom sequences, the responsestop_reasonvalue will be"stop_sequence"and the responsestop_sequencevalue will contain the matched stop sequence.
-
system
final Optional<MessageCreateParams.System> system()
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.
-
temperature
@Deprecated(message = "Deprecated. Models released after Claude Opus 4.6 do not support setting temperature. A value of 1.0 of will be accepted for backwards compatibility, all other values will be rejected with a 400 error.") final Optional<Double> temperature()
Amount of randomness injected into the response.
Defaults to
1.0. Ranges from0.0to1.0. Usetemperaturecloser to0.0for analytical / multiple choice, and closer to1.0for creative and generative tasks.Note that even with
temperatureof0.0, the results will not be fully deterministic.
-
thinking
final Optional<BetaThinkingConfigParam> thinking()
Configuration for enabling Claude's extended thinking.
When enabled, responses include
thinkingcontent blocks showing Claude's thinking process before the final answer. Requires a minimum budget of 1,024 tokens and counts towards yourmax_tokenslimit.See extended thinking for details.
-
toolChoice
final Optional<BetaToolChoice> toolChoice()
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.
-
tools
final Optional<List<BetaToolUnion>> tools()
Definitions of tools that the model may use.
If you include
toolsin your API request, the model may returntool_usecontent 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 usingtool_resultcontent 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
toolsas:[ { "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_usecontent 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_pricetool with{"ticker": "^GSPC"}as an input, and return the following back to the model in a subsequentusermessage:[ { "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.
-
topK
@Deprecated(message = "Deprecated. Models released after Claude Opus 4.6 do not accept top_k; any value will be rejected with a 400 error.") final Optional<Long> topK()
Only sample from the top K options for each subsequent token.
Used to remove "long tail" low probability responses. Learn more technical details here.
Recommended for advanced use cases only.
-
topP
@Deprecated(message = "Deprecated. Models released after Claude Opus 4.6 do not support setting top_p. A value >= 0.99 will be accepted for backwards compatibility, all other values will be rejected with a 400 error.") final Optional<Double> topP()
Use nucleus sampling.
In nucleus sampling, we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by
top_p.Recommended for advanced use cases only.
-
userProfileId
final Optional<String> userProfileId()
The user profile ID to attribute this request to. Use when acting on behalf of a party other than your organization.
-
_maxTokens
final JsonField<Long> _maxTokens()
Returns the raw JSON value of maxTokens.
Unlike maxTokens, this method doesn't throw if the JSON field has an unexpected type.
-
_messages
final JsonField<List<BetaMessageParam>> _messages()
Returns the raw JSON value of messages.
Unlike messages, this method doesn't throw if the JSON field has an unexpected type.
-
_model
final JsonField<Model> _model()
Returns the raw JSON value of model.
Unlike model, this method doesn't throw if the JSON field has an unexpected type.
-
_cacheControl
final JsonField<BetaCacheControlEphemeral> _cacheControl()
Returns the raw JSON value of cacheControl.
Unlike cacheControl, this method doesn't throw if the JSON field has an unexpected type.
-
_container
final JsonField<MessageCreateParams.Container> _container()
Returns the raw JSON value of container.
Unlike container, this method doesn't throw if the JSON field has an unexpected type.
-
_contextManagement
final JsonField<BetaContextManagementConfig> _contextManagement()
Returns the raw JSON value of contextManagement.
Unlike contextManagement, this method doesn't throw if the JSON field has an unexpected type.
-
_diagnostics
final JsonField<BetaDiagnosticsParam> _diagnostics()
Returns the raw JSON value of diagnostics.
Unlike diagnostics, this method doesn't throw if the JSON field has an unexpected type.
-
_fallbackCreditToken
final JsonField<String> _fallbackCreditToken()
Returns the raw JSON value of fallbackCreditToken.
Unlike fallbackCreditToken, this method doesn't throw if the JSON field has an unexpected type.
-
_fallbacks
final JsonField<List<BetaFallbackParam>> _fallbacks()
Returns the raw JSON value of fallbacks.
Unlike fallbacks, this method doesn't throw if the JSON field has an unexpected type.
-
_inferenceGeo
final JsonField<String> _inferenceGeo()
Returns the raw JSON value of inferenceGeo.
Unlike inferenceGeo, this method doesn't throw if the JSON field has an unexpected type.
-
_mcpServers
final JsonField<List<BetaRequestMcpServerUrlDefinition>> _mcpServers()
Returns the raw JSON value of mcpServers.
Unlike mcpServers, this method doesn't throw if the JSON field has an unexpected type.
-
_metadata
final JsonField<BetaMetadata> _metadata()
Returns the raw JSON value of metadata.
Unlike metadata, this method doesn't throw if the JSON field has an unexpected type.
-
_outputConfig
final JsonField<BetaOutputConfig> _outputConfig()
Returns the raw JSON value of outputConfig.
Unlike outputConfig, this method doesn't throw if the JSON field has an unexpected type.
-
_outputFormat
@Deprecated(message = "deprecated") final JsonField<BetaJsonOutputFormat> _outputFormat()
Returns the raw JSON value of outputFormat.
Unlike outputFormat, this method doesn't throw if the JSON field has an unexpected type.
-
_serviceTier
final JsonField<MessageCreateParams.ServiceTier> _serviceTier()
Returns the raw JSON value of serviceTier.
Unlike serviceTier, this method doesn't throw if the JSON field has an unexpected type.
-
_speed
final JsonField<MessageCreateParams.Speed> _speed()
Returns the raw JSON value of speed.
Unlike speed, this method doesn't throw if the JSON field has an unexpected type.
-
_stopSequences
final JsonField<List<String>> _stopSequences()
Returns the raw JSON value of stopSequences.
Unlike stopSequences, this method doesn't throw if the JSON field has an unexpected type.
-
_system
final JsonField<MessageCreateParams.System> _system()
Returns the raw JSON value of system.
Unlike system, this method doesn't throw if the JSON field has an unexpected type.
-
_temperature
@Deprecated(message = "Deprecated. Models released after Claude Opus 4.6 do not support setting temperature. A value of 1.0 of will be accepted for backwards compatibility, all other values will be rejected with a 400 error.") final JsonField<Double> _temperature()
Returns the raw JSON value of temperature.
Unlike temperature, this method doesn't throw if the JSON field has an unexpected type.
-
_thinking
final JsonField<BetaThinkingConfigParam> _thinking()
Returns the raw JSON value of thinking.
Unlike thinking, this method doesn't throw if the JSON field has an unexpected type.
-
_toolChoice
final JsonField<BetaToolChoice> _toolChoice()
Returns the raw JSON value of toolChoice.
Unlike toolChoice, this method doesn't throw if the JSON field has an unexpected type.
-
_tools
final JsonField<List<BetaToolUnion>> _tools()
Returns the raw JSON value of tools.
Unlike tools, this method doesn't throw if the JSON field has an unexpected type.
-
_topK
@Deprecated(message = "Deprecated. Models released after Claude Opus 4.6 do not accept top_k; any value will be rejected with a 400 error.") final JsonField<Long> _topK()
Returns the raw JSON value of topK.
Unlike topK, this method doesn't throw if the JSON field has an unexpected type.
-
_topP
@Deprecated(message = "Deprecated. Models released after Claude Opus 4.6 do not support setting top_p. A value >= 0.99 will be accepted for backwards compatibility, all other values will be rejected with a 400 error.") final JsonField<Double> _topP()
Returns the raw JSON value of topP.
Unlike topP, this method doesn't throw if the JSON field has an unexpected type.
-
_userProfileId
final JsonField<String> _userProfileId()
Returns the raw JSON value of userProfileId.
Unlike userProfileId, this method doesn't throw if the JSON field has an unexpected type.
-
_additionalProperties
final Map<String, JsonValue> _additionalProperties()
-
toBuilder
final MessageCreateParams.Body.Builder toBuilder()
-
validate
final MessageCreateParams.Body validate()
Validates that the types of all values in this object match their expected types recursively.
This method is not forwards compatible with new types from the API for existing fields.
-
builder
final static MessageCreateParams.Body.Builder builder()
Returns a mutable builder for constructing an instance of Body.
The following fields are required:
.maxTokens() .messages() .model()
-
-
-
-