Package com.tnsai.llm.providers
Class AnthropicClient.Builder
java.lang.Object
com.tnsai.llm.providers.AnthropicClient.Builder
- Enclosing class:
AnthropicClient
Builder for creating AnthropicClient instances.
Example usage:
AnthropicClient client = AnthropicClient.builder()
.apiKey("sk-...")
.model("claude-sonnet-4-20250514")
.temperature(0.7f)
.maxTokens(4096)
.beta("advanced-tool-use-2025-11-20")
.build();
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSets the API key.Sets the API base URL.Adds a beta feature identifier.Adds multiple beta feature identifiers.build()Builds the AnthropicClient instance.cacheLastNTurns(int n) Upper bound on how many of the last user messages in history get a cache_control marker (issue #27).enableEphemeralCaching(boolean enabled) Toggles cache_control marker injection on the system prompt and the lastcacheLastNTurns(int)user messages in history (issue #27).maxTokens(int maxTokens) Sets the maximum number of tokens to generate.Sets the model to use.temperature(float temperature) Sets the temperature for response generation.topP(float topP) Sets the top-p (nucleus sampling) value.Enables advanced tool use features (tool search, programmatic calling).Enables computer use capabilities.Enables prompt caching for reduced latency and ~75% lower input-token cost on repeated prompts (issue #27).Enables web search capability.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
baseUrl
Sets the API base URL. Defaults to Anthropic's API. -
apiKey
Sets the API key. If not set, will use ANTHROPIC_API_KEY environment variable. -
model
Sets the model to use. -
temperature
Sets the temperature for response generation. -
topP
Sets the top-p (nucleus sampling) value. -
maxTokens
Sets the maximum number of tokens to generate. -
beta
Adds a beta feature identifier. -
betas
Adds multiple beta feature identifiers. -
withAdvancedToolUse
Enables advanced tool use features (tool search, programmatic calling). -
withWebSearch
Enables web search capability. -
withPromptCaching
Enables prompt caching for reduced latency and ~75% lower input-token cost on repeated prompts (issue #27). Adds the prompt-caching beta header AND turns on cache_control marker injection — these only work together, requiring users to remember both is a footgun.Equivalent to
.enableEphemeralCaching(true). -
enableEphemeralCaching
Toggles cache_control marker injection on the system prompt and the lastcacheLastNTurns(int)user messages in history (issue #27). Auto-adds the prompt-caching beta header at build time when enabled.- Since:
- 0.5.0 (issue #27)
-
cacheLastNTurns
Upper bound on how many of the last user messages in history get a cache_control marker (issue #27). Capped internally toMAX_CACHE_BREAKPOINTS - 1(currently 3) so total breakpoints — system (1) + history (N) — never exceed Anthropic's 4-per-request limit. Default: 3.- Throws:
IllegalArgumentException- if negative- Since:
- 0.5.0 (issue #27)
-
withComputerUse
Enables computer use capabilities. -
build
Builds the AnthropicClient instance.
-