claude-pricing 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 xiangnuans
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,175 @@
1
+ # claude-pricing
2
+
3
+ > Calculate and track Claude API costs from token usage. Bundled pricing table + custom overrides. **Zero dependencies.**
4
+
5
+ ```ts
6
+ import { calculateCost, formatUSD, CostTracker } from "claude-pricing";
7
+
8
+ // One-shot cost calculation
9
+ const cost = calculateCost("claude-opus-4-7", {
10
+ input_tokens: 1500,
11
+ output_tokens: 800,
12
+ cache_read_input_tokens: 5000,
13
+ });
14
+ console.log(formatUSD(cost.total)); // "$0.0900"
15
+
16
+ // Session tracker with budget alert
17
+ const tracker = new CostTracker({
18
+ budgetUSD: 1.0,
19
+ onBudgetExceeded: (total, budget) =>
20
+ alert(`Budget blown: ${formatUSD(total)} > ${formatUSD(budget)}`),
21
+ });
22
+
23
+ tracker.add("claude-opus-4-7", usage, { label: "planning" });
24
+ tracker.add("claude-sonnet-4-6", usage, { label: "draft" });
25
+
26
+ console.log(formatUSD(tracker.total().total));
27
+ console.log(tracker.byModel());
28
+ ```
29
+
30
+ ## Why this exists
31
+
32
+ You're running Claude API in production. You want to know:
33
+
34
+ - **What did this one call cost?** The SDK returns `usage` but doesn't tell you the dollars.
35
+ - **Did this session blow my budget?** You want a running total across an agent loop.
36
+ - **Where's my money going?** Per-model breakdown for cost optimization.
37
+ - **What about cache and batch?** The pricing math is non-obvious (1.25× input for cache write, 50% off for batch).
38
+
39
+ This package is ~180 lines of TypeScript. Zero deps. Bundled with up-to-date Anthropic pricing, but **everything is overridable** because list prices change and you may have a custom contract.
40
+
41
+ ## Install
42
+
43
+ ```bash
44
+ npm install claude-pricing
45
+ ```
46
+
47
+ ## API
48
+
49
+ ### `calculateCost(model, usage, options?)`
50
+
51
+ ```ts
52
+ function calculateCost(
53
+ model: string,
54
+ usage: TokenUsage,
55
+ options?: { pricing?: ModelPricing | Record<string, ModelPricing>; batch?: boolean }
56
+ ): CostBreakdown;
57
+ ```
58
+
59
+ Returns `{ input, output, cacheWrite, cacheRead, total }` — all in USD.
60
+
61
+ ### `CostTracker`
62
+
63
+ ```ts
64
+ const tracker = new CostTracker({
65
+ pricing?: customTable,
66
+ budgetUSD?: 5.00,
67
+ onBudgetExceeded?: (total, budget) => ...,
68
+ });
69
+
70
+ tracker.add(model, usage, { label?: 'step-1', batch?: true });
71
+ tracker.total(); // { input, output, cacheWrite, cacheRead, total }
72
+ tracker.byModel(); // { 'claude-opus-4-7': { calls, usage, breakdown }, ... }
73
+ tracker.reset();
74
+ tracker.getEntries(); // readonly array of { model, usage, breakdown, timestamp, label }
75
+ ```
76
+
77
+ ### `formatUSD(amount)`
78
+
79
+ Smart-precision formatter:
80
+ - `$1.23` for amounts ≥ $1
81
+ - `$0.0123` for amounts ≥ $0.01
82
+ - `$0.000123` for sub-cent
83
+
84
+ ### `ANTHROPIC_PRICING`
85
+
86
+ The bundled default table (USD per million tokens):
87
+
88
+ | Model | Input | Output | Cache write | Cache read |
89
+ |---|---|---|---|---|
90
+ | claude-opus-4-7 | $15 | $75 | $18.75 | $1.50 |
91
+ | claude-sonnet-4-6 | $3 | $15 | $3.75 | $0.30 |
92
+ | claude-haiku-4-5 | $0.80 | $4 | $1.00 | $0.08 |
93
+
94
+ ⚠️ **Snapshot taken 2026-05. Verify against [Anthropic pricing](https://docs.anthropic.com/en/docs/about-claude/pricing) for production.** Pass your own table via `options.pricing` for current rates.
95
+
96
+ ## Recipes
97
+
98
+ ### Override pricing for current rates
99
+
100
+ ```ts
101
+ const myPricing = {
102
+ "claude-opus-4-7": { input: 14, output: 70 }, // discounted contract
103
+ };
104
+ const cost = calculateCost(model, usage, { pricing: myPricing });
105
+ ```
106
+
107
+ ### Use for any custom/fine-tuned model
108
+
109
+ ```ts
110
+ const cost = calculateCost(
111
+ "my-fine-tune",
112
+ usage,
113
+ { pricing: { input: 8, output: 24 } } // single ModelPricing
114
+ );
115
+ ```
116
+
117
+ ### Pair with `claude-stream-collector`
118
+
119
+ ```ts
120
+ import { collectStream } from "claude-stream-collector";
121
+ import { calculateCost, formatUSD } from "claude-pricing";
122
+
123
+ const result = await collectStream(stream);
124
+ const cost = calculateCost(result.model, result.usage);
125
+ console.log(formatUSD(cost.total));
126
+ ```
127
+
128
+ The `TokenUsage` shape is compatible — pass result.usage directly.
129
+
130
+ ### Track an agent loop with budget cap
131
+
132
+ ```ts
133
+ const tracker = new CostTracker({
134
+ budgetUSD: 0.10,
135
+ onBudgetExceeded: () => { throw new Error("Cost limit reached"); }
136
+ });
137
+
138
+ for (const step of agent.run()) {
139
+ tracker.add(step.model, step.usage, { label: step.name });
140
+ // throws automatically when total > $0.10
141
+ }
142
+
143
+ console.log(tracker.byModel());
144
+ ```
145
+
146
+ ### Batch API (50% off)
147
+
148
+ ```ts
149
+ calculateCost(model, usage, { batch: true });
150
+ // Or per add():
151
+ tracker.add(model, usage, { batch: true });
152
+ ```
153
+
154
+ ## Tests & build
155
+
156
+ ```bash
157
+ npm install
158
+ npm test # vitest run
159
+ npm run build # tsc
160
+ ```
161
+
162
+ ## License
163
+
164
+ MIT — © 2026 xiangnuans
165
+
166
+ ## Part of a series
167
+
168
+ The **3rd** package in small, focused Claude SDK helpers built in public.
169
+
170
+ - ✅ [`claude-stream-collector`](https://github.com/xiangnuans/claude-stream-collector) — Consume streaming events into typed result
171
+ - ✅ [`claude-retry`](https://github.com/xiangnuans/claude-retry) — Smart retry with backoff
172
+ - ✅ `claude-pricing` — Cost calculation + session tracker (this package)
173
+ - 🚧 `claude-prompt-toolkit` — Prompt templating, versioning
174
+
175
+ Follow the journey: [ship-log-2026](https://github.com/xiangnuans/ship-log-2026).
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Convert a `TokenUsage` record into a typed `CostBreakdown` (USD).
3
+ */
4
+ import type { CostBreakdown, ModelPricing, TokenUsage } from "./types.js";
5
+ export interface CalculateCostOptions {
6
+ /**
7
+ * Override the entire pricing table OR pass a single `ModelPricing` to use
8
+ * regardless of `model`.
9
+ */
10
+ pricing?: Record<string, ModelPricing> | ModelPricing;
11
+ /**
12
+ * Apply Anthropic batch API discount (50% off both input and output).
13
+ * Default: false
14
+ */
15
+ batch?: boolean;
16
+ }
17
+ /**
18
+ * Calculate cost in USD for a single Claude API call.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const cost = calculateCost("claude-opus-4-7", {
23
+ * input_tokens: 1000,
24
+ * output_tokens: 500,
25
+ * cache_read_input_tokens: 5000,
26
+ * });
27
+ * console.log(cost.total); // 0.0525
28
+ * ```
29
+ *
30
+ * @example Custom pricing override
31
+ * ```ts
32
+ * const cost = calculateCost("my-fine-tuned-model", usage, {
33
+ * pricing: { input: 5, output: 20 },
34
+ * });
35
+ * ```
36
+ */
37
+ export declare function calculateCost(model: string, usage: TokenUsage, options?: CalculateCostOptions): CostBreakdown;
38
+ /**
39
+ * Format a cost amount as a USD string with reasonable precision.
40
+ *
41
+ * - amounts ≥ $1.00 → 2 decimals ($1.23)
42
+ * - amounts ≥ $0.01 → 4 decimals ($0.0123)
43
+ * - smaller → 6 decimals ($0.000123)
44
+ */
45
+ export declare function formatUSD(amount: number): string;
46
+ //# sourceMappingURL=calculate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculate.d.ts","sourceRoot":"","sources":["../src/calculate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAI1E,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,YAAY,CAAC;IAEtD;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,UAAU,EACjB,OAAO,GAAE,oBAAyB,GACjC,aAAa,CAyBf;AAkBD;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAMhD"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Convert a `TokenUsage` record into a typed `CostBreakdown` (USD).
3
+ */
4
+ import { ANTHROPIC_PRICING, resolveModelAlias } from "./pricing-table.js";
5
+ const MILLION = 1_000_000;
6
+ /**
7
+ * Calculate cost in USD for a single Claude API call.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const cost = calculateCost("claude-opus-4-7", {
12
+ * input_tokens: 1000,
13
+ * output_tokens: 500,
14
+ * cache_read_input_tokens: 5000,
15
+ * });
16
+ * console.log(cost.total); // 0.0525
17
+ * ```
18
+ *
19
+ * @example Custom pricing override
20
+ * ```ts
21
+ * const cost = calculateCost("my-fine-tuned-model", usage, {
22
+ * pricing: { input: 5, output: 20 },
23
+ * });
24
+ * ```
25
+ */
26
+ export function calculateCost(model, usage, options = {}) {
27
+ const price = resolvePricing(model, options.pricing);
28
+ if (!price) {
29
+ const available = Object.keys(ANTHROPIC_PRICING).join(", ");
30
+ throw new Error(`claude-pricing: no pricing for model "${model}". Available defaults: ${available}. Pass an explicit pricing override via options.pricing.`);
31
+ }
32
+ const discount = options.batch ? 0.5 : 1;
33
+ const cacheWritePrice = price.cacheWrite ?? price.input * 1.25;
34
+ const cacheReadPrice = price.cacheRead ?? price.input * 0.1;
35
+ const input = (usage.input_tokens * price.input * discount) / MILLION;
36
+ const output = (usage.output_tokens * price.output * discount) / MILLION;
37
+ const cacheWrite = ((usage.cache_creation_input_tokens ?? 0) * cacheWritePrice) / MILLION;
38
+ const cacheRead = ((usage.cache_read_input_tokens ?? 0) * cacheReadPrice) / MILLION;
39
+ return {
40
+ input,
41
+ output,
42
+ cacheWrite,
43
+ cacheRead,
44
+ total: input + output + cacheWrite + cacheRead,
45
+ };
46
+ }
47
+ function resolvePricing(model, override) {
48
+ if (override) {
49
+ // Single ModelPricing — has `input` field directly
50
+ if ("input" in override && typeof override.input === "number") {
51
+ return override;
52
+ }
53
+ // Custom table
54
+ const table = override;
55
+ return resolveModelAlias(model, table) ?? table[model];
56
+ }
57
+ return resolveModelAlias(model);
58
+ }
59
+ /**
60
+ * Format a cost amount as a USD string with reasonable precision.
61
+ *
62
+ * - amounts ≥ $1.00 → 2 decimals ($1.23)
63
+ * - amounts ≥ $0.01 → 4 decimals ($0.0123)
64
+ * - smaller → 6 decimals ($0.000123)
65
+ */
66
+ export function formatUSD(amount) {
67
+ const abs = Math.abs(amount);
68
+ let precision = 6;
69
+ if (abs >= 1)
70
+ precision = 2;
71
+ else if (abs >= 0.01)
72
+ precision = 4;
73
+ return `$${amount.toFixed(precision)}`;
74
+ }
75
+ //# sourceMapp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M,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,uBAAuB,IAAI,CAAC,CAAC,GAAG,cAAc,CAAC,GAAG,OAAO,CAAC;IAEpF,OAAO;QACL,KAAK;QACL,MAAM;QACN,UAAU;QACV,SAAS;QACT,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS;KAC/C,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CACrB,KAAa,EACb,QAAsD;IAEtD,IAAI,QAAQ,EAAE,CAAC;QACb,mDAAmD;QACnD,IAAI,OAAO,IAAI,QAAQ,IAAI,OAAO,QAAQ,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9D,OAAO,QAAwB,CAAC;QAClC,CAAC;QACD,eAAe;QACf,MAAM,KAAK,GAAG,QAAwC,CAAC;QACvD,OAAO,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,iBAAiB,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,MAAc;IACtC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7B,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,GAAG,IAAI,CAAC;QAAE,SAAS,GAAG,CAAC,CAAC;SACvB,IAAI,GAAG,IAAI,IAAI;QAAE,SAAS,GAAG,CAAC,CAAC;IACpC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;AACzC,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * claude-pricing
3
+ *
4
+ * Calculate and track Claude API costs from token usage.
5
+ * Bundled pricing table + custom overrides. Zero dependencies.
6
+ */
7
+ export { calculateCost, formatUSD, type CalculateCostOptions } from "./calculate.js";
8
+ export { CostTracker, type CostTrackerOptions } from "./tracker.js";
9
+ export { ANTHROPIC_PRICING, resolveModelAlias } from "./pricing-table.js";
10
+ export type { CostBreakdown, CostEntry, ModelPricing, ModelSummary, TokenUsage, } from "./types.js";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,KAAK,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACrF,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE1E,YAAY,EACV,aAAa,EACb,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,UAAU,GACX,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * claude-pricing
3
+ *
4
+ * Calculate and track Claude API costs from token usage.
5
+ * Bundled pricing table + custom overrides. Zero dependencies.
6
+ */
7
+ export { calculateCost, formatUSD } from "./calculate.js";
8
+ export { CostTracker } from "./tracker.js";
9
+ export { ANTHROPIC_PRICING, resolveModelAlias } from "./pricing-table.js";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,SAAS,EAA6B,MAAM,gBAAgB,CAAC;AACrF,OAAO,EAAE,WAAW,EAA2B,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Default Anthropic pricing table — USD per million tokens (MTok).
3
+ *
4
+ * ⚠️ Snapshot taken 2026-05 from Anthropic's public pricing page. Prices change.
5
+ * For production use, pass your own `ModelPricing` override and verify against
6
+ * https://docs.anthropic.com/en/docs/about-claude/pricing.
7
+ *
8
+ * Cache pricing assumes the 5-minute ephemeral cache:
9
+ * - cacheWrite = 1.25× input
10
+ * - cacheRead = 0.10× input
11
+ *
12
+ * For the 1-hour cache (Opus / Sonnet only): cacheWrite = 2× input.
13
+ */
14
+ import type { ModelPricing } from "./types.js";
15
+ export declare const ANTHROPIC_PRICING: Record<string, ModelPricing>;
16
+ /**
17
+ * Best-effort model alias resolution.
18
+ *
19
+ * Strips date suffixes (`-20251001`) and `-latest` to find a base model entry.
20
+ * E.g. `claude-opus-4-7-20260301` → looks up `claude-opus-4-7`.
21
+ */
22
+ export declare function resolveModelAlias(model: string, table?: Record<string, ModelPricing>): ModelPricing | undefined;
23
+ //# sourceMappingURL=pricing-table.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pricing-table.d.ts","sourceRoot":"","sources":["../src/pricing-table.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAkD1D,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAqB,GACtD,YAAY,GAAG,SAAS,CAY1B"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Default Anthropic pricing table — USD per million tokens (MTok).
3
+ *
4
+ * ⚠️ Snapshot taken 2026-05 from Anthropic's public pricing page. Prices change.
5
+ * For production use, pass your own `ModelPricing` override and verify against
6
+ * https://docs.anthropic.com/en/docs/about-claude/pricing.
7
+ *
8
+ * Cache pricing assumes the 5-minute ephemeral cache:
9
+ * - cacheWrite = 1.25× input
10
+ * - cacheRead = 0.10× input
11
+ *
12
+ * For the 1-hour cache (Opus / Sonnet only): cacheWrite = 2× input.
13
+ */
14
+ export const ANTHROPIC_PRICING = {
15
+ // Claude Opus 4.7
16
+ "claude-opus-4-7": {
17
+ input: 15,
18
+ output: 75,
19
+ cacheWrite: 18.75,
20
+ cacheRead: 1.5,
21
+ },
22
+ // Claude Sonnet 4.6
23
+ "claude-sonnet-4-6": {
24
+ input: 3,
25
+ output: 15,
26
+ cacheWrite: 3.75,
27
+ cacheRead: 0.3,
28
+ },
29
+ // Claude Haiku 4.5
30
+ "claude-haiku-4-5": {
31
+ input: 0.8,
32
+ output: 4,
33
+ cacheWrite: 1,
34
+ cacheRead: 0.08,
35
+ },
36
+ "claude-haiku-4-5-20251001": {
37
+ input: 0.8,
38
+ output: 4,
39
+ cacheWrite: 1,
40
+ cacheRead: 0.08,
41
+ },
42
+ // Legacy / older — for users still on these
43
+ "claude-3-5-sonnet-latest": {
44
+ input: 3,
45
+ output: 15,
46
+ cacheWrite: 3.75,
47
+ cacheRead: 0.3,
48
+ },
49
+ "claude-3-5-haiku-latest": {
50
+ input: 0.8,
51
+ output: 4,
52
+ cacheWrite: 1,
53
+ cacheRead: 0.08,
54
+ },
55
+ "claude-3-opus-latest": {
56
+ input: 15,
57
+ output: 75,
58
+ cacheWrite: 18.75,
59
+ cacheRead: 1.5,
60
+ },
61
+ };
62
+ /**
63
+ * Best-effort model alias resolution.
64
+ *
65
+ * Strips date suffixes (`-20251001`) and `-latest` to find a base model entry.
66
+ * E.g. `claude-opus-4-7-20260301` → looks up `claude-opus-4-7`.
67
+ */
68
+ export function resolveModelAlias(model, table = ANTHROPIC_PRICING) {
69
+ if (table[model])
70
+ return table[model];
71
+ // Strip trailing date (-YYYYMMDD)
72
+ const stripped = model.replace(/-\d{8}$/, "");
73
+ if (table[stripped])
74
+ return table[stripped];
75
+ // Strip -latest
76
+ const noLatest = model.replace(/-latest$/, "");
77
+ if (table[noLatest])
78
+ return table[noLatest];
79
+ return undefined;
80
+ }
81
+ //# sourceMappingURL=pricing-table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pricing-table.js","sourceRoot":"","sources":["../src/pricing-table.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,MAAM,CAAC,MAAM,iBAAiB,GAAiC;IAC7D,kBAAkB;IAClB,iBAAiB,EAAE;QACjB,KAAK,EAAE,EAAE;QACT,MAAM,EAAE,EAAE;QACV,UAAU,EAAE,KAAK;QACjB,SAAS,EAAE,GAAG;KACf;IAED,oBAAoB;IACpB,mBAAmB,EAAE;QACnB,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,EAAE;QACV,UAAU,EAAE,IAAI;QAChB,SAAS,EAAE,GAAG;KACf;IAED,mBAAmB;IACnB,kBAAkB,EAAE;QAClB,KAAK,EAAE,GAAG;QACV,MAAM,EAAE,CAAC;QACT,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,IAAI;KAChB;IACD,2BAA2B,EAAE;QAC3B,KAAK,EAAE,GAAG;QACV,MAAM,EAAE,CAAC;QACT,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,IAAI;KAChB;IAED,4CAA4C;IAC5C,0BAA0B,EAAE;QAC1B,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,EAAE;QACV,UAAU,EAAE,IAAI;QAChB,SAAS,EAAE,GAAG;KACf;IACD,yBAAyB,EAAE;QACzB,KAAK,EAAE,GAAG;QACV,MAAM,EAAE,CAAC;QACT,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,IAAI;KAChB;IACD,sBAAsB,EAAE;QACtB,KAAK,EAAE,EAAE;QACT,MAAM,EAAE,EAAE;QACV,UAAU,EAAE,KAAK;QACjB,SAAS,EAAE,GAAG;KACf;CACF,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAa,EACb,QAAsC,iBAAiB;IAEvD,IAAI,KAAK,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC;IAEtC,kCAAkC;IAClC,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAC9C,IAAI,KAAK,CAAC,QAAQ,CAAC;QAAE,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC;IAE5C,gBAAgB;IAChB,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC/C,IAAI,KAAK,CAAC,QAAQ,CAAC;QAAE,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC;IAE5C,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * `CostTracker` — accumulate per-call costs across a session.
3
+ *
4
+ * Useful for long-running agents, multi-step pipelines, or anywhere you want
5
+ * a running budget total + per-model breakdown.
6
+ */
7
+ import type { CostBreakdown, CostEntry, ModelPricing, ModelSummary, TokenUsage } from "./types.js";
8
+ export interface CostTrackerOptions {
9
+ /** Pricing override applied to every `add()` call */
10
+ pricing?: Record<string, ModelPricing>;
11
+ /** Optional cost ceiling in USD; tracker emits a warning past this */
12
+ budgetUSD?: number;
13
+ /** Called when budget is exceeded (only fires once per add that crosses) */
14
+ onBudgetExceeded?: (total: number, budget: number) => void;
15
+ }
16
+ export declare class CostTracker {
17
+ private entries;
18
+ private opts;
19
+ private alertedBudget;
20
+ constructor(opts?: CostTrackerOptions);
21
+ /**
22
+ * Record a single call and return its computed breakdown.
23
+ */
24
+ add(model: string, usage: TokenUsage, options?: {
25
+ label?: string;
26
+ batch?: boolean;
27
+ }): CostBreakdown;
28
+ /**
29
+ * Total cost across all entries.
30
+ */
31
+ total(): CostBreakdown;
32
+ /**
33
+ * Per-model summary — call count, summed usage, summed cost.
34
+ */
35
+ byModel(): Record<string, ModelSummary>;
36
+ /** Number of recorded calls */
37
+ get callCount(): number;
38
+ /** Read-only access to entries */
39
+ getEntries(): readonly CostEntry[];
40
+ /** Reset all state */
41
+ reset(): void;
42
+ private checkBudget;
43
+ }
44
+ //# sourceMappingURL=tracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracker.d.ts","sourceRoot":"","sources":["../src/tracker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EACV,aAAa,EACb,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,UAAU,EACX,MAAM,YAAY,CAAC;AAepB,MAAM,WAAW,kBAAkB;IACjC,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAEvC,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,4EAA4E;IAC5E,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5D;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,IAAI,CAAqB;IACjC,OAAO,CAAC,aAAa,CAAS;gBAElB,IAAI,GAAE,kBAAuB;IAIzC;;OAEG;IACH,GAAG,CACD,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,UAAU,EACjB,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAO,GAChD,aAAa;IAmBhB;;OAEG;IACH,KAAK,IAAI,aAAa;IAatB;;OAEG;IACH,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;IAkCvC,+BAA+B;IAC/B,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,kCAAkC;IAClC,UAAU,IAAI,SAAS,SAAS,EAAE;IAIlC,sBAAsB;IACtB,KAAK,IAAI,IAAI;IAKb,OAAO,CAAC,WAAW;CASpB"}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * `CostTracker` — accumulate per-call costs across a session.
3
+ *
4
+ * Useful for long-running agents, multi-step pipelines, or anywhere you want
5
+ * a running budget total + per-model breakdown.
6
+ */
7
+ import { calculateCost } from "./calculate.js";
8
+ const EMPTY_BREAKDOWN = {
9
+ input: 0,
10
+ output: 0,
11
+ cacheWrite: 0,
12
+ cacheRead: 0,
13
+ total: 0,
14
+ };
15
+ const EMPTY_USAGE = {
16
+ input_tokens: 0,
17
+ output_tokens: 0,
18
+ };
19
+ export class CostTracker {
20
+ entries = [];
21
+ opts;
22
+ alertedBudget = false;
23
+ constructor(opts = {}) {
24
+ this.opts = opts;
25
+ }
26
+ /**
27
+ * Record a single call and return its computed breakdown.
28
+ */
29
+ add(model, usage, options = {}) {
30
+ const calcOpts = {
31
+ pricing: this.opts.pricing,
32
+ batch: options.batch,
33
+ };
34
+ const breakdown = calculateCost(model, usage, calcOpts);
35
+ this.entries.push({
36
+ model,
37
+ usage,
38
+ breakdown,
39
+ timestamp: Date.now(),
40
+ label: options.label,
41
+ });
42
+ this.checkBudget();
43
+ return breakdown;
44
+ }
45
+ /**
46
+ * Total cost across all entries.
47
+ */
48
+ total() {
49
+ return this.entries.reduce((acc, e) => ({
50
+ input: acc.input + e.breakdown.input,
51
+ output: acc.output + e.breakdown.output,
52
+ cacheWrite: acc.cacheWrite + e.breakdown.cacheWrite,
53
+ cacheRead: acc.cacheRead + e.breakdown.cacheRead,
54
+ total: acc.total + e.breakdown.total,
55
+ }), { ...EMPTY_BREAKDOWN });
56
+ }
57
+ /**
58
+ * Per-model summary — call count, summed usage, summed cost.
59
+ */
60
+ byModel() {
61
+ const result = {};
62
+ for (const e of this.entries) {
63
+ const summary = result[e.model] ?? {
64
+ calls: 0,
65
+ usage: { ...EMPTY_USAGE },
66
+ breakdown: { ...EMPTY_BREAKDOWN },
67
+ };
68
+ summary.calls += 1;
69
+ summary.usage.input_tokens += e.usage.input_tokens;
70
+ summary.usage.output_tokens += e.usage.output_tokens;
71
+ if (e.usage.cache_creation_input_tokens !== undefined) {
72
+ summary.usage.cache_creation_input_tokens =
73
+ (summary.usage.cache_creation_input_tokens ?? 0) + e.usage.cache_creation_input_tokens;
74
+ }
75
+ if (e.usage.cache_read_input_tokens !== undefined) {
76
+ summary.usage.cache_read_input_tokens =
77
+ (summary.usage.cache_read_input_tokens ?? 0) + e.usage.cache_read_input_tokens;
78
+ }
79
+ summary.breakdown.input += e.breakdown.input;
80
+ summary.breakdown.output += e.breakdown.output;
81
+ summary.breakdown.cacheWrite += e.breakdown.cacheWrite;
82
+ summary.breakdown.cacheRead += e.breakdown.cacheRead;
83
+ summary.breakdown.total += e.breakdown.total;
84
+ result[e.model] = summary;
85
+ }
86
+ return result;
87
+ }
88
+ /** Number of recorded calls */
89
+ get callCount() {
90
+ return this.entries.length;
91
+ }
92
+ /** Read-only access to entries */
93
+ getEntries() {
94
+ return this.entries;
95
+ }
96
+ /** Reset all state */
97
+ reset() {
98
+ this.entries = [];
99
+ this.alertedBudget = false;
100
+ }
101
+ checkBudget() {
102
+ const budget = this.opts.budgetUSD;
103
+ if (budget === undefined || this.alertedBudget)
104
+ return;
105
+ const total = this.total().total;
106
+ if (total >= budget) {
107
+ this.alertedBudget = true;
108
+ this.opts.onBudgetExceeded?.(total, budget);
109
+ }
110
+ }
111
+ }
112
+ //# sourceMappingURL=tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracker.js","sourceRoot":"","sources":["../src/tracker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAA6B,MAAM,gBAAgB,CAAC;AAS1E,MAAM,eAAe,GAAkB;IACrC,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;IACT,UAAU,EAAE,CAAC;IACb,SAAS,EAAE,CAAC;IACZ,KAAK,EAAE,CAAC;CACT,CAAC;AAEF,MAAM,WAAW,GAAe;IAC9B,YAAY,EAAE,CAAC;IACf,aAAa,EAAE,CAAC;CACjB,CAAC;AAaF,MAAM,OAAO,WAAW;IACd,OAAO,GAAgB,EAAE,CAAC;IAC1B,IAAI,CAAqB;IACzB,aAAa,GAAG,KAAK,CAAC;IAE9B,YAAY,OAA2B,E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,CAAC;YAE7C,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC;QAC5B,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,+BAA+B;IAC/B,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IAC7B,CAAC;IAED,kCAAkC;IAClC,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,sBAAsB;IACtB,KAAK;QACH,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;IAC7B,CAAC;IAEO,WAAW;QACjB,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;QACnC,IAAI,MAAM,KAAK,SAAS,IAAI,IAAI,CAAC,aAAa;YAAE,OAAO;QACvD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC;QACjC,IAAI,KAAK,IAAI,MAAM,EAAE,CAAC;YACpB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;YAC1B,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Token usage shape — compatible with `@anthropic-ai/sdk` and `claude-stream-collector`.
3
+ */
4
+ export interface TokenUsage {
5
+ input_tokens: number;
6
+ output_tokens: number;
7
+ cache_creation_input_tokens?: number;
8
+ cache_read_input_tokens?: number;
9
+ }
10
+ /**
11
+ * Pricing for a single model, in USD per million tokens (MTok).
12
+ *
13
+ * `cacheWrite` defaults to 1.25× input price (5-minute cache) when omitted.
14
+ * `cacheRead` defaults to 0.1× input price (10% of input) when omitted.
15
+ */
16
+ export interface ModelPricing {
17
+ /** USD per million input tokens */
18
+ input: number;
19
+ /** USD per million output tokens */
20
+ output: number;
21
+ /** USD per million tokens for cache creation (write). Default: input × 1.25 */
22
+ cacheWrite?: number;
23
+ /** USD per million tokens for cache reads. Default: input × 0.1 */
24
+ cacheRead?: number;
25
+ }
26
+ /**
27
+ * Cost breakdown in USD.
28
+ */
29
+ export interface CostBreakdown {
30
+ input: number;
31
+ output: number;
32
+ cacheWrite: number;
33
+ cacheRead: number;
34
+ total: number;
35
+ }
36
+ /**
37
+ * A single recorded entry in a `CostTracker`.
38
+ */
39
+ export interface CostEntry {
40
+ model: string;
41
+ usage: TokenUsage;
42
+ breakdown: CostBreakdown;
43
+ timestamp: number;
44
+ label?: string;
45
+ }
46
+ /**
47
+ * Per-model aggregate stats in a tracker.
48
+ */
49
+ export interface ModelSummary {
50
+ calls: number;
51
+ usage: TokenUsage;
52
+ breakdown: CostBreakdown;
53
+ }
54
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC;AAED;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAC;IAEd,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;IAEf,+EAA+E;IAC/E,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,mEAAmE;IACnE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,UAAU,CAAC;IAClB,SAAS,EAAE,aAAa,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,UAAU,CAAC;IAClB,SAAS,EAAE,aAAa,CAAC;CAC1B"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "claude-pricing",
3
+ "version": "0.1.0",
4
+ "description": "Calculate and track Claude API costs from token usage. Bundled pricing table + custom override. Zero dependencies.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": ["dist", "README.md", "LICENSE"],
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "test": "vitest run",
18
+ "test:watch": "vitest",
19
+ "clean": "rm -rf dist"
20
+ },
21
+ "keywords": [
22
+ "claude",
23
+ "anthropic",
24
+ "pricing",
25
+ "cost",
26
+ "tokens",
27
+ "usage",
28
+ "budget",
29
+ "llm",
30
+ "ai"
31
+ ],
32
+ "author": "xiangnuans",
33
+ "license": "MIT",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/xiangnuans/claude-pricing.git"
37
+ },
38
+ "homepage": "https://github.com/xiangnuans/claude-pricing",
39
+ "bugs": "https://github.com/xiangnuans/claude-pricing/issues",
40
+ "devDependencies": {
41
+ "@types/node": "^22.0.0",
42
+ "typescript": "^5.5.0",
43
+ "vitest": "^2.0.0"
44
+ },
45
+ "engines": {
46
+ "node": ">=18"
47
+ }
48
+ }