@trazum/core 2.7.3 → 2.7.5
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/dist/anthropic-cost.d.ts +22 -5
- package/dist/anthropic-cost.d.ts.map +1 -1
- package/dist/anthropic-cost.js +33 -10
- package/dist/anthropic-cost.js.map +1 -1
- package/dist/anthropic-usage.d.ts +15 -2
- package/dist/anthropic-usage.d.ts.map +1 -1
- package/dist/anthropic-usage.js +41 -5
- package/dist/anthropic-usage.js.map +1 -1
- package/dist/batch-results.d.ts +77 -0
- package/dist/batch-results.d.ts.map +1 -0
- package/dist/batch-results.js +145 -0
- package/dist/batch-results.js.map +1 -0
- package/dist/billing.d.ts +10 -0
- package/dist/billing.d.ts.map +1 -1
- package/dist/billing.js +15 -0
- package/dist/billing.js.map +1 -1
- package/dist/claude-code.d.ts +4 -0
- package/dist/claude-code.d.ts.map +1 -1
- package/dist/claude-code.js +14 -1
- package/dist/claude-code.js.map +1 -1
- package/dist/connector.d.ts +19 -1
- package/dist/connector.d.ts.map +1 -1
- package/dist/connector.js +46 -6
- package/dist/connector.js.map +1 -1
- package/dist/csv.d.ts +1 -1
- package/dist/csv.d.ts.map +1 -1
- package/dist/csv.js +11 -0
- package/dist/csv.js.map +1 -1
- package/dist/gateway.d.ts +2 -0
- package/dist/gateway.d.ts.map +1 -1
- package/dist/gateway.js +16 -0
- package/dist/gateway.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/openai-usage.d.ts +5 -1
- package/dist/openai-usage.d.ts.map +1 -1
- package/dist/openai-usage.js +20 -4
- package/dist/openai-usage.js.map +1 -1
- package/dist/pricing-overlay.d.ts +1 -1
- package/dist/pricing-overlay.d.ts.map +1 -1
- package/dist/pricing-overlay.js +11 -0
- package/dist/pricing-overlay.js.map +1 -1
- package/dist/pricing.d.ts +8 -0
- package/dist/pricing.d.ts.map +1 -1
- package/dist/pricing.js +74 -17
- package/dist/pricing.js.map +1 -1
- package/dist/receipt.d.ts +38 -4
- package/dist/receipt.d.ts.map +1 -1
- package/dist/receipt.js +19 -1
- package/dist/receipt.js.map +1 -1
- package/dist/repeats.d.ts.map +1 -1
- package/dist/repeats.js +3 -2
- package/dist/repeats.js.map +1 -1
- package/dist/rollup.d.ts.map +1 -1
- package/dist/rollup.js +4 -0
- package/dist/rollup.js.map +1 -1
- package/dist/session-cost.d.ts.map +1 -1
- package/dist/session-cost.js +4 -2
- package/dist/session-cost.js.map +1 -1
- package/dist/store.d.ts +5 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +4 -0
- package/dist/store.js.map +1 -1
- package/dist/truncation-retry.d.ts.map +1 -1
- package/dist/truncation-retry.js +3 -2
- package/dist/truncation-retry.js.map +1 -1
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/usage.d.ts +42 -0
- package/dist/usage.d.ts.map +1 -1
- package/dist/usage.js +42 -3
- package/dist/usage.js.map +1 -1
- package/package.json +1 -1
- package/src/anthropic-cost.ts +46 -12
- package/src/anthropic-usage.ts +54 -7
- package/src/batch-results.ts +174 -0
- package/src/billing.ts +16 -0
- package/src/claude-code.ts +16 -1
- package/src/connector.ts +68 -8
- package/src/csv.ts +11 -0
- package/src/gateway.ts +16 -0
- package/src/index.ts +2 -0
- package/src/openai-usage.ts +24 -5
- package/src/pricing-overlay.ts +15 -0
- package/src/pricing.ts +83 -17
- package/src/receipt.ts +53 -6
- package/src/repeats.ts +3 -2
- package/src/rollup.ts +4 -0
- package/src/session-cost.ts +4 -2
- package/src/store.ts +9 -0
- package/src/truncation-retry.ts +3 -2
- package/src/types.ts +13 -0
- package/src/usage.ts +84 -3
package/dist/anthropic-cost.d.ts
CHANGED
|
@@ -39,10 +39,15 @@
|
|
|
39
39
|
* `group_by[]=description`:
|
|
40
40
|
*
|
|
41
41
|
* - **`cost_type` other than `tokens`** — web search, code execution, session
|
|
42
|
-
* usage. Trazum prices
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
42
|
+
* usage. Trazum prices web searches (since 2.7.5) and none of the rest, so
|
|
43
|
+
* what is set against this charge is the receipt's own `webSearchUsd`, and
|
|
44
|
+
* the difference between the two is billed money Trazum never claimed to
|
|
45
|
+
* cover. Named rather than blamed.
|
|
46
|
+
* - **`service_tier: "batch"`** — billed at the batch tier, which Trazum
|
|
47
|
+
* prices at each model's batch rate since 2.7.4. Set against the receipt's
|
|
48
|
+
* own `batchUsd`, not taken out whole: taking out the provider's whole
|
|
49
|
+
* batch charge when Trazum's figure already holds its own batch calls
|
|
50
|
+
* understated the remainder by exactly those calls.
|
|
46
51
|
*
|
|
47
52
|
* What is left after both is the **remainder**, and it is the only figure here
|
|
48
53
|
* worth arguing about: the same standard-tier tokens, priced two ways, or
|
|
@@ -108,9 +113,19 @@ export interface Reconciliation {
|
|
|
108
113
|
billedUsd: number;
|
|
109
114
|
/** Billed minus computed. Positive means the provider charged more. */
|
|
110
115
|
differenceUsd: number;
|
|
111
|
-
/**
|
|
116
|
+
/** What the provider billed for something other than tokens, and at the batch tier. */
|
|
112
117
|
notTokensUsd: number;
|
|
113
118
|
batchUsd: number;
|
|
119
|
+
/**
|
|
120
|
+
* What Trazum's own figure holds of each: web searches, and calls priced at
|
|
121
|
+
* the batch rate. `null` when the receipt does not say, which is every
|
|
122
|
+
* receipt before 2.7.5; the comparison then reads them as zero and says so
|
|
123
|
+
* (`computedSplitKnown`).
|
|
124
|
+
*/
|
|
125
|
+
computedWebSearchUsd: number | null;
|
|
126
|
+
computedBatchUsd: number | null;
|
|
127
|
+
/** Whether the receipt said what its batch calls and searches cost. */
|
|
128
|
+
computedSplitKnown: boolean;
|
|
114
129
|
/**
|
|
115
130
|
* What neither figure explains: the same standard-tier tokens priced two
|
|
116
131
|
* ways, or usage the log never saw. The only number here worth arguing
|
|
@@ -162,6 +177,8 @@ export declare function reconcile(computed: {
|
|
|
162
177
|
usd: number;
|
|
163
178
|
fromMs: number;
|
|
164
179
|
toMs: number;
|
|
180
|
+
batchUsd?: number;
|
|
181
|
+
webSearchUsd?: number;
|
|
165
182
|
}, billed: BilledReading): Reconciliation;
|
|
166
183
|
/**
|
|
167
184
|
* Whether this text is a cost report rather than some other JSON.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-cost.d.ts","sourceRoot":"","sources":["../src/anthropic-cost.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"anthropic-cost.d.ts","sourceRoot":"","sources":["../src/anthropic-cost.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,mDAAmD;IACnD,GAAG,EAAE,MAAM,CAAC;IACZ,6EAA6E;IAC7E,YAAY,EAAE,MAAM,CAAC;IACrB,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,cAAc,EAAE,OAAO,CAAC;IACxB;;;;;;OAMG;IACH,SAAS,EAAE,OAAO,CAAC;IACnB,4EAA4E;IAC5E,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAChD,yEAAyE;IACzE,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,wDAAwD;AACxD,MAAM,WAAW,oBAAqB,SAAQ,aAAa;IACzD,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,gBAAgB,EAAE,MAAM,CAAC;IACzB,4EAA4E;IAC5E,SAAS,EAAE,OAAO,CAAC;IACnB,wDAAwD;IACxD,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,+DAA+D;AAC/D,MAAM,WAAW,cAAc;IAC7B,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;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,SAAO,GAAG,OAAO,CAIhF"}
|
package/dist/anthropic-cost.js
CHANGED
|
@@ -39,10 +39,15 @@
|
|
|
39
39
|
* `group_by[]=description`:
|
|
40
40
|
*
|
|
41
41
|
* - **`cost_type` other than `tokens`** — web search, code execution, session
|
|
42
|
-
* usage. Trazum prices
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
42
|
+
* usage. Trazum prices web searches (since 2.7.5) and none of the rest, so
|
|
43
|
+
* what is set against this charge is the receipt's own `webSearchUsd`, and
|
|
44
|
+
* the difference between the two is billed money Trazum never claimed to
|
|
45
|
+
* cover. Named rather than blamed.
|
|
46
|
+
* - **`service_tier: "batch"`** — billed at the batch tier, which Trazum
|
|
47
|
+
* prices at each model's batch rate since 2.7.4. Set against the receipt's
|
|
48
|
+
* own `batchUsd`, not taken out whole: taking out the provider's whole
|
|
49
|
+
* batch charge when Trazum's figure already holds its own batch calls
|
|
50
|
+
* understated the remainder by exactly those calls.
|
|
46
51
|
*
|
|
47
52
|
* What is left after both is the **remainder**, and it is the only figure here
|
|
48
53
|
* worth arguing about: the same standard-tier tokens, priced two ways, or
|
|
@@ -169,12 +174,18 @@ export function anthropicCostReport(text) {
|
|
|
169
174
|
* missing money nobody would see was missing.
|
|
170
175
|
*/
|
|
171
176
|
export function reconcile(computed, billed) {
|
|
177
|
+
const known = (value) => typeof value === 'number' && Number.isFinite(value) ? value : null;
|
|
178
|
+
const computedBatchUsd = known(computed.batchUsd);
|
|
179
|
+
const computedWebSearchUsd = known(computed.webSearchUsd);
|
|
172
180
|
const bare = {
|
|
173
181
|
computedUsd: computed.usd,
|
|
174
182
|
billedUsd: billed.usd,
|
|
175
183
|
differenceUsd: billed.usd - computed.usd,
|
|
176
184
|
notTokensUsd: billed.notTokensUsd,
|
|
177
185
|
batchUsd: billed.batchUsd,
|
|
186
|
+
computedWebSearchUsd,
|
|
187
|
+
computedBatchUsd,
|
|
188
|
+
computedSplitKnown: computedBatchUsd !== null && computedWebSearchUsd !== null,
|
|
178
189
|
remainderUsd: 0,
|
|
179
190
|
attributable: billed.described,
|
|
180
191
|
batchSeparable: billed.batchSeparable,
|
|
@@ -195,15 +206,27 @@ export function reconcile(computed, billed) {
|
|
|
195
206
|
};
|
|
196
207
|
}
|
|
197
208
|
/*
|
|
198
|
-
The remainder is what is left when the report's own explanations
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
209
|
+
The remainder is what is left when each of the report's own explanations
|
|
210
|
+
is set against what Trazum computed for the same thing and the two
|
|
211
|
+
differences are taken out: billed non-token charges against computed
|
|
212
|
+
searches, billed batch against computed batch. What remains is the
|
|
213
|
+
standard-tier tokens, billed against computed. It is deliberately not
|
|
214
|
+
clamped at zero. A negative one is a real answer -- Trazum priced more
|
|
215
|
+
than the provider charged -- and reporting it as zero would hide a stale
|
|
216
|
+
rate in exactly the direction that costs somebody money.
|
|
203
217
|
*/
|
|
218
|
+
/*
|
|
219
|
+
A category is set off only where the report can name it. A report that
|
|
220
|
+
cannot say which lines were batch (OpenAI's, or one not grouped by
|
|
221
|
+
description) has its batch charge inside its total like Trazum's figure
|
|
222
|
+
has its batch calls, and taking out Trazum's side alone would move the
|
|
223
|
+
remainder by exactly those calls. The same for non-token charges.
|
|
224
|
+
*/
|
|
225
|
+
const nonTokens = billed.described ? billed.notTokensUsd - (computedWebSearchUsd ?? 0) : 0;
|
|
226
|
+
const batch = billed.batchSeparable ? billed.batchUsd - (computedBatchUsd ?? 0) : 0;
|
|
204
227
|
return {
|
|
205
228
|
...bare,
|
|
206
|
-
remainderUsd: bare.differenceUsd -
|
|
229
|
+
remainderUsd: bare.differenceUsd - nonTokens - batch,
|
|
207
230
|
refusal: null,
|
|
208
231
|
};
|
|
209
232
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-cost.js","sourceRoot":"","sources":["../src/anth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AI;IACrE,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IACxC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7E,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -152,6 +152,8 @@ export interface AnthropicUsageRecord {
|
|
|
152
152
|
speed?: 'fast';
|
|
153
153
|
/** `"us"` when the report says the row ran with US-only inference. */
|
|
154
154
|
inference_geo?: 'us';
|
|
155
|
+
/** `"batch"` when the row ran on the Batch API: billed at the row's batch ratio. */
|
|
156
|
+
service_tier?: 'batch';
|
|
155
157
|
};
|
|
156
158
|
}
|
|
157
159
|
export interface AnthropicUsageConversion {
|
|
@@ -162,8 +164,13 @@ export interface AnthropicUsageConversion {
|
|
|
162
164
|
rows: number;
|
|
163
165
|
/** Results with `model: null`, which nothing can price. */
|
|
164
166
|
unnamedModel: number;
|
|
165
|
-
/**
|
|
167
|
+
/**
|
|
168
|
+
* Results at a tier no rate here prices, left out: priority, flex, or batch
|
|
169
|
+
* on a model with no batch rate.
|
|
170
|
+
*/
|
|
166
171
|
nonStandardTier: number;
|
|
172
|
+
/** Results on the Batch API that became records priced at the row's batch ratio. */
|
|
173
|
+
batchRows: number;
|
|
167
174
|
/**
|
|
168
175
|
* Whether any result named its tier at all.
|
|
169
176
|
*
|
|
@@ -201,8 +208,14 @@ export interface AnthropicUsageConversion {
|
|
|
201
208
|
* a geography. Read as global, because nothing on the row says otherwise, and said.
|
|
202
209
|
*/
|
|
203
210
|
geoUnknownMultiplied: number;
|
|
204
|
-
/**
|
|
211
|
+
/**
|
|
212
|
+
* Web searches carried onto the rows they ran on, as
|
|
213
|
+
* `usage.server_tool_use.web_search_requests`, and billed at the model's
|
|
214
|
+
* per-search fee: $10 per 1,000 on every Claude model, on top of the tokens.
|
|
215
|
+
*/
|
|
205
216
|
webSearchRequests: number;
|
|
217
|
+
/** Web searches on rows left out above (a tier or speed with no rate, no model): in no bill. */
|
|
218
|
+
webSearchLeftOut: number;
|
|
206
219
|
/** `has_more`: this is one page and the bill from it is understated. */
|
|
207
220
|
truncated: boolean;
|
|
208
221
|
/** Records whose label came from a workspace rule rather than `--label`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-usage.d.ts","sourceRoot":"","sources":["../src/anthropic-usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsHG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,yEAAyE;AACzE,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,QAAQ,EAAE,IAAI,CAAC;IACf,KAAK,EAAE;QACL,YAAY,EAAE,MAAM,CAAC;QACrB,aAAa,EAAE,MAAM,CAAC;QACtB,uBAAuB,CAAC,EAAE,MAAM,CAAC;QACjC,cAAc,CAAC,EAAE;YACf,yBAAyB,EAAE,MAAM,CAAC;YAClC,yBAAyB,EAAE,MAAM,CAAC;SACnC,CAAC;QACF,4FAA4F;QAC5F,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,sEAAsE;QACtE,aAAa,CAAC,EAAE,IAAI,CAAC;
|
|
1
|
+
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
117
117
|
* Anything finer would be a precision the source does not have, and
|
|
118
118
|
* `bucket_width=1h` is there for an operator who wants it.
|
|
119
119
|
*/
|
|
120
|
-
import { BUNDLED_CATALOGUE } from './pricing.js';
|
|
120
|
+
import { BUNDLED_CATALOGUE, multipliersFor } from './pricing.js';
|
|
121
121
|
const count = (value) => typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
122
122
|
/**
|
|
123
123
|
* @param label the project this usage belongs to, chosen by the operator.
|
|
@@ -133,6 +133,7 @@ export function anthropicUsageRecords(text, options = {}) {
|
|
|
133
133
|
rows: 0,
|
|
134
134
|
unnamedModel: 0,
|
|
135
135
|
nonStandardTier: 0,
|
|
136
|
+
batchRows: 0,
|
|
136
137
|
tierNamed: false,
|
|
137
138
|
fastRows: 0,
|
|
138
139
|
fastUnpriced: 0,
|
|
@@ -144,6 +145,7 @@ export function anthropicUsageRecords(text, options = {}) {
|
|
|
144
145
|
geoNamed: false,
|
|
145
146
|
geoUnknownMultiplied: 0,
|
|
146
147
|
webSearchRequests: 0,
|
|
148
|
+
webSearchLeftOut: 0,
|
|
147
149
|
truncated: false,
|
|
148
150
|
labelledByWorkspace: 0,
|
|
149
151
|
unruledWorkspace: 0,
|
|
@@ -196,8 +198,10 @@ export function anthropicUsageRecords(text, options = {}) {
|
|
|
196
198
|
let rows = 0;
|
|
197
199
|
let unnamedModel = 0;
|
|
198
200
|
let nonStandardTier = 0;
|
|
201
|
+
let batchRows = 0;
|
|
199
202
|
let tierNamed = false;
|
|
200
203
|
let webSearchRequests = 0;
|
|
204
|
+
let webSearchSeen = 0;
|
|
201
205
|
for (const entry of report.data) {
|
|
202
206
|
if (typeof entry !== 'object' || entry === null)
|
|
203
207
|
continue;
|
|
@@ -211,13 +215,33 @@ export function anthropicUsageRecords(text, options = {}) {
|
|
|
211
215
|
if (typeof found !== 'object' || found === null)
|
|
212
216
|
continue;
|
|
213
217
|
const result = found;
|
|
218
|
+
/*
|
|
219
|
+
Counted here, before any refusal below, so that searches on a row that
|
|
220
|
+
is then left out are said as left out rather than lost: what reaches a
|
|
221
|
+
record is billed, and the difference is named.
|
|
222
|
+
*/
|
|
214
223
|
const tool = result.server_tool_use;
|
|
215
|
-
|
|
224
|
+
const searches = count(tool?.web_search_requests);
|
|
225
|
+
webSearchSeen += searches;
|
|
226
|
+
let batchRow = false;
|
|
216
227
|
if (typeof result.service_tier === 'string') {
|
|
217
228
|
tierNamed = true;
|
|
218
|
-
/*
|
|
219
|
-
|
|
220
|
-
|
|
229
|
+
/*
|
|
230
|
+
Standard is the row's own rate, and batch is the row's batch ratio,
|
|
231
|
+
half of it, which the pricing page publishes as its own table and
|
|
232
|
+
`price-drift.mjs` checks weekly. Everything else (priority, flex) is
|
|
233
|
+
billed on terms no page here publishes, and is left out rather than
|
|
234
|
+
mispriced. A batch row on a model with no batch rate is left out too.
|
|
235
|
+
*/
|
|
236
|
+
if (result.service_tier === 'batch') {
|
|
237
|
+
const row = typeof result.model === 'string' ? catalogue.byId.get(result.model) : undefined;
|
|
238
|
+
if (row === undefined || multipliersFor(row).batch === null) {
|
|
239
|
+
nonStandardTier += 1;
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
batchRow = true;
|
|
243
|
+
}
|
|
244
|
+
else if (result.service_tier !== 'standard') {
|
|
221
245
|
nonStandardTier += 1;
|
|
222
246
|
continue;
|
|
223
247
|
}
|
|
@@ -297,9 +321,19 @@ export function anthropicUsageRecords(text, options = {}) {
|
|
|
297
321
|
: {}),
|
|
298
322
|
...(fast ? { speed: 'fast' } : {}),
|
|
299
323
|
...(usOnly ? { inference_geo: 'us' } : {}),
|
|
324
|
+
...(batchRow ? { service_tier: 'batch' } : {}),
|
|
325
|
+
/*
|
|
326
|
+
Billed per search on top of the tokens, at the same fee on the
|
|
327
|
+
Batch API and whatever the speed or geography: the row's searches
|
|
328
|
+
ride on the row and `profileUsage` prices them off the model.
|
|
329
|
+
*/
|
|
330
|
+
...(searches > 0 ? { server_tool_use: { web_search_requests: searches } } : {}),
|
|
300
331
|
},
|
|
301
332
|
});
|
|
333
|
+
webSearchRequests += searches;
|
|
302
334
|
rows += 1;
|
|
335
|
+
if (batchRow)
|
|
336
|
+
batchRows += 1;
|
|
303
337
|
if (fast)
|
|
304
338
|
fastRows += 1;
|
|
305
339
|
if (usOnly) {
|
|
@@ -316,6 +350,7 @@ export function anthropicUsageRecords(text, options = {}) {
|
|
|
316
350
|
rows,
|
|
317
351
|
unnamedModel,
|
|
318
352
|
nonStandardTier,
|
|
353
|
+
batchRows,
|
|
319
354
|
tierNamed,
|
|
320
355
|
fastRows,
|
|
321
356
|
fastUnpriced,
|
|
@@ -327,6 +362,7 @@ export function anthropicUsageRecords(text, options = {}) {
|
|
|
327
362
|
geoNamed,
|
|
328
363
|
geoUnknownMultiplied,
|
|
329
364
|
webSearchRequests,
|
|
365
|
+
webSearchLeftOut: webSearchSeen - webSearchRequests,
|
|
330
366
|
truncated: report.has_more === true,
|
|
331
367
|
labelledByWorkspace,
|
|
332
368
|
unruledWorkspace,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-usage.js","sourceRoot":"","sources":["../src/anthropic-usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsHG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"anthropic-usage.js","sourceRoot":"","sources":["../src/anthropic-usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsHG;AAEH,OAAO,EAAE,iBAAiB,EAAE,cAAc,E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,QAAQ,CAAC,eAAe,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A provider's Batch API results file, read as a usage log.
|
|
3
|
+
*
|
|
4
|
+
* Both providers return a batch's results as JSON Lines, one per request, and
|
|
5
|
+
* bill every one that ran at half the standard price. Neither shape is a usage
|
|
6
|
+
* line: the model and usage sit one or two objects down, so `parseUsageLine`
|
|
7
|
+
* read a whole results file as nothing at all. This converter takes each line
|
|
8
|
+
* that was billed, keeps its model, usage and end reason, marks it `batch`, and
|
|
9
|
+
* drops everything else, the generated text first among it.
|
|
10
|
+
*
|
|
11
|
+
* ## The two shapes, each from its provider's own page
|
|
12
|
+
*
|
|
13
|
+
* **Anthropic** (platform.claude.com/docs/en/build-with-claude/batch-processing,
|
|
14
|
+
* read 2026-11-05): `{"custom_id", "result": {"type", "message"}}`. `type` is
|
|
15
|
+
* `succeeded`, `errored`, `canceled` or `expired`, and the page says of the
|
|
16
|
+
* last three "You will not be billed for these requests". A succeeded result's
|
|
17
|
+
* `message` is a Messages response, `usage` and all.
|
|
18
|
+
*
|
|
19
|
+
* **OpenAI** (developers.openai.com/api/docs/guides/batch, read 2026-11-05):
|
|
20
|
+
* `{"id", "custom_id", "response": {"status_code", "request_id", "body"},
|
|
21
|
+
* "error"}`. `body` is the endpoint's own response, a Responses or Chat
|
|
22
|
+
* Completions object. An expired request is written with `"response": null`
|
|
23
|
+
* and an `error`; the page says "You will be charged for tokens consumed from
|
|
24
|
+
* any completed requests", so a line is billed only when it carries a 200 and
|
|
25
|
+
* a body with usage.
|
|
26
|
+
*
|
|
27
|
+
* ## What it does not invent
|
|
28
|
+
*
|
|
29
|
+
* **No time.** An Anthropic result carries none; it is counted as undated, the
|
|
30
|
+
* way `bill` already names an undated call, rather than stamped with the day
|
|
31
|
+
* the file was read. An OpenAI body's `created` is Unix seconds and is kept.
|
|
32
|
+
*
|
|
33
|
+
* **No price.** The record says `batch: true` and the model; the batch ratio is
|
|
34
|
+
* the catalogue's, applied where every other call is priced.
|
|
35
|
+
*
|
|
36
|
+
* **No content.** The message's `content`, the body's `output` and `choices`,
|
|
37
|
+
* the `custom_id` (which a caller may have filled with anything) and every id
|
|
38
|
+
* are dropped. A test plants a marker in each and greps the output.
|
|
39
|
+
*/
|
|
40
|
+
/** One converted record, in the shape `parseUsageLine` reads. */
|
|
41
|
+
export interface BatchResultRecord {
|
|
42
|
+
model: string;
|
|
43
|
+
ts?: string;
|
|
44
|
+
label?: string;
|
|
45
|
+
/** Always true: every line here ran on the Batch API. */
|
|
46
|
+
batch: true;
|
|
47
|
+
stop_reason?: string;
|
|
48
|
+
usage: Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
export interface BatchResultConversion {
|
|
51
|
+
records: BatchResultRecord[];
|
|
52
|
+
/** Which provider's shape the file was, or null when no line was either. */
|
|
53
|
+
provider: 'anthropic' | 'openai' | null;
|
|
54
|
+
/** Non-blank lines read. */
|
|
55
|
+
lines: number;
|
|
56
|
+
/** Results the provider says it did not bill: errored, canceled, expired, or not a 200. */
|
|
57
|
+
notBilled: number;
|
|
58
|
+
/** Billed results with no model or usage to price them by. */
|
|
59
|
+
unpriceable: number;
|
|
60
|
+
/** Lines that were not JSON, or neither shape. */
|
|
61
|
+
unparseable: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @param label the project these results belong to, chosen by the operator.
|
|
65
|
+
*/
|
|
66
|
+
export declare function batchResultRecords(text: string, options?: {
|
|
67
|
+
label?: string;
|
|
68
|
+
}): BatchResultConversion;
|
|
69
|
+
/**
|
|
70
|
+
* Whether this text is a Batch API results file.
|
|
71
|
+
*
|
|
72
|
+
* Every line carries a `custom_id`, which no other log here does, beside
|
|
73
|
+
* either Anthropic's `result` with a `type` or OpenAI's `response` with a
|
|
74
|
+
* `status_code`. The first line decides; one that is neither is not this.
|
|
75
|
+
*/
|
|
76
|
+
export declare function looksLikeBatchResults(text: string, prefixBytes?: number): boolean;
|
|
77
|
+
//# sourceMappingURL=batch-results.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-results.d.ts","sourceRoot":"","sources":["../src/batch-results.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,iEAAiE;AACjE,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,KAAK,EAAE,IAAI,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,4EAA4E;IAC5E,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,IAAI,CAAC;IACxC,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,2FAA2F;IAC3F,SAAS,EAAE,MAAM,CAAC;IAClB,8DAA8D;IAC9D,WAAW,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;CACrB;AAUD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,qBAAqB,CA4ExG;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,SAAO,GAAG,OAAO,CAY/E"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A provider's Batch API results file, read as a usage log.
|
|
3
|
+
*
|
|
4
|
+
* Both providers return a batch's results as JSON Lines, one per request, and
|
|
5
|
+
* bill every one that ran at half the standard price. Neither shape is a usage
|
|
6
|
+
* line: the model and usage sit one or two objects down, so `parseUsageLine`
|
|
7
|
+
* read a whole results file as nothing at all. This converter takes each line
|
|
8
|
+
* that was billed, keeps its model, usage and end reason, marks it `batch`, and
|
|
9
|
+
* drops everything else, the generated text first among it.
|
|
10
|
+
*
|
|
11
|
+
* ## The two shapes, each from its provider's own page
|
|
12
|
+
*
|
|
13
|
+
* **Anthropic** (platform.claude.com/docs/en/build-with-claude/batch-processing,
|
|
14
|
+
* read 2026-11-05): `{"custom_id", "result": {"type", "message"}}`. `type` is
|
|
15
|
+
* `succeeded`, `errored`, `canceled` or `expired`, and the page says of the
|
|
16
|
+
* last three "You will not be billed for these requests". A succeeded result's
|
|
17
|
+
* `message` is a Messages response, `usage` and all.
|
|
18
|
+
*
|
|
19
|
+
* **OpenAI** (developers.openai.com/api/docs/guides/batch, read 2026-11-05):
|
|
20
|
+
* `{"id", "custom_id", "response": {"status_code", "request_id", "body"},
|
|
21
|
+
* "error"}`. `body` is the endpoint's own response, a Responses or Chat
|
|
22
|
+
* Completions object. An expired request is written with `"response": null`
|
|
23
|
+
* and an `error`; the page says "You will be charged for tokens consumed from
|
|
24
|
+
* any completed requests", so a line is billed only when it carries a 200 and
|
|
25
|
+
* a body with usage.
|
|
26
|
+
*
|
|
27
|
+
* ## What it does not invent
|
|
28
|
+
*
|
|
29
|
+
* **No time.** An Anthropic result carries none; it is counted as undated, the
|
|
30
|
+
* way `bill` already names an undated call, rather than stamped with the day
|
|
31
|
+
* the file was read. An OpenAI body's `created` is Unix seconds and is kept.
|
|
32
|
+
*
|
|
33
|
+
* **No price.** The record says `batch: true` and the model; the batch ratio is
|
|
34
|
+
* the catalogue's, applied where every other call is priced.
|
|
35
|
+
*
|
|
36
|
+
* **No content.** The message's `content`, the body's `output` and `choices`,
|
|
37
|
+
* the `custom_id` (which a caller may have filled with anything) and every id
|
|
38
|
+
* are dropped. A test plants a marker in each and greps the output.
|
|
39
|
+
*/
|
|
40
|
+
const asObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
41
|
+
? value
|
|
42
|
+
: null;
|
|
43
|
+
/** Usage as the response gave it, minus nothing it bills by and plus nothing. */
|
|
44
|
+
const usageOf = (value) => asObject(value);
|
|
45
|
+
/**
|
|
46
|
+
* @param label the project these results belong to, chosen by the operator.
|
|
47
|
+
*/
|
|
48
|
+
export function batchResultRecords(text, options = {}) {
|
|
49
|
+
const records = [];
|
|
50
|
+
let provider = null;
|
|
51
|
+
let lines = 0;
|
|
52
|
+
let notBilled = 0;
|
|
53
|
+
let unpriceable = 0;
|
|
54
|
+
let unparseable = 0;
|
|
55
|
+
for (const raw of text.split('\n')) {
|
|
56
|
+
if (raw.trim() === '')
|
|
57
|
+
continue;
|
|
58
|
+
lines += 1;
|
|
59
|
+
let parsed;
|
|
60
|
+
try {
|
|
61
|
+
parsed = JSON.parse(raw);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
unparseable += 1;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const line = asObject(parsed);
|
|
68
|
+
if (line === null || typeof line.custom_id !== 'string') {
|
|
69
|
+
unparseable += 1;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const result = asObject(line.result);
|
|
73
|
+
if (result !== null && typeof result.type === 'string') {
|
|
74
|
+
provider ??= 'anthropic';
|
|
75
|
+
if (result.type !== 'succeeded') {
|
|
76
|
+
notBilled += 1;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const message = asObject(result.message);
|
|
80
|
+
const usage = usageOf(message?.usage);
|
|
81
|
+
if (message === null || typeof message.model !== 'string' || usage === null) {
|
|
82
|
+
unpriceable += 1;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
records.push({
|
|
86
|
+
model: message.model,
|
|
87
|
+
...(options.label === undefined ? {} : { label: options.label }),
|
|
88
|
+
batch: true,
|
|
89
|
+
...(typeof message.stop_reason === 'string' ? { stop_reason: message.stop_reason } : {}),
|
|
90
|
+
usage,
|
|
91
|
+
});
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if ('response' in line) {
|
|
95
|
+
provider ??= 'openai';
|
|
96
|
+
const response = asObject(line.response);
|
|
97
|
+
if (response === null || response.status_code !== 200) {
|
|
98
|
+
notBilled += 1;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const body = asObject(response.body);
|
|
102
|
+
const usage = usageOf(body?.usage);
|
|
103
|
+
if (body === null || typeof body.model !== 'string' || usage === null) {
|
|
104
|
+
unpriceable += 1;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const created = typeof body.created_at === 'number' ? body.created_at : typeof body.created === 'number' ? body.created : null;
|
|
108
|
+
records.push({
|
|
109
|
+
model: body.model,
|
|
110
|
+
...(created !== null && Number.isFinite(created) ? { ts: new Date(created * 1000).toISOString() } : {}),
|
|
111
|
+
...(options.label === undefined ? {} : { label: options.label }),
|
|
112
|
+
batch: true,
|
|
113
|
+
usage,
|
|
114
|
+
});
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
unparseable += 1;
|
|
118
|
+
}
|
|
119
|
+
return { records, provider, lines, notBilled, unpriceable, unparseable };
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Whether this text is a Batch API results file.
|
|
123
|
+
*
|
|
124
|
+
* Every line carries a `custom_id`, which no other log here does, beside
|
|
125
|
+
* either Anthropic's `result` with a `type` or OpenAI's `response` with a
|
|
126
|
+
* `status_code`. The first line decides; one that is neither is not this.
|
|
127
|
+
*/
|
|
128
|
+
export function looksLikeBatchResults(text, prefixBytes = 8192) {
|
|
129
|
+
const first = text.slice(0, prefixBytes).split('\n').find((line) => line.trim() !== '');
|
|
130
|
+
if (first === undefined || !first.includes('"custom_id"'))
|
|
131
|
+
return false;
|
|
132
|
+
try {
|
|
133
|
+
const line = asObject(JSON.parse(first));
|
|
134
|
+
if (line === null || typeof line.custom_id !== 'string')
|
|
135
|
+
return false;
|
|
136
|
+
const result = asObject(line.result);
|
|
137
|
+
if (result !== null && typeof result.type === 'string')
|
|
138
|
+
return true;
|
|
139
|
+
return 'response' in line && ('error' in line || asObject(line.response)?.status_code !== undefined);
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=batch-results.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-results.js","sourceRoot":"","sources":["../src/batch-results.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AA2BH,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAkC,EAAE,CAClE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;IAClE,CAAC,CAAE,KAAiC;IACpC,CAAC,CAAC,IAAI,CAAC;AAEX,iFAAiF;AACjF,MAAM,OAAO,GAAG,CAAC,KAAc,EAAkC,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAEpF;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,OAAO,GAAuB,EAAE;IAC/E,MAAM,OAAO,GAAwB,EAAE,CAAC;IACxC,IAAI,QAAQ,GAAsC,IAAI,CAAC;IACvD,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,WAAW,GAAG,CAAC,CAAC;IAEpB,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE;YAAE,SAAS;QAChC,KAAK,IAAI,CAAC,CAAC;Q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,SAAS,CAAC,CAAC;IACvG,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/dist/billing.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PromptSize } from './pricing.js';
|
|
2
|
+
import type { ModelPricing } from './types.js';
|
|
2
3
|
import type { UsageRecord } from './usage.js';
|
|
3
4
|
/**
|
|
4
5
|
* The instant a record was billed at: its own clock, or `on` when it has none.
|
|
@@ -17,4 +18,13 @@ export declare function billedAt(record: UsageRecord, on: Date): Date;
|
|
|
17
18
|
* requests says only that no request in it was larger than the whole row.
|
|
18
19
|
*/
|
|
19
20
|
export declare function promptSizeOf(record: UsageRecord): PromptSize;
|
|
21
|
+
/**
|
|
22
|
+
* What a record's web searches cost: per search, at the row's fee, flat.
|
|
23
|
+
*
|
|
24
|
+
* Here beside `billedAt` and `promptSizeOf` for the same reason they are: the
|
|
25
|
+
* total and every tracker under it price a call, and a finding that costs a
|
|
26
|
+
* call without its searches disagrees with the bill it sits under. Zero for a
|
|
27
|
+
* row with no fee, whose searches the total names as unpriced instead.
|
|
28
|
+
*/
|
|
29
|
+
export declare function webSearchUsdOf(record: UsageRecord, model: ModelPricing): number;
|
|
20
30
|
//# sourceMappingURL=billing.d.ts.map
|
package/dist/billing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billing.d.ts","sourceRoot":"","sources":["../src/billing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAY9C;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,EAAE,IAAI,GAAG,IAAI,CAE5D;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"billing.d.ts","sourceRoot":"","sources":["../src/billing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAY9C;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,EAAE,IAAI,GAAG,IAAI,CAE5D;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,UAAU,CAU5D;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,GAAG,MAAM,CAI/E"}
|