CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-io-quarkiverse-langchain4j--quarkus-langchain4j-anthropic

Quarkus extension for integrating Anthropic Claude LLM models into Quarkus applications via LangChain4j

Overview
Eval results
Files

configuration.mddocs/

Configuration

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.

Configuration Interfaces

LangChain4jAnthropicConfig

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();
}

AnthropicConfig

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();
}

ChatModelConfig

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();
}

ThinkingConfig

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

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();
}

Configuration Properties

Connection Properties

PropertyTypeDefaultDescription
quarkus.langchain4j.anthropic.api-keyString"dummy"Anthropic API key (required)
quarkus.langchain4j.anthropic.base-urlStringhttps://api.anthropic.com/v1/API base URL
quarkus.langchain4j.anthropic.versionString"2023-06-01"Anthropic API version
quarkus.langchain4j.anthropic.timeoutDuration10sRequest timeout
quarkus.langchain4j.anthropic.enable-integrationBooleantrueEnable/disable integration
quarkus.langchain4j.anthropic.disable-beta-headerBooleanfalseDisable beta headers

Logging Properties

PropertyTypeDefaultDescription
quarkus.langchain4j.anthropic.log-requestsBooleanfalseLog HTTP requests
quarkus.langchain4j.anthropic.log-responsesBooleanfalseLog HTTP responses
quarkus.langchain4j.anthropic.log-requests-curlBooleanfalseLog requests as cURL commands

Chat Model Properties

Prefix: quarkus.langchain4j.anthropic.chat-model.

PropertyTypeDefaultDescription
model-nameStringclaude-3-haiku-20240307Claude model name
max-tokensInteger1024Maximum output tokens
temperatureDouble0.7Sampling temperature (0.0-1.0)
top-pDouble1.0Nucleus sampling (0.0-1.0)
top-kInteger40Diversity control
max-retriesInteger1Maximum retry attempts (deprecated - use MicroProfile Fault Tolerance)
stop-sequencesList<String>noneCustom stop sequences
cache-system-messagesBooleanfalseEnable prompt caching for system messages
cache-toolsBooleanfalseEnable prompt caching for tools
log-requestsBooleanfalseLog chat requests
log-responsesBooleanfalseLog chat responses

Thinking Properties

Prefix: quarkus.langchain4j.anthropic.chat-model.thinking.

PropertyTypeDefaultDescription
typeStringnoneThinking type (e.g., "enabled")
budget-tokensIntegernoneToken budget for thinking
return-thinkingBooleanfalseReturn thinking in response
send-thinkingBooleantrueSend thinking in follow-ups
interleavedBooleanfalseInterleaved thinking (Claude 4 only)

Build-Time Properties

PropertyTypeDefaultDescription
quarkus.langchain4j.anthropic.chat-model.enabledBooleantrueEnable ChatModel bean creation

Configuration Examples

Basic Configuration

# 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

Full Configuration Example

# 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=false

Named Model Configurations

Configure 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=true

Inject named models:

@Inject
@ModelName("fast")
ChatModel fastModel;

@Inject
@ModelName("smart")
ChatModel smartModel;

Environment Variables

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=8000

Dev Mode vs Prod Configuration

Use 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=60s

Configuration Best Practices

API Key Management

  1. Never commit API keys to source control
  2. Use environment variables in production:
    export QUARKUS_LANGCHAIN4J_ANTHROPIC_API_KEY=sk-ant-...
  3. Use Quarkus Vault or similar for secret management in production

Model Selection

  • claude-3-haiku-20240307: Fast, cost-effective for simple tasks
  • claude-3-sonnet-20240229: Balanced performance and cost
  • claude-3-opus-20240229: Most capable Claude 3, higher cost
  • claude-sonnet-4-20250514: Latest balanced Claude 4 model
  • claude-opus-4-20250514: Most capable, supports extended thinking

Performance Tuning

  • Increase timeout for complex requests requiring extended thinking
  • Reduce max-tokens for faster responses and lower costs
  • Use temperature=0.0 for deterministic outputs
  • Enable prompt caching for repeated system messages or tool definitions

Extended Thinking

  • Enable only when needed - adds latency and token costs
  • Set reasonable budget-tokens - typically 5000-10000
  • Use with Claude 4 models for best results
  • Set return-thinking=true during development to observe reasoning
  • Set return-thinking=false in production if thinking content isn't needed

Logging

  • Enable in development for debugging
  • Disable in production unless troubleshooting
  • Use log-requests-curl to replay requests for debugging
  • Be careful with response logging - can expose sensitive data

Configuration Precedence

Configuration values are resolved in the following order (highest to lowest precedence):

  1. System properties (-Dquarkus.langchain4j.anthropic.api-key=...)
  2. Environment variables (QUARKUS_LANGCHAIN4J_ANTHROPIC_API_KEY=...)
  3. application.properties in src/main/resources
  4. Default values defined in config interfaces

Install with Tessl CLI

npx tessl i tessl/maven-io-quarkiverse-langchain4j--quarkus-langchain4j-anthropic@1.7.0

docs

advanced-features.md

cdi-injection.md

client-api.md

configuration.md

index.md

tile.json