Skip to content

Commit 6a91385

Browse files
authored
feat: add Claude 4.5 Sonnet model across all providers (#8368)
1 parent c943ba7 commit 6a91385

File tree

9 files changed

+98
-5
lines changed

9 files changed

+98
-5
lines changed

packages/types/src/providers/anthropic.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,28 @@ export type AnthropicModelId = keyof typeof anthropicModels
66
export const anthropicDefaultModelId: AnthropicModelId = "claude-sonnet-4-20250514"
77

88
export const anthropicModels = {
9+
"claude-4.5-sonnet": {
10+
maxTokens: 64_000, // Overridden to 8k if `enableReasoningEffort` is false.
11+
contextWindow: 200_000, // Default 200K, extendable to 1M with beta flag 'context-1m-2025-08-07'
12+
supportsImages: true,
13+
supportsComputerUse: true,
14+
supportsPromptCache: true,
15+
inputPrice: 3.0, // $3 per million input tokens (≤200K context)
16+
outputPrice: 15.0, // $15 per million output tokens (≤200K context)
17+
cacheWritesPrice: 3.75, // $3.75 per million tokens
18+
cacheReadsPrice: 0.3, // $0.30 per million tokens
19+
supportsReasoningBudget: true,
20+
// Tiered pricing for extended context (requires beta flag 'context-1m-2025-08-07')
21+
tiers: [
22+
{
23+
contextWindow: 1_000_000, // 1M tokens with beta flag
24+
inputPrice: 6.0, // $6 per million input tokens (>200K context)
25+
outputPrice: 22.5, // $22.50 per million output tokens (>200K context)
26+
cacheWritesPrice: 7.5, // $7.50 per million tokens (>200K context)
27+
cacheReadsPrice: 0.6, // $0.60 per million tokens (>200K context)
28+
},
29+
],
30+
},
931
"claude-sonnet-4-20250514": {
1032
maxTokens: 64_000, // Overridden to 8k if `enableReasoningEffort` is false.
1133
contextWindow: 200_000, // Default 200K, extendable to 1M with beta flag 'context-1m-2025-08-07'

packages/types/src/providers/bedrock.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ export const bedrockDefaultPromptRouterModelId: BedrockModelId = "anthropic.clau
1313
// of the default prompt routers AWS enabled for GA of the promot router
1414
// feature.
1515
export const bedrockModels = {
16+
"anthropic.claude-4.5-sonnet-v1:0": {
17+
maxTokens: 8192,
18+
contextWindow: 200_000,
19+
supportsImages: true,
20+
supportsComputerUse: true,
21+
supportsPromptCache: true,
22+
supportsReasoningBudget: true,
23+
inputPrice: 3.0,
24+
outputPrice: 15.0,
25+
cacheWritesPrice: 3.75,
26+
cacheReadsPrice: 0.3,
27+
minTokensPerCachePoint: 1024,
28+
maxCachePoints: 4,
29+
cachableFields: ["system", "messages", "tools"],
30+
},
1631
"amazon.nova-pro-v1:0": {
1732
maxTokens: 5000,
1833
contextWindow: 300_000,

packages/types/src/providers/claude-code.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ export function getClaudeCodeModelId(baseModelId: ClaudeCodeModelId, useVertex =
4040
}
4141

4242
export const claudeCodeModels = {
43+
"claude-4.5-sonnet": {
44+
...anthropicModels["claude-4.5-sonnet"],
45+
supportsImages: false,
46+
supportsPromptCache: true, // Claude Code does report cache tokens
47+
supportsReasoningEffort: false,
48+
supportsReasoningBudget: false,
49+
requiredReasoningBudget: false,
50+
},
4351
"claude-sonnet-4-20250514": {
4452
...anthropicModels["claude-sonnet-4-20250514"],
4553
supportsImages: false,

packages/types/src/providers/openrouter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const OPEN_ROUTER_PROMPT_CACHING_MODELS = new Set([
3838
"anthropic/claude-3.7-sonnet:beta",
3939
"anthropic/claude-3.7-sonnet:thinking",
4040
"anthropic/claude-sonnet-4",
41+
"anthropic/claude-4.5-sonnet",
4142
"anthropic/claude-opus-4",
4243
"anthropic/claude-opus-4.1",
4344
"google/gemini-2.5-flash-preview",
@@ -59,6 +60,7 @@ export const OPEN_ROUTER_COMPUTER_USE_MODELS = new Set([
5960
"anthropic/claude-3.7-sonnet:beta",
6061
"anthropic/claude-3.7-sonnet:thinking",
6162
"anthropic/claude-sonnet-4",
63+
"anthropic/claude-4.5-sonnet",
6264
"anthropic/claude-opus-4",
6365
"anthropic/claude-opus-4.1",
6466
])
@@ -81,6 +83,7 @@ export const OPEN_ROUTER_REASONING_BUDGET_MODELS = new Set([
8183
"anthropic/claude-opus-4",
8284
"anthropic/claude-opus-4.1",
8385
"anthropic/claude-sonnet-4",
86+
"anthropic/claude-4.5-sonnet",
8487
"google/gemini-2.5-pro-preview",
8588
"google/gemini-2.5-pro",
8689
"google/gemini-2.5-flash-preview-05-20",

packages/types/src/providers/vertex.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ export type VertexModelId = keyof typeof vertexModels
66
export const vertexDefaultModelId: VertexModelId = "claude-sonnet-4@20250514"
77

88
export const vertexModels = {
9+
"claude-4.5-sonnet": {
10+
maxTokens: 8192,
11+
contextWindow: 200_000,
12+
supportsImages: true,
13+
supportsComputerUse: true,
14+
supportsPromptCache: true,
15+
inputPrice: 3.0,
16+
outputPrice: 15.0,
17+
cacheWritesPrice: 3.75,
18+
cacheReadsPrice: 0.3,
19+
supportsReasoningBudget: true,
20+
},
921
"gemini-2.5-flash-preview-05-20:thinking": {
1022
maxTokens: 65_535,
1123
contextWindow: 1_048_576,

src/api/providers/__tests__/anthropic.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,5 +264,29 @@ describe("AnthropicHandler", () => {
264264
expect(result.reasoningBudget).toBeUndefined()
265265
expect(result.temperature).toBe(0)
266266
})
267+
268+
it("should handle Claude 4.5 Sonnet model correctly", () => {
269+
const handler = new AnthropicHandler({
270+
apiKey: "test-api-key",
271+
apiModelId: "claude-4.5-sonnet",
272+
})
273+
const model = handler.getModel()
274+
expect(model.id).toBe("claude-4.5-sonnet")
275+
expect(model.info.maxTokens).toBe(64000)
276+
expect(model.info.contextWindow).toBe(200000)
277+
expect(model.info.supportsReasoningBudget).toBe(true)
278+
})
279+
280+
it("should enable 1M context for Claude 4.5 Sonnet when beta flag is set", () => {
281+
const handler = new AnthropicHandler({
282+
apiKey: "test-api-key",
283+
apiModelId: "claude-4.5-sonnet",
284+
anthropicBeta1MContext: true,
285+
})
286+
const model = handler.getModel()
287+
expect(model.info.contextWindow).toBe(1000000)
288+
expect(model.info.inputPrice).toBe(6.0)
289+
expect(model.info.outputPrice).toBe(22.5)
290+
})
267291
})
268292
})

src/api/providers/anthropic.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,16 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
4545
const cacheControl: CacheControlEphemeral = { type: "ephemeral" }
4646
let { id: modelId, betas = [], maxTokens, temperature, reasoning: thinking } = this.getModel()
4747

48-
// Add 1M context beta flag if enabled for Claude Sonnet 4
49-
if (modelId === "claude-sonnet-4-20250514" && this.options.anthropicBeta1MContext) {
48+
// Add 1M context beta flag if enabled for Claude Sonnet 4 and 4.5
49+
if (
50+
(modelId === "claude-sonnet-4-20250514" || modelId === "claude-4.5-sonnet") &&
51+
this.options.anthropicBeta1MContext
52+
) {
5053
betas.push("context-1m-2025-08-07")
5154
}
5255

5356
switch (modelId) {
57+
case "claude-4.5-sonnet":
5458
case "claude-sonnet-4-20250514":
5559
case "claude-opus-4-1-20250805":
5660
case "claude-opus-4-20250514":
@@ -110,6 +114,7 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
110114

111115
// Then check for models that support prompt caching
112116
switch (modelId) {
117+
case "claude-4.5-sonnet":
113118
case "claude-sonnet-4-20250514":
114119
case "claude-opus-4-1-20250805":
115120
case "claude-opus-4-20250514":
@@ -243,8 +248,8 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
243248
let id = modelId && modelId in anthropicModels ? (modelId as AnthropicModelId) : anthropicDefaultModelId
244249
let info: ModelInfo = anthropicModels[id]
245250

246-
// If 1M context beta is enabled for Claude Sonnet 4, update the model info
247-
if (id === "claude-sonnet-4-20250514" && this.options.anthropicBeta1MContext) {
251+
// If 1M context beta is enabled for Claude Sonnet 4 or 4.5, update the model info
252+
if ((id === "claude-sonnet-4-20250514" || id === "claude-4.5-sonnet") && this.options.anthropicBeta1MContext) {
248253
// Use the tier pricing for 1M context
249254
const tier = info.tiers?.[0]
250255
if (tier) {

src/api/providers/fetchers/__tests__/openrouter.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe("OpenRouter API", () => {
3434
"google/gemini-2.5-flash", // OpenRouter doesn't report this as supporting prompt caching
3535
"google/gemini-2.5-flash-lite-preview-06-17", // OpenRouter doesn't report this as supporting prompt caching
3636
"anthropic/claude-opus-4.1", // Not yet available in OpenRouter API
37+
"anthropic/claude-4.5-sonnet", // Not yet available in OpenRouter API
3738
])
3839

3940
const ourCachingModels = Array.from(OPEN_ROUTER_PROMPT_CACHING_MODELS).filter(
@@ -52,6 +53,7 @@ describe("OpenRouter API", () => {
5253

5354
const excludedComputerUseModels = new Set([
5455
"anthropic/claude-opus-4.1", // Not yet available in OpenRouter API
56+
"anthropic/claude-4.5-sonnet", // Not yet available in OpenRouter API
5557
])
5658

5759
const expectedComputerUseModels = Array.from(OPEN_ROUTER_COMPUTER_USE_MODELS)
@@ -134,6 +136,7 @@ describe("OpenRouter API", () => {
134136
"google/gemini-2.5-flash-lite-preview-06-17",
135137
"google/gemini-2.5-pro",
136138
"anthropic/claude-opus-4.1", // Not yet available in OpenRouter API
139+
"anthropic/claude-4.5-sonnet", // Not yet available in OpenRouter API
137140
])
138141

139142
const expectedReasoningBudgetModels = Array.from(OPEN_ROUTER_REASONING_BUDGET_MODELS)

webview-ui/src/components/settings/providers/Anthropic.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export const Anthropic = ({ apiConfiguration, setApiConfigurationField }: Anthro
2222
const [anthropicBaseUrlSelected, setAnthropicBaseUrlSelected] = useState(!!apiConfiguration?.anthropicBaseUrl)
2323

2424
// Check if the current model supports 1M context beta
25-
const supports1MContextBeta = selectedModel?.id === "claude-sonnet-4-20250514"
25+
const supports1MContextBeta =
26+
selectedModel?.id === "claude-sonnet-4-20250514" || selectedModel?.id === "claude-4.5-sonnet"
2627

2728
const handleInputChange = useCallback(
2829
<K extends keyof ProviderSettings, E>(

0 commit comments

Comments
 (0)