From 4029ba140f4f52f8fbeeabd118296537b5061368 Mon Sep 17 00:00:00 2001 From: Asjad Abbas <215788583+asjad3@users.noreply.github.com> Date: Mon, 3 Aug 2026 11:40:29 +0500 Subject: [PATCH] fix(core): add pricing for current Claude models calculateAnthropicCost returns null for any model missing from its prefix table, which means no cost is displayed at all. The table stopped at Opus 4.6 and Sonnet 4.6, so Opus 5/4.8/4.7, Sonnet 5, Sonnet 4.5, Haiku 4.5 and Fable 5 all showed nothing. Also corrected three comments that named the wrong model. --- core/llm/utils/calculateRequestCost.ts | 62 +++++++++++++- core/llm/utils/calculateRequestCost.vitest.ts | 80 +++++++++++++++++++ 2 files changed, 139 insertions(+), 3 deletions(-) diff --git a/core/llm/utils/calculateRequestCost.ts b/core/llm/utils/calculateRequestCost.ts index 794524d448d..379cad6d3e9 100644 --- a/core/llm/utils/calculateRequestCost.ts +++ b/core/llm/utils/calculateRequestCost.ts @@ -17,6 +17,46 @@ function calculateAnthropicCost( string, { input: number; output: number; cacheWrite: number; cacheRead: number } > = { + // Claude Fable 5 + "claude-fable-5": { + input: 10, + output: 50, + cacheWrite: 12.5, + cacheRead: 1, + }, + + // Claude Opus 5 + "claude-opus-5": { + input: 5, + output: 25, + cacheWrite: 6.25, + cacheRead: 0.5, + }, + + // Claude Opus 4.8 + "claude-opus-4-8": { + input: 5, + output: 25, + cacheWrite: 6.25, + cacheRead: 0.5, + }, + + // Claude Opus 4.7 + "claude-opus-4-7": { + input: 5, + output: 25, + cacheWrite: 6.25, + cacheRead: 0.5, + }, + + // Claude Sonnet 5 + "claude-sonnet-5": { + input: 3, + output: 15, + cacheWrite: 3.75, + cacheRead: 0.3, + }, + // Claude Sonnet 4.6 "claude-sonnet-4-6": { input: 3, @@ -25,6 +65,22 @@ function calculateAnthropicCost( cacheRead: 0.3, }, + // Claude Sonnet 4.5 + "claude-sonnet-4-5": { + input: 3, + output: 15, + cacheWrite: 3.75, + cacheRead: 0.3, + }, + + // Claude Haiku 4.5 + "claude-haiku-4-5": { + input: 1, + output: 5, + cacheWrite: 1.25, + cacheRead: 0.1, + }, + // Claude Opus 4.6 "claude-opus-4-6": { input: 5, @@ -41,7 +97,7 @@ function calculateAnthropicCost( cacheRead: 0.5, }, - // Claude Opus 4 (legacy) + // Claude 3 Opus (legacy) "claude-3-opus": { input: 15, output: 75, @@ -49,7 +105,7 @@ function calculateAnthropicCost( cacheRead: 1.5, }, - // Claude Sonnet 4 (optimal balance) + // Claude 3.5 Sonnet (legacy) "claude-3-5-sonnet": { input: 3, output: 15, @@ -57,7 +113,7 @@ function calculateAnthropicCost( cacheRead: 0.3, }, - // Claude Haiku 3.5 (fastest, most cost-effective) + // Claude 3.5 Haiku (legacy) "claude-3-5-haiku": { input: 0.8, output: 4, diff --git a/core/llm/utils/calculateRequestCost.vitest.ts b/core/llm/utils/calculateRequestCost.vitest.ts index 32183ca1b49..bdf2940412b 100644 --- a/core/llm/utils/calculateRequestCost.vitest.ts +++ b/core/llm/utils/calculateRequestCost.vitest.ts @@ -199,6 +199,86 @@ describe("calculateRequestCost", () => { description: "Provider name case insensitive", }, + // Anthropic Claude Opus 5 + { + provider: "anthropic", + model: "claude-opus-5", + promptTokens: 1000, + completionTokens: 500, + expectedCost: 0.0175, + description: "Claude Opus 5 basic usage", + }, + { + provider: "anthropic", + model: "claude-opus-5", + promptTokens: 1000, + completionTokens: 500, + cachedTokens: 2000, + cacheWriteTokens: 300, + expectedCost: 0.020375, + description: "Claude Opus 5 with cache reads and writes", + }, + + // Anthropic Claude Opus 4.8 + { + provider: "anthropic", + model: "claude-opus-4-8", + promptTokens: 1000, + completionTokens: 500, + expectedCost: 0.0175, + description: "Claude Opus 4.8", + }, + + // Anthropic Claude Opus 4.7 + { + provider: "anthropic", + model: "claude-opus-4-7", + promptTokens: 1000, + completionTokens: 500, + expectedCost: 0.0175, + description: "Claude Opus 4.7", + }, + + // Anthropic Claude Sonnet 5 + { + provider: "anthropic", + model: "claude-sonnet-5", + promptTokens: 1000, + completionTokens: 500, + expectedCost: 0.0105, + description: "Claude Sonnet 5", + }, + + // Anthropic Claude Sonnet 4.5 + { + provider: "anthropic", + model: "claude-sonnet-4-5", + promptTokens: 1000, + completionTokens: 500, + expectedCost: 0.0105, + description: "Claude Sonnet 4.5", + }, + + // Anthropic Claude Haiku 4.5 + { + provider: "anthropic", + model: "claude-haiku-4-5", + promptTokens: 1000, + completionTokens: 500, + expectedCost: 0.0035, + description: "Claude Haiku 4.5", + }, + + // Anthropic Claude Fable 5 + { + provider: "anthropic", + model: "claude-fable-5", + promptTokens: 1000, + completionTokens: 500, + expectedCost: 0.035, + description: "Claude Fable 5", + }, + // Unknown models/providers { provider: "anthropic",