@trazum/core 2.7.1 → 2.7.2

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
@@ -222,6 +222,22 @@ export interface PricingTier {
222
222
  outputPerMTok: number;
223
223
  }
224
224
 
225
+ /**
226
+ * A provider's service tier other than its standard one, as a response names it
227
+ * after normalising: OpenAI's `service_tier` of `"flex"`, `"fast"` or
228
+ * `"priority"` (the same tier, under its name before 2026-07-30), and
229
+ * `"ultrafast"`. See `ModelPricing.serviceTiers`.
230
+ */
231
+ export type ServiceTier = 'flex' | 'fast' | 'ultrafast';
232
+
233
+ /** The rates one service tier charges, with its own conditional bands. */
234
+ export interface ServiceTierRates {
235
+ inputPerMTok: number;
236
+ outputPerMTok: number;
237
+ /** The tier's own long-prompt band, when its table publishes one. */
238
+ tiers?: PricingTier[];
239
+ }
240
+
225
241
  /** One published price this model carried until an instant. See `ModelPricing.history`. */
226
242
  export interface PricePeriod {
227
243
  /** ISO 8601 instant, exclusive: a call at exactly this instant is priced by what came after. */
@@ -357,6 +373,29 @@ export interface ModelPricing {
357
373
  * earliest period stands for it, and the row's note says so.
358
374
  */
359
375
  history?: PricePeriod[];
376
+ /**
377
+ * What the same tokens cost at another of the provider's service tiers.
378
+ *
379
+ * OpenAI sells three besides its standard one, chosen per request with
380
+ * `service_tier` and named again in the response: Flex at about half the
381
+ * price, Fast (called Priority until 2026-07-30) at up to twice, and
382
+ * Ultrafast on two models at six times. Each is a separate table on the
383
+ * pricing page, with its own long-prompt band, and the rates are not one
384
+ * multiple of the standard ones (GPT-4o's Fast is 1.7x, GPT-5.2's 2x), so
385
+ * each is written out per model as the page prints it.
386
+ *
387
+ * Kept apart from `tiers` on purpose. A tier is a condition on the call that
388
+ * may be undecided, so it is never below the base, and Flex is. A service
389
+ * tier is decided by the response that names it, and replaces the base and
390
+ * its tiers whole: Flex on a long prompt is Flex's own long band, never a
391
+ * composite of two tables. The cache and batch ratios stay the row's, which
392
+ * is what the page's own figures show (Flex's cached input is a tenth of
393
+ * Flex's input wherever the standard one is a tenth).
394
+ *
395
+ * A response naming a tier this row has no sheet for is priced at the
396
+ * standard rate: the page publishes nothing else for it.
397
+ */
398
+ serviceTiers?: Partial<Record<ServiceTier, ServiceTierRates>>;
360
399
  /**
361
400
  * Other ids that bill at exactly this rate.
362
401
  *
package/src/usage.ts CHANGED
@@ -185,6 +185,14 @@ export interface UsageRecord {
185
185
  * opt-in that every response names.
186
186
  */
187
187
  speed?: string;
188
+ /**
189
+ * The service tier the provider says answered, when the log kept it:
190
+ * OpenAI's top-level `service_tier`, `"flex"`, `"priority"` or `"fast"`,
191
+ * `"ultrafast"`, or `"default"`. Flex bills about half the standard rate
192
+ * and Fast up to twice, from tables of their own (`serviceTiers` in the
193
+ * catalogue). Absent, or `"default"`, is the standard rate.
194
+ */
195
+ serviceTier?: string;
188
196
  /**
189
197
  * Set when an OpenAI-shaped line split its cache writes by lifetime and the
190
198
  * parts did not add up to the total. The lifetime is then unknown even on a
@@ -966,6 +974,15 @@ export function parseUsageLine(line: string): UsageRecord | null {
966
974
  * field is priced by it. Absent stays absent, which prices as standard.
967
975
  */
968
976
  ...(typeof usage.speed === 'string' && usage.speed !== '' ? { speed: usage.speed } : {}),
977
+ /*
978
+ * OpenAI's `service_tier`, which a Chat Completions or Responses object
979
+ * carries at the top level beside `usage`, and names the tier that
980
+ * actually ran: a Fast request downgraded under load says "default" and
981
+ * is billed at the standard rate. Priced from that tier's own table.
982
+ */
983
+ ...(typeof record.service_tier === 'string' && record.service_tier !== ''
984
+ ? { serviceTier: record.service_tier }
985
+ : {}),
969
986
  ...(openAiSplitGiven && !openAiSplitAgrees ? { writeSplitContradicted: true as const } : {}),
970
987
  };
971
988
  }