Skip to content

Commit 1adc8a9

Browse files
authored
feat(anthropic): add new Claude models and update naming conventions (#4516)
- Add CLAUDE_SONNET_4_5 and CLAUDE_OPUS_4_1 model constants - Rename CLAUDE_OPUS_4 to CLAUDE_OPUS_4_0 and CLAUDE_SONNET_4 to CLAUDE_SONNET_4_0 for consistency - Remove deprecated legacy models CLAUDE_2_1 and CLAUDE_2 - Update test references to use renamed CLAUDE_SONNET_4_0 constant Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
1 parent 74aa539 commit 1adc8a9

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/api/AnthropicApi.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,25 @@ private void addDefaultHeadersIfMissing(HttpHeaders headers) {
275275
public enum ChatModel implements ChatModelDescription {
276276

277277
// @formatter:off
278+
/**
279+
* The claude-sonnet-4-5 model.
280+
*/
281+
CLAUDE_SONNET_4_5("claude-sonnet-4-5"),
282+
283+
/**
284+
* The claude-opus-4-1 model.
285+
*/
286+
CLAUDE_OPUS_4_1("claude-opus-4-1"),
287+
278288
/**
279289
* The claude-opus-4-0 model.
280290
*/
281-
CLAUDE_OPUS_4("claude-opus-4-0"),
291+
CLAUDE_OPUS_4_0("claude-opus-4-0"),
282292

283293
/**
284294
* The claude-sonnet-4-0 model.
285295
*/
286-
CLAUDE_SONNET_4("claude-sonnet-4-0"),
296+
CLAUDE_SONNET_4_0("claude-sonnet-4-0"),
287297

288298
/**
289299
* The claude-3-7-sonnet-latest model.
@@ -313,18 +323,7 @@ public enum ChatModel implements ChatModelDescription {
313323
/**
314324
* The CLAUDE_3_HAIKU
315325
*/
316-
CLAUDE_3_HAIKU("claude-3-haiku-20240307"),
317-
318-
// Legacy models
319-
/**
320-
* The CLAUDE_2_1 (Deprecated. To be removed on July 21, 2025)
321-
*/
322-
CLAUDE_2_1("claude-2.1"),
323-
324-
/**
325-
* The CLAUDE_2_0 (Deprecated. To be removed on July 21, 2025)
326-
*/
327-
CLAUDE_2("claude-2.0");
326+
CLAUDE_3_HAIKU("claude-3-haiku-20240307");
328327

329328
// @formatter:on
330329

models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/AnthropicPromptCachingIT.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void shouldCacheSystemMessageOnly() {
101101
String systemPrompt = loadPrompt("system-only-cache-prompt.txt");
102102

103103
AnthropicChatOptions options = AnthropicChatOptions.builder()
104-
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4.getValue())
104+
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4_0.getValue())
105105
.cacheOptions(AnthropicCacheOptions.builder().strategy(AnthropicCacheStrategy.SYSTEM_ONLY).build())
106106
.maxTokens(150)
107107
.temperature(0.3)
@@ -142,7 +142,7 @@ void shouldCacheSystemAndTools() {
142142
MockWeatherService weatherService = new MockWeatherService();
143143

144144
AnthropicChatOptions options = AnthropicChatOptions.builder()
145-
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4.getValue())
145+
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4_0.getValue())
146146
.cacheOptions(AnthropicCacheOptions.builder().strategy(AnthropicCacheStrategy.SYSTEM_AND_TOOLS).build())
147147
.maxTokens(200)
148148
.temperature(0.3)
@@ -233,7 +233,7 @@ void shouldCacheConversationHistory() {
233233
String response = chatClient.prompt()
234234
.user("What career advice would you give me based on our conversation?")
235235
.options(AnthropicChatOptions.builder()
236-
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4.getValue())
236+
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4_0.getValue())
237237
.cacheOptions(
238238
AnthropicCacheOptions.builder().strategy(AnthropicCacheStrategy.CONVERSATION_HISTORY).build())
239239
.maxTokens(200)
@@ -258,7 +258,7 @@ void shouldRespectMinLengthForSystemCaching() {
258258
String systemPrompt = loadPrompt("system-only-cache-prompt.txt");
259259

260260
AnthropicChatOptions options = AnthropicChatOptions.builder()
261-
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4.getValue())
261+
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4_0.getValue())
262262
.cacheOptions(AnthropicCacheOptions.builder()
263263
.strategy(AnthropicCacheStrategy.SYSTEM_ONLY)
264264
// Set min length above actual system prompt length to prevent caching
@@ -287,7 +287,7 @@ void shouldRespectMinLengthForUserHistoryCaching() {
287287

288288
// Set USER min length high so caching should not apply
289289
AnthropicChatOptions noCacheOptions = AnthropicChatOptions.builder()
290-
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4.getValue())
290+
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4_0.getValue())
291291
.cacheOptions(AnthropicCacheOptions.builder()
292292
.strategy(AnthropicCacheStrategy.CONVERSATION_HISTORY)
293293
.messageTypeMinContentLength(MessageType.USER, userMessage.length() + 1)
@@ -305,7 +305,7 @@ void shouldRespectMinLengthForUserHistoryCaching() {
305305

306306
// Now allow caching by lowering the USER min length
307307
AnthropicChatOptions cacheOptions = AnthropicChatOptions.builder()
308-
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4.getValue())
308+
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4_0.getValue())
309309
.cacheOptions(AnthropicCacheOptions.builder()
310310
.strategy(AnthropicCacheStrategy.CONVERSATION_HISTORY)
311311
.messageTypeMinContentLength(MessageType.USER, userMessage.length() - 1)
@@ -334,7 +334,7 @@ void shouldRespectAllButLastUserMessageForUserHistoryCaching() {
334334
// The combined length of the first two USER messages exceeds the min length,
335335
// so caching should apply
336336
AnthropicChatOptions cacheOptions = AnthropicChatOptions.builder()
337-
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4.getValue())
337+
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4_0.getValue())
338338
.cacheOptions(AnthropicCacheOptions.builder()
339339
.strategy(AnthropicCacheStrategy.CONVERSATION_HISTORY)
340340
.messageTypeMinContentLength(MessageType.USER, userMessage.length())
@@ -357,7 +357,7 @@ void shouldHandleExtendedTtlCaching() {
357357
String systemPrompt = loadPrompt("extended-ttl-cache-prompt.txt");
358358

359359
AnthropicChatOptions options = AnthropicChatOptions.builder()
360-
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4.getValue())
360+
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4_0.getValue())
361361
.cacheOptions(AnthropicCacheOptions.builder()
362362
.strategy(AnthropicCacheStrategy.SYSTEM_ONLY)
363363
.messageTypeTtl(MessageType.SYSTEM, AnthropicCacheTtl.ONE_HOUR)
@@ -398,7 +398,7 @@ void shouldNotCacheWithNoneStrategy() {
398398
String systemPrompt = "You are a helpful assistant.";
399399

400400
AnthropicChatOptions options = AnthropicChatOptions.builder()
401-
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4.getValue())
401+
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4_0.getValue())
402402
.cacheOptions(AnthropicCacheOptions.builder().strategy(AnthropicCacheStrategy.NONE).build())
403403
.maxTokens(50)
404404
.temperature(0.3)
@@ -428,15 +428,15 @@ void shouldHandleMultipleCacheStrategiesInSession() {
428428
responses.add(this.chatModel.call(new Prompt(
429429
List.of(new SystemMessage("You are a math tutor."), new UserMessage("What is calculus?")),
430430
AnthropicChatOptions.builder()
431-
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4.getValue())
431+
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4_0.getValue())
432432
.cacheOptions(AnthropicCacheOptions.builder().strategy(AnthropicCacheStrategy.SYSTEM_ONLY).build())
433433
.maxTokens(100)
434434
.build())));
435435

436436
// Second: No caching
437437
responses.add(this.chatModel.call(new Prompt(List.of(new UserMessage("What's 5+5?")),
438438
AnthropicChatOptions.builder()
439-
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4.getValue())
439+
.model(AnthropicApi.ChatModel.CLAUDE_SONNET_4_0.getValue())
440440
.cacheOptions(AnthropicCacheOptions.builder().strategy(AnthropicCacheStrategy.NONE).build())
441441
.maxTokens(50)
442442
.build())));

0 commit comments

Comments
 (0)