Skip to content
Open
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
40 changes: 28 additions & 12 deletions src/pricing.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Claude Price calculation by model

import { ModelPricing } from './types';
import { ModelPricing } from "./types";

export interface TokenUsage {
input_tokens: number;
Expand All @@ -16,71 +16,87 @@ const MILL = 1_000_000;
// https://platform.claude.com/docs/en/about-claude/pricing
const MODEL_PRICING: Record<string, ModelPricing> = {
// Claude Sonnet 4
'claude-sonnet-4-20250514': {
"claude-sonnet-4-20250514": {
input_cost_per_token: 3 / MILL, // $3.00 / 1M tokens
output_cost_per_token: 15 / MILL, // $15.00 / 1M tokens
cache_creation_input_token_cost: 3.75 / MILL, // $3.75 / 1M tokens (5min caching)
cache_read_input_token_cost: 0.3 / MILL, // $0.30 / 1M tokens
},

// Claude Opus 4
'claude-opus-4-20250514': {
"claude-opus-4-20250514": {
input_cost_per_token: 15 / MILL, // $15.00 / 1M tokens
output_cost_per_token: 75 / MILL, // $75.00 / 1M tokens
cache_creation_input_token_cost: 18.75 / MILL, // $18.75 / 1M tokens (5min caching)
cache_read_input_token_cost: 1.5 / MILL, // $1.50 / 1M tokens
},

// Claude Opus 4.1 (2025-08-05)
'claude-opus-4-1-20250805': {
"claude-opus-4-1-20250805": {
input_cost_per_token: 15 / MILL, // $15.00 / 1M tokens
output_cost_per_token: 75 / MILL, // $75.00 / 1M tokens
cache_creation_input_token_cost: 18.75 / MILL, // $18.75 / 1M tokens (5min caching)
cache_read_input_token_cost: 1.5 / MILL, // $1.50 / 1M tokens
},

// Claude Opus 4.1 (alias)
'claude-opus-4-1': {
"claude-opus-4-1": {
input_cost_per_token: 15 / MILL, // $15.00 / 1M tokens
output_cost_per_token: 75 / MILL, // $75.00 / 1M tokens
cache_creation_input_token_cost: 18.75 / MILL, // $18.75 / 1M tokens (5min caching)
cache_read_input_token_cost: 1.5 / MILL, // $1.50 / 1M tokens
},

// Claude Opus 4.5 (2025-11 v01)
'claude-opus-4-5-20251101': {
"claude-opus-4-5-20251101": {
input_cost_per_token: 5 / MILL, // $5.00 / 1M tokens
output_cost_per_token: 25 / MILL, // $25.00 / 1M tokens
cache_creation_input_token_cost: 6 / MILL, // $6 / 1M tokens (5min caching)
cache_read_input_token_cost: 0.5 / MILL, // $0.50 / 1M tokens
},

// Claude Opus 4.5 (alias)
'claude-opus-4-5': {
"claude-opus-4-5": {
input_cost_per_token: 5 / MILL, // $5.00 / 1M tokens
output_cost_per_token: 25 / MILL, // $25.00 / 1M tokens
cache_creation_input_token_cost: 6 / MILL, // $6 / 1M tokens (5min caching)
cache_creation_input_token_cost: 6.25 / MILL, // $6.25 / 1M tokens (5min caching)
cache_read_input_token_cost: 0.5 / MILL, // $0.50 / 1M tokens
},

//Claude Opus 4.6
"claude-opus-4-6": {
input_cost_per_token: 5 / MILL, // $5.00 / 1M tokens
output_cost_per_token: 25 / MILL, // $25.00 / 1M tokens
cache_creation_input_token_cost: 6.25 / MILL, // $6 / 1M tokens (5min caching)
cache_read_input_token_cost: 0.5 / MILL, // $0.50 / 1M tokens
},

//Claude Opus 4.7
"claude-opus-4-7": {
input_cost_per_token: 5 / MILL, // $5.00 / 1M tokens
output_cost_per_token: 25 / MILL, // $25.00 / 1M tokens
cache_creation_input_token_cost: 6.25 / MILL, // $6 / 1M tokens (5min caching)
cache_read_input_token_cost: 0.5 / MILL, // $0.50 / 1M tokens
},

// Claude Sonnet 3.5 (2024-10-22)
'claude-3-5-sonnet-20241022': {
"claude-3-5-sonnet-20241022": {
input_cost_per_token: 3 / MILL, // $3.00 / 1M tokens
output_cost_per_token: 15 / MILL, // $15.00 / 1M tokens
cache_creation_input_token_cost: 3.75 / MILL, // $3.75 / 1M tokens (5min caching)
cache_read_input_token_cost: 0.3 / MILL, // $0.30 / 1M tokens
},

// Claude Haiku 3.5 (Not used anymore)
'claude-3-5-haiku-20241022': {
"claude-3-5-haiku-20241022": {
input_cost_per_token: 0.8 / MILL, // $0.8 / 1M tokens
output_cost_per_token: 4 / MILL, // $4.00 / 1M tokens
cache_creation_input_token_cost: 1.6 / MILL, // $1.6 / 1M tokens
cache_read_input_token_cost: 0.08 / MILL, // $0.08 / 1M tokens
},

// Claude Haiku 4.5 (2025-10 v01)
'claude-haiku-4-5-20251001': {
"claude-haiku-4-5-20251001": {
input_cost_per_token: 1 / MILL, // $1.00 / 1M tokens
output_cost_per_token: 5 / MILL, // $5.00 / 1M tokens
cache_creation_input_token_cost: 1.25 / MILL, // $1.25 / 1M tokens
Expand Down Expand Up @@ -114,7 +130,7 @@ export function getModelPricing(modelName: string | undefined): ModelPricing | n

// If unknown model, use Sonnet 4 pricing as default
console.warn(`Unknown model: ${modelName}, using Sonnet 4 pricing as fallback`);
return MODEL_PRICING['claude-sonnet-4-20250514'];
return MODEL_PRICING["claude-sonnet-4-20250514"];
}

/**
Expand Down