8000 Add Claude Sonnet 4 and Claude Opus 4 models with thinking variants by shariqriazz · Pull Request #3844 · RooCodeInc/Roo-Code · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add Claude Sonnet 4 and Claude Opus 4 models with thinking variants #3844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/api/providers/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
let { id: modelId, maxTokens, thinking, temperature, virtualId } = this.getModel()

switch (modelId) {
case "claude-sonnet-4-20250514":
case "claude-opus-4-20250514":
case "claude-3-7-sonnet-20250219":
case "claude-3-5-sonnet-20241022":
case "claude-3-5-haiku-20241022":
Expand Down Expand Up @@ -92,13 +94,16 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa

const betas = []

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

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

// The `:thinking` variant is a virtual identifier for the
// `claude-3-7-sonnet-20250219` model with a thinking budget.
// The `:thinking` variants are virtual identifiers for models with a thinking budget.
// We can handle this more elegantly in the future.
if (id === "claude-3-7-sonnet-20250219:thinking") {
id = "claude-3-7-sonnet-20250219"
} else if (id === "claude-sonnet-4-20250514:thinking") {
id = "claude-sonnet-4-20250514"
} else if (id === "claude-opus-4-20250514:thinking") {
id = "claude-opus-4-20250514"
}

return {
Expand Down
132 changes: 132 additions & 0 deletions src/shared/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,54 @@ export type ApiHandlerOptions = Omit<ProviderSettings, "apiProvider" | "id">
export type AnthropicModelId = keyof typeof anthropicModels
export const anthropicDefaultModelId: AnthropicModelId = "claude-3-7-sonnet-20250219"
export const anthropicModels = {
"claude-sonnet-4-20250514:thinking": {
maxTokens: 64_000,
contextWindow: 200_000,
supportsImages: true,
supportsComputerUse: true,
supportsPromptCache: true,
inputPrice: 3.0, // $3 per million input tokens
outputPrice: 15.0, // $15 per million output tokens
cacheWritesPrice: 3.75, // $3.75 per million tokens
cacheReadsPrice: 0.3, // $0.30 per million tokens
thinking: true,
},
"claude-sonnet-4-20250514": {
maxTokens: 8192,
contextWindow: 200_000,
supportsImages: true,
supportsComputerUse: true,
supportsPromptCache: true,
inputPrice: 3.0, // $3 per million input tokens
outputPrice: 15.0, // $15 per million output tokens
cacheWritesPrice: 3.75, // $3.75 per million tokens
cacheReadsPrice: 0.3, // $0.30 per million tokens
thinking: false,
},
"claude-opus-4-20250514:thinking": {
maxTokens: 64_000,
contextWindow: 200_000,
supportsImages: true,
supportsComputerUse: true,
supportsPromptCache: true,
inputPrice: 15.0, // $15 per million input tokens
outputPrice: 75.0, // $75 per million output tokens
cacheWritesPrice: 18.75, // $18.75 per million tokens
cacheReadsPrice: 1.5, // $1.50 per million tokens
thinking: true,
},
"claude-opus-4-20250514": {
maxTokens: 8192,
contextWindow: 200_000,
supportsImages: true,
supportsComputerUse: true,
supportsPromptCache: true,
inputPrice: 15.0, // $15 per million input tokens
outputPrice: 75.0, // $75 per million output tokens
cacheWritesPrice: 18.75, // $18.75 per million tokens
cacheReadsPrice: 1.5, // $1.50 per million tokens
thinking: false,
},
"claude-3-7-sonnet-20250219:thinking": {
maxTokens: 128_000,
contextWindow: 200_000,
Expand Down Expand Up @@ -160,6 +208,34 @@ export const bedrockModels = {
maxCachePoints: 1,
cachableFields: ["system"],
},
"anthropic.claude-sonnet-4-20250514-v1:0": {
maxTokens: 8192,
contextWindow: 200_000,
supportsImages: true,
supportsComputerUse: true,
supportsPromptCache: true,
inputPrice: 3.0,
outputPrice: 15.0,
cacheWritesPrice: 3.75,
cacheReadsPrice: 0.3,
minTokensPerCachePoint: 1024,
maxCachePoints: 4,
cachableFields: ["system", "messages", "tools"],
},
"anthropic.claude-opus-4-20250514-v1:0": {
maxTokens: 8192,
contextWindow: 200_000,
supportsImages: true,
supportsComputerUse: true,
supportsPromptCache: true,
inputPrice: 15.0,
outputPrice: 75.0,
cacheWritesPrice: 18.75,
cacheReadsPrice: 1.5,
minTokensPerCachePoint: 1024,
maxCachePoints: 4,
cachableFields: ["system", "messages", "tools"],
},
"anthropic.claude-3-7-sonnet-20250219-v1:0": {
maxTokens: 8192,
contextWindow: 200_000,
Expand Down Expand Up @@ -582,6 +658,54 @@ export const vertexModels = {
inputPrice: 1.25,
outputPrice: 5,
},
"claude-sonnet-4-20250514:thinking": {
maxTokens: 64_000,
contextWindow: 200_000,
supportsImages: true,
supportsComputerUse: true,
supportsPromptCache: true,
inputPrice: 3.0,
outputPrice: 15.0,
cacheWritesPrice: 3.75,
cacheReadsPrice: 0.3,
thinking: true,
},
"claude-sonnet-4-20250514": {
maxTokens: 8192,
contextWindow: 200_000,
supportsImages: true,
supportsComputerUse: true,
supportsPromptCache: true,
inputPrice: 3.0,
outputPrice: 15.0,
cacheWritesPrice: 3.75,
cacheReadsPrice: 0.3,
thinking: false,
},
"claude-opus-4-20250514:thinking": {
maxTokens: 64_000,
contextWindow: 200_000,
supportsImages: true,
supportsComputerUse: true,
supportsPromptCache: true,
inputPrice: 15.0,
outputPrice: 75.0,
cacheWritesPrice: 18.75,
cacheReadsPrice: 1.5,
thinking: true,
},
"claude-opus-4-20250514": {
maxTokens: 8192,
contextWindow: 200_000,
supportsImages: true,
supportsComputerUse: true,
supportsPromptCache: true,
inputPrice: 15.0,
outputPrice: 75.0,
cacheWritesPrice: 18.75,
cacheReadsPrice: 1.5,
thinking: false,
},
"claude-3-7-sonnet@20250219:thinking": {
maxTokens: 64_000,
contextWindow: 200_000,
Expand Down Expand Up @@ -1797,6 +1921,10 @@ export const PROMPT_CACHING_MODELS = new Set([
"anthropic/claude-3.7-sonnet",
"anthropic/claude-3.7-sonnet:beta",
"anthropic/claude-3.7-sonnet:thinking",
"anthropic/claude-sonnet-4-20250514",
"anthropic/claude-sonnet-4-20250514:thinking",
"anthropic/claude-opus-4-20250514",
"anthropic/claude-opus-4-20250514:thinking",
"google/gemini-2.5-pro-preview",
"google/gemini-2.5-flash-preview",
"google/gemini-2.5-flash-preview:thinking",
Expand All @@ -1814,6 +1942,10 @@ export const COMPUTER_USE_MODELS = new Set([
"anthropic/claude-3.7-sonnet",
"anthropic/claude-3.7-sonnet:beta",
"anthropic/claude-3.7-sonnet:thinking",
"anthropic/claude-sonnet-4-20250514",
"anthropic/claude-sonnet-4-20250514:thinking",
"anthropic/claude-opus-4-20250514",
"anthropic/claude-opus-4-20250514:thinking",
])

const routerNames = ["openrouter", "requesty", "glama", "unbound", "litellm"] as const
Expand Down
0