The official Anthropic Java SDK (com.anthropic:anthropic-java) provides idiomatic, type-safe access to the Claude API — including messages, streaming, tool use, and multi-platform deployment to Anthropic API, AWS Bedrock, and Google Vertex AI.
Why Trial
Anthropic released the first-party Java SDK in late 2024; it's now at v2.18 with a stable API. Use it directly when you want precise control over Claude API parameters without a framework abstraction layer. For Spring Boot apps, the Spring AI Anthropic starter is simpler — but for non-Spring projects or when you need exact control, this is the right choice.
Setup
<dependency>
<groupId>com.anthropic</groupId>
<artifactId>anthropic-java</artifactId>
<version>2.18.0</version>
</dependency>
Usage
Basic message:
// Automatically reads ANTHROPIC_API_KEY from environment
AnthropicClient client = AnthropicOkHttpClient.fromEnv();
Message message = client.messages().create(
MessageCreateParams.builder()
.model(Model.CLAUDE_SONNET_4_6)
.maxTokens(1024L)
.addUserMessage("Explain Java virtual threads in two sentences.")
.build()
);
System.out.println(message.content().get(0).text());
Streaming:
client.messages().createStreaming(params)
.stream()
.flatMap(event -> event.delta().stream())
.filter(delta -> delta.type().equals("text_delta"))
.forEach(delta -> System.out.print(delta.text()));
Tool use:
Tool orderLookup = Tool.builder()
.name("lookup_order")
.description("Look up a customer's order by order ID")
.inputSchema(/* JSON schema */)
.build();
Message response = client.messages().create(
MessageCreateParams.builder()
.model(Model.CLAUDE_SONNET_4_6)
.addTool(orderLookup)
.addUserMessage("What's the status of order 12345?")
.build()
);
Multi-Platform: Bedrock and Vertex AI
The same SDK works against AWS Bedrock and Google Vertex AI — only the client builder changes:
// AWS Bedrock
AnthropicClient bedrockClient = AnthropicBedrock.builder()
.region("us-east-1")
.build();
// Google Vertex AI
AnthropicClient vertexClient = AnthropicVertex.builder()
.project("my-project")
.region("us-central1")
.build();
This matters for teams that want Claude but must route traffic through their cloud provider for compliance, billing, or data residency reasons.
Spring Boot Integration
If you're on Spring Boot, prefer the Spring AI starter — it wraps this SDK with auto-configuration:
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-anthropic</artifactId>
</dependency>
spring.ai.anthropic.api-key=${ANTHROPIC_API_KEY}
spring.ai.anthropic.chat.model=claude-sonnet-4-6
Key Characteristics
| Property | Value |
|---|---|
| Group ID | com.anthropic |
| Latest version | 2.18.0 |
| Java compatibility | Java 8+ (built with JDK 21) |
| Platforms | Anthropic API, AWS Bedrock, Google Vertex AI |
| Licence | MIT |