CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-dev-langchain4j--langchain4j-anthropic

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.

Overview
Eval results
Files

model-names.mddocs/

Model Names

The AnthropicChatModelName enum provides predefined identifiers for Claude models.

Capabilities

Model Name Enum

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

Using Model Names

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 version

Null Safety:

  • Enum constants are never null
  • toString() returns never null
  • String parameter methods throw if null provided

Model String Values

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
// ...

Available Models

Claude 4.5 Series

  • CLAUDE_OPUS_4_5_20251101: "claude-opus-4-5-20251101" - Most powerful model with extended thinking

    • Context window: 200K tokens
    • Max output: 16K tokens
    • Supports: Vision, PDF, thinking, tools, caching
    • Best for: Complex reasoning, research, analysis
  • CLAUDE_SONNET_4_5_20250929: "claude-sonnet-4-5-20250929" - Balanced intelligence and speed

    • Context window: 200K tokens
    • Max output: 8K tokens
    • Supports: Vision, PDF, tools, caching
    • Best for: General purpose, production workloads
  • CLAUDE_HAIKU_4_5_20251001: "claude-haiku-4-5-20251001" - Fastest model for simple tasks

    • Context window: 200K tokens
    • Max output: 4K tokens
    • Supports: Vision, PDF, tools, caching
    • Best for: High-volume, cost-sensitive applications

Claude 4.1 Series

  • CLAUDE_OPUS_4_1_20250805: "claude-opus-4-1-20250805" - Previous generation Opus
    • Context window: 200K tokens
    • Max output: 16K tokens
    • Supports: Vision, PDF, tools, caching
    • Best for: Complex tasks without thinking requirement

Claude 4 Series

  • CLAUDE_OPUS_4_20250514: "claude-opus-4-20250514" - Claude 4 Opus

    • Context window: 200K tokens
    • Max output: 16K tokens
    • Supports: Vision, PDF, tools, caching
    • Best for: High-quality outputs
  • CLAUDE_SONNET_4_20250514: "claude-sonnet-4-20250514" - Claude 4 Sonnet

    • Context window: 200K tokens
    • Max output: 8K tokens
    • Supports: Vision, PDF, tools, caching
    • Best for: Balanced use cases

Claude 3.5 Series

  • CLAUDE_3_5_HAIKU_20241022: "claude-3-5-haiku-20241022" - Claude 3.5 Haiku
    • Context window: 200K tokens
    • Max output: 4K tokens
    • Supports: Vision, tools, caching
    • Best for: Fast responses, simple tasks

Claude 3 Series

  • CLAUDE_3_HAIKU_20240307: "claude-3-haiku-20240307" - Claude 3 Haiku
    • Context window: 200K tokens
    • Max output: 4K tokens
    • Supports: Vision, tools
    • Best for: Legacy applications

Model Selection Guidelines

Use CLAUDE_OPUS_4_5_20251101 for:

  • Complex reasoning tasks
  • Extended thinking requirements
  • Research and analysis
  • Advanced problem-solving
  • Mathematical proofs
  • Code analysis and debugging

Example:

// Complex research task
AnthropicChatModel model = AnthropicChatModel.builder()
    .apiKey(apiKey)
    .modelName(AnthropicChatModelName.CLAUDE_OPUS_4_5_20251101)
    .thinkingType("enabled")
    .thinkingBudgetTokens(10000)
    .build();

Use CLAUDE_SONNET_4_5_20250929 for:

  • General-purpose applications
  • Balanced performance and cost
  • Most production use cases
  • Tool use and function calling
  • Content generation
  • Document analysis

Example:

// Production chatbot
AnthropicChatModel model = AnthropicChatModel.builder()
    .apiKey(apiKey)
    .modelName(AnthropicChatModelName.CLAUDE_SONNET_4_5_20250929)
    .temperature(0.7)
    .maxTokens(2048)
    .build();

Use CLAUDE_HAIKU_4_5_20251001 for:

  • Simple, fast responses
  • High-volume requests
  • Cost-sensitive applications
  • Quick data transformations
  • Classification tasks
  • Simple Q&A

Example:

// High-volume classification
AnthropicChatModel model = AnthropicChatModel.builder()
    .apiKey(apiKey)
    .modelName(AnthropicChatModelName.CLAUDE_HAIKU_4_5_20251001)
    .maxTokens(512)
    .temperature(0.0)  // Deterministic
    .build();

Usage Examples

Selecting by Use Case

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

Dynamic Model Selection

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:

  • Invalid taskComplexity falls back to Sonnet (safe default)
  • Consider validating input before selection
  • Log model selection for debugging

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 Comparison Table

ModelContextMax OutputSpeedCostThinkingBest For
Opus 4.5200K16KSlowHighComplex reasoning
Sonnet 4.5200K8KMediumMediumGeneral purpose
Haiku 4.5200K4KFastLowSimple tasks
Opus 4.1200K16KSlowHighQuality outputs
Opus 4200K16KSlowHighLegacy high-quality
Sonnet 4200K8KMediumMediumLegacy balanced
Haiku 3.5200K4KFastLowLegacy fast
Haiku 3200K4KFastLowLegacy simple

Performance Notes:

  • Speed: Relative latency (tokens/second)
  • Cost: Relative pricing per 1M tokens
  • Context: All models support 200K token context
  • Max Output: Configurable via maxTokens(), but cannot exceed model limit

Behavioral Differences Between Models

Intelligence Level

  • Opus: Best reasoning, fewer errors, handles ambiguity well
  • Sonnet: Good balance, occasional misunderstandings on complex tasks
  • Haiku: Best for structured tasks, may struggle with nuance

Response Style

  • Opus: Thorough, detailed, considers edge cases
  • Sonnet: Concise yet complete, balanced detail level
  • Haiku: Direct, brief, focused on task completion

Tool Usage

  • Opus: Strategic tool selection, handles complex multi-tool workflows
  • Sonnet: Reliable tool use, good for standard workflows
  • Haiku: Basic tool use, best for single-tool scenarios

Error Handling

  • Opus: Graceful degradation, asks clarifying questions
  • Sonnet: Standard error messages, good error recovery
  • Haiku: Direct error reporting, minimal recovery attempts

Version Date Significance

Model version dates indicate release snapshots:

  • Format: YYYYMMDD (e.g., 20250929 = September 29, 2025)
  • Purpose: Explicit versioning for reproducibility
  • Updates: New dates released as models improve
  • Deprecation: Old versions eventually deprecated (6-12 months notice)

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)

Notes

  • Model availability may vary by region and API key permissions
  • Extended thinking is only available on Opus 4.5+ models
  • Newer models generally have improved capabilities
  • Model names include version dates for explicit versioning
  • Always check Anthropic's documentation for the latest model information
  • Enum constants updated with library releases
  • String-based names allow forward compatibility with unreleased models
  • Context windows are consistent across tiers (200K tokens)
  • Max output tokens vary by tier (Opus: 16K, Sonnet: 8K, Haiku: 4K)

Resource Lifecycle:

  • Model enum values are constants (no resource management)
  • Safe to use across threads and instances
  • No memory overhead beyond enum constant itself

Thread Safety:

  • Enum constants are inherently thread-safe
  • toString() is thread-safe (immutable)
  • Safe for concurrent access from multiple threads

Install with Tessl CLI

npx tessl i tessl/maven-dev-langchain4j--langchain4j-anthropic@1.11.0

docs

chat-model.md

content-types.md

index.md

model-catalog.md

model-names.md

response-metadata.md

streaming-chat-model.md

token-count-estimator.md

tools.md

tile.json