@trazum/core 2.7.2 → 2.7.4
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-usage.d.ts +66 -1
- package/dist/anthropic-usage.d.ts.map +1 -1
- package/dist/anthropic-usage.js +114 -3
- 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.map +1 -1
- package/dist/billing.js +2 -0
- package/dist/billing.js.map +1 -1
- package/dist/claude-code.d.ts +2 -0
- package/dist/claude-code.d.ts.map +1 -1
- package/dist/claude-code.js +9 -0
- package/dist/claude-code.js.map +1 -1
- package/dist/connector.d.ts +3 -1
- package/dist/connector.d.ts.map +1 -1
- package/dist/connector.js +72 -5
- package/dist/connector.js.map +1 -1
- package/dist/gateway.d.ts +10 -0
- package/dist/gateway.d.ts.map +1 -1
- package/dist/gateway.js +7 -1
- package/dist/gateway.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/openai-usage.d.ts +43 -7
- package/dist/openai-usage.d.ts.map +1 -1
- package/dist/openai-usage.js +63 -11
- 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 +21 -0
- package/dist/pricing-overlay.js.map +1 -1
- package/dist/pricing.d.ts +24 -1
- package/dist/pricing.d.ts.map +1 -1
- package/dist/pricing.js +87 -0
- package/dist/pricing.js.map +1 -1
- package/dist/store.d.ts +4 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +22 -1
- package/dist/store.js.map +1 -1
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/usage.d.ts +16 -0
- package/dist/usage.d.ts.map +1 -1
- package/dist/usage.js +16 -0
- package/dist/usage.js.map +1 -1
- package/package.json +1 -1
- package/src/anthropic-usage.ts +163 -5
- package/src/batch-results.ts +174 -0
- package/src/billing.ts +2 -0
- package/src/claude-code.ts +11 -0
- package/src/connector.ts +76 -6
- package/src/gateway.ts +16 -2
- package/src/index.ts +3 -0
- package/src/openai-usage.ts +95 -14
- package/src/pricing-overlay.ts +21 -0
- package/src/pricing.ts +105 -1
- package/src/store.ts +24 -3
- package/src/types.ts +18 -0
- package/src/usage.ts +32 -0
|
@@ -53,6 +53,26 @@
|
|
|
53
53
|
* and counted, the same way an unpriceable line becomes a named gap rather
|
|
54
54
|
* than a guess.
|
|
55
55
|
*
|
|
56
|
+
* **A fast-mode row on a model with no fast table.** Fast mode bills Opus 5.5
|
|
57
|
+
* at $8/$40 against $4/$20, and the report says which speed ran in `speed`
|
|
58
|
+
* once it is grouped by it. A fast row is carried with `usage.speed: "fast"`
|
|
59
|
+
* and priced from the model's own fast rates, exactly as a logged response
|
|
60
|
+
* carrying the same field is. A fast row on a model the catalogue has no
|
|
61
|
+
* fast rate for is left out and named, never priced at the standard rate,
|
|
62
|
+
* which would put it at well under its cost. A report not grouped by speed
|
|
63
|
+
* cannot say, so a row on a model that has a fast rate is read as standard
|
|
64
|
+
* and the conversion says the question was not asked.
|
|
65
|
+
*
|
|
66
|
+
* **US-only inference.** `inference_geo: "us"` bills 1.1x on every token
|
|
67
|
+
* category of Claude 4.6 and later, the pricing page says, and the catalogue
|
|
68
|
+
* carries that multiplier on each of those rows. A US-only row is written
|
|
69
|
+
* with `usage.inference_geo: "us"` and priced at it, exactly as a logged
|
|
70
|
+
* response carrying the field is. One on a model the catalogue has no
|
|
71
|
+
* multiplier for is priced at the global rate and counted as a floor, never
|
|
72
|
+
* multiplied by a figure the row does not publish. A report not grouped by
|
|
73
|
+
* `inference_geo` cannot say, so its rows are read as global and the
|
|
74
|
+
* conversion says the question was not asked.
|
|
75
|
+
*
|
|
56
76
|
* **Web search requests.** `server_tool_use.web_search_requests` is billed per
|
|
57
77
|
* request, not per token, so no token rate reaches it. Counted and named, so a
|
|
58
78
|
* total that is missing them says so.
|
|
@@ -97,6 +117,7 @@
|
|
|
97
117
|
* Anything finer would be a precision the source does not have, and
|
|
98
118
|
* `bucket_width=1h` is there for an operator who wants it.
|
|
99
119
|
*/
|
|
120
|
+
import type { PricingCatalogue } from './pricing.js';
|
|
100
121
|
/**
|
|
101
122
|
* One workspace, and the project name the operator gives it.
|
|
102
123
|
*
|
|
@@ -127,6 +148,12 @@ export interface AnthropicUsageRecord {
|
|
|
127
148
|
ephemeral_5m_input_tokens: number;
|
|
128
149
|
ephemeral_1h_input_tokens: number;
|
|
129
150
|
};
|
|
151
|
+
/** `"fast"` when the report says the row ran in fast mode and the model has a fast rate. */
|
|
152
|
+
speed?: 'fast';
|
|
153
|
+
/** `"us"` when the report says the row ran with US-only inference. */
|
|
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';
|
|
130
157
|
};
|
|
131
158
|
}
|
|
132
159
|
export interface AnthropicUsageConversion {
|
|
@@ -137,8 +164,13 @@ export interface AnthropicUsageConversion {
|
|
|
137
164
|
rows: number;
|
|
138
165
|
/** Results with `model: null`, which nothing can price. */
|
|
139
166
|
unnamedModel: number;
|
|
140
|
-
/**
|
|
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
|
+
*/
|
|
141
171
|
nonStandardTier: number;
|
|
172
|
+
/** Results on the Batch API that became records priced at the row's batch ratio. */
|
|
173
|
+
batchRows: number;
|
|
142
174
|
/**
|
|
143
175
|
* Whether any result named its tier at all.
|
|
144
176
|
*
|
|
@@ -149,6 +181,33 @@ export interface AnthropicUsageConversion {
|
|
|
149
181
|
* question was answered that was never asked.
|
|
150
182
|
*/
|
|
151
183
|
tierNamed: boolean;
|
|
184
|
+
/** Results in fast mode that became records priced from the model's fast rate. */
|
|
185
|
+
fastRows: number;
|
|
186
|
+
/** Results in fast mode on a model the catalogue has no fast rate for, left out. */
|
|
187
|
+
fastUnpriced: number;
|
|
188
|
+
/** The models those results named, so the refusal has a name. */
|
|
189
|
+
fastUnpricedModels: string[];
|
|
190
|
+
/** Whether any result named its speed at all. */
|
|
191
|
+
speedNamed: boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Results on a model with a fast rate, in a report that never named a speed.
|
|
194
|
+
* Read as standard, because nothing on the row says otherwise, and said.
|
|
195
|
+
*/
|
|
196
|
+
speedUnknownFastCapable: number;
|
|
197
|
+
/** Results with `inference_geo: "us"` priced at the model's published US-only multiplier. */
|
|
198
|
+
usOnlyRows: number;
|
|
199
|
+
/**
|
|
200
|
+
* Results with `inference_geo: "us"` on a model the catalogue has no
|
|
201
|
+
* US-only multiplier for, priced at the global rate: their figure is a floor.
|
|
202
|
+
*/
|
|
203
|
+
usOnlyFloor: number;
|
|
204
|
+
/** Whether any result named its inference geography at all. */
|
|
205
|
+
geoNamed: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Results on a model with a US-only multiplier, in a report that never named
|
|
208
|
+
* a geography. Read as global, because nothing on the row says otherwise, and said.
|
|
209
|
+
*/
|
|
210
|
+
geoUnknownMultiplied: number;
|
|
152
211
|
/** Server-side tool calls billed per request, which no token rate prices. */
|
|
153
212
|
webSearchRequests: number;
|
|
154
213
|
/** `has_more`: this is one page and the bill from it is understated. */
|
|
@@ -184,6 +243,12 @@ export interface AnthropicUsageConversion {
|
|
|
184
243
|
export declare function anthropicUsageRecords(text: string, options?: {
|
|
185
244
|
label?: string;
|
|
186
245
|
labelByWorkspace?: readonly WorkspaceLabel[];
|
|
246
|
+
/**
|
|
247
|
+
* Where a model's fast rate is looked for. The bundled catalogue unless a
|
|
248
|
+
* caller prices with another; a fast row whose model has no fast rate in
|
|
249
|
+
* it is refused, never priced at the standard one.
|
|
250
|
+
*/
|
|
251
|
+
catalogue?: PricingCatalogue;
|
|
187
252
|
}): AnthropicUsageConversion;
|
|
188
253
|
/**
|
|
189
254
|
* Whether this text is an Anthropic usage report rather than some other JSON.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-usage.d.ts","sourceRoot":"","sources":["../src/anthropic-usage.ts"],"names":[],"mappings":"AAAA
|
|
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;QACrB,oFAAoF;QACpF,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB,CAAC;CACH;AAED,MAAM,WAAW,wBAA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AAgB,CAAC;CACzB,GACL,wBAAwB,CAyP1B;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,SAAO,GAAG,OAAO,CAIjF"}
|
package/dist/anthropic-usage.js
CHANGED
|
@@ -53,6 +53,26 @@
|
|
|
53
53
|
* and counted, the same way an unpriceable line becomes a named gap rather
|
|
54
54
|
* than a guess.
|
|
55
55
|
*
|
|
56
|
+
* **A fast-mode row on a model with no fast table.** Fast mode bills Opus 5.5
|
|
57
|
+
* at $8/$40 against $4/$20, and the report says which speed ran in `speed`
|
|
58
|
+
* once it is grouped by it. A fast row is carried with `usage.speed: "fast"`
|
|
59
|
+
* and priced from the model's own fast rates, exactly as a logged response
|
|
60
|
+
* carrying the same field is. A fast row on a model the catalogue has no
|
|
61
|
+
* fast rate for is left out and named, never priced at the standard rate,
|
|
62
|
+
* which would put it at well under its cost. A report not grouped by speed
|
|
63
|
+
* cannot say, so a row on a model that has a fast rate is read as standard
|
|
64
|
+
* and the conversion says the question was not asked.
|
|
65
|
+
*
|
|
66
|
+
* **US-only inference.** `inference_geo: "us"` bills 1.1x on every token
|
|
67
|
+
* category of Claude 4.6 and later, the pricing page says, and the catalogue
|
|
68
|
+
* carries that multiplier on each of those rows. A US-only row is written
|
|
69
|
+
* with `usage.inference_geo: "us"` and priced at it, exactly as a logged
|
|
70
|
+
* response carrying the field is. One on a model the catalogue has no
|
|
71
|
+
* multiplier for is priced at the global rate and counted as a floor, never
|
|
72
|
+
* multiplied by a figure the row does not publish. A report not grouped by
|
|
73
|
+
* `inference_geo` cannot say, so its rows are read as global and the
|
|
74
|
+
* conversion says the question was not asked.
|
|
75
|
+
*
|
|
56
76
|
* **Web search requests.** `server_tool_use.web_search_requests` is billed per
|
|
57
77
|
* request, not per token, so no token rate reaches it. Counted and named, so a
|
|
58
78
|
* total that is missing them says so.
|
|
@@ -97,6 +117,7 @@
|
|
|
97
117
|
* Anything finer would be a precision the source does not have, and
|
|
98
118
|
* `bucket_width=1h` is there for an operator who wants it.
|
|
99
119
|
*/
|
|
120
|
+
import { BUNDLED_CATALOGUE, multipliersFor } from './pricing.js';
|
|
100
121
|
const count = (value) => typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
101
122
|
/**
|
|
102
123
|
* @param label the project this usage belongs to, chosen by the operator.
|
|
@@ -112,7 +133,17 @@ export function anthropicUsageRecords(text, options = {}) {
|
|
|
112
133
|
rows: 0,
|
|
113
134
|
unnamedModel: 0,
|
|
114
135
|
nonStandardTier: 0,
|
|
136
|
+
batchRows: 0,
|
|
115
137
|
tierNamed: false,
|
|
138
|
+
fastRows: 0,
|
|
139
|
+
fastUnpriced: 0,
|
|
140
|
+
fastUnpricedModels: [],
|
|
141
|
+
speedNamed: false,
|
|
142
|
+
speedUnknownFastCapable: 0,
|
|
143
|
+
usOnlyRows: 0,
|
|
144
|
+
usOnlyFloor: 0,
|
|
145
|
+
geoNamed: false,
|
|
146
|
+
geoUnknownMultiplied: 0,
|
|
116
147
|
webSearchRequests: 0,
|
|
117
148
|
truncated: false,
|
|
118
149
|
labelledByWorkspace: 0,
|
|
@@ -146,13 +177,27 @@ export function anthropicUsageRecords(text, options = {}) {
|
|
|
146
177
|
&& entry.results.some((found) => typeof found === 'object'
|
|
147
178
|
&& found !== null
|
|
148
179
|
&& typeof found.workspace_id === 'string'));
|
|
180
|
+
const catalogue = options.catalogue ?? BUNDLED_CATALOGUE;
|
|
181
|
+
const hasFastRate = (model) => catalogue.byId.get(model)?.tiers?.some((tier) => tier.when.kind === 'speed' && tier.when.speed === 'fast')
|
|
182
|
+
?? false;
|
|
149
183
|
const records = [];
|
|
184
|
+
const fastUnpricedModels = new Set();
|
|
185
|
+
let fastRows = 0;
|
|
186
|
+
let fastUnpriced = 0;
|
|
187
|
+
let speedNamed = false;
|
|
188
|
+
let speedUnknownFastCapable = 0;
|
|
189
|
+
let usOnlyRows = 0;
|
|
190
|
+
let usOnlyFloor = 0;
|
|
191
|
+
let geoNamed = false;
|
|
192
|
+
let geoUnknownMultiplied = 0;
|
|
193
|
+
const hasUsMultiplier = (model) => catalogue.byId.get(model)?.inferenceGeoMultipliers?.us !== undefined;
|
|
150
194
|
let labelledByWorkspace = 0;
|
|
151
195
|
let unruledWorkspace = 0;
|
|
152
196
|
let buckets = 0;
|
|
153
197
|
let rows = 0;
|
|
154
198
|
let unnamedModel = 0;
|
|
155
199
|
let nonStandardTier = 0;
|
|
200
|
+
let batchRows = 0;
|
|
156
201
|
let tierNamed = false;
|
|
157
202
|
let webSearchRequests = 0;
|
|
158
203
|
for (const entry of report.data) {
|
|
@@ -170,11 +215,25 @@ export function anthropicUsageRecords(text, options = {}) {
|
|
|
170
215
|
const result = found;
|
|
171
216
|
const tool = result.server_tool_use;
|
|
172
217
|
webSearchRequests += count(tool?.web_search_requests);
|
|
218
|
+
let batchRow = false;
|
|
173
219
|
if (typeof result.service_tier === 'string') {
|
|
174
220
|
tierNamed = true;
|
|
175
|
-
/*
|
|
176
|
-
|
|
177
|
-
|
|
221
|
+
/*
|
|
222
|
+
Standard is the row's own rate, and batch is the row's batch ratio,
|
|
223
|
+
half of it, which the pricing page publishes as its own table and
|
|
224
|
+
`price-drift.mjs` checks weekly. Everything else (priority, flex) is
|
|
225
|
+
billed on terms no page here publishes, and is left out rather than
|
|
226
|
+
mispriced. A batch row on a model with no batch rate is left out too.
|
|
227
|
+
*/
|
|
228
|
+
if (result.service_tier === 'batch') {
|
|
229
|
+
const row = typeof result.model === 'string' ? catalogue.byId.get(result.model) : undefined;
|
|
230
|
+
if (row === undefined || multipliersFor(row).batch === null) {
|
|
231
|
+
nonStandardTier += 1;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
batchRow = true;
|
|
235
|
+
}
|
|
236
|
+
else if (result.service_tier !== 'standard') {
|
|
178
237
|
nonStandardTier += 1;
|
|
179
238
|
continue;
|
|
180
239
|
}
|
|
@@ -183,6 +242,25 @@ export function anthropicUsageRecords(text, options = {}) {
|
|
|
183
242
|
unnamedModel += 1;
|
|
184
243
|
continue;
|
|
185
244
|
}
|
|
245
|
+
/*
|
|
246
|
+
Fast mode is a rate of its own, decided by the row: priced from it
|
|
247
|
+
when the model has one, refused and named when it does not.
|
|
248
|
+
*/
|
|
249
|
+
let fast = false;
|
|
250
|
+
if (typeof result.speed === 'string') {
|
|
251
|
+
speedNamed = true;
|
|
252
|
+
if (result.speed === 'fast') {
|
|
253
|
+
if (!hasFastRate(result.model)) {
|
|
254
|
+
fastUnpriced += 1;
|
|
255
|
+
fastUnpricedModels.add(result.model);
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
fast = true;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
else if (hasFastRate(result.model)) {
|
|
262
|
+
speedUnknownFastCapable += 1;
|
|
263
|
+
}
|
|
186
264
|
/*
|
|
187
265
|
The operator's mapping wins where it matches, `--label` stands where
|
|
188
266
|
it does not, and a `null` workspace is the default one only when the
|
|
@@ -202,6 +280,16 @@ export function anthropicUsageRecords(text, options = {}) {
|
|
|
202
280
|
unruledWorkspace += 1;
|
|
203
281
|
}
|
|
204
282
|
}
|
|
283
|
+
/*
|
|
284
|
+
US-only inference is the row's own fact, priced by the model's
|
|
285
|
+
published multiplier where it has one. A report not grouped by
|
|
286
|
+
geography says nothing either way, and that is said.
|
|
287
|
+
*/
|
|
288
|
+
const usOnly = result.inference_geo === 'us';
|
|
289
|
+
if (typeof result.inference_geo === 'string')
|
|
290
|
+
geoNamed = true;
|
|
291
|
+
else if (hasUsMultiplier(result.model))
|
|
292
|
+
geoUnknownMultiplied += 1;
|
|
205
293
|
const creation = result.cache_creation;
|
|
206
294
|
const write5m = count(creation?.ephemeral_5m_input_tokens);
|
|
207
295
|
const write1h = count(creation?.ephemeral_1h_input_tokens);
|
|
@@ -223,9 +311,22 @@ export function anthropicUsageRecords(text, options = {}) {
|
|
|
223
311
|
},
|
|
224
312
|
}
|
|
225
313
|
: {}),
|
|
314
|
+
...(fast ? { speed: 'fast' } : {}),
|
|
315
|
+
...(usOnly ? { inference_geo: 'us' } : {}),
|
|
316
|
+
...(batchRow ? { service_tier: 'batch' } : {}),
|
|
226
317
|
},
|
|
227
318
|
});
|
|
228
319
|
rows += 1;
|
|
320
|
+
if (batchRow)
|
|
321
|
+
batchRows += 1;
|
|
322
|
+
if (fast)
|
|
323
|
+
fastRows += 1;
|
|
324
|
+
if (usOnly) {
|
|
325
|
+
if (hasUsMultiplier(result.model))
|
|
326
|
+
usOnlyRows += 1;
|
|
327
|
+
else
|
|
328
|
+
usOnlyFloor += 1;
|
|
329
|
+
}
|
|
229
330
|
}
|
|
230
331
|
}
|
|
231
332
|
return {
|
|
@@ -234,7 +335,17 @@ export function anthropicUsageRecords(text, options = {}) {
|
|
|
234
335
|
rows,
|
|
235
336
|
unnamedModel,
|
|
236
337
|
nonStandardTier,
|
|
338
|
+
batchRows,
|
|
237
339
|
tierNamed,
|
|
340
|
+
fastRows,
|
|
341
|
+
fastUnpriced,
|
|
342
|
+
fastUnpricedModels: [...fastUnpricedModels],
|
|
343
|
+
speedNamed,
|
|
344
|
+
speedUnknownFastCapable,
|
|
345
|
+
usOnlyRows,
|
|
346
|
+
usOnlyFloor,
|
|
347
|
+
geoNamed,
|
|
348
|
+
geoUnknownMultiplied,
|
|
238
349
|
webSearchRequests,
|
|
239
350
|
truncated: report.has_more === true,
|
|
240
351
|
labelledByWorkspace,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-usage.js","sourceRoot":"","sources":["../src/anthropic-usage.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"anthropic-usage.js","sourceRoot":"","sources":["../src/anthropic-usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAC;YAC7B,IAAI,IAAI;gBAAE,QAAQ,IAAI,CAAC,CAAC;YACxB,IAAI,MAAM,EAAE,CAAC;gBACX,IAAI,eAAe,CAAC,MAAM,CAAC,KAAK,CAAC;oBAAE,UAAU,IAAI,CAAC,CAAC;;oBAC9C,WAAW,IAAI,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO;QACP,OAAO;QACP,IAAI;QACJ,YAAY;QACZ,eAAe;QACf,SAAS;QACT,SAAS;QACT,QAAQ;QACR,YAAY;QACZ,kBAAkB,EAAE,CAAC,GAAG,kBAAkB,CAAC;QAC3C,UAAU;QACV,uBAAuB;QACvB,UAAU;QACV,WAAW;QACX,QAAQ;QACR,oBAAoB;QACpB,iBAAiB;QACjB,SAAS,EAAE,MAAM,CAAC,QAAQ,KAAK,IAAI;QACnC,mBAAmB;QACnB,gBAAgB;QAChB,mBAAmB,EAAE,KAAK,KAAK,SAAS,IAAI,CAAC,OAAO;QACpD,WAAW,EAAE,CAAC;KACf,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAY,EAAE,WAAW,GAAG,IAAI;IACtE,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IACxC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,yBAAyB,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5D,OAAO,IAAI,CAAC,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
|
|
@@ -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AAE,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,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"}
|
package/dist/billing.js
CHANGED
|
@@ -30,6 +30,8 @@ export function promptSizeOf(record) {
|
|
|
30
30
|
const how = {
|
|
31
31
|
...(record.speed === undefined ? {} : { speed: record.speed }),
|
|
32
32
|
...(record.serviceTier === undefined ? {} : { serviceTier: record.serviceTier }),
|
|
33
|
+
...(record.inferenceGeo === undefined ? {} : { inferenceGeo: record.inferenceGeo }),
|
|
34
|
+
...(record.batch === true ? { batch: true } : {}),
|
|
33
35
|
};
|
|
34
36
|
return record.requests === undefined ? { inputTokens: prompt, ...how } : { inputTokensAtMost: prompt, ...how };
|
|
35
37
|
}
|
package/dist/billing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../src/billing.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,MAAmB,EAAE,EAAQ;IACpD,OAAO,MAAM,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CA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KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC;QAChF,GAAG,CAAC,MAAM,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE,CAAC;QACnF,GAAG,CAAC,MAAM,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAClD,CAAC;IACF,OAAO,MAAM,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,MAAM,EAAE,GAAG,GAAG,EAAE,CAAC;AACjH,CAAC"}
|
package/dist/claude-code.d.ts
CHANGED
|
@@ -77,6 +77,8 @@ export interface ClaudeCodeRecord {
|
|
|
77
77
|
};
|
|
78
78
|
/** The response's `usage.speed`, kept because fast mode bills at a multiple of standard. */
|
|
79
79
|
speed?: string;
|
|
80
|
+
/** The response's `usage.inference_geo`, kept because US-only inference bills 1.1x on Claude 4.6 and later. */
|
|
81
|
+
inference_geo?: string;
|
|
80
82
|
};
|
|
81
83
|
}
|
|
82
84
|
export interface ClaudeCodeConversion {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-code.d.ts","sourceRoot":"","sources":["../src/claude-code.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,QAAQ;IACvB,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,yEAAyE;AACzE,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,C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4F;QAC5F,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,+GAA+G;QAC/G,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;CACH;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B,mEAAmE;IACnE,SAAS,EAAE,MAAM,CAAC;IAClB,0EAA0E;IAC1E,WAAW,EAAE,MAAM,CAAC;IACpB,iFAAiF;IACjF,UAAU,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAC;IACpB,+DAA+D;IAC/D,qBAAqB,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;;;;;;OAOG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,MAAM,EAAE;QACN,gFAAgF;QAChF,IAAI,EAAE,MAAM,CAAC;QACb,yDAAyD;QACzD,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAgCD,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,SAAS,QAAQ,EAAE,CAAA;CAAO,GACjE,oBAAoB,CA4KtB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,SAAM,GAAG,OAAO,CAkBhF"}
|
package/dist/claude-code.js
CHANGED
|
@@ -153,6 +153,15 @@ export function claudeCodeRecords(text, options = {}) {
|
|
|
153
153
|
* priced every fast call at the standard rate: half its cost.
|
|
154
154
|
*/
|
|
155
155
|
...(typeof usage.speed === 'string' && usage.speed !== '' ? { speed: usage.speed } : {}),
|
|
156
|
+
/*
|
|
157
|
+
* And the geography that ran: US-only inference bills 1.1x on Claude
|
|
158
|
+
* 4.6 and later, on every token category. Every Claude Code line
|
|
159
|
+
* carries it, "global" or "not_available" unless the workspace pins
|
|
160
|
+
* "us"; dropping it priced every US-only call at a tenth under its cost.
|
|
161
|
+
*/
|
|
162
|
+
...(typeof usage.inference_geo === 'string' && usage.inference_geo !== ''
|
|
163
|
+
? { inference_geo: usage.inference_geo }
|
|
164
|
+
: {}),
|
|
156
165
|
},
|
|
157
166
|
};
|
|
158
167
|
const requestId = typeof entry.requestId === 'string' ? entry.requestId : null;
|