From 32f200e83791c1c79423c0ed3f1a01d60a2dd3a9 Mon Sep 17 00:00:00 2001 From: Evan <58194240+celestial-vault@users.noreply.github.com> Date: Thu, 22 May 2025 12:44:33 -0700 Subject: [PATCH] Prompt caching Claude 4 Openrouter/Cline (#3722) * add prompt caching and suggested models * wording * change wording again * remove opus recommended --------- Co-authored-by: Elephant Lumps --- .changeset/strong-dolphins-lay.md | 5 +++++ src/api/transform/openrouter-stream.ts | 6 ++++++ src/core/controller/models/refreshOpenRouterModels.ts | 2 ++ src/core/controller/ui/index.ts | 2 +- src/core/controller/ui/methods.ts | 2 +- src/shared/api.ts | 4 ++-- .../src/components/settings/OpenRouterModelPicker.tsx | 11 ++++++----- 7 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 .changeset/strong-dolphins-lay.md diff --git a/.changeset/strong-dolphins-lay.md b/.changeset/strong-dolphins-lay.md new file mode 100644 index 00000000..1b90e104 --- /dev/null +++ b/.changeset/strong-dolphins-lay.md @@ -0,0 +1,5 @@ +--- +"claude-dev": minor +--- + +Add prompt caching for Claude 4 models on Cline and Openrouter providers diff --git a/src/api/transform/openrouter-stream.ts b/src/api/transform/openrouter-stream.ts index e3887752..edc38334 100644 --- a/src/api/transform/openrouter-stream.ts +++ b/src/api/transform/openrouter-stream.ts @@ -23,6 +23,8 @@ export async function createOpenRouterStream( // this was initially specifically for claude models (some models may 'support prompt caching' automatically without this) // handles direct model.id match logic switch (model.id) { + case "anthropic/claude-sonnet-4": + case "anthropic/claude-opus-4": case "anthropic/claude-3.7-sonnet": case "anthropic/claude-3.7-sonnet:beta": case "anthropic/claude-3.7-sonnet:thinking": @@ -79,6 +81,8 @@ export async function createOpenRouterStream( // (models usually default to max tokens allowed) let maxTokens: number | undefined switch (model.id) { + case "anthropic/claude-sonnet-4": + case "anthropic/claude-opus-4": case "anthropic/claude-3.7-sonnet": case "anthropic/claude-3.7-sonnet:beta": case "anthropic/claude-3.7-sonnet:thinking": @@ -112,6 +116,8 @@ export async function createOpenRouterStream( let reasoning: { max_tokens: number } | undefined = undefined switch (model.id) { + case "anthropic/claude-sonnet-4": + case "anthropic/claude-opus-4": case "anthropic/claude-3.7-sonnet": case "anthropic/claude-3.7-sonnet:beta": case "anthropic/claude-3.7-sonnet:thinking": diff --git a/src/core/controller/models/refreshOpenRouterModels.ts b/src/core/controller/models/refreshOpenRouterModels.ts index 412c04b5..7d5480e9 100644 --- a/src/core/controller/models/refreshOpenRouterModels.ts +++ b/src/core/controller/models/refreshOpenRouterModels.ts @@ -43,6 +43,8 @@ export async function refreshOpenRouterModels( } switch (rawModel.id) { + case "anthropic/claude-sonnet-4": + case "anthropic/claude-opus-4": case "anthropic/claude-3-7-sonnet": case "anthropic/claude-3-7-sonnet:beta": case "anthropic/claude-3.7-sonnet": diff --git a/src/core/controller/ui/index.ts b/src/core/controller/ui/index.ts index d97ded27..00a6baa4 100644 --- a/src/core/controller/ui/index.ts +++ b/src/core/controller/ui/index.ts @@ -19,4 +19,4 @@ export const handleUiServiceStreamingRequest = uiService.handleStreamingRequest export const isStreamingMethod = uiService.isStreamingMethod // Register all ui methods -registerAllMethods() +registerAllMethods() \ No newline at end of file diff --git a/src/core/controller/ui/methods.ts b/src/core/controller/ui/methods.ts index e779ee05..a3d0c1ef 100644 --- a/src/core/controller/ui/methods.ts +++ b/src/core/controller/ui/methods.ts @@ -11,4 +11,4 @@ export function registerAllMethods(): void { // Register each method with the registry registerMethod("onDidShowAnnouncement", onDidShowAnnouncement) registerMethod("scrollToSettings", scrollToSettings) -} +} \ No newline at end of file diff --git a/src/shared/api.ts b/src/shared/api.ts index f3a36413..2f42d1de 100644 --- a/src/shared/api.ts +++ b/src/shared/api.ts @@ -338,7 +338,7 @@ export const bedrockModels = { // OpenRouter // https://openrouter.ai/models?order=newest&supported_parameters=tools -export const openRouterDefaultModelId = "anthropic/claude-3.7-sonnet" // will always exist in openRouterModels +export const openRouterDefaultModelId = "anthropic/claude-sonnet-4" // will always exist in openRouterModels export const openRouterDefaultModelInfo: ModelInfo = { maxTokens: 8192, contextWindow: 200_000, @@ -350,7 +350,7 @@ export const openRouterDefaultModelInfo: ModelInfo = { cacheWritesPrice: 3.75, cacheReadsPrice: 0.3, description: - "Claude 3.7 Sonnet is an advanced large language model with improved reasoning, coding, and problem-solving capabilities. It introduces a hybrid reasoning approach, allowing users to choose between rapid responses and extended, step-by-step processing for complex tasks. The model demonstrates notable improvements in coding, particularly in front-end development and full-stack updates, and excels in agentic workflows, where it can autonomously navigate multi-step processes. \n\nClaude 3.7 Sonnet maintains performance parity with its predecessor in standard mode while offering an extended reasoning mode for enhanced accuracy in math, coding, and instruction-following tasks.\n\nRead more at the [blog post here](https://www.anthropic.com/news/claude-3-7-sonnet)", + "Claude 4 Sonnet is an advanced large language model with improved reasoning, coding, and problem-solving capabilities. It introduces a hybrid reasoning approach, allowing users to choose between rapid responses and extended, step-by-step processing for complex tasks. The model demonstrates notable improvements in coding, particularly in front-end development and full-stack updates, and excels in agentic workflows, where it can autonomously navigate multi-step processes. \n\nClaude 4 Sonnet maintains performance parity with its predecessor in standard mode while offering an extended reasoning mode for enhanced accuracy in math, coding, and instruction-following tasks.\n\nRead more at the [blog post here](https://www.anthropic.com/news/claude-4)", } // Vertex AI // https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude diff --git a/webview-ui/src/components/settings/OpenRouterModelPicker.tsx b/webview-ui/src/components/settings/OpenRouterModelPicker.tsx index 40f398c5..4d80bb44 100644 --- a/webview-ui/src/components/settings/OpenRouterModelPicker.tsx +++ b/webview-ui/src/components/settings/OpenRouterModelPicker.tsx @@ -7,7 +7,6 @@ import styled from "styled-components" import { openRouterDefaultModelId } from "@shared/api" import { useExtensionState } from "@/context/ExtensionStateContext" import { ModelsServiceClient, StateServiceClient } from "@/services/grpc-client" -import { vscode } from "@/utils/vscode" import { highlight } from "../history/HistoryView" import { ModelInfoView, normalizeApiConfiguration } from "./ApiOptions" import { CODE_BLOCK_BG_COLOR } from "@/components/common/CodeBlock" @@ -42,8 +41,8 @@ export interface OpenRouterModelPickerProps { // Featured models for Cline provider const featuredModels = [ { - id: "anthropic/claude-3.7-sonnet", - description: "Leading model for agentic coding", + id: "anthropic/claude-sonnet-4", + description: "Best model for agentic coding", label: "Best", }, { @@ -199,6 +198,8 @@ const OpenRouterModelPicker: React.FC = ({ isPopup } const showBudgetSlider = useMemo(() => { return ( + selectedModelId?.toLowerCase().includes("claude-sonnet-4") || + selectedModelId?.toLowerCase().includes("claude-opus-4") || selectedModelId?.toLowerCase().includes("claude-3-7-sonnet") || selectedModelId?.toLowerCase().includes("claude-3.7-sonnet") || selectedModelId?.toLowerCase().includes("claude-3.7-sonnet:thinking") @@ -335,8 +336,8 @@ const OpenRouterModelPicker: React.FC = ({ isPopup } If you're unsure which model to choose, Cline works best with{" "} handleModelChange("anthropic/claude-3.7-sonnet")}> - anthropic/claude-3.7-sonnet. + onClick={() => handleModelChange("anthropic/claude-sonnet-4")}> + anthropic/claude-sonnet-4. You can also try searching "free" for no-cost options currently available.