@trazum/cli 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trazum/cli",
3
- "version": "2.7.2",
3
+ "version": "2.7.4",
4
4
  "description": "What your AI agents cost, per project, offline: one bill across Claude Code, Codex and Gemini CLI sessions, plus Anthropic, OpenAI, Gemini, OpenRouter, OTel and LiteLLM usage, written as PDF, HTML or CSV, with budgets enforced in CI.",
5
5
  "license": "MIT",
6
6
  "author": "David Mu\u00f1oz Rey",
@@ -53,7 +53,7 @@
53
53
  "prepublishOnly": "npm run build && npm test"
54
54
  },
55
55
  "dependencies": {
56
- "@trazum/core": "2.7.2"
56
+ "@trazum/core": "2.7.4"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/node": "^26.6.6",
package/src/connect.ts CHANGED
@@ -103,12 +103,23 @@ function urlFor(provider: string, fromMs: number, toMs: number, page: string | n
103
103
  url.searchParams.set('starting_at', new Date(fromMs).toISOString());
104
104
  url.searchParams.set('ending_at', new Date(toMs).toISOString());
105
105
  url.searchParams.set('bucket_width', '1d');
106
- url.searchParams.append('group_by[]', 'model');
106
+ /*
107
+ * Model, and the three groupings that change what a token costs: the
108
+ * service tier (batch is billed at a discount), the speed (fast mode at a
109
+ * multiple) and the geography (US-only inference at 1.1x on Claude 4.6
110
+ * and later). Without them every row sums all of those at one rate.
111
+ */
112
+ for (const group of ['model', 'service_tier', 'speed', 'inference_geo']) {
113
+ url.searchParams.append('group_by[]', group);
114
+ }
107
115
  } else {
108
116
  url.searchParams.set('start_time', String(Math.floor(fromMs / 1000)));
109
117
  url.searchParams.set('end_time', String(Math.floor(toMs / 1000)));
110
118
  url.searchParams.set('bucket_width', '1d');
111
- url.searchParams.append('group_by[]', 'model');
119
+ // Model, batch (billed at a discount) and service tier (Flex, Fast, each its own table).
120
+ for (const group of ['model', 'batch', 'service_tier']) {
121
+ url.searchParams.append('group_by[]', group);
122
+ }
112
123
  url.searchParams.set('limit', '31');
113
124
  }
114
125
  if (page !== null) url.searchParams.set('page', page);
@@ -368,6 +368,7 @@ function describe(body: string, provider: string, modelFromPath: string | null):
368
368
  session: string | null;
369
369
  speed: string | null;
370
370
  serviceTier: string | null;
371
+ inferenceGeo: string | null;
371
372
  } | null {
372
373
  let parsed: unknown;
373
374
  try {
@@ -439,6 +440,13 @@ function describe(body: string, provider: string, modelFromPath: string | null):
439
440
  * is judged by has to know it.
440
441
  */
441
442
  speed: typeof request.speed === 'string' && request.speed !== '' ? request.speed : null,
443
+ /**
444
+ * Anthropic's `inference_geo: "us"`: a setting, not content, and one that
445
+ * bills the call at 1.1x on Claude 4.6 and later, so the estimate a budget
446
+ * is judged by has to know it. The response says which geography ran.
447
+ */
448
+ inferenceGeo:
449
+ typeof request.inference_geo === 'string' && request.inference_geo !== '' ? request.inference_geo : null,
442
450
  /**
443
451
  * OpenAI's `service_tier`: Flex bills about half the standard rate and
444
452
  * Fast up to twice, so the estimate a budget is judged by has to know it.
@@ -106,6 +106,8 @@ export class GatewaySpend {
106
106
  ...(usage.speed === undefined ? {} : { speed: usage.speed }),
107
107
  // So does OpenAI's service tier, each priced from its own table.
108
108
  ...(usage.serviceTier === undefined ? {} : { service_tier: usage.serviceTier }),
109
+ // And US-only inference, 1.1x on Claude 4.6 and later.
110
+ ...(usage.inferenceGeo === undefined ? {} : { inference_geo: usage.inferenceGeo }),
109
111
  }));
110
112
  const index = record === null ? null : indexUsage([record], { catalogue: this.catalogue, on: new Date(now) });
111
113
  if (index === null || index.unpriced > 0 || index.dayUsd === null) {
package/src/i18n/en.ts CHANGED
@@ -2034,9 +2034,23 @@ ${bold('EXAMPLES')}
2034
2034
  unnamedModel: (count) =>
2035
2035
  `${count} row(s) named no model and are not in the output: the report was not grouped by model, so nothing on the row says what answered. Add group_by[]=model to the request.`,
2036
2036
  nonStandardTier: (count) =>
2037
- `${count} row(s) were billed at a tier a catalogue rate is not the rate for (batch, priority, flex) and are not in the output. Pricing them from the standard rate would overstate the bill and look right doing it.`,
2037
+ `${count} row(s) were billed at a tier no published rate here prices (priority, flex, or batch on a model with no batch rate) and are not in the output. Pricing them from the standard rate would be a guess nobody can check.`,
2038
+ batchPriced: (count) =>
2039
+ `${count} row(s) ran on the Batch API and are priced at the model's batch rate, half the standard one, as the pricing page publishes it.`,
2038
2040
  tierUnknown: () =>
2039
2041
  'The report never named a service tier, so a batch row and a standard row are indistinguishable here. Everything was read as standard. Add group_by[]=service_tier if any of this usage is batched.',
2042
+ fastPriced: (count) =>
2043
+ `${count} row(s) ran in fast mode and are priced from the model's own fast rate, as a logged response with usage.speed "fast" would be.`,
2044
+ fastUnpriced: (count, models) =>
2045
+ `${count} row(s) ran in fast mode on a model Trazum has no fast rate for (${models}) and are not in the output. The standard rate is well under fast mode's, so pricing them at it would understate the bill.`,
2046
+ speedUnknown: (count) =>
2047
+ `The report never named a speed, and ${count} row(s) are on a model with a fast mode, which bills at a higher rate. They were read as standard. Add group_by[]=speed if any of this usage ran fast.`,
2048
+ usOnly: (count) =>
2049
+ `${count} row(s) ran with inference_geo "us" and are priced at the published 1.1x that US-only inference bills on Claude 4.6 and later.`,
2050
+ usOnlyFloor: (count) =>
2051
+ `${count} row(s) ran with inference_geo "us" on a model Trazum has no US-only multiplier for. They are priced at the global rate, so their figure is a floor.`,
2052
+ geoUnknown: (count) =>
2053
+ `The report never named an inference geography, and ${count} row(s) are on a model that bills US-only inference at 1.1x. They were read as global. Add group_by[]=inference_geo if any workspace pins inference to the US.`,
2040
2054
  webSearch: (count) =>
2041
2055
  `${count} web search request(s) are in this report and in no line of the output: server tools are billed per request, not per token, so no token rate reaches them.`,
2042
2056
  truncated: () =>
@@ -2067,11 +2081,15 @@ ${bold('EXAMPLES')}
2067
2081
  unnamedModel: (count) =>
2068
2082
  `${count} row(s) named no model and are not in the output: the report was not grouped by model, so nothing on the row says what answered. Add group_by[]=model to the request.`,
2069
2083
  batch: (count) =>
2070
- `${count} row(s) were batch jobs and are not in the output: batch is billed at a discount, and pricing it from a catalogue rate would overstate the bill and look right doing it.`,
2084
+ `${count} row(s) were batch jobs on a model Trazum has no batch rate for, and are not in the output: batch is billed at a discount, and pricing it from the standard rate would overstate the bill and look right doing it.`,
2085
+ batchPriced: (count) =>
2086
+ `${count} row(s) were batch jobs and are priced at the model's batch rate, half the standard one, as the pricing page publishes it.`,
2071
2087
  batchUnknown: () =>
2072
2088
  'The report never said whether anything was batch, so a batch row and a standard row are indistinguishable here. Everything was read as standard. Add group_by[]=batch if any of this usage is batched.',
2073
2089
  nonDefaultTier: (count, tiers) =>
2074
- `${count} row(s) were at a service tier a catalogue rate is not the rate for (${tiers}) and are not in the output. The schema does not list the tiers, so they are named rather than guessed at.`,
2090
+ `${count} row(s) were at a service tier Trazum has no table for on that model (${tiers}) and are not in the output. The standard rate is not that tier's rate, and the schema does not list the tiers, so they are named rather than guessed at.`,
2091
+ serviceTierPriced: (count, tiers) =>
2092
+ `${count} row(s) ran at another service tier (${tiers}) and are priced from that tier's own table, as a logged response naming it would be.`,
2075
2093
  tierUnknown: () =>
2076
2094
  'The report never named a service tier. Everything was read as the default tier. Add group_by[]=service_tier if any of this usage runs on another.',
2077
2095
  mixed: (rows, tokens, cacheWrites) =>
package/src/i18n/es.ts CHANGED
@@ -2064,9 +2064,23 @@ ${bold('EJEMPLOS')}
2064
2064
  unnamedModel: (count) =>
2065
2065
  `${count} fila(s) no nombraron modelo y no están en la salida: el informe no se agrupó por modelo, así que nada en la fila dice qué respondió. Añade group_by[]=model a la petición.`,
2066
2066
  nonStandardTier: (count) =>
2067
- `${count} fila(s) se facturaron en un tramo para el que una tarifa de catálogo no es la tarifa (batch, priority, flex) y no están en la salida. Cobrarlas a la tarifa estándar inflaría la factura y parecería correcto.`,
2067
+ `${count} fila(s) se facturaron en un tramo que ninguna tarifa publicada aquí cubre (priority, flex, o batch en un modelo sin tarifa batch) y no están en la salida. Cobrarlas a la tarifa estándar sería adivinar sin forma de comprobarlo.`,
2068
+ batchPriced: (count) =>
2069
+ `${count} fila(s) corrieron en la Batch API y se cobran a la tarifa batch del modelo, la mitad de la estándar, como la publica la página de precios.`,
2068
2070
  tierUnknown: () =>
2069
2071
  'El informe no nombró ningún tramo de servicio, así que una fila batch y una estándar son indistinguibles aquí. Todo se leyó como estándar. Añade group_by[]=service_tier si parte de este uso va por lotes.',
2072
+ fastPriced: (count) =>
2073
+ `${count} fila(s) corrieron en modo rápido y se cobran con la tarifa rápida del propio modelo, como se cobraría una respuesta registrada con usage.speed "fast".`,
2074
+ fastUnpriced: (count, models) =>
2075
+ `${count} fila(s) corrieron en modo rápido en un modelo para el que Trazum no tiene tarifa rápida (${models}) y no están en la salida. La tarifa estándar queda muy por debajo de la del modo rápido, así que cobrarlas con ella dejaría la factura corta.`,
2076
+ speedUnknown: (count) =>
2077
+ `El informe no nombró ninguna velocidad, y ${count} fila(s) son de un modelo con modo rápido, que se factura más caro. Se leyeron como estándar. Añade group_by[]=speed si parte de este uso corrió en modo rápido.`,
2078
+ usOnly: (count) =>
2079
+ `${count} fila(s) corrieron con inference_geo "us" y se cobran al 1,1x publicado que la inferencia solo en EE. UU. factura en Claude 4.6 y posteriores.`,
2080
+ usOnlyFloor: (count) =>
2081
+ `${count} fila(s) corrieron con inference_geo "us" en un modelo para el que Trazum no tiene multiplicador de EE. UU. Se cobran a la tarifa global, así que su cifra es un suelo.`,
2082
+ geoUnknown: (count) =>
2083
+ `El informe no nombró ninguna geografía de inferencia, y ${count} fila(s) son de un modelo que factura la inferencia solo en EE. UU. a 1,1x. Se leyeron como globales. Añade group_by[]=inference_geo si algún workspace fija la inferencia en EE. UU.`,
2070
2084
  webSearch: (count) =>
2071
2085
  `${count} petición(es) de búsqueda web están en el informe y en ninguna línea de la salida: las herramientas de servidor se facturan por petición, no por token, así que ninguna tarifa por token llega a ellas.`,
2072
2086
  truncated: () =>
@@ -2097,11 +2111,15 @@ ${bold('EJEMPLOS')}
2097
2111
  unnamedModel: (count) =>
2098
2112
  `${count} fila(s) no nombraron modelo y no están en la salida: el informe no se agrupó por modelo, así que nada en la fila dice qué respondió. Añade group_by[]=model a la petición.`,
2099
2113
  batch: (count) =>
2100
- `${count} fila(s) eran trabajos por lotes y no están en la salida: batch se factura con descuento, y cobrarlo a tarifa de catálogo inflaría la factura y parecería correcto.`,
2114
+ `${count} fila(s) eran trabajos por lotes en un modelo para el que Trazum no tiene tarifa batch, y no están en la salida: batch se factura con descuento, y cobrarlo a la tarifa estándar inflaría la factura y parecería correcto.`,
2115
+ batchPriced: (count) =>
2116
+ `${count} fila(s) eran trabajos por lotes y se cobran a la tarifa batch del modelo, la mitad de la estándar, como la publica la página de precios.`,
2101
2117
  batchUnknown: () =>
2102
2118
  'El informe nunca dijo si algo fue batch, así que una fila por lotes y una estándar son indistinguibles aquí. Todo se leyó como estándar. Añade group_by[]=batch si parte de este uso va por lotes.',
2103
2119
  nonDefaultTier: (count, tiers) =>
2104
- `${count} fila(s) estaban en un tramo de servicio para el que una tarifa de catálogo no es la tarifa (${tiers}) y no están en la salida. El esquema no lista los tramos, así que se nombran en vez de adivinarse.`,
2120
+ `${count} fila(s) estaban en un tramo de servicio para el que Trazum no tiene tabla en ese modelo (${tiers}) y no están en la salida. La tarifa estándar no es la de ese tramo, y el esquema no lista los tramos, así que se nombran en vez de adivinarse.`,
2121
+ serviceTierPriced: (count, tiers) =>
2122
+ `${count} fila(s) corrieron en otro tramo de servicio (${tiers}) y se cobran con la tabla propia de ese tramo, como se cobraría una respuesta registrada que lo nombre.`,
2105
2123
  tierUnknown: () =>
2106
2124
  'El informe no nombró ningún tramo de servicio. Todo se leyó como el tramo por defecto. Añade group_by[]=service_tier si parte de este uso corre en otro.',
2107
2125
  mixed: (rows, tokens, cacheWrites) =>
package/src/i18n/types.ts CHANGED
@@ -706,9 +706,16 @@ export interface CliMessages {
706
706
  unnamedModel(count: number): string;
707
707
  /** Batch and priority are not billed at a catalogue rate. */
708
708
  nonStandardTier(count: number): string;
709
+ batchPriced(count: number): string;
709
710
  /** Said when the report never named a tier: the question was not asked. */
710
711
  tierUnknown(): string;
711
712
  /** Server tools are billed per request, and no token rate reaches them. */
713
+ fastPriced(count: number): string;
714
+ fastUnpriced(count: number, models: string): string;
715
+ speedUnknown(count: number): string;
716
+ usOnly(count: number): string;
717
+ usOnlyFloor(count: number): string;
718
+ geoUnknown(count: number): string;
712
719
  webSearch(count: number): string;
713
720
  /** One page of several: the bill from it is understated. */
714
721
  truncated(): string;
@@ -731,10 +738,12 @@ export interface CliMessages {
731
738
  unnamedModel(count: number): string;
732
739
  /** batch: true rows are billed at a discount no catalogue rate is. */
733
740
  batch(count: number): string;
741
+ batchPriced(count: number): string;
734
742
  /** The report never said whether anything was batch. */
735
743
  batchUnknown(): string;
736
744
  /** Any tier but default, named rather than counted. */
737
745
  nonDefaultTier(count: number, tiers: string): string;
746
+ serviceTierPriced(count: number, tiers: string): string;
738
747
  tierUnknown(): string;
739
748
  /** Rows reduced to their text part; audio and image tokens set aside. */
740
749
  mixed(rows: number, tokens: number, cacheWrites: number): string;
package/src/index.ts CHANGED
@@ -140,6 +140,8 @@ import {
140
140
  looksLikeLiteLlm,
141
141
  looksLikeOpenaiUsage,
142
142
  looksLikeOpenrouterActivity,
143
+ looksLikeBatchResults,
144
+ batchResultRecords,
143
145
  looksLikeOtel,
144
146
  openaiCostReport,
145
147
  openaiUsageRecords,
@@ -3530,6 +3532,7 @@ type UsageSource =
3530
3532
  | 'langsmith'
3531
3533
  | 'anthropic-usage'
3532
3534
  | 'openai-usage'
3535
+ | 'batch-results'
3533
3536
  | 'openrouter'
3534
3537
  | 'usage-log';
3535
3538
 
@@ -3546,6 +3549,7 @@ function usageSourcesOf(text: string): UsageSource[] {
3546
3549
  if (looksLikeOtel(text)) claims.push('otel');
3547
3550
  if (looksLikeAnthropicUsage(text)) claims.push('anthropic-usage');
3548
3551
  if (looksLikeOpenaiUsage(text)) claims.push('openai-usage');
3552
+ if (looksLikeBatchResults(text)) claims.push('batch-results');
3549
3553
  if (looksLikeOpenrouterActivity(text)) claims.push('openrouter');
3550
3554
  if (looksLikeHelicone(text)) claims.push('helicone');
3551
3555
  if (looksLikeLangsmith(text)) claims.push('langsmith');
@@ -3762,7 +3766,7 @@ async function commandBill(args: Args, pricing: PricingCatalogue, t: CliMessages
3762
3766
  case 'anthropic-usage': {
3763
3767
  const c = anthropicUsageRecords(text, withLabel);
3764
3768
  records = c.records;
3765
- leftOut = c.unnamedModel + c.nonStandardTier;
3769
+ leftOut = c.unnamedModel + c.nonStandardTier + c.fastUnpriced;
3766
3770
  break;
3767
3771
  }
3768
3772
  case 'openai-usage': {
@@ -3771,6 +3775,14 @@ async function commandBill(args: Args, pricing: PricingCatalogue, t: CliMessages
3771
3775
  leftOut = c.unnamedModel + c.batch + c.nonDefaultTier + c.unsplitRows;
3772
3776
  break;
3773
3777
  }
3778
+ case 'batch-results': {
3779
+ /* A provider's Batch API results: every billed line at the batch rate,
3780
+ and the requests the provider says it did not bill left out. */
3781
+ const c = batchResultRecords(text, withLabel);
3782
+ records = c.records;
3783
+ leftOut = c.unpriceable + c.unparseable;
3784
+ break;
3785
+ }
3774
3786
  case 'openrouter': {
3775
3787
  const c = openrouterActivityRecords(text, withLabel);
3776
3788
  records = c.records;
@@ -4723,10 +4735,23 @@ async function commandFromAnthropic(args: Args, t: CliMessages): Promise<void> {
4723
4735
  acts in: what was read, then what was left out, then what to ask for. */
4724
4736
  console.error(t.fromAnthropic.summary(conversion.buckets, conversion.rows));
4725
4737
  if (conversion.unnamedModel > 0) console.error(t.fromAnthropic.unnamedModel(conversion.unnamedModel));
4738
+ if (conversion.batchRows > 0) console.error(t.fromAnthropic.batchPriced(conversion.batchRows));
4726
4739
  if (conversion.nonStandardTier > 0) {
4727
4740
  console.error(t.fromAnthropic.nonStandardTier(conversion.nonStandardTier));
4728
4741
  }
4729
4742
  if (!conversion.tierNamed && conversion.rows > 0) console.error(t.fromAnthropic.tierUnknown());
4743
+ if (conversion.fastRows > 0) console.error(t.fromAnthropic.fastPriced(conversion.fastRows));
4744
+ if (conversion.fastUnpriced > 0) {
4745
+ console.error(t.fromAnthropic.fastUnpriced(conversion.fastUnpriced, conversion.fastUnpricedModels.join(', ')));
4746
+ }
4747
+ if (!conversion.speedNamed && conversion.speedUnknownFastCapable > 0) {
4748
+ console.error(t.fromAnthropic.speedUnknown(conversion.speedUnknownFastCapable));
4749
+ }
4750
+ if (conversion.usOnlyRows > 0) console.error(t.fromAnthropic.usOnly(conversion.usOnlyRows));
4751
+ if (conversion.usOnlyFloor > 0) console.error(t.fromAnthropic.usOnlyFloor(conversion.usOnlyFloor));
4752
+ if (!conversion.geoNamed && conversion.geoUnknownMultiplied > 0) {
4753
+ console.error(t.fromAnthropic.geoUnknown(conversion.geoUnknownMultiplied));
4754
+ }
4730
4755
  if (conversion.webSearchRequests > 0) console.error(t.fromAnthropic.webSearch(conversion.webSearchRequests));
4731
4756
  if (conversion.labelledByWorkspace > 0) {
4732
4757
  console.error(t.fromAnthropic.labelledByWorkspace(conversion.labelledByWorkspace));
@@ -4778,8 +4803,12 @@ async function commandFromOpenai(args: Args, t: CliMessages): Promise<void> {
4778
4803
  was left out and why, what to ask the endpoint for next time. */
4779
4804
  console.error(t.fromOpenai.summary(conversion.buckets, conversion.rows, conversion.requests));
4780
4805
  if (conversion.unnamedModel > 0) console.error(t.fromOpenai.unnamedModel(conversion.unnamedModel));
4806
+ if (conversion.batchRows > 0) console.error(t.fromOpenai.batchPriced(conversion.batchRows));
4781
4807
  if (conversion.batch > 0) console.error(t.fromOpenai.batch(conversion.batch));
4782
4808
  if (!conversion.batchNamed && conversion.rows > 0) console.error(t.fromOpenai.batchUnknown());
4809
+ if (conversion.serviceTierRows > 0) {
4810
+ console.error(t.fromOpenai.serviceTierPriced(conversion.serviceTierRows, conversion.tiersPriced.join(', ')));
4811
+ }
4783
4812
  if (conversion.nonDefaultTier > 0) {
4784
4813
  console.error(t.fromOpenai.nonDefaultTier(conversion.nonDefaultTier, conversion.tiersRefused.join(', ')));
4785
4814
  }