From 4bb505a13328169ed0ce962e67fbd8a6c082dbca Mon Sep 17 00:00:00 2001 From: Gurden Batra Date: Fri, 12 Jun 2026 00:04:11 +0200 Subject: [PATCH] =?UTF-8?q?fix(llm):=20correct=20model=20cost=20table=20?= =?UTF-8?q?=E2=80=94=20Haiku=204.5=20and=20Opus=20were=20mispriced?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit usage.ts priced Haiku 4.5 at Haiku-3 rates (25/125 micro-cents/1k = $0.25/$1.25 per MTok) — actual Haiku 4.5 is $1/$5 per MTok. Opus was at 1500/7500 ($15/$75) — actual Opus 4.7/4.8 is $5/$25. The Settings usage dashboard computes cost from this table at read time, so it was understating extraction spend ~4x and overstating any Opus use ~3x. Corrected to per-MTok×100 micro-cents/1k: Haiku 100/500, Opus 500/2500; added the claude-haiku-4-5 alias and a claude-opus-4-8 row. Updated tests. --- src/lib/llm/__tests__/usage.test.ts | 13 ++++++++++--- src/lib/llm/usage.ts | 10 +++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/lib/llm/__tests__/usage.test.ts b/src/lib/llm/__tests__/usage.test.ts index ff1ecc4..a620f46 100644 --- a/src/lib/llm/__tests__/usage.test.ts +++ b/src/lib/llm/__tests__/usage.test.ts @@ -3,10 +3,17 @@ import { estimateCostMicroCents } from '../usage'; describe('estimateCostMicroCents', () => { it('estimates cost for Haiku model', () => { - // Haiku: $0.00025/1k input, $0.00125/1k output - // 1000 input + 1000 output = $0.00025 + $0.00125 = $0.0015 = 150 micro-cents + // Haiku 4.5: $1/MTok input, $5/MTok output → $0.001/1k in, $0.005/1k out + // 1000 input + 1000 output = $0.001 + $0.005 = $0.006 = 600 micro-cents const cost = estimateCostMicroCents('claude-haiku-4-5-20251001', 1000, 1000); - expect(cost).toBe(150); + expect(cost).toBe(600); + }); + + it('estimates cost for Opus model', () => { + // Opus 4.8: $5/MTok input, $25/MTok output → $0.005/1k in, $0.025/1k out + // 1000 input + 1000 output = $0.005 + $0.025 = $0.03 = 3000 micro-cents + const cost = estimateCostMicroCents('claude-opus-4-8', 1000, 1000); + expect(cost).toBe(3000); }); it('estimates cost for Sonnet model', () => { diff --git a/src/lib/llm/usage.ts b/src/lib/llm/usage.ts index 69740a6..64b51c2 100644 --- a/src/lib/llm/usage.ts +++ b/src/lib/llm/usage.ts @@ -1,11 +1,15 @@ import type { LLMResponse } from './index'; -// Cost in micro-cents per 1k tokens (1 micro-cent = $0.00001) +// Cost in micro-cents per 1k tokens (1 micro-cent = $0.00001). +// Per-1k micro-cents = (USD per 1M tokens) × 100. Rates per Anthropic pricing: +// Haiku 4.5 $1 / $5 Sonnet 4.6 $3 / $15 Opus 4.7/4.8 $5 / $25 const MODEL_COSTS: Record = { - 'claude-haiku-4-5-20251001': { inputPer1k: 25, outputPer1k: 125 }, + 'claude-haiku-4-5-20251001': { inputPer1k: 100, outputPer1k: 500 }, + 'claude-haiku-4-5': { inputPer1k: 100, outputPer1k: 500 }, 'claude-sonnet-4-6': { inputPer1k: 300, outputPer1k: 1500 }, 'claude-sonnet-4-20250514': { inputPer1k: 300, outputPer1k: 1500 }, - 'claude-opus-4-7': { inputPer1k: 1500, outputPer1k: 7500 }, + 'claude-opus-4-8': { inputPer1k: 500, outputPer1k: 2500 }, + 'claude-opus-4-7': { inputPer1k: 500, outputPer1k: 2500 }, }; export function estimateCostMicroCents(