This package provides an integration layer between the LangChain4j framework and Anthropic's Claude language models, enabling Java developers to seamlessly incorporate Anthropic's AI capabilities into their applications.
The AnthropicChatModelName enum provides predefined identifiers for Claude models.
Predefined Claude model identifiers with version dates.
package dev.langchain4j.model.anthropic;
/**
* Enum of Claude model identifiers with version dates.
* Each constant maps to a specific model version string.
*
* @since 1.0.0
*/
public enum AnthropicChatModelName {
/** Claude Opus 4.5 released November 2025 - most powerful with thinking */
CLAUDE_OPUS_4_5_20251101,
/** Claude Sonnet 4.5 released September 2025 - balanced intelligence and speed */
CLAUDE_SONNET_4_5_20250929,
/** Claude Haiku 4.5 released October 2025 - fastest for simple tasks */
CLAUDE_HAIKU_4_5_20251001,
/** Claude Opus 4.1 released August 2025 - previous generation Opus */
CLAUDE_OPUS_4_1_20250805,
/** Claude Opus 4 released May 2025 */
CLAUDE_OPUS_4_20250514,
/** Claude Sonnet 4 released May 2025 */
CLAUDE_SONNET_4_20250514,
/** Claude 3.5 Haiku released October 2024 */
CLAUDE_3_5_HAIKU_20241022,
/** Claude 3 Haiku released March 2024 */
CLAUDE_3_HAIKU_20240307;
/**
* Returns API model name string.
* Format: "claude-{tier}-{version}-{date}"
* Example: "claude-sonnet-4-5-20250929"
*
* @return model name for API requests, never null
*/
public String toString();
}Model names can be used with all chat model builders.
import dev.langchain4j.model.anthropic.AnthropicChatModel;
import dev.langchain4j.model.anthropic.AnthropicChatModelName;
// Using enum constant
AnthropicChatModel model = AnthropicChatModel.builder()
.apiKey(apiKey)
.modelName(AnthropicChatModelName.CLAUDE_SONNET_4_5_20250929)
.build();
// Using string directly
AnthropicChatModel model2 = AnthropicChatModel.builder()
.apiKey(apiKey)
.modelName("claude-sonnet-4-5-20250929")
.build();Error Handling:
IllegalArgumentException: modelName null or empty (if using string method)RuntimeException: Model not available for API key (at runtime during API call)RuntimeException: Model name typo (at runtime during API call)Common Pitfalls:
❌ DON'T use hardcoded strings
.modelName("claude-sonnet") // Ambiguous, will fail✅ DO use enum constants or full strings
.modelName(AnthropicChatModelName.CLAUDE_SONNET_4_5_20250929) // Type-safe
// OR
.modelName("claude-sonnet-4-5-20250929") // Explicit versionNull Safety:
Each enum constant has a corresponding string value.
String modelString = AnthropicChatModelName.CLAUDE_SONNET_4_5_20250929.toString();
// Returns: "claude-sonnet-4-5-20250929"Usage Example:
// Get all model names as strings
for (AnthropicChatModelName model : AnthropicChatModelName.values()) {
System.out.println(model.name() + " -> " + model.toString());
}
// Output:
// CLAUDE_OPUS_4_5_20251101 -> claude-opus-4-5-20251101
// CLAUDE_SONNET_4_5_20250929 -> claude-sonnet-4-5-20250929
// CLAUDE_HAIKU_4_5_20251001 -> claude-haiku-4-5-20251001
// ...CLAUDE_OPUS_4_5_20251101: "claude-opus-4-5-20251101" - Most powerful model with extended thinking
CLAUDE_SONNET_4_5_20250929: "claude-sonnet-4-5-20250929" - Balanced intelligence and speed
CLAUDE_HAIKU_4_5_20251001: "claude-haiku-4-5-20251001" - Fastest model for simple tasks
"claude-opus-4-1-20250805" - Previous generation Opus
CLAUDE_OPUS_4_20250514: "claude-opus-4-20250514" - Claude 4 Opus
CLAUDE_SONNET_4_20250514: "claude-sonnet-4-20250514" - Claude 4 Sonnet
"claude-3-5-haiku-20241022" - Claude 3.5 Haiku
"claude-3-haiku-20240307" - Claude 3 Haiku
Example:
// Complex research task
AnthropicChatModel model = AnthropicChatModel.builder()
.apiKey(apiKey)
.modelName(AnthropicChatModelName.CLAUDE_OPUS_4_5_20251101)
.thinkingType("enabled")
.thinkingBudgetTokens(10000)
.build();Example:
// Production chatbot
AnthropicChatModel model = AnthropicChatModel.builder()
.apiKey(apiKey)
.modelName(AnthropicChatModelName.CLAUDE_SONNET_4_5_20250929)
.temperature(0.7)
.maxTokens(2048)
.build();Example:
// High-volume classification
AnthropicChatModel model = AnthropicChatModel.builder()
.apiKey(apiKey)
.modelName(AnthropicChatModelName.CLAUDE_HAIKU_4_5_20251001)
.maxTokens(512)
.temperature(0.0) // Deterministic
.build();// For complex reasoning
AnthropicChatModel reasoningModel = AnthropicChatModel.builder()
.apiKey(apiKey)
.modelName(AnthropicChatModelName.CLAUDE_OPUS_4_5_20251101)
.thinkingType("enabled")
.thinkingBudgetTokens(10000)
.build();
// For general use
AnthropicChatModel generalModel = AnthropicChatModel.builder()
.apiKey(apiKey)
.modelName(AnthropicChatModelName.CLAUDE_SONNET_4_5_20250929)
.build();
// For fast, simple tasks
AnthropicChatModel fastModel = AnthropicChatModel.builder()
.apiKey(apiKey)
.modelName(AnthropicChatModelName.CLAUDE_HAIKU_4_5_20251001)
.maxTokens(512)
.build();AnthropicChatModelName selectModel(String taskComplexity) {
return switch (taskComplexity) {
case "complex" -> AnthropicChatModelName.CLAUDE_OPUS_4_5_20251101;
case "medium" -> AnthropicChatModelName.CLAUDE_SONNET_4_5_20250929;
case "simple" -> AnthropicChatModelName.CLAUDE_HAIKU_4_5_20251001;
default -> AnthropicChatModelName.CLAUDE_SONNET_4_5_20250929;
};
}
AnthropicChatModel model = AnthropicChatModel.builder()
.apiKey(apiKey)
.modelName(selectModel("complex"))
.build();Error Handling:
Common Pitfalls:
❌ DON'T always use Opus
.modelName(AnthropicChatModelName.CLAUDE_OPUS_4_5_20251101) // Expensive for simple tasks✅ DO match model to task complexity
String complexity = assessComplexity(task);
.modelName(selectModel(complexity)) // Cost-effective| Model | Context | Max Output | Speed | Cost | Thinking | Best For |
|---|---|---|---|---|---|---|
| Opus 4.5 | 200K | 16K | Slow | High | ✅ | Complex reasoning |
| Sonnet 4.5 | 200K | 8K | Medium | Medium | ❌ | General purpose |
| Haiku 4.5 | 200K | 4K | Fast | Low | ❌ | Simple tasks |
| Opus 4.1 | 200K | 16K | Slow | High | ❌ | Quality outputs |
| Opus 4 | 200K | 16K | Slow | High | ❌ | Legacy high-quality |
| Sonnet 4 | 200K | 8K | Medium | Medium | ❌ | Legacy balanced |
| Haiku 3.5 | 200K | 4K | Fast | Low | ❌ | Legacy fast |
| Haiku 3 | 200K | 4K | Fast | Low | ❌ | Legacy simple |
Performance Notes:
Model version dates indicate release snapshots:
Example:
// Pin to specific version for reproducibility
.modelName("claude-sonnet-4-5-20250929") // Exact version
// vs. using enum (automatically updated with library)
.modelName(AnthropicChatModelName.CLAUDE_SONNET_4_5_20250929)Resource Lifecycle:
Thread Safety:
Install with Tessl CLI
npx tessl i tessl/maven-dev-langchain4j--langchain4j-anthropic@1.11.0