Add support for 200k context for claude sonnet 4 using openrouter/cline (#5569)
* Add support for 200k context for claude sonnet 4 using openrouter/cline * Update announcement * Create beige-singers-jog.md
This commit is contained in:
1 parent
3175e19bd7
commit
fbc517c9e5
6 files changed
+65
-22
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"claude-dev": patch
|
||||
---
|
||||
|
||||
Add support for 200k context for claude sonnet 4 using openrouter/cline
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ModelInfo } from "@shared/api"
|
||||
import { CLAUDE_SONNET_4_1M_SUFFIX, ModelInfo, openRouterClaudeSonnet41mModelId } from "@shared/api"
|
||||
import { convertToOpenAiMessages } from "@api/transform/openai-format"
|
||||
import { convertToR1Format } from "@api/transform/r1-format"
|
||||
import { Anthropic } from "@anthropic-ai/sdk"
|
||||
@@ -19,6 +19,12 @@ export async function createOpenRouterStream(
|
||||
...convertToOpenAiMessages(messages),
|
||||
]
|
||||
|
||||
const isClaudeSonnet41m = model.id === openRouterClaudeSonnet41mModelId
|
||||
if (isClaudeSonnet41m) {
|
||||
// remove the custom :1m suffix, to create the model id openrouter API expects
|
||||
model.id = model.id.slice(0, -CLAUDE_SONNET_4_1M_SUFFIX.length)
|
||||
}
|
||||
|
||||
// prompt caching: https://openrouter.ai/docs/prompt-caching
|
||||
// this was initially specifically for claude models (some models may 'support prompt caching' automatically without this)
|
||||
// handles direct model.id match logic
|
||||
@@ -146,9 +152,6 @@ 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,
|
||||
@@ -168,7 +171,7 @@ export async function createOpenRouterStream(
|
||||
? { 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 } } : {}),
|
||||
...(isClaudeSonnet41m ? { provider: { order: ["anthropic", "amazon-bedrock"], allow_fallbacks: false } } : {}),
|
||||
})
|
||||
|
||||
return stream
|
||||
|
||||
@@ -6,7 +6,8 @@ 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"
|
||||
import { CLAUDE_SONNET_4_1M_TIERS, openRouterClaudeSonnet41mModelId } from "@/shared/api"
|
||||
import cloneDeep from "clone-deep"
|
||||
|
||||
/**
|
||||
* Refreshes the OpenRouter models and returns the updated model list
|
||||
@@ -50,12 +51,6 @@ 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":
|
||||
@@ -147,6 +142,14 @@ export async function refreshOpenRouterModels(
|
||||
}
|
||||
|
||||
models[rawModel.id] = modelInfo
|
||||
|
||||
// add custom :1m model variant
|
||||
if (rawModel.id === "anthropic/claude-sonnet-4") {
|
||||
const claudeSonnet41mModelInfo = cloneDeep(modelInfo)
|
||||
claudeSonnet41mModelInfo.contextWindow = 1_000_000 // limiting providers to those that support 1m context window
|
||||
claudeSonnet41mModelInfo.tiers = CLAUDE_SONNET_4_1M_TIERS
|
||||
models[openRouterClaudeSonnet41mModelId] = claudeSonnet41mModelInfo
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.error("Invalid response from OpenRouter API")
|
||||
|
||||
+2
-3
@@ -521,17 +521,16 @@ export const bedrockModels = {
|
||||
// OpenRouter
|
||||
// https://openrouter.ai/models?order=newest&supported_parameters=tools
|
||||
export const openRouterDefaultModelId = "anthropic/claude-sonnet-4" // will always exist in openRouterModels
|
||||
export const openRouterClaudeSonnet41mModelId = `anthropic/claude-sonnet-4${CLAUDE_SONNET_4_1M_SUFFIX}`
|
||||
export const openRouterDefaultModelInfo: ModelInfo = {
|
||||
maxTokens: 8192,
|
||||
contextWindow: 1_000_000,
|
||||
contextWindow: 200_000,
|
||||
supportsImages: true,
|
||||
|
||||
supportsPromptCache: true,
|
||||
inputPrice: 3.0,
|
||||
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)",
|
||||
}
|
||||
|
||||
@@ -45,11 +45,12 @@ const Announcement = ({ version, hideAnnouncement }: AnnouncementProps) => {
|
||||
🎉{" "}New in v{minorVersion}
|
||||
</h3>
|
||||
<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{" "}
|
||||
more complex tasks. Cline/OpenRouter users get instant access, Anthropic users need Tier 4, and Bedrock users must be
|
||||
on a supported region. Select the{" "}
|
||||
<code>
|
||||
claude-sonnet-4-20250514<b>:1m</b>
|
||||
claude-sonnet-4<b>:1m</b>
|
||||
</code>{" "}
|
||||
model.
|
||||
model for 1M context, or use the original for 200K.
|
||||
<Accordion isCompact className="pl-0">
|
||||
<AccordionItem
|
||||
key="1"
|
||||
|
||||
@@ -51,13 +51,13 @@ const featuredModels = [
|
||||
label: "Best",
|
||||
},
|
||||
{
|
||||
id: "anthropic/claude-opus-4.1",
|
||||
description: "Anthropic's newest model topping benchmarks",
|
||||
id: "anthropic/claude-sonnet-4:1m",
|
||||
description: "Large 1M context window for complex tasks",
|
||||
label: "New",
|
||||
},
|
||||
{
|
||||
id: "google/gemini-2.5-pro",
|
||||
description: "Large 1M context window, great value",
|
||||
id: "anthropic/claude-opus-4.1",
|
||||
description: "Anthropic's newest model topping benchmarks",
|
||||
label: "Trending",
|
||||
},
|
||||
]
|
||||
@@ -219,6 +219,24 @@ const OpenRouterModelPicker: React.FC<OpenRouterModelPickerProps> = ({ isPopup,
|
||||
)
|
||||
}, [selectedModelId])
|
||||
|
||||
// Check if the current model is Claude Sonnet 4 and determine the alternate variant
|
||||
const claudeSonnet4Variant = useMemo(() => {
|
||||
if (selectedModelId === "anthropic/claude-sonnet-4") {
|
||||
return {
|
||||
current: "anthropic/claude-sonnet-4",
|
||||
alternate: "anthropic/claude-sonnet-4:1m",
|
||||
linkText: "Switch to 1M context window model",
|
||||
}
|
||||
} else if (selectedModelId === "anthropic/claude-sonnet-4:1m") {
|
||||
return {
|
||||
current: "anthropic/claude-sonnet-4:1m",
|
||||
alternate: "anthropic/claude-sonnet-4",
|
||||
linkText: "Switch to 200K context window model",
|
||||
}
|
||||
}
|
||||
return null
|
||||
}, [selectedModelId])
|
||||
|
||||
return (
|
||||
<div style={{ width: "100%" }}>
|
||||
<style>
|
||||
@@ -318,6 +336,20 @@ const OpenRouterModelPicker: React.FC<OpenRouterModelPickerProps> = ({ isPopup,
|
||||
</DropdownList>
|
||||
)}
|
||||
</DropdownWrapper>
|
||||
|
||||
{claudeSonnet4Variant && (
|
||||
<div style={{ marginBottom: 2 }}>
|
||||
<VSCodeLink
|
||||
style={{
|
||||
display: "inline",
|
||||
fontSize: "10.5px",
|
||||
color: "var(--vscode-textLink-foreground)",
|
||||
}}
|
||||
onClick={() => handleModelChange(claudeSonnet4Variant.alternate)}>
|
||||
{claudeSonnet4Variant.linkText}
|
||||
</VSCodeLink>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{hasInfo ? (
|
||||
|
||||
Reference in new issue
Block a user