Quarkus extension for integrating Anthropic Claude LLM models into Quarkus applications via LangChain4j
The quarkus-langchain4j-anthropic extension uses SmallRye Config for comprehensive configuration management. All configuration properties are prefixed with quarkus.langchain4j.anthropic and can be set via application.properties, environment variables, or system properties.
Root configuration interface for the Anthropic extension.
package io.quarkiverse.langchain4j.anthropic.runtime.config;
@ConfigRoot(phase = RUN_TIME)
@ConfigMapping(prefix = "quarkus.langchain4j.anthropic")
interface LangChain4jAnthropicConfig {
/**
* Default model configuration (no name prefix)
*/
AnthropicConfig defaultConfig();
/**
* Named model configurations (with name prefix)
* Key: model name
* Value: model configuration
*/
Map<String, AnthropicConfig> namedConfig();
}Configuration group for a single Anthropic model configuration.
@ConfigGroup
interface AnthropicConfig {
/**
* Base URL of the Anthropic API
* Default: "https://api.anthropic.com/v1/"
*/
String baseUrl();
/**
* Anthropic API key (required)
* Default: "dummy" (must be overridden)
*/
String apiKey();
/**
* The Anthropic API version
* Default: "2023-06-01"
*/
String version();
/**
* Timeout for Anthropic calls
* Default: ${quarkus.langchain4j.timeout} (10s)
*/
Optional<Duration> timeout();
/**
* Whether the Anthropic client should log requests
* Default: ${quarkus.langchain4j.log-requests} (false)
*/
Optional<Boolean> logRequests();
/**
* Whether the Anthropic client should log responses
* Default: ${quarkus.langchain4j.log-responses} (false)
*/
Optional<Boolean> logResponses();
/**
* Whether the Anthropic client should log requests as cURL commands
* Default: ${quarkus.langchain4j.log-requests-curl} (false)
*/
Optional<Boolean> logRequestsCurl();
/**
* If set to true, the "anthropic-beta" header will never be sent
* Default: false
*/
Optional<Boolean> disableBetaHeader();
/**
* Whether to enable the integration. Set to false to disable all requests.
* Default: true
*/
Boolean enableIntegration();
/**
* Chat model related settings
*/
ChatModelConfig chatModel();
}Configuration for Anthropic chat model parameters.
package io.quarkiverse.langchain4j.anthropic.runtime.config;
@ConfigGroup
interface ChatModelConfig {
/**
* Model name to use
* Default: "claude-3-haiku-20240307"
*
* Supported models:
* - claude-opus-4-20250514
* - claude-sonnet-4-20250514
* - claude-3-5-sonnet-20241022
* - claude-3-opus-20240229
* - claude-3-sonnet-20240229
* - claude-3-haiku-20240307
*/
String modelName();
/**
* What sampling temperature to use, between 0.0 and 1.0.
* Higher values like 0.8 will make the output more random,
* while lower values like 0.2 will make it more focused and deterministic.
* Default: ${quarkus.langchain4j.temperature} (0.7)
*/
OptionalDouble temperature();
/**
* The maximum number of tokens to generate in the completion.
* The token count of your prompt plus max_tokens cannot exceed
* the model's context length.
* Default: 1024
*/
Integer maxTokens();
/**
* Nucleus sampling (0.0-1.0). The model considers the results of the
* tokens with top_p probability mass. So 0.1 means only the tokens
* comprising the top 10% probability mass are considered.
* Default: 1.0
*/
OptionalDouble topP();
/**
* Reduces the probability of generating nonsense.
* A higher value (e.g. 100) will give more diverse answers,
* while a lower value (e.g. 10) will be more conservative.
* Default: 40
*/
OptionalInt topK();
/**
* The maximum number of times to retry. 1 means exactly one attempt,
* with retrying disabled.
* Default: 1
* @deprecated Use MicroProfile Fault Tolerance instead
*/
@Deprecated
Integer maxRetries();
/**
* Custom text sequences that will cause the model to stop generating.
*/
Optional<List<String>> stopSequences();
/**
* Whether chat model requests should be logged.
* Default: false
*/
Optional<Boolean> logRequests();
/**
* Whether chat model responses should be logged.
* Default: false
*/
Optional<Boolean> logResponses();
/**
* Cache system messages to reduce costs for repeated prompts.
* Requires minimum 1024 tokens (Claude Opus/Sonnet) or
* 2048-4096 tokens (Haiku).
* Supported models: Claude Opus 4.1, Sonnet 4.5, Haiku 4.5, and later.
* Default: false
*/
Boolean cacheSystemMessages();
/**
* Cache tool definitions to reduce costs.
* Requires minimum 1024 tokens (Claude Opus/Sonnet) or
* 2048-4096 tokens (Haiku).
* Supported models: Claude Opus 4.1, Sonnet 4.5, Haiku 4.5, and later.
* Default: false
*/
Boolean cacheTools();
/**
* Thinking related configuration for extended reasoning mode.
*/
ThinkingConfig thinking();
}Configuration for Claude's extended reasoning/thinking mode.
@ConfigGroup
interface ThinkingConfig {
/**
* The thinking type to enable Claude's reasoning process.
* Set to "enabled" to activate extended thinking.
*/
Optional<String> type();
/**
* The token budget for the model's thinking process.
* This allocates tokens specifically for internal reasoning
* before generating the final response.
*/
Optional<Integer> budgetTokens();
/**
* Whether thinking results should be returned in the response.
* When true, the thinking content is included in the AiMessage.
* Default: false
*/
Optional<Boolean> returnThinking();
/**
* Whether previously stored thinking should be sent in follow-up requests.
* Maintains reasoning context across multiple interactions.
* Default: true
*/
Optional<Boolean> sendThinking();
/**
* Enable interleaved thinking for Claude 4 models.
* Allows reasoning between tool calls.
* Requires Claude 4 model (e.g., claude-opus-4-20250514)
* and thinking.type: enabled.
* Default: false
*/
Optional<Boolean> interleaved();
}Build-time configuration for controlling bean creation.
package io.quarkiverse.langchain4j.anthropic.deployment;
@ConfigRoot(phase = BUILD_TIME)
@ConfigMapping(prefix = "quarkus.langchain4j.anthropic")
interface LangChain4jAnthropicBuildConfig {
/**
* Build-time chat model settings
*/
ChatModelBuildConfig chatModel();
}
@ConfigGroup
interface ChatModelBuildConfig {
/**
* Whether to enable ChatModel bean creation at build time.
* Default: true
*/
Optional<Boolean> enabled();
}| Property | Type | Default | Description |
|---|---|---|---|
quarkus.langchain4j.anthropic.api-key | String | "dummy" | Anthropic API key (required) |
quarkus.langchain4j.anthropic.base-url | String | https://api.anthropic.com/v1/ | API base URL |
quarkus.langchain4j.anthropic.version | String | "2023-06-01" | Anthropic API version |
quarkus.langchain4j.anthropic.timeout | Duration | 10s | Request timeout |
quarkus.langchain4j.anthropic.enable-integration | Boolean | true | Enable/disable integration |
quarkus.langchain4j.anthropic.disable-beta-header | Boolean | false | Disable beta headers |
| Property | Type | Default | Description |
|---|---|---|---|
quarkus.langchain4j.anthropic.log-requests | Boolean | false | Log HTTP requests |
quarkus.langchain4j.anthropic.log-responses | Boolean | false | Log HTTP responses |
quarkus.langchain4j.anthropic.log-requests-curl | Boolean | false | Log requests as cURL commands |
Prefix: quarkus.langchain4j.anthropic.chat-model.
| Property | Type | Default | Description |
|---|---|---|---|
model-name | String | claude-3-haiku-20240307 | Claude model name |
max-tokens | Integer | 1024 | Maximum output tokens |
temperature | Double | 0.7 | Sampling temperature (0.0-1.0) |
top-p | Double | 1.0 | Nucleus sampling (0.0-1.0) |
top-k | Integer | 40 | Diversity control |
max-retries | Integer | 1 | Maximum retry attempts (deprecated - use MicroProfile Fault Tolerance) |
stop-sequences | List<String> | none | Custom stop sequences |
cache-system-messages | Boolean | false | Enable prompt caching for system messages |
cache-tools | Boolean | false | Enable prompt caching for tools |
log-requests | Boolean | false | Log chat requests |
log-responses | Boolean | false | Log chat responses |
Prefix: quarkus.langchain4j.anthropic.chat-model.thinking.
| Property | Type | Default | Description |
|---|---|---|---|
type | String | none | Thinking type (e.g., "enabled") |
budget-tokens | Integer | none | Token budget for thinking |
return-thinking | Boolean | false | Return thinking in response |
send-thinking | Boolean | true | Send thinking in follow-ups |
interleaved | Boolean | false | Interleaved thinking (Claude 4 only) |
| Property | Type | Default | Description |
|---|---|---|---|
quarkus.langchain4j.anthropic.chat-model.enabled | Boolean | true | Enable ChatModel bean creation |
# Required: Set your API key
quarkus.langchain4j.anthropic.api-key=sk-ant-...
# Optional: Choose a model (default is claude-3-haiku-20240307)
quarkus.langchain4j.anthropic.chat-model.model-name=claude-opus-4-20250514# Connection
quarkus.langchain4j.anthropic.api-key=sk-ant-...
quarkus.langchain4j.anthropic.base-url=https://api.anthropic.com/v1/
quarkus.langchain4j.anthropic.version=2023-06-01
quarkus.langchain4j.anthropic.timeout=30s
# Model Parameters
quarkus.langchain4j.anthropic.chat-model.model-name=claude-opus-4-20250514
quarkus.langchain4j.anthropic.chat-model.max-tokens=2048
quarkus.langchain4j.anthropic.chat-model.temperature=0.7
quarkus.langchain4j.anthropic.chat-model.top-p=1.0
quarkus.langchain4j.anthropic.chat-model.top-k=40
quarkus.langchain4j.anthropic.chat-model.stop-sequences=STOP,END
# Extended Thinking
quarkus.langchain4j.anthropic.chat-model.thinking.type=enabled
quarkus.langchain4j.anthropic.chat-model.thinking.budget-tokens=8000
quarkus.langchain4j.anthropic.chat-model.thinking.return-thinking=true
quarkus.langchain4j.anthropic.chat-model.thinking.send-thinking=true
quarkus.langchain4j.anthropic.chat-model.thinking.interleaved=false
# Prompt Caching
quarkus.langchain4j.anthropic.chat-model.cache-system-messages=true
quarkus.langchain4j.anthropic.chat-model.cache-tools=true
# Logging
quarkus.langchain4j.anthropic.log-requests=true
quarkus.langchain4j.anthropic.log-responses=false
quarkus.langchain4j.anthropic.log-requests-curl=true
# Integration Control
quarkus.langchain4j.anthropic.enable-integration=true
quarkus.langchain4j.anthropic.disable-beta-header=falseConfigure multiple models with different settings:
# Fast model for simple queries
quarkus.langchain4j.anthropic.fast.api-key=sk-ant-...
quarkus.langchain4j.anthropic.fast.chat-model.model-name=claude-3-haiku-20240307
quarkus.langchain4j.anthropic.fast.chat-model.max-tokens=1024
quarkus.langchain4j.anthropic.fast.chat-model.temperature=0.3
# Smart model for complex reasoning
quarkus.langchain4j.anthropic.smart.api-key=sk-ant-...
quarkus.langchain4j.anthropic.smart.chat-model.model-name=claude-opus-4-20250514
quarkus.langchain4j.anthropic.smart.chat-model.max-tokens=4096
quarkus.langchain4j.anthropic.smart.chat-model.temperature=0.7
quarkus.langchain4j.anthropic.smart.chat-model.thinking.type=enabled
quarkus.langchain4j.anthropic.smart.chat-model.thinking.budget-tokens=10000
quarkus.langchain4j.anthropic.smart.chat-model.thinking.return-thinking=trueInject named models:
@Inject
@ModelName("fast")
ChatModel fastModel;
@Inject
@ModelName("smart")
ChatModel smartModel;All configuration properties can be set via environment variables using uppercase with underscores:
# API key
export QUARKUS_LANGCHAIN4J_ANTHROPIC_API_KEY=sk-ant-...
# Model
export QUARKUS_LANGCHAIN4J_ANTHROPIC_CHAT_MODEL_MODEL_NAME=claude-opus-4-20250514
# Thinking
export QUARKUS_LANGCHAIN4J_ANTHROPIC_CHAT_MODEL_THINKING_TYPE=enabled
export QUARKUS_LANGCHAIN4J_ANTHROPIC_CHAT_MODEL_THINKING_BUDGET_TOKENS=8000Use Quarkus profile-specific configuration:
# Default (applies to all profiles)
quarkus.langchain4j.anthropic.chat-model.model-name=claude-3-haiku-20240307
# Development profile
%dev.quarkus.langchain4j.anthropic.log-requests=true
%dev.quarkus.langchain4j.anthropic.log-requests-curl=true
# Production profile
%prod.quarkus.langchain4j.anthropic.chat-model.model-name=claude-opus-4-20250514
%prod.quarkus.langchain4j.anthropic.chat-model.max-tokens=4096
%prod.quarkus.langchain4j.anthropic.timeout=60sexport QUARKUS_LANGCHAIN4J_ANTHROPIC_API_KEY=sk-ant-...timeout for complex requests requiring extended thinkingmax-tokens for faster responses and lower coststemperature=0.0 for deterministic outputsbudget-tokens - typically 5000-10000return-thinking=true during development to observe reasoningreturn-thinking=false in production if thinking content isn't neededlog-requests-curl to replay requests for debuggingConfiguration values are resolved in the following order (highest to lowest precedence):
-Dquarkus.langchain4j.anthropic.api-key=...)QUARKUS_LANGCHAIN4J_ANTHROPIC_API_KEY=...)application.properties in src/main/resourcesInstall with Tessl CLI
npx tessl i tessl/maven-io-quarkiverse-langchain4j--quarkus-langchain4j-anthropic