@trazum/core 2.7.1 → 2.7.3
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 +58 -0
- package/dist/anthropic-usage.d.ts.map +1 -1
- package/dist/anthropic-usage.js +91 -0
- package/dist/anthropic-usage.js.map +1 -1
- package/dist/billing.d.ts.map +1 -1
- package/dist/billing.js +6 -2
- 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 +64 -5
- package/dist/connector.js.map +1 -1
- package/dist/gateway.d.ts +18 -0
- package/dist/gateway.d.ts.map +1 -1
- package/dist/gateway.js +20 -1
- package/dist/gateway.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/openai-usage.d.ts +38 -6
- package/dist/openai-usage.d.ts.map +1 -1
- package/dist/openai-usage.js +44 -8
- 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 +37 -1
- package/dist/pricing.d.ts.map +1 -1
- package/dist/pricing.js +528 -9
- 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 +54 -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 +17 -0
- package/dist/usage.js.map +1 -1
- package/package.json +1 -1
- package/src/anthropic-usage.ts +134 -1
- package/src/billing.ts +6 -2
- package/src/claude-code.ts +11 -0
- package/src/connector.ts +69 -6
- package/src/gateway.ts +35 -2
- package/src/index.ts +2 -0
- package/src/openai-usage.ts +72 -10
- package/src/pricing-overlay.ts +21 -0
- package/src/pricing.ts +552 -10
- package/src/store.ts +24 -3
- package/src/types.ts +57 -0
- package/src/usage.ts +33 -0
package/src/index.ts
CHANGED
|
@@ -443,6 +443,8 @@ export {
|
|
|
443
443
|
cheapestOfTierIn,
|
|
444
444
|
multipliersFor,
|
|
445
445
|
isOffered,
|
|
446
|
+
serviceTierOf,
|
|
447
|
+
inferenceGeoOf,
|
|
446
448
|
} from './pricing.js';
|
|
447
449
|
export type { PricingCatalogue, PromptSize } from './pricing.js';
|
|
448
450
|
export type { CachingMode, Capability, CostMultipliers } from './types.js';
|
package/src/openai-usage.ts
CHANGED
|
@@ -51,11 +51,21 @@
|
|
|
51
51
|
* conversion says the question was not asked, because the alternative is a
|
|
52
52
|
* reader assuming it was answered.
|
|
53
53
|
*
|
|
54
|
-
* **A service tier
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
54
|
+
* **A service tier with no table of its own.** OpenAI sells Flex, Fast
|
|
55
|
+
* (Priority until 2026-07-30) and Ultrafast from tables of their own, and the
|
|
56
|
+
* catalogue writes each model's row of each one out in `serviceTiers`. A row
|
|
57
|
+
* at one of those tiers, on a model whose catalogue row has that tier's table,
|
|
58
|
+
* is carried into the record as `service_tier` and priced from that table,
|
|
59
|
+
* exactly as a logged response naming the same tier is: the published rate
|
|
60
|
+
* for the tier that ran, not a multiple of another.
|
|
61
|
+
*
|
|
62
|
+
* Anything else is still left out, counted, and *named*: a tier the
|
|
63
|
+
* catalogue has no table for on that model (GPT-4o has no Flex), and any
|
|
64
|
+
* value `serviceTierOf` does not know, because the schema does not enumerate
|
|
65
|
+
* the tiers and so this does not either. Pricing such a row at the standard
|
|
66
|
+
* rate would put a Flex bill at twice its cost and look right doing it; the
|
|
67
|
+
* operator sees `flex` or `scale` or whatever the report said, never a
|
|
68
|
+
* number standing in for it.
|
|
59
69
|
*
|
|
60
70
|
* **Audio and image tokens.** `input_tokens` folds text, audio and image
|
|
61
71
|
* tokens together, and a text rate is not the rate for the other two. A row
|
|
@@ -84,6 +94,9 @@
|
|
|
84
94
|
* absence and no second reading to derive.
|
|
85
95
|
*/
|
|
86
96
|
|
|
97
|
+
import { BUNDLED_CATALOGUE, serviceTierOf } from './pricing.js';
|
|
98
|
+
import type { PricingCatalogue } from './pricing.js';
|
|
99
|
+
|
|
87
100
|
/** One project, and the label the operator gives it. Matched exactly. */
|
|
88
101
|
export interface ProjectLabel {
|
|
89
102
|
project: string;
|
|
@@ -101,6 +114,13 @@ export interface OpenaiUsageRecord {
|
|
|
101
114
|
* request, which is then a call like any other. See `UsageRecord.requests`.
|
|
102
115
|
*/
|
|
103
116
|
requests?: number | null;
|
|
117
|
+
/**
|
|
118
|
+
* The report's own tier, as it spelled it, when it is one the catalogue
|
|
119
|
+
* prices this model from: `parseUsageLine` reads it as a response's
|
|
120
|
+
* `service_tier` and the call is priced from that tier's table. Absent for
|
|
121
|
+
* the default tier.
|
|
122
|
+
*/
|
|
123
|
+
service_tier?: string;
|
|
104
124
|
usage: {
|
|
105
125
|
prompt_tokens: number;
|
|
106
126
|
completion_tokens: number;
|
|
@@ -127,10 +147,18 @@ export interface OpenaiUsageConversion {
|
|
|
127
147
|
batch: number;
|
|
128
148
|
/** Whether any result said whether it was batch at all. */
|
|
129
149
|
batchNamed: boolean;
|
|
130
|
-
/**
|
|
150
|
+
/**
|
|
151
|
+
* Results at a service tier other than `default` that no table prices, left
|
|
152
|
+
* out: a tier the model's catalogue row has no table for, or a value
|
|
153
|
+
* `serviceTierOf` does not know.
|
|
154
|
+
*/
|
|
131
155
|
nonDefaultTier: number;
|
|
132
156
|
/** The tiers those results named, so the refusal has a name. */
|
|
133
157
|
tiersRefused: string[];
|
|
158
|
+
/** Results at Flex, Fast or Ultrafast that became records priced from that tier's own table. */
|
|
159
|
+
serviceTierRows: number;
|
|
160
|
+
/** The tiers those results named, as the report spelled them. */
|
|
161
|
+
tiersPriced: string[];
|
|
134
162
|
/** Whether any result named a tier at all. */
|
|
135
163
|
tierNamed: boolean;
|
|
136
164
|
/** Results that carried audio or image tokens and were reduced to text. */
|
|
@@ -183,7 +211,16 @@ const NON_TEXT = [
|
|
|
183
211
|
*/
|
|
184
212
|
export function openaiUsageRecords(
|
|
185
213
|
text: string,
|
|
186
|
-
options: {
|
|
214
|
+
options: {
|
|
215
|
+
label?: string;
|
|
216
|
+
labelByProject?: readonly ProjectLabel[];
|
|
217
|
+
/**
|
|
218
|
+
* Where a tier's table is looked for. The bundled catalogue unless a
|
|
219
|
+
* caller prices with another; a row whose model this catalogue has no
|
|
220
|
+
* table for at that tier is refused, never priced at the standard rate.
|
|
221
|
+
*/
|
|
222
|
+
catalogue?: PricingCatalogue;
|
|
223
|
+
} = {},
|
|
187
224
|
): OpenaiUsageConversion {
|
|
188
225
|
const empty: OpenaiUsageConversion = {
|
|
189
226
|
records: [],
|
|
@@ -195,6 +232,8 @@ export function openaiUsageRecords(
|
|
|
195
232
|
batchNamed: false,
|
|
196
233
|
nonDefaultTier: 0,
|
|
197
234
|
tiersRefused: [],
|
|
235
|
+
serviceTierRows: 0,
|
|
236
|
+
tiersPriced: [],
|
|
198
237
|
tierNamed: false,
|
|
199
238
|
mixedRows: 0,
|
|
200
239
|
nonTextTokens: 0,
|
|
@@ -219,7 +258,9 @@ export function openaiUsageRecords(
|
|
|
219
258
|
|
|
220
259
|
const rules = options.labelByProject;
|
|
221
260
|
const records: OpenaiUsageRecord[] = [];
|
|
261
|
+
const catalogue = options.catalogue ?? BUNDLED_CATALOGUE;
|
|
222
262
|
const tiersRefused = new Set<string>();
|
|
263
|
+
const tiersPriced = new Set<string>();
|
|
223
264
|
let buckets = 0;
|
|
224
265
|
let rows = 0;
|
|
225
266
|
let requests = 0;
|
|
@@ -227,6 +268,7 @@ export function openaiUsageRecords(
|
|
|
227
268
|
let batch = 0;
|
|
228
269
|
let batchNamed = false;
|
|
229
270
|
let nonDefaultTier = 0;
|
|
271
|
+
let serviceTierRows = 0;
|
|
230
272
|
let tierNamed = false;
|
|
231
273
|
let mixedRows = 0;
|
|
232
274
|
let nonTextTokens = 0;
|
|
@@ -261,12 +303,25 @@ export function openaiUsageRecords(
|
|
|
261
303
|
}
|
|
262
304
|
}
|
|
263
305
|
|
|
306
|
+
let serviceTier: string | undefined;
|
|
264
307
|
if (typeof result.service_tier === 'string') {
|
|
265
308
|
tierNamed = true;
|
|
266
309
|
if (result.service_tier !== 'default') {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
310
|
+
/*
|
|
311
|
+
Priced only from a table that exists for this model at this tier.
|
|
312
|
+
The response path falls back to the standard rate for a tier with
|
|
313
|
+
no table, because a response is one call the provider really ran;
|
|
314
|
+
a report row is the sum of many, and a Flex row priced at the
|
|
315
|
+
standard rate is twice its cost.
|
|
316
|
+
*/
|
|
317
|
+
const named = serviceTierOf(result.service_tier);
|
|
318
|
+
const row = typeof result.model === 'string' ? catalogue.byId.get(result.model) : undefined;
|
|
319
|
+
if (named === undefined || row?.serviceTiers?.[named] === undefined) {
|
|
320
|
+
nonDefaultTier += 1;
|
|
321
|
+
tiersRefused.add(result.service_tier);
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
serviceTier = result.service_tier;
|
|
270
325
|
}
|
|
271
326
|
}
|
|
272
327
|
|
|
@@ -334,6 +389,7 @@ export function openaiUsageRecords(
|
|
|
334
389
|
ts,
|
|
335
390
|
...(label === undefined ? {} : { label }),
|
|
336
391
|
...requestsField(result.num_model_requests),
|
|
392
|
+
...(serviceTier === undefined ? {} : { service_tier: serviceTier }),
|
|
337
393
|
usage: {
|
|
338
394
|
prompt_tokens: prompt,
|
|
339
395
|
completion_tokens: completion,
|
|
@@ -348,6 +404,10 @@ export function openaiUsageRecords(
|
|
|
348
404
|
},
|
|
349
405
|
});
|
|
350
406
|
rows += 1;
|
|
407
|
+
if (serviceTier !== undefined) {
|
|
408
|
+
serviceTierRows += 1;
|
|
409
|
+
tiersPriced.add(serviceTier);
|
|
410
|
+
}
|
|
351
411
|
}
|
|
352
412
|
}
|
|
353
413
|
|
|
@@ -361,6 +421,8 @@ export function openaiUsageRecords(
|
|
|
361
421
|
batchNamed,
|
|
362
422
|
nonDefaultTier,
|
|
363
423
|
tiersRefused: [...tiersRefused],
|
|
424
|
+
serviceTierRows,
|
|
425
|
+
tiersPriced: [...tiersPriced],
|
|
364
426
|
tierNamed,
|
|
365
427
|
mixedRows,
|
|
366
428
|
nonTextTokens,
|
package/src/pricing-overlay.ts
CHANGED
|
@@ -35,8 +35,12 @@ export const PRICING_MODEL_KEYS = [
|
|
|
35
35
|
'notes',
|
|
36
36
|
'promo',
|
|
37
37
|
'multipliers',
|
|
38
|
+
'inferenceGeoMultipliers',
|
|
38
39
|
] as const;
|
|
39
40
|
|
|
41
|
+
/** The geographies a provider prices differently, as `InferenceGeo` names them. */
|
|
42
|
+
const INFERENCE_GEO_KEYS = ['us'] as const;
|
|
43
|
+
|
|
40
44
|
const PROMO_KEYS = ['inputPerMTok', 'outputPerMTok', 'until'] as const;
|
|
41
45
|
|
|
42
46
|
/**
|
|
@@ -260,6 +264,23 @@ function parseModel(
|
|
|
260
264
|
if (raw.multipliers !== undefined) {
|
|
261
265
|
model.multipliers = parseMultipliers(raw.multipliers, `models.${id}.multipliers`, source);
|
|
262
266
|
}
|
|
267
|
+
/*
|
|
268
|
+
* The multiplier a provider publishes for one geography, as the catalogue
|
|
269
|
+
* carries it on Claude 4.6 and later. Accepted so a catalogue row copied into
|
|
270
|
+
* an overlay is still a valid overlay row, and so a model added there can say
|
|
271
|
+
* what US-only inference costs on it. Zero and negatives are refused, as for
|
|
272
|
+
* every other rate here.
|
|
273
|
+
*/
|
|
274
|
+
if (raw.inferenceGeoMultipliers !== undefined) {
|
|
275
|
+
const label = `models.${id}.inferenceGeoMultipliers`;
|
|
276
|
+
const geo = raw.inferenceGeoMultipliers;
|
|
277
|
+
if (!isPlainObject(geo)) {
|
|
278
|
+
throw new PricingOverlayError(`"${label}" must be an object such as {"us": 1.1}`, source);
|
|
279
|
+
}
|
|
280
|
+
rejectUnknownKeys(geo, INFERENCE_GEO_KEYS, source, `${label}.`);
|
|
281
|
+
model.inferenceGeoMultipliers = {};
|
|
282
|
+
if (geo.us !== undefined) model.inferenceGeoMultipliers.us = positiveNumber(geo.us, `${label}.us`, source);
|
|
283
|
+
}
|
|
263
284
|
|
|
264
285
|
return model;
|
|
265
286
|
}
|