@trazum/core 2.4.1 → 2.4.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/src/types.ts CHANGED
@@ -203,6 +203,18 @@ export interface PricingTier {
203
203
  outputPerMTok: number;
204
204
  }
205
205
 
206
+ /** One published price this model carried until an instant. See `ModelPricing.history`. */
207
+ export interface PricePeriod {
208
+ /** ISO 8601 instant, exclusive: a call at exactly this instant is priced by what came after. */
209
+ until: string;
210
+ inputPerMTok: number;
211
+ outputPerMTok: number;
212
+ /** The conditional rates in force during the period; none means none applied. */
213
+ tiers?: PricingTier[];
214
+ /** The cache and batch ratios during the period; absent means the row's own. */
215
+ multipliers?: CostMultipliers;
216
+ }
217
+
206
218
  export interface ModelPricing {
207
219
  id: string;
208
220
  displayName: string;
@@ -298,6 +310,22 @@ export interface ModelPricing {
298
310
  * and keeps this field optional in effect as well as in the type.
299
311
  */
300
312
  tiers?: PricingTier[];
313
+ /**
314
+ * What this id cost before its current price, earliest period first.
315
+ *
316
+ * A usage log is history, and a provider that cuts a price at 04:00 UTC on
317
+ * a Thursday has billed the same id two ways in one month. One price for
318
+ * all time priced the older calls at the newer rate, or the newer at the
319
+ * older, and nothing on screen said which. A call at `on` is priced by the
320
+ * first period whose `until` is after it; a call at or after the last
321
+ * `until` takes the fields above. Each period carries its own tiers and
322
+ * cache ratio, because a provider that reprices usually reprices both.
323
+ *
324
+ * Only periods a provider published, with the instant it published. A
325
+ * period before the first one this table can source is not guessed at: the
326
+ * earliest period stands for it, and the row's note says so.
327
+ */
328
+ history?: PricePeriod[];
301
329
  /**
302
330
  * Other ids that bill at exactly this rate.
303
331
  *
package/src/usage.ts CHANGED
@@ -944,8 +944,20 @@ function add(into: UsageBreakdown, record: UsageRecord, catalogue: PricingCatalo
944
944
  if (!model) return false;
945
945
 
946
946
  countInto(into, record);
947
- const { inputPerMTok, outputPerMTok } = effectivePricing(model, on);
948
- const rates = multipliersFor(model);
947
+ /**
948
+ * **Each call at the price of its own moment.** A bill is history: a call
949
+ * made inside a promotion was billed at the promotional rate, a DeepSeek
950
+ * call at 03:00 UTC on a weekday was billed at peak, and a call before a
951
+ * published price change was billed at the old price. Priced at the report's
952
+ * date instead, every one of those came out at whatever applied the day the
953
+ * report ran: a clock-priced log read during peak hours was all peak, and an
954
+ * August log read in October lost its August promotion. `on` is the date for
955
+ * a record that carries no clock, which is the only thing it can mean here.
956
+ */
957
+ const at = record.ts !== null ? new Date(record.ts) : on;
958
+ const { inputPerMTok, outputPerMTok } = effectivePricing(model, at);
959
+ // Dated, like the rate above: a repriced cache read is part of the reprice.
960
+ const rates = multipliersFor(model, at);
949
961
  const per = (tokens: number, rate: number): number => (tokens / 1_000_000) * rate;
950
962
 
951
963
  into.inputUsd += per(record.inputTokens, inputPerMTok);
@@ -991,7 +1003,11 @@ function add(into: UsageBreakdown, record: UsageRecord, catalogue: PricingCatalo
991
1003
 
992
1004
  export interface UsageProfileOptions {
993
1005
  catalogue: PricingCatalogue;
994
- /** Date the prices are read at, so a promotional rate resolves the same way. */
1006
+ /**
1007
+ * The date a record with no timestamp is priced at, and the date the
1008
+ * forward-looking findings (levers, what-ifs) are priced at. A record that
1009
+ * carries its own `ts` is billed at its own moment: see `add`.
1010
+ */
995
1011
  on?: Date;
996
1012
  /**
997
1013
  * Profile only the records carrying this label — the drill-down, once the