Skip to content

Commit 8a8fadd

Browse files
shariqriazzcte
andauthored
Add Claude Sonnet 4 and Claude Opus 4 models with thinking variants (#3844)
Co-authored-by: cte <[email protected]>
1 parent edcaa15 commit 8a8fadd

File tree

2 files changed

+143
-3
lines changed

2 files changed

+143
-3
lines changed

src/api/providers/anthropic.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
3636
let { id: modelId, maxTokens, thinking, temperature, virtualId } = this.getModel()
3737

3838
switch (modelId) {
39+
case "claude-sonnet-4-20250514":
40+
case "claude-opus-4-20250514":
3941
case "claude-3-7-sonnet-20250219":
4042
case "claude-3-5-sonnet-20241022":
4143
case "claude-3-5-haiku-20241022":
@@ -92,13 +94,16 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
9294

9395
const betas = []
9496

95-
// Check for the thinking-128k variant first
97+
// Enable extended thinking for Claude 3.7 Sonnet only.
98+
// https://docs.anthropic.com/en/docs/about-claude/models/migrating-to-claude-4#extended-output-no-longer-supported
9699
if (virtualId === "claude-3-7-sonnet-20250219:thinking") {
97100
betas.push("output-128k-2025-02-19")
98101
}
99102

100103
// Then check for models that support prompt caching
101104
switch (modelId) {
105+
case "claude-sonnet-4-20250514":
106+
case "claude-opus-4-20250514":
102107
case "claude-3-7-sonnet-20250219":
103108
case "claude-3-5-sonnet-20241022":
104109
case "claude-3-5-haiku-20241022":
@@ -202,11 +207,14 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
202207
// Track the original model ID for special variant handling
203208
const virtualId = id
204209

205-
// The `:thinking` variant is a virtual identifier for the
206-
// `claude-3-7-sonnet-20250219` model with a thinking budget.
210+
// The `:thinking` variants are virtual identifiers for models with a thinking budget.
207211
// We can handle this more elegantly in the future.
208212
if (id === "claude-3-7-sonnet-20250219:thinking") {
209213
id = "claude-3-7-sonnet-20250219"
214+
} else if (id === "claude-sonnet-4-20250514:thinking") {
215+
id = "claude-sonnet-4-20250514"
216+
} else if (id === "claude-opus-4-20250514:thinking") {
217+
id = "claude-opus-4-20250514"
210218
}
211219

212220
return {

src/shared/api.ts

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,54 @@ export type ApiHandlerOptions = Omit<ProviderSettings, "apiProvider" | "id">
99
export type AnthropicModelId = keyof typeof anthropicModels
1010
export const anthropicDefaultModelId: AnthropicModelId = "claude-3-7-sonnet-20250219"
1111
export const anthropicModels = {
12+
"claude-sonnet-4-20250514:thinking": {
13+
maxTokens: 64_000,
14+
contextWindow: 200_000,
15+
supportsImages: true,
16+
supportsComputerUse: true,
17+
supportsPromptCache: true,
18+
inputPrice: 3.0, // $3 per million input tokens
19+
outputPrice: 15.0, // $15 per million output tokens
20+
cacheWritesPrice: 3.75, // $3.75 per million tokens
21+
cacheReadsPrice: 0.3, // $0.30 per million tokens
22+
thinking: true,
23+
},
24+
"claude-sonnet-4-20250514": {
25+
maxTokens: 8192,
26+
contextWindow: 200_000,
27+
supportsImages: true,
28+
supportsComputerUse: true,
29+
supportsPromptCache: true,
30+
inputPrice: 3.0, // $3 per million input tokens
31+
outputPrice: 15.0, // $15 per million output tokens
32+
cacheWritesPrice: 3.75, // $3.75 per million tokens
33+
cacheReadsPrice: 0.3, // $0.30 per million tokens
34+
thinking: false,
35+
},
36+
"claude-opus-4-20250514:thinking": {
37+
maxTokens: 64_000,
38+
contextWindow: 200_000,
39+
supportsImages: true,
40+
supportsComputerUse: true,
41+
supportsPromptCache: true,
42+
inputPrice: 15.0, // $15 per million input tokens
43+
outputPrice: 75.0, // $75 per million output tokens
44+
cacheWritesPrice: 18.75, // $18.75 per million tokens
45+
cacheReadsPrice: 1.5, // $1.50 per million tokens
46+
thinking: true,
47+
},
48+
"claude-opus-4-20250514": {
49+
maxTokens: 8192,
50+
contextWindow: 200_000,
51+
supportsImages: true,
52+
supportsComputerUse: true,
53+
supportsPromptCache: true,
54+
inputPrice: 15.0, // $15 per million input tokens
55+
outputPrice: 75.0, // $75 per million output tokens
56+
cacheWritesPrice: 18.75, // $18.75 per million tokens
57+
cacheReadsPrice: 1.5, // $1.50 per million tokens
58+
thinking: false,
59+
},
1260
"claude-3-7-sonnet-20250219:thinking": {
1361
maxTokens: 128_000,
1462
contextWindow: 200_000,
@@ -160,6 +208,34 @@ export const bedrockModels = {
160208
maxCachePoints: 1,
161209
cachableFields: ["system"],
162210
},
211+
"anthropic.claude-sonnet-4-20250514-v1:0": {
212+
maxTokens: 8192,
213+
contextWindow: 200_000,
214+
supportsImages: true,
215+
supportsComputerUse: true,
216+
supportsPromptCache: true,
217+
inputPrice: 3.0,
218+
outputPrice: 15.0,
219+
cacheWritesPrice: 3.75,
220+
cacheReadsPrice: 0.3,
221+
minTokensPerCachePoint: 1024,
222+
maxCachePoints: 4,
223+
cachableFields: ["system", "messages", "tools"],
224+
},
225+
"anthropic.claude-opus-4-20250514-v1:0": {
226+
maxTokens: 8192,
227+
contextWindow: 200_000,
228+
supportsImages: true,
229+
supportsComputerUse: true,
230+
supportsPromptCache: true,
231+
inputPrice: 15.0,
232+
outputPrice: 75.0,
233+
cacheWritesPrice: 18.75,
234+
cacheReadsPrice: 1.5,
235+
minTokensPerCachePoint: 1024,
236+
maxCachePoints: 4,
237+
cachableFields: ["system", "messages", "tools"],
238+
},
163239
"anthropic.claude-3-7-sonnet-20250219-v1:0": {
164240
maxTokens: 8192,
165241
contextWindow: 200_000,
@@ -582,6 +658,54 @@ export const vertexModels = {
582658
inputPrice: 1.25,
583659
outputPrice: 5,
584660
},
661+
"claude-sonnet-4-20250514:thinking": {
662+
maxTokens: 64_000,
663+
contextWindow: 200_000,
664+
supportsImages: true,
665+
supportsComputerUse: true,
666+
supportsPromptCache: true,
667+
inputPrice: 3.0,
668+
outputPrice: 15.0,
669+
cacheWritesPrice: 3.75,
670+
cacheReadsPrice: 0.3,
671+
thinking: true,
672+
},
673+
"claude-sonnet-4-20250514": {
674+
maxTokens: 8192,
675+
contextWindow: 200_000,
676+
supportsImages: true,
677+
supportsComputerUse: true,
678+
supportsPromptCache: true,
679+
inputPrice: 3.0,
680+
outputPrice: 15.0,
681+
cacheWritesPrice: 3.75,
682+
cacheReadsPrice: 0.3,
683+
thinking: false,
684+
},
685+
"claude-opus-4-20250514:thinking": {
686+
maxTokens: 64_000,
687+
contextWindow: 200_000,
688+
supportsImages: true,
689+
supportsComputerUse: true,
690+
supportsPromptCache: true,
691+
inputPrice: 15.0,
692+
outputPrice: 75.0,
693+
cacheWritesPrice: 18.75,
694+
cacheReadsPrice: 1.5,
695+
thinking: true,
696+
},
697+
"claude-opus-4-20250514": {
698+
maxTokens: 8192,
699+
contextWindow: 200_000,
700+
supportsImages: true,
701+
supportsComputerUse: true,
702+
supportsPromptCache: true,
703+
inputPrice: 15.0,
704+
outputPrice: 75.0,
705+
cacheWritesPrice: 18.75,
706+
cacheReadsPrice: 1.5,
707+
thinking: false,
708+
},
585709
"claude-3-7-sonnet@20250219:thinking": {
586710
maxTokens: 64_000,
587711
contextWindow: 200_000,
@@ -1797,6 +1921,10 @@ export const PROMPT_CACHING_MODELS = new Set([
17971921
"anthropic/claude-3.7-sonnet",
17981922
"anthropic/claude-3.7-sonnet:beta",
17991923
"anthropic/claude-3.7-sonnet:thinking",
1924+
"anthropic/claude-sonnet-4-20250514",
1925+
"anthropic/claude-sonnet-4-20250514:thinking",
1926+
"anthropic/claude-opus-4-20250514",
1927+
"anthropic/claude-opus-4-20250514:thinking",
18001928
"google/gemini-2.5-pro-preview",
18011929
"google/gemini-2.5-flash-preview",
18021930
"google/gemini-2.5-flash-preview:thinking",
@@ -1814,6 +1942,10 @@ export const COMPUTER_USE_MODELS = new Set([
18141942
"anthropic/claude-3.7-sonnet",
18151943
"anthropic/claude-3.7-sonnet:beta",
18161944
"anthropic/claude-3.7-sonnet:thinking",
1945+
"anthropic/claude-sonnet-4-20250514",
1946+
"anthropic/claude-sonnet-4-20250514:thinking",
1947+
"anthropic/claude-opus-4-20250514",
1948+
"anthropic/claude-opus-4-20250514:thinking",
18171949
])
18181950

18191951
const routerNames = ["openrouter", "requesty", "glama", "unbound", "litellm"] as const

0 commit comments

Comments
 (0)