@trazum/core 2.7.8 → 2.7.11

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/levers.ts CHANGED
@@ -120,6 +120,17 @@ export interface BillLevers {
120
120
  promptCeilingShare: number;
121
121
  /** The bill the shares are taken against. */
122
122
  totalUsd: number;
123
+ /**
124
+ * Input and output dollars the batch lever left out, on models whose
125
+ * provider sells a Batch API: calls already billed at the batch rate, and
126
+ * calls something waited on (`interactive` on the record).
127
+ *
128
+ * Stated because its absence reads as an oversight. Somebody who knows the
129
+ * Batch API halves a price, and sees no batch row against their coding
130
+ * agent's bill, should be told the row was left out on purpose and for what
131
+ * reason, with the money it would have been drawn on. Never a saving.
132
+ */
133
+ batchExcludedUsd: number;
123
134
  }
124
135
 
125
136
  /**
@@ -144,12 +155,16 @@ function stepDown(capability: Capability): Capability | null {
144
155
  return at <= 0 ? null : CAPABILITY_LADDER[at - 1]!;
145
156
  }
146
157
 
147
- /** What a breakdown's tokens would cost at a model's rates, split so batch can apply. */
158
+ /**
159
+ * What a breakdown's tokens would cost at a model's rates, split so batch can
160
+ * apply. `batchableUsd` is the input and output of the calls that could still
161
+ * move to the Batch API, at these rates: see `batchExcludedUsd`.
162
+ */
148
163
  function repriceAt(
149
164
  breakdown: UsageBreakdown,
150
165
  model: ModelPricing,
151
166
  on: Date,
152
- ): { inputUsd: number; outputUsd: number; cacheUsd: number; totalUsd: number } {
167
+ ): { inputUsd: number; outputUsd: number; cacheUsd: number; totalUsd: number; batchableUsd: number } {
153
168
  // The breakdown's largest call bounds every prompt in it: see `PromptSize`.
154
169
  const { inputPerMTok, outputPerMTok } = effectivePricing(model, on, {
155
170
  inputTokensAtMost: breakdown.maxCallInputTokens,
@@ -170,9 +185,23 @@ function repriceAt(
170
185
  per(breakdown.cacheReadTokens, inputPerMTok * rates.cacheRead) +
171
186
  per(breakdown.cacheWriteTokens, inputPerMTok * rates.cacheWrite5m);
172
187
 
173
- return { inputUsd, outputUsd, cacheUsd, totalUsd: inputUsd + outputUsd + cacheUsd };
188
+ const batchableUsd =
189
+ per(Math.max(0, breakdown.inputTokens - excluded(breakdown.batchExcludedInputTokens)), inputPerMTok) +
190
+ per(Math.max(0, breakdown.outputTokens - excluded(breakdown.batchExcludedOutputTokens)), outputPerMTok);
191
+
192
+ return { inputUsd, outputUsd, cacheUsd, totalUsd: inputUsd + outputUsd + cacheUsd, batchableUsd };
174
193
  }
175
194
 
195
+ /**
196
+ * A `batchExcluded*` figure, or zero when the breakdown has none.
197
+ *
198
+ * A breakdown read back from a document written before the fields existed
199
+ * carries no such number. Zero is what that document meant: it excluded
200
+ * nothing, because nothing told it to.
201
+ */
202
+ const excluded = (value: number | undefined): number =>
203
+ typeof value === 'number' && Number.isFinite(value) ? value : 0;
204
+
176
205
  /**
177
206
  * The cheapest recommendable model one capability step below, same provider.
178
207
  *
@@ -251,10 +280,11 @@ export function billLevers(
251
280
  report.total.inputUsd + report.total.cacheReadUsd + report.total.cacheWriteUsd;
252
281
 
253
282
  if (totalUsd <= 0) {
254
- return { slices: [], promptCeilingUsd, promptCeilingShare: 0, totalUsd };
283
+ return { slices: [], promptCeilingUsd, promptCeilingShare: 0, totalUsd, batchExcludedUsd: 0 };
255
284
  }
256
285
 
257
286
  const slices: SliceLevers[] = [];
287
+ let batchExcludedUsd = 0;
258
288
 
259
289
  for (const { label, model: modelId, breakdown } of report.byLabelAndModel) {
260
290
  const model = catalogue.byId.get(modelId);
@@ -280,12 +310,26 @@ export function billLevers(
280
310
  * lines; whether it also reaches cache reads and writes is not something this
281
311
  * catalogue records, so they stay at full price. That understates the saving,
282
312
  * which is the direction to be wrong in.
313
+ *
314
+ * **And only to calls that could move.** A call already billed at the batch
315
+ * rate cannot be halved again, and a call something waited on cannot wait a
316
+ * day: a turn of a coding agent is the plainest case. Both used to be
317
+ * offered the lever. A log of twenty calls that all ran on the Batch API
318
+ * was told it could save half of a bill that was already the half, and a
319
+ * converted Claude Code session was asked whether its turns "can wait for a
320
+ * batch window". The breakdown says what to leave out, and a slice with
321
+ * nothing left has no batch lever at all.
283
322
  */
284
323
  const batchRate = multipliersFor(model).batch;
285
- const batchable = batchRate !== null && batchRate < 1;
286
- const batch = batchable
287
- ? { savingUsd: (breakdown.inputUsd + breakdown.outputUsd) * (1 - batchRate!) }
288
- : null;
324
+ const batchableUsd = Math.max(
325
+ 0,
326
+ breakdown.inputUsd + breakdown.outputUsd - excluded(breakdown.batchExcludedUsd),
327
+ );
328
+ // A cent of a cent left by floating point is not a lever.
329
+ const batchable = batchRate !== null && batchRate < 1 && batchableUsd > 1e-9;
330
+ const batch = batchable ? { savingUsd: batchableUsd * (1 - batchRate!) } : null;
331
+ // Counted for every slice a Batch API exists for, listed below or not.
332
+ if (batchRate !== null && batchRate < 1) batchExcludedUsd += excluded(breakdown.batchExcludedUsd);
289
333
 
290
334
  /**
291
335
  * Both together — **computed, never summed.**
@@ -299,9 +343,10 @@ export function billLevers(
299
343
  outputUsd: breakdown.outputUsd,
300
344
  cacheUsd: breakdown.cacheReadUsd + breakdown.cacheWriteUsd,
301
345
  totalUsd: breakdown.totalUsd,
346
+ batchableUsd,
302
347
  };
303
348
  const combinedCost = batchable
304
- ? afterBoth.totalUsd - (afterBoth.inputUsd + afterBoth.outputUsd) * (1 - batchRate!)
349
+ ? afterBoth.totalUsd - afterBoth.batchableUsd * (1 - batchRate!)
305
350
  : afterBoth.totalUsd;
306
351
  const combinedUsd = breakdown.totalUsd - combinedCost;
307
352
 
@@ -327,6 +372,7 @@ export function billLevers(
327
372
  promptCeilingUsd,
328
373
  promptCeilingShare: promptCeilingUsd / totalUsd,
329
374
  totalUsd,
375
+ batchExcludedUsd,
330
376
  };
331
377
  }
332
378
 
package/src/plan.ts CHANGED
@@ -106,6 +106,13 @@ export interface PlanDocument {
106
106
  measuredStakeUsd: number;
107
107
  /** The bill the plan was made against. */
108
108
  totalUsd: number;
109
+ /**
110
+ * Input and output dollars no batch action here was drawn on: calls already
111
+ * billed at the batch rate, and calls something waited on (`interactive` on
112
+ * the record, which the agent session converters write). Zero when the log
113
+ * marked neither. A fact about what the plan left out, never a saving.
114
+ */
115
+ batchExcludedUsd: number;
109
116
  }
110
117
 
111
118
  /**
@@ -223,6 +230,7 @@ export function buildPlan(
223
230
  projectedSavingUsd: actions.reduce((sum, a) => sum + (a.savingUsd ?? 0), 0),
224
231
  measuredStakeUsd: actions.reduce((sum, a) => sum + (a.stakeUsd ?? 0), 0),
225
232
  totalUsd: report.total.totalUsd,
233
+ batchExcludedUsd: levers.batchExcludedUsd,
226
234
  };
227
235
  }
228
236
 
package/src/pricing.ts CHANGED
@@ -109,8 +109,25 @@ export const PROVIDER_REVIEWED: Readonly<Record<string, string>> = Object.freeze
109
109
  * the 25% this table carried. Gemini 3.8 Flash was added, and Gemini 3.1
110
110
  * Pro Preview on 2026-10-11 with per-request pricing, which its prompts
111
111
  * over 200k need. 2.5 Pro's own long-context rate is named in its note.
112
+ *
113
+ * Re-read 2026-11-16. The docs moved: ai.google.dev/gemini-api/docs/pricing
114
+ * now 301s to aistudio.google.com/docs/pricing, which serves Markdown, and
115
+ * the review of 2026-11-05 could not reach it. Read there with
116
+ * docs/deprecations, docs/caching and the model pages of every row and of
117
+ * 3.5 Flash-Lite. Every price, cache price, batch price, storage price,
118
+ * context window and cache minimum matched, and 3.6 and 3.8 Flash still
119
+ * rise to $1.50/$7.50 on 2027-01-01. What changed is the two retired 2.5
120
+ * models: "Effective December 1, 2026" Google routes `gemini-2.5-pro` to
121
+ * 3.8 Flash and `gemini-2.5-flash` to 3.5 Flash-Lite, each "billed at" its
122
+ * target's rates. 2.5 Pro carries that as a second period; 2.5 Flash's text
123
+ * rates are 3.5 Flash-Lite's, so its price does not move. The Gemini 4
124
+ * family and 3.5 Flash-Lite are priced in their own rows, from the same
125
+ * read; the page's other models are still unpriced. Not modelled: the
126
+ * Batch tabs of 3.1 Pro Preview and both
127
+ * 2.5 models charge the standard cache price, and this table bills a batch
128
+ * call's cache reads at half of it, as it does every other rate.
112
129
  */
113
- google: '2026-10-10',
130
+ google: '2026-11-16',
114
131
  /*
115
132
  * platform.kimi.ai/docs/pricing/chat, models and pricing/batch, read
116
133
  * 2026-10-11 in their Markdown form; the HTML renders its tables in the
@@ -317,6 +334,12 @@ const OPENAI_EARLIER_LONG_NOTE =
317
334
  const OPENAI_EARLIER_NO_CACHE_NOTE = 'OpenAI publishes no cached-input price for this model, so caching is not priced.';
318
335
  const OPENAI_DEPRECATED_SUFFIX = ' Deprecated by OpenAI: priced for the logs that hold it, never recommended.';
319
336
  const OPENAI_SHUT_DOWN_SUFFIX = ' Shut down by OpenAI: priced for the logs that hold it, never recommended.';
337
+ /** What the three Gemini 4 rows share, from Google's pricing page and docs/caching, read 2026-11-16. */
338
+ const GEMINI_4_NOTE =
339
+ 'Implicit caching is automatic above 4,096 tokens and is the only kind: Google does not support explicit caching'
340
+ + ' on Gemini 4. In a multi-turn conversation the previous request is cached only when the new one adds at least'
341
+ + ' 2,050 tokens. Google also sells a Flex tier at half this price and a Priority tier at 1.8 times it; a call on'
342
+ + ' either is priced here at the standard rate.';
320
343
  const OPENAI_CODEX_NOTE =
321
344
  'Caching is automatic; a write costs what input costs. Responses API only, and no batch. OpenAI says the minimum for'
322
345
  + ' models before GPT-5.6 varies by request settings, so 1,024 here is the nearest published floor.';
@@ -1715,15 +1738,35 @@ export const MODELS: ModelPricing[] = [
1715
1738
  // Google
1716
1739
  // ------------------------------------------------------------------------
1717
1740
  {
1741
+ /*
1742
+ * From aistudio.google.com/docs/pricing, docs/deprecations and the model
1743
+ * page, read 2026-11-16: "Effective December 1, 2026, all API requests to
1744
+ * `gemini-2.5-pro` will automatically route to Gemini 3.8 Flash
1745
+ * (`gemini-3.8-flash`) and be billed at Gemini 3.8 Flash rates." So the id
1746
+ * has two periods, as `grok-4` does. Up to that day it bills its own
1747
+ * $1.25/$10, read 2026-10-10 and again 2026-11-16. From it, 3.8 Flash's:
1748
+ * $0.75/$3.75 through 2026-12-31 and $1.50/$7.50 from 2027-01-01, with
1749
+ * the same promotion and the same confirmation as the 3.8 Flash row.
1750
+ *
1751
+ * Google gives a day, not an instant, so the period ends at 00:00 UTC, the
1752
+ * reading this table gives every Google date. The cache minimum stays
1753
+ * 2,048, which docs/caching still lists for 2.5 Pro; a request routed to
1754
+ * 3.8 Flash caches from 4,096.
1755
+ */
1718
1756
  id: 'gemini-2.5-pro',
1719
1757
  provider: 'google',
1720
1758
  displayName: 'Gemini 2.5 Pro',
1721
- inputPerMTok: 1.25,
1722
- outputPerMTok: 10,
1759
+ inputPerMTok: 1.5,
1760
+ outputPerMTok: 7.5,
1761
+ promo: { inputPerMTok: 0.75, outputPerMTok: 3.75, until: '2026-12-31', confirmedOn: '2026-11-16' },
1762
+ history: [
1763
+ /* Its own price: $0.125 cached (10%) and batch half, the ratios 3.8 Flash also has. */
1764
+ { until: '2026-12-01T00:00:00Z', inputPerMTok: 1.25, outputPerMTok: 10 },
1765
+ ],
1723
1766
  contextWindow: 1_048_576,
1724
1767
  cacheMinTokens: 2048,
1725
1768
  caching: 'automatic',
1726
- /* $0.125 cached against $1.25 input for prompts up to 200k, read 2026-10-10. */
1769
+ /* 10% cached and batch half on both sides: $0.125 against $1.25, then $0.075 against $0.75. */
1727
1770
  multipliers: { cacheRead: 0.1, cacheWrite5m: 1, cacheWrite1h: 1, batch: 0.5 },
1728
1771
  /* Refused on 2026-08-28: still in `GET /v1beta/models`, and a 404 to a request. */
1729
1772
  retired: {
@@ -1734,11 +1777,21 @@ export const MODELS: ModelPricing[] = [
1734
1777
  capability: 'large',
1735
1778
  tier: 'opus',
1736
1779
  notes:
1737
- 'Prompts over 200k tokens are billed $2.50 in and $15.00 out; this row prices every prompt at the up-to-200k rate,'
1738
- + ' because no log Trazum prices says how long each prompt was. Implicit caching is automatic; explicit caching is'
1739
- + ' also billed for storage per hour.',
1780
+ 'From 2026-12-01 Google routes this id to Gemini 3.8 Flash and bills it at 3.8 Flash rates.'
1781
+ + ' Before then it bills $1.25/$10, and $2.50/$15.00 for a prompt over 200k tokens; this row prices every prompt'
1782
+ + ' before then at the up-to-200k rate, because no log Trazum prices says how long each prompt was. Implicit caching'
1783
+ + ' is automatic; explicit caching is also billed for storage per hour.',
1740
1784
  },
1741
1785
  {
1786
+ /*
1787
+ * From aistudio.google.com/docs/pricing and docs/deprecations, read
1788
+ * 2026-11-16: "Effective December 1, 2026, all API requests to
1789
+ * `gemini-2.5-flash` will automatically route to Gemini 3.5 Flash-Lite
1790
+ * (`gemini-3.5-flash-lite`) and be billed at Gemini 3.5 Flash-Lite rates."
1791
+ * Those are $0.30/$2.50 and $0.03 cached for text, this row's own, so it
1792
+ * needs no second period. Audio input, which this row does not price,
1793
+ * falls from $1.00 to $0.30.
1794
+ */
1742
1795
  id: 'gemini-2.5-flash',
1743
1796
  provider: 'google',
1744
1797
  displayName: 'Gemini 2.5 Flash',
@@ -1747,7 +1800,7 @@ export const MODELS: ModelPricing[] = [
1747
1800
  contextWindow: 1_048_576,
1748
1801
  cacheMinTokens: 2048,
1749
1802
  caching: 'automatic',
1750
- /* $0.03 cached against $0.30 input (text), read 2026-10-10. */
1803
+ /* $0.03 cached against $0.30 input (text), read 2026-10-10 and again 2026-11-16. */
1751
1804
  multipliers: { cacheRead: 0.1, cacheWrite5m: 1, cacheWrite1h: 1, batch: 0.5 },
1752
1805
  /* Refused on 2026-08-28: still in `GET /v1beta/models`, and a 404 to a request. */
1753
1806
  retired: {
@@ -1757,6 +1810,9 @@ export const MODELS: ModelPricing[] = [
1757
1810
  },
1758
1811
  capability: 'mid',
1759
1812
  tier: 'sonnet',
1813
+ notes:
1814
+ 'From 2026-12-01 Google routes this id to Gemini 3.5 Flash-Lite and bills it at 3.5 Flash-Lite rates,'
1815
+ + ' which for text are the $0.30/$2.50 and $0.03 cached this row carries.',
1760
1816
  },
1761
1817
 
1762
1818
  {
@@ -1775,6 +1831,10 @@ export const MODELS: ModelPricing[] = [
1775
1831
  * again that day: "$0.75 through December 31, 2026. $1.50 starting January
1776
1832
  * 1, 2027", "$3.75 ... $7.50" for output and "$0.075 ... $0.15" for the
1777
1833
  * cache, word for word what it said in October. The rise stands.
1834
+ *
1835
+ * The page now lives at aistudio.google.com/docs/pricing, where the old
1836
+ * address redirects. Read there the same day: batch $0.375/$1.875, then
1837
+ * $0.75/$3.75, and storage $0.50, then $1.00 per 1M tokens per hour.
1778
1838
  */
1779
1839
  id: 'gemini-3.6-flash',
1780
1840
  provider: 'google',
@@ -1806,7 +1866,9 @@ export const MODELS: ModelPricing[] = [
1806
1866
  * and $3.75 through 2026-12-31, $1.50 and $7.50 from 2027-01-01, and the
1807
1867
  * cache price scales with them ($0.075, then $0.15). Read again on
1808
1868
  * 2026-11-16, inside the promotion's last 45 days: the same six figures
1809
- * and the same two dates.
1869
+ * and the same two dates, at aistudio.google.com/docs/pricing, where the
1870
+ * old address now redirects. From 2026-12-01 `gemini-2.5-pro` bills at
1871
+ * these rates too.
1810
1872
  */
1811
1873
  id: 'gemini-3.8-flash',
1812
1874
  provider: 'google',
@@ -1834,6 +1896,9 @@ export const MODELS: ModelPricing[] = [
1834
1896
  * $0.20 and $0.40 (10% in both bands), batch $1/$6 and $2/$9 (half in
1835
1897
  * both). 1,048,576 tokens in, 65,536 out, implicit caching from 4,096.
1836
1898
  * The `-customtools` endpoint is "same as Gemini 3.1 Pro Preview pricing".
1899
+ * Read again 2026-11-16 at aistudio.google.com/docs/pricing, where the old
1900
+ * address now redirects: every figure the same, storage $4.50 per 1M
1901
+ * tokens per hour, and the deprecations page announces no shutdown date.
1837
1902
  *
1838
1903
  * A preview, and priced because a log carries it: Google's 2.5 Pro
1839
1904
  * refusal sends every caller here.
@@ -1863,6 +1928,105 @@ export const MODELS: ModelPricing[] = [
1863
1928
  + ' Implicit caching is automatic above 4,096 tokens; explicit caching is also billed for storage,'
1864
1929
  + ' $4.50 per 1M tokens per hour.',
1865
1930
  },
1931
+ /*
1932
+ * The Gemini 4 family, from ai.google.dev/gemini-api/docs/pricing, the three
1933
+ * model pages and docs/caching, read 2026-11-16.
1934
+ *
1935
+ * Carbon ("our most capable reasoning model") and Argon ("our efficient
1936
+ * Gemini 4 frontier reasoning model") carry one table: "$2.00 through
1937
+ * November 30, 2026. $4.00 starting December 1, 2026" in, "$10.00 ...
1938
+ * $20.00" out, and the cache at "$0.10 ... $0.20", which is 5% of input on
1939
+ * both sides of the date, so one ratio serves. Batch is half of each
1940
+ * ($1.00/$5.00, then $2.00/$10.00). Hydrogen has no introductory price:
1941
+ * $1.50/$7.50, the cache at $0.075 (5% again), batch $0.75/$3.75.
1942
+ *
1943
+ * All three: a 1,048,576-token window that input and output share,
1944
+ * implicit caching from 4,096 tokens, and "implicit caching only (explicit
1945
+ * caching is not supported)", so there is no storage price to name.
1946
+ *
1947
+ * The introductory window was fourteen days from its end when these rows
1948
+ * were written, inside the 45 days `pricing-review.test.js` asks about, so
1949
+ * each records the day the page was read. On 2026-12-01 that test fails
1950
+ * until $2/$10 is moved into `history` and the promotion removed.
1951
+ *
1952
+ * Not here, and on the page: the Flex tier (the batch figures) and the
1953
+ * Priority tier (1.8 times standard, $3.60/$18.00 then $7.20/$36.00 on
1954
+ * Carbon and Argon, $2.70/$13.50 on Hydrogen). No Google row in this table
1955
+ * carries a service tier yet, and a tier whose price also changes on a date
1956
+ * needs a shape `serviceTiers` does not have. A call on either is priced at
1957
+ * the standard rate, and the note says so.
1958
+ */
1959
+ {
1960
+ id: 'gemini-4-carbon',
1961
+ provider: 'google',
1962
+ displayName: 'Gemini 4 Carbon',
1963
+ inputPerMTok: 4,
1964
+ outputPerMTok: 20,
1965
+ promo: { inputPerMTok: 2, outputPerMTok: 10, until: '2026-11-30', confirmedOn: '2026-11-16' },
1966
+ contextWindow: 1_048_576,
1967
+ cacheMinTokens: 4096,
1968
+ caching: 'automatic',
1969
+ multipliers: { cacheRead: 0.05, cacheWrite5m: 1, cacheWrite1h: 1, batch: 0.5 },
1970
+ capability: 'frontier',
1971
+ tier: 'frontier',
1972
+ notes: GEMINI_4_NOTE,
1973
+ },
1974
+ {
1975
+ id: 'gemini-4-argon',
1976
+ provider: 'google',
1977
+ displayName: 'Gemini 4 Argon',
1978
+ inputPerMTok: 4,
1979
+ outputPerMTok: 20,
1980
+ promo: { inputPerMTok: 2, outputPerMTok: 10, until: '2026-11-30', confirmedOn: '2026-11-16' },
1981
+ contextWindow: 1_048_576,
1982
+ cacheMinTokens: 4096,
1983
+ caching: 'automatic',
1984
+ multipliers: { cacheRead: 0.05, cacheWrite5m: 1, cacheWrite1h: 1, batch: 0.5 },
1985
+ capability: 'frontier',
1986
+ tier: 'frontier',
1987
+ notes: GEMINI_4_NOTE,
1988
+ },
1989
+ {
1990
+ id: 'gemini-4-hydrogen',
1991
+ provider: 'google',
1992
+ displayName: 'Gemini 4 Hydrogen',
1993
+ inputPerMTok: 1.5,
1994
+ outputPerMTok: 7.5,
1995
+ contextWindow: 1_048_576,
1996
+ cacheMinTokens: 4096,
1997
+ caching: 'automatic',
1998
+ multipliers: { cacheRead: 0.05, cacheWrite5m: 1, cacheWrite1h: 1, batch: 0.5 },
1999
+ capability: 'mid',
2000
+ tier: 'sonnet',
2001
+ notes: GEMINI_4_NOTE,
2002
+ },
2003
+ {
2004
+ /*
2005
+ * The pricing page and the model page, read 2026-11-16: $0.30 in for
2006
+ * text, image, video and audio alike, $2.50 out, the cache at $0.03 (10%),
2007
+ * batch $0.15/$1.25. 1,048,576 tokens in, 65,536 out. Added because
2008
+ * Google's deprecation page names it as where every request to
2009
+ * `gemini-2.5-flash` goes from 2026-12-01.
2010
+ *
2011
+ * No cache minimum: docs/caching says implicit caching is on "for all
2012
+ * Gemini 2.5 and newer models" and its table of minimums has no row for
2013
+ * this one, so none is written.
2014
+ */
2015
+ id: 'gemini-3.5-flash-lite',
2016
+ provider: 'google',
2017
+ displayName: 'Gemini 3.5 Flash-Lite',
2018
+ inputPerMTok: 0.3,
2019
+ outputPerMTok: 2.5,
2020
+ contextWindow: 1_048_576,
2021
+ cacheMinTokens: null,
2022
+ caching: 'automatic',
2023
+ multipliers: { cacheRead: 0.1, cacheWrite5m: 1, cacheWrite1h: 1, batch: 0.5 },
2024
+ capability: 'small',
2025
+ tier: 'haiku',
2026
+ notes:
2027
+ 'Implicit caching is automatic, and no minimum prefix length is published for this model. Explicit caching is'
2028
+ + ' also billed for storage, $1.00 per 1M tokens per hour.',
2029
+ },
1866
2030
 
1867
2031
  // ------------------------------------------------------------------------
1868
2032
  // Moonshot
package/src/rollup.ts CHANGED
@@ -323,6 +323,9 @@ const BREAKDOWN_SUM = [
323
323
  'webSearchUsd',
324
324
  'webSearchUnpricedRequests',
325
325
  'batchUsd',
326
+ 'batchExcludedInputTokens',
327
+ 'batchExcludedOutputTokens',
328
+ 'batchExcludedUsd',
326
329
  ] as const;
327
330
 
328
331
  /** Fields whose combination is a maximum, because a sum would invent a call. */
@@ -337,6 +340,7 @@ const COVERAGE_FIELDS = [
337
340
  'stopReason',
338
341
  'cacheTtl',
339
342
  'cacheWrites',
343
+ 'interactive',
340
344
  'parsed',
341
345
  ] as const;
342
346
 
package/src/schemas.ts CHANGED
@@ -65,6 +65,7 @@ export const CONTRACT_SCHEMAS: Record<ContractName, Record<string, unknown>> = {
65
65
  label: string,
66
66
  session: string,
67
67
  thread: string,
68
+ interactive: boolean,
68
69
  outcome: string,
69
70
  stop_reason: string,
70
71
  },
package/src/usage.ts CHANGED
@@ -222,6 +222,20 @@ export interface UsageRecord {
222
222
  * report converters write for a batch row. Absent is not batch.
223
223
  */
224
224
  batch?: true;
225
+ /**
226
+ * True when something waited on the answer: a person in a conversation, or
227
+ * an agent whose next step needed it. The Batch API answers within a day,
228
+ * so a call like this cannot move to it, and the batch lever leaves it out
229
+ * (`batchExcludedUsd` on the breakdown) instead of asking the reader whether
230
+ * a turn of their coding agent "can wait for a batch window".
231
+ *
232
+ * Read from a record-level `interactive: true`, which is what the agent
233
+ * session converters write on every line: `from-claude-code`, `from-codex`
234
+ * and `from-gemini-cli`. Absent says nothing either way. A log that marks
235
+ * none of its calls is read as it always was, because most logs never
236
+ * recorded who was waiting.
237
+ */
238
+ interactive?: true;
225
239
  /**
226
240
  * Web searches the call ran, when the log counted any: Anthropic's
227
241
  * `usage.server_tool_use.web_search_requests`, which every Messages
@@ -355,6 +369,22 @@ export interface UsageBreakdown {
355
369
  * difference. Their searches are in `webSearchUsd`, at the same fee as any.
356
370
  */
357
371
  batchUsd: number;
372
+ /**
373
+ * The input and output the Batch API lever leaves out, in tokens and in
374
+ * dollars at each call's own rate: calls already billed at the batch rate,
375
+ * which cannot be halved twice, and calls something waited on
376
+ * (`interactive` on the record), which cannot wait a day.
377
+ *
378
+ * Already inside `inputTokens`, `outputTokens`, `inputUsd` and `outputUsd`.
379
+ * Input and output only, because those are the two lines the lever prices.
380
+ * Tokens as well as dollars, because a batch saving on another model's rates
381
+ * is priced from the tokens. Written as what is left out, never as what is
382
+ * left in, so a document from before the fields existed reads as zero and
383
+ * prices the lever as it always did.
384
+ */
385
+ batchExcludedInputTokens: number;
386
+ batchExcludedOutputTokens: number;
387
+ batchExcludedUsd: number;
358
388
  }
359
389
 
360
390
  /**
@@ -379,6 +409,8 @@ export interface FieldCoverage {
379
409
  cacheTtl: number;
380
410
  /** Records that wrote to the cache at all — the denominator for `cacheTtl`. */
381
411
  cacheWrites: number;
412
+ /** Records marked `interactive`: something waited on the answer. */
413
+ interactive: number;
382
414
  /** Every record that parsed, priced or not — the denominator for the rest. */
383
415
  parsed: number;
384
416
  }
@@ -722,6 +754,9 @@ const EMPTY = (): UsageBreakdown => ({
722
754
  webSearchUsd: 0,
723
755
  webSearchUnpricedRequests: 0,
724
756
  batchUsd: 0,
757
+ batchExcludedInputTokens: 0,
758
+ batchExcludedOutputTokens: 0,
759
+ batchExcludedUsd: 0,
725
760
  });
726
761
 
727
762
  /**
@@ -1081,6 +1116,8 @@ export function parseUsageLine(line: string): UsageRecord | null {
1081
1116
  * cannot collide on a flat record.
1082
1117
  */
1083
1118
  ...(record.batch === true || usage.service_tier === 'batch' ? { batch: true as const } : {}),
1119
+ /* Said by the record alone: nothing a provider returns names who was waiting. */
1120
+ ...(record.interactive === true ? { interactive: true as const } : {}),
1084
1121
  ...(valueOf(webSearch) > 0 ? { webSearchRequests: valueOf(webSearch) } : {}),
1085
1122
  ...(openAiSplitGiven && !openAiSplitAgrees ? { writeSplitContradicted: true as const } : {}),
1086
1123
  };
@@ -1223,6 +1260,16 @@ function add(into: UsageBreakdown, record: UsageRecord, catalogue: PricingCatalo
1223
1260
  per(record.cacheWrite1hTokens, input * rates.cacheWrite1h) +
1224
1261
  per(record.outputTokens, output);
1225
1262
  if (priced.batch === true) into.batchUsd += recordUsd(inputPerMTok, outputPerMTok);
1263
+ /*
1264
+ * What the batch lever must not count: a call the log says ran on the Batch
1265
+ * API, and a call something waited on. By the record, not by the price: a
1266
+ * batch call on a model with no batch rate is still a call that was batched.
1267
+ */
1268
+ if (record.batch === true || record.interactive === true) {
1269
+ into.batchExcludedInputTokens += record.inputTokens;
1270
+ into.batchExcludedOutputTokens += record.outputTokens;
1271
+ into.batchExcludedUsd += per(record.inputTokens, inputPerMTok) + per(record.outputTokens, outputPerMTok);
1272
+ }
1226
1273
  const floor = priced.tier?.decided === false ? priced.tier.floor : undefined;
1227
1274
  if (floor !== undefined) {
1228
1275
  into.tierCeilingCalls += 1;
@@ -1355,7 +1402,7 @@ export function profileUsage(text: string, options: UsageProfileOptions): UsageP
1355
1402
  const outcomesByModel = new Map<string, Map<string, { calls: number; usd: number }>>();
1356
1403
  const unrecordedByLabel = new Map<string, number>();
1357
1404
  const unrecordedByModel = new Map<string, number>();
1358
- const coverage = { label: 0, session: 0, outcome: 0, ts: 0, stopReason: 0, cacheTtl: 0, cacheWrites: 0, parsed: 0 };
1405
+ const coverage = { label: 0, session: 0, outcome: 0, ts: 0, stopReason: 0, cacheTtl: 0, cacheWrites: 0, interactive: 0, parsed: 0 };
1359
1406
  /**
1360
1407
  * Raw lines already seen, for the duplicate check. Bounded by the number of
1361
1408
  * *timestamped* lines — the price of catching a doubled bill, paid only on
@@ -1443,6 +1490,7 @@ export function profileUsage(text: string, options: UsageProfileOptions): UsageP
1443
1490
  */
1444
1491
  coverage.parsed += 1;
1445
1492
  if (record.label !== null) coverage.label += 1;
1493
+ if (record.interactive === true) coverage.interactive += 1;
1446
1494
  if (record.session !== null) coverage.session += 1;
1447
1495
  if (record.outcome !== null) coverage.outcome += 1;
1448
1496
  if (record.ts !== null) coverage.ts += 1;