Class AnthropicBatchChatModel.Builder
- Enclosing class:
AnthropicBatchChatModel
-
Method Summary
Modifier and TypeMethodDescriptionSets the Anthropic API key used to authenticate requests.Sets the base URL of the Anthropic API.Sets the value of theanthropic-betarequest header to opt into beta features.build()customHeaders(Supplier<Map<String, String>> customHeadersSupplier) Sets a supplier of custom HTTP headers, invoked for every request to the Anthropic API.customHeaders(Map<String, String> customHeaders) Sets custom HTTP headers sent with every request to the Anthropic API.customParameters(Map<String, Object> customParameters) Sets additional top-level parameters added verbatim to every batched request body.defaultRequestParameters(ChatRequestParameters parameters) Sets the defaultChatRequestParametersapplied to every batched request.httpClientBuilder(HttpClientBuilder httpClientBuilder) Sets a customHttpClientBuilderfor the underlying HTTP client.logRequests(Boolean logRequests) Enables debug logging of HTTP request bodies sent to the Anthropic API.logResponses(Boolean logResponses) Enables debug logging of HTTP response bodies received from the Anthropic API.maxRetries(Integer maxRetries) Sets the number of times to retry a request on transient errors (e.g. rate limits, server errors).Sets the maximum number of tokens to generate per batched request.modelName(AnthropicChatModelName modelName) Sets the model applied to every batched request.Sets the model applied to every batched request, specified as a string model ID.returnServerToolResults(Boolean returnServerToolResults) Controls whether to return server tool results (e.g. web_search, code_execution) insideAiMessage.attributes()under the key "server_tool_results".returnThinking(Boolean returnThinking) Controls whether thinking returned by the API is stored inAiMessage.thinking().serverTools(AnthropicServerTool... serverTools) serverTools(List<AnthropicServerTool> serverTools) Specifies server tools (e.g. web search, code execution) to be included in every batched request.skills(AnthropicSkill... skills) skills(List<AnthropicSkill> skills) Enables Anthropic Agent Skills for every batched request.stopSequences(List<String> stopSequences) Sets sequences that, when generated, will cause the model to stop generating further tokens.strictTools(Boolean strictTools) Enables strict mode for tools, guaranteeing that generated tool arguments match the tool's schema.temperature(Double temperature) Sets the sampling temperature in the range[0.0, 1.0].thinkingDisplay(String thinkingDisplay) Controls how thinking is returned by the API, e.g.Sets the HTTP request timeout for calls to the Anthropic API.toolMetadataKeysToSend(String... toolMetadataKeysToSend) toolMetadataKeysToSend(Set<String> toolMetadataKeysToSend) Specifies metadata keys from theToolSpecification.metadata()to be included in the request.Sets the top-K sampling value.Sets the nucleus sampling probability (top-p) in the range(0.0, 1.0].Sets the value of theanthropic-versionrequest header.
-
Method Details
-
httpClientBuilder
Sets a customHttpClientBuilderfor the underlying HTTP client. Use this to configure timeouts, proxies, or other HTTP-level settings.- Parameters:
httpClientBuilder- the HTTP client builder- Returns:
this
-
baseUrl
Sets the base URL of the Anthropic API.Defaults to
https://api.anthropic.com/v1/.- Parameters:
baseUrl- the base URL- Returns:
this
-
apiKey
Sets the Anthropic API key used to authenticate requests.- Parameters:
apiKey- the API key- Returns:
this
-
version
Sets the value of theanthropic-versionrequest header.Defaults to
2023-06-01. See the Anthropic API versioning docs.- Parameters:
version- the API version string- Returns:
this
-
beta
Sets the value of theanthropic-betarequest header to opt into beta features.See the Anthropic beta headers docs.
- Parameters:
beta- the beta feature identifier- Returns:
this
-
modelName
Sets the model applied to every batched request, specified as a string model ID.See
AnthropicChatModelNamefor available model constants. It can be overridden per request viaChatRequestParameters.modelName().- Parameters:
modelName- the model ID, e.g."claude-opus-4-5"- Returns:
this
-
modelName
Sets the model applied to every batched request.It can be overridden per request via
ChatRequestParameters.modelName().- Parameters:
modelName- the model- Returns:
this
-
maxTokens
Sets the maximum number of tokens to generate per batched request.Defaults to
1024if not set.- Parameters:
maxTokens- the maximum number of output tokens- Returns:
this
-
temperature
Sets the sampling temperature in the range[0.0, 1.0]. Higher values produce more random output; lower values produce more deterministic output.Cannot be used together with
topP(Double).- Parameters:
temperature- the sampling temperature- Returns:
this
-
topP
Sets the nucleus sampling probability (top-p) in the range(0.0, 1.0]. Only the tokens whose cumulative probability exceeds this threshold are considered.Cannot be used together with
temperature(Double).- Parameters:
topP- the nucleus sampling threshold- Returns:
this
-
topK
Sets the top-K sampling value. Only thetopKmost-likely next tokens are considered at each step.Recommended for advanced use only;
temperature(Double)is usually sufficient.- Parameters:
topK- the number of top tokens to sample from- Returns:
this
-
stopSequences
Sets sequences that, when generated, will cause the model to stop generating further tokens.- Parameters:
stopSequences- the list of stop sequences- Returns:
this
-
timeout
Sets the HTTP request timeout for calls to the Anthropic API.- Parameters:
timeout- the request timeout- Returns:
this
-
maxRetries
Sets the number of times to retry a request on transient errors (e.g. rate limits, server errors).Defaults to
2.- Parameters:
maxRetries- the maximum number of retry attempts- Returns:
this
-
logRequests
Enables debug logging of HTTP request bodies sent to the Anthropic API.- Parameters:
logRequests- whether to log requests- Returns:
this
-
logResponses
Enables debug logging of HTTP response bodies received from the Anthropic API.- Parameters:
logResponses- whether to log responses- Returns:
this
-
defaultRequestParameters
Sets the defaultChatRequestParametersapplied to every batched request.Pass
AnthropicChatRequestParametersto configure Anthropic-specific defaults such as thinking, prompt caching and tool choice. Individual builder methods (e.g.modelName(String)) take precedence over the corresponding value here, and per-request parameters take precedence over both.- Parameters:
parameters- the default request parameters- Returns:
this
-
thinkingDisplay
Controls how thinking is returned by the API, e.g."summarized"or"omitted".Applies only when thinking is enabled via
AnthropicChatRequestParameters.Builder.thinkingType(String).- Parameters:
thinkingDisplay- the thinking display mode- Returns:
this- See Also:
-
returnThinking
Controls whether thinking returned by the API is stored inAiMessage.thinking().Disabled by default. Unlike
AnthropicChatModel, this is resolved once per model rather than per request, because results are mapped inAnthropicBatchChatModel.retrieve(String), which has no access to the originating request.- Parameters:
returnThinking- whether to return thinking- Returns:
this
-
returnServerToolResults
Controls whether to return server tool results (e.g. web_search, code_execution) insideAiMessage.attributes()under the key "server_tool_results".Disabled by default to avoid returning potentially large data.
- Parameters:
returnServerToolResults- whether to return server tool results- Returns:
this- See Also:
-
serverTools
Specifies server tools (e.g. web search, code execution) to be included in every batched request.- Parameters:
serverTools- the server tools- Returns:
this- See Also:
-
serverTools
- See Also:
-
skills
Enables Anthropic Agent Skills for every batched request.The required beta features must be opted into via
beta(String).- Parameters:
skills- the skills to enable- Returns:
this- See Also:
-
skills
- See Also:
-
toolMetadataKeysToSend
Specifies metadata keys from theToolSpecification.metadata()to be included in the request.- Parameters:
toolMetadataKeysToSend- the metadata keys- Returns:
this
-
toolMetadataKeysToSend
- See Also:
-
strictTools
Enables strict mode for tools, guaranteeing that generated tool arguments match the tool's schema.- Parameters:
strictTools- whether tools are strict- Returns:
this
-
customParameters
Sets additional top-level parameters added verbatim to every batched request body. Use this to send parameters that are not yet supported by langchain4j.- Parameters:
customParameters- the custom parameters- Returns:
this
-
customHeaders
Sets custom HTTP headers sent with every request to the Anthropic API.- Parameters:
customHeaders- a map of header names to values- Returns:
this
-
customHeaders
public AnthropicBatchChatModel.Builder customHeaders(Supplier<Map<String, String>> customHeadersSupplier) Sets a supplier of custom HTTP headers, invoked for every request to the Anthropic API. Use this when header values need to be refreshed, e.g. for short-lived tokens.- Parameters:
customHeadersSupplier- a supplier that returns a map of header names to values- Returns:
this
-
build
- Returns:
- a new
AnthropicBatchChatModelconfigured with this builder's values.
-