Add 1m context window model variant for claude sonnet 4 (#5526)
* Add 1m context window model variant for claude sonnet 4 * Fix cost calculation for 1m tier * Add new 1m context window announcement * Create beige-bobcats-watch.md * Add bedrock support for 1m context
This commit is contained in:
1 parent
94acfec39f
commit
79bda976cb
11 files changed
+114
-54
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"claude-dev": patch
|
||||
---
|
||||
|
||||
Add 1m context window model support for claude sonnet 4
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Anthropic } from "@anthropic-ai/sdk"
|
||||
import { Stream as AnthropicStream } from "@anthropic-ai/sdk/streaming"
|
||||
import { withRetry } from "../retry"
|
||||
import { anthropicDefaultModelId, AnthropicModelId, anthropicModels, ApiHandlerOptions, ModelInfo } from "@shared/api"
|
||||
import { anthropicDefaultModelId, AnthropicModelId, anthropicModels, CLAUDE_SONNET_4_1M_SUFFIX, ModelInfo } from "@shared/api"
|
||||
import { ApiHandler } from "../index"
|
||||
import { withRetry } from "../retry"
|
||||
import { ApiStream } from "../transform/stream"
|
||||
|
||||
interface AnthropicHandlerOptions {
|
||||
@@ -43,7 +43,11 @@ export class AnthropicHandler implements ApiHandler {
|
||||
|
||||
const model = this.getModel()
|
||||
let stream: AnthropicStream<Anthropic.RawMessageStreamEvent>
|
||||
const modelId = model.id
|
||||
|
||||
const modelId = model.id.endsWith(CLAUDE_SONNET_4_1M_SUFFIX)
|
||||
? model.id.slice(0, -CLAUDE_SONNET_4_1M_SUFFIX.length)
|
||||
: model.id
|
||||
const enable1mContextWindow = model.id.endsWith(CLAUDE_SONNET_4_1M_SUFFIX)
|
||||
|
||||
const budget_tokens = this.options.thinkingBudgetTokens || 0
|
||||
const reasoningOn = (modelId.includes("3-7") || modelId.includes("4-")) && budget_tokens !== 0 ? true : false
|
||||
@@ -117,25 +121,15 @@ export class AnthropicHandler implements ApiHandler {
|
||||
stream: true,
|
||||
},
|
||||
(() => {
|
||||
// prompt caching: https://x.com/alexalbert__/status/1823751995901272068
|
||||
// https://github.com/anthropics/anthropic-sdk-typescript?tab=readme-ov-file#default-headers
|
||||
// https://github.com/anthropics/anthropic-sdk-typescript/commit/c920b77fc67bd839bfeb6716ceab9d7c9bbe7393
|
||||
switch (modelId) {
|
||||
case "claude-sonnet-4-20250514":
|
||||
case "claude-opus-4-20250514":
|
||||
case "claude-opus-4-1-20250805":
|
||||
case "claude-3-7-sonnet-20250219":
|
||||
case "claude-3-5-sonnet-20241022":
|
||||
case "claude-3-5-haiku-20241022":
|
||||
case "claude-3-opus-20240229":
|
||||
case "claude-3-haiku-20240307":
|
||||
return {
|
||||
headers: {
|
||||
"anthropic-beta": "prompt-caching-2024-07-31",
|
||||
},
|
||||
}
|
||||
default:
|
||||
return undefined
|
||||
// 1m context window beta header
|
||||
if (enable1mContextWindow) {
|
||||
return {
|
||||
headers: {
|
||||
"anthropic-beta": "context-1m-2025-08-07",
|
||||
},
|
||||
}
|
||||
} else {
|
||||
return undefined
|
||||
}
|
||||
})(),
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Anthropic } from "@anthropic-ai/sdk"
|
||||
import { withRetry } from "../retry"
|
||||
import { ApiHandler } from "../"
|
||||
import { convertToR1Format } from "../transform/r1-format"
|
||||
import { bedrockDefaultModelId, BedrockModelId, bedrockModels, ModelInfo } from "@shared/api"
|
||||
import { bedrockDefaultModelId, BedrockModelId, bedrockModels, CLAUDE_SONNET_4_1M_SUFFIX, ModelInfo } from "@shared/api"
|
||||
import { calculateApiCostOpenAI } from "../../utils/cost"
|
||||
import { ApiStream } from "../transform/stream"
|
||||
import { fromNodeProviderChain } from "@aws-sdk/credential-providers"
|
||||
@@ -117,7 +117,14 @@ export class AwsBedrockHandler implements ApiHandler {
|
||||
@withRetry({ maxRetries: 4 })
|
||||
async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream {
|
||||
// cross region inference requires prefixing the model id with the region
|
||||
const modelId = await this.getModelId()
|
||||
const rawModelId = await this.getModelId()
|
||||
|
||||
const modelId = rawModelId.endsWith(CLAUDE_SONNET_4_1M_SUFFIX)
|
||||
? rawModelId.slice(0, -CLAUDE_SONNET_4_1M_SUFFIX.length)
|
||||
: rawModelId
|
||||
|
||||
const enable1mContextWindow = rawModelId.endsWith(CLAUDE_SONNET_4_1M_SUFFIX)
|
||||
|
||||
const model = this.getModel()
|
||||
|
||||
// This baseModelId is used to indicate the capabilities of the model.
|
||||
@@ -139,7 +146,7 @@ export class AwsBedrockHandler implements ApiHandler {
|
||||
}
|
||||
|
||||
// Default: Use Anthropic Converse API for all Anthropic models
|
||||
yield* this.createAnthropicMessage(systemPrompt, messages, modelId, model)
|
||||
yield* this.createAnthropicMessage(systemPrompt, messages, modelId, model, enable1mContextWindow)
|
||||
}
|
||||
|
||||
getModel(): { id: string; info: ModelInfo } {
|
||||
@@ -743,6 +750,7 @@ export class AwsBedrockHandler implements ApiHandler {
|
||||
messages: Anthropic.Messages.MessageParam[],
|
||||
modelId: string,
|
||||
model: { id: string; info: ModelInfo },
|
||||
enable1mContextWindow: boolean,
|
||||
): ApiStream {
|
||||
// Format messages for Anthropic model using unified formatter
|
||||
const formattedMessages = this.formatMessagesForConverseAPI(messages)
|
||||
@@ -773,15 +781,18 @@ export class AwsBedrockHandler implements ApiHandler {
|
||||
messages: messagesWithCache,
|
||||
system: systemMessages,
|
||||
inferenceConfig: this.getInferenceConfig(model.info, "anthropic"),
|
||||
// Add thinking configuration as per LangChain documentation
|
||||
additionalModelRequestFields: reasoningOn
|
||||
? {
|
||||
thinking: {
|
||||
type: "enabled",
|
||||
budget_tokens: budget_tokens,
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
additionalModelRequestFields: {
|
||||
// Add thinking configuration as per LangChain documentation
|
||||
...(reasoningOn && {
|
||||
thinking: {
|
||||
type: "enabled",
|
||||
budget_tokens: budget_tokens,
|
||||
},
|
||||
}),
|
||||
...(enable1mContextWindow && {
|
||||
anthropic_beta: ["context-1m-2025-08-07"],
|
||||
}),
|
||||
},
|
||||
})
|
||||
|
||||
// Execute the streaming request using unified handler
|
||||
|
||||
@@ -146,6 +146,9 @@ export async function createOpenRouterStream(
|
||||
const isKimiK2 = model.id === "moonshotai/kimi-k2"
|
||||
openRouterProviderSorting = isKimiK2 ? undefined : openRouterProviderSorting
|
||||
|
||||
// Force 1m context window for Claude Sonnet 4
|
||||
const isClaudeSonnet4 = model.id === "anthropic/claude-sonnet-4"
|
||||
|
||||
// @ts-ignore-next-line
|
||||
const stream = await client.chat.completions.create({
|
||||
model: model.id,
|
||||
@@ -164,6 +167,8 @@ export async function createOpenRouterStream(
|
||||
...(isKimiK2
|
||||
? { provider: { order: ["groq", "together", "baseten", "parasail", "novita", "deepinfra"], allow_fallbacks: false } }
|
||||
: {}),
|
||||
// limit providers to only those that support the 1m context window
|
||||
...(isClaudeSonnet4 ? { provider: { order: ["anthropic", "amazon-bedrock"], allow_fallbacks: false } } : {}),
|
||||
})
|
||||
|
||||
return stream
|
||||
|
||||
@@ -6,6 +6,7 @@ import path from "path"
|
||||
import fs from "fs/promises"
|
||||
import { fileExistsAtPath } from "@utils/fs"
|
||||
import { GlobalFileNames } from "@core/storage/disk"
|
||||
import { CLAUDE_SONNET_4_1M_TIERS } from "@/shared/api"
|
||||
|
||||
/**
|
||||
* Refreshes the OpenRouter models and returns the updated model list
|
||||
@@ -49,6 +50,12 @@ export async function refreshOpenRouterModels(
|
||||
|
||||
switch (rawModel.id) {
|
||||
case "anthropic/claude-sonnet-4":
|
||||
modelInfo.supportsPromptCache = true
|
||||
modelInfo.cacheWritesPrice = 3.75
|
||||
modelInfo.cacheReadsPrice = 0.3
|
||||
modelInfo.contextWindow = 1_000_000 // limiting providers to those that support 1m context window
|
||||
modelInfo.tiers = CLAUDE_SONNET_4_1M_TIERS
|
||||
break
|
||||
case "anthropic/claude-3-7-sonnet":
|
||||
case "anthropic/claude-3-7-sonnet:beta":
|
||||
case "anthropic/claude-3.7-sonnet":
|
||||
|
||||
+42
-1
@@ -200,11 +200,40 @@ export interface OpenAiCompatibleModelInfo extends ModelInfo {
|
||||
isR1FormatRequired?: boolean
|
||||
}
|
||||
|
||||
export const CLAUDE_SONNET_4_1M_SUFFIX = ":1m"
|
||||
export const CLAUDE_SONNET_4_1M_TIERS = [
|
||||
{
|
||||
contextWindow: 200000,
|
||||
inputPrice: 3.0,
|
||||
outputPrice: 15,
|
||||
cacheWritesPrice: 3.75,
|
||||
cacheReadsPrice: 0.3,
|
||||
},
|
||||
{
|
||||
contextWindow: Number.MAX_SAFE_INTEGER, // storing infinity in vs storage is not possible, it converts to 'null', which causes crash in webview ModelInfoView
|
||||
inputPrice: 6,
|
||||
outputPrice: 22.5,
|
||||
cacheWritesPrice: 7.5,
|
||||
cacheReadsPrice: 0.6,
|
||||
},
|
||||
]
|
||||
|
||||
// Anthropic
|
||||
// https://docs.anthropic.com/en/docs/about-claude/models // prices updated 2025-01-02
|
||||
export type AnthropicModelId = keyof typeof anthropicModels
|
||||
export const anthropicDefaultModelId: AnthropicModelId = "claude-sonnet-4-20250514"
|
||||
export const anthropicModels = {
|
||||
"claude-sonnet-4-20250514:1m": {
|
||||
maxTokens: 8192,
|
||||
contextWindow: 1_000_000,
|
||||
supportsImages: true,
|
||||
supportsPromptCache: true,
|
||||
inputPrice: 3.0,
|
||||
outputPrice: 15.0,
|
||||
cacheWritesPrice: 3.75,
|
||||
cacheReadsPrice: 0.3,
|
||||
tiers: CLAUDE_SONNET_4_1M_TIERS,
|
||||
},
|
||||
"claude-sonnet-4-20250514": {
|
||||
maxTokens: 8192,
|
||||
contextWindow: 200_000,
|
||||
@@ -331,6 +360,17 @@ export const claudeCodeModels = {
|
||||
export type BedrockModelId = keyof typeof bedrockModels
|
||||
export const bedrockDefaultModelId: BedrockModelId = "anthropic.claude-sonnet-4-20250514-v1:0"
|
||||
export const bedrockModels = {
|
||||
"anthropic.claude-sonnet-4-20250514-v1:0:1m": {
|
||||
maxTokens: 8192,
|
||||
contextWindow: 1_000_000,
|
||||
supportsImages: true,
|
||||
supportsPromptCache: true,
|
||||
inputPrice: 3.0,
|
||||
outputPrice: 15.0,
|
||||
cacheWritesPrice: 3.75,
|
||||
cacheReadsPrice: 0.3,
|
||||
tiers: CLAUDE_SONNET_4_1M_TIERS,
|
||||
},
|
||||
"anthropic.claude-sonnet-4-20250514-v1:0": {
|
||||
maxTokens: 8192,
|
||||
contextWindow: 200_000,
|
||||
@@ -482,7 +522,7 @@ export const bedrockModels = {
|
||||
export const openRouterDefaultModelId = "anthropic/claude-sonnet-4" // will always exist in openRouterModels
|
||||
export const openRouterDefaultModelInfo: ModelInfo = {
|
||||
maxTokens: 8192,
|
||||
contextWindow: 200_000,
|
||||
contextWindow: 1_000_000,
|
||||
supportsImages: true,
|
||||
|
||||
supportsPromptCache: true,
|
||||
@@ -490,6 +530,7 @@ export const openRouterDefaultModelInfo: ModelInfo = {
|
||||
outputPrice: 15.0,
|
||||
cacheWritesPrice: 3.75,
|
||||
cacheReadsPrice: 0.3,
|
||||
tiers: CLAUDE_SONNET_4_1M_TIERS,
|
||||
description:
|
||||
"Claude Sonnet 4 delivers superior intelligence across coding, agentic search, and AI agent capabilities. It's a powerful choice for agentic coding, and can complete tasks across the entire software development lifecycle—from initial planning to bug fixes, maintenance to large refactors. It offers strong performance in both planning and solving for complex coding tasks, making it an ideal choice to power end-to-end software development processes.\n\nRead more in the [blog post here](https://www.anthropic.com/claude/sonnet)",
|
||||
}
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ export function calculateApiCostAnthropic(
|
||||
outputTokens,
|
||||
cacheCreationInputTokensNum,
|
||||
cacheReadInputTokensNum,
|
||||
inputTokens,
|
||||
inputTokens + cacheCreationInputTokensNum + cacheReadInputTokensNum, // used for tiered price lookup
|
||||
thinkingBudgetTokens,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -44,20 +44,12 @@ const Announcement = ({ version, hideAnnouncement }: AnnouncementProps) => {
|
||||
<h3 style={h3TitleStyle}>
|
||||
🎉{" "}New in v{minorVersion}
|
||||
</h3>
|
||||
<ul style={ulStyle}>
|
||||
<li>
|
||||
<b>GPT-5 Model Support:</b> Added support for the new GPT-5 model family including GPT-5, GPT-5 Mini, and
|
||||
GPT-5 Nano with prompt caching support. GPT-5 is now the default model for new users.
|
||||
</li>
|
||||
<li>
|
||||
<b>Improved Onboarding:</b> New users now see a "Take a Tour" button that opens the VSCode walkthrough to help
|
||||
them get started with Cline more easily.
|
||||
</li>
|
||||
<li>
|
||||
<b>Enhanced Plan Mode:</b> Better exploration parameter support in plan mode for more thorough planning before
|
||||
execution.
|
||||
</li>
|
||||
</ul>
|
||||
<b>1M Context Window:</b> Claude Sonnet 4 now supports a 1 million token context window to handle larger codebases and
|
||||
more complex tasks. Cline/OpenRouter users get instant access, Anthropic users with Tier 4 access can select the{" "}
|
||||
<code>
|
||||
claude-sonnet-4-20250514<b>:1m</b>
|
||||
</code>{" "}
|
||||
model.
|
||||
<Accordion isCompact className="pl-0">
|
||||
<AccordionItem
|
||||
key="1"
|
||||
|
||||
@@ -33,13 +33,13 @@ const formatTiers = (
|
||||
return (
|
||||
<span style={{ paddingLeft: "15px" }} key={index}>
|
||||
{formatPrice(price)}/million tokens (
|
||||
{tier.contextWindow === Number.POSITIVE_INFINITY ? (
|
||||
{tier.contextWindow === Number.POSITIVE_INFINITY || tier.contextWindow >= Number.MAX_SAFE_INTEGER ? (
|
||||
<span>
|
||||
{">"} {prevLimit.toLocaleString()}
|
||||
</span>
|
||||
) : (
|
||||
<span>
|
||||
{"<="} {tier.contextWindow.toLocaleString()}
|
||||
{"<="} {tier.contextWindow?.toLocaleString()}
|
||||
</span>
|
||||
)}
|
||||
{" tokens)"}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { anthropicModels } from "@shared/api"
|
||||
import { anthropicModels, CLAUDE_SONNET_4_1M_SUFFIX } from "@shared/api"
|
||||
import { ApiKeyField } from "../common/ApiKeyField"
|
||||
import { BaseUrlField } from "../common/BaseUrlField"
|
||||
import { ModelSelector } from "../common/ModelSelector"
|
||||
@@ -13,6 +13,7 @@ import { Mode } from "@shared/storage/types"
|
||||
export const SUPPORTED_ANTHROPIC_THINKING_MODELS = [
|
||||
"claude-3-7-sonnet-20250219",
|
||||
"claude-sonnet-4-20250514",
|
||||
`claude-sonnet-4-20250514${CLAUDE_SONNET_4_1M_SUFFIX}`,
|
||||
"claude-opus-4-20250514",
|
||||
"claude-opus-4-1-20250805",
|
||||
]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { bedrockDefaultModelId, bedrockModels } from "@shared/api"
|
||||
import { bedrockDefaultModelId, bedrockModels, CLAUDE_SONNET_4_1M_SUFFIX } from "@shared/api"
|
||||
import { VSCodeCheckbox, VSCodeDropdown, VSCodeOption, VSCodeRadio, VSCodeRadioGroup } from "@vscode/webview-ui-toolkit/react"
|
||||
import { useState } from "react"
|
||||
import { DebouncedTextField } from "../common/DebouncedTextField"
|
||||
@@ -314,12 +314,16 @@ export const BedrockProvider = ({ showModelOptions, isPopup, currentMode }: Bedr
|
||||
|
||||
{(selectedModelId === "anthropic.claude-3-7-sonnet-20250219-v1:0" ||
|
||||
selectedModelId === "anthropic.claude-sonnet-4-20250514-v1:0" ||
|
||||
selectedModelId === `anthropic.claude-sonnet-4-20250514-v1:0${CLAUDE_SONNET_4_1M_SUFFIX}` ||
|
||||
selectedModelId === "anthropic.claude-opus-4-1-20250805-v1:0" ||
|
||||
selectedModelId === "anthropic.claude-opus-4-20250514-v1:0" ||
|
||||
(modeFields.awsBedrockCustomSelected &&
|
||||
modeFields.awsBedrockCustomModelBaseId === "anthropic.claude-3-7-sonnet-20250219-v1:0") ||
|
||||
(modeFields.awsBedrockCustomSelected &&
|
||||
modeFields.awsBedrockCustomModelBaseId === "anthropic.claude-sonnet-4-20250514-v1:0") ||
|
||||
(modeFields.awsBedrockCustomSelected &&
|
||||
modeFields.awsBedrockCustomModelBaseId ===
|
||||
`anthropic.claude-sonnet-4-20250514-v1:0${CLAUDE_SONNET_4_1M_SUFFIX}`) ||
|
||||
(modeFields.awsBedrockCustomSelected &&
|
||||
modeFields.awsBedrockCustomModelBaseId === "anthropic.claude-opus-4-1-20250805-v1:0") ||
|
||||
(modeFields.awsBedrockCustomSelected &&
|
||||
|
||||
Reference in new issue
Block a user