@trazum/core 2.7.4 → 2.7.5

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.
Files changed (79) hide show
  1. package/dist/anthropic-cost.d.ts +22 -5
  2. package/dist/anthropic-cost.d.ts.map +1 -1
  3. package/dist/anthropic-cost.js +33 -10
  4. package/dist/anthropic-cost.js.map +1 -1
  5. package/dist/anthropic-usage.d.ts +7 -1
  6. package/dist/anthropic-usage.d.ts.map +1 -1
  7. package/dist/anthropic-usage.js +17 -1
  8. package/dist/anthropic-usage.js.map +1 -1
  9. package/dist/billing.d.ts +10 -0
  10. package/dist/billing.d.ts.map +1 -1
  11. package/dist/billing.js +14 -0
  12. package/dist/billing.js.map +1 -1
  13. package/dist/claude-code.d.ts +4 -0
  14. package/dist/claude-code.d.ts.map +1 -1
  15. package/dist/claude-code.js +14 -1
  16. package/dist/claude-code.js.map +1 -1
  17. package/dist/connector.d.ts +19 -1
  18. package/dist/connector.d.ts.map +1 -1
  19. package/dist/connector.js +34 -2
  20. package/dist/connector.js.map +1 -1
  21. package/dist/csv.d.ts +1 -1
  22. package/dist/csv.d.ts.map +1 -1
  23. package/dist/csv.js +11 -0
  24. package/dist/csv.js.map +1 -1
  25. package/dist/gateway.d.ts +2 -0
  26. package/dist/gateway.d.ts.map +1 -1
  27. package/dist/gateway.js +16 -0
  28. package/dist/gateway.js.map +1 -1
  29. package/dist/pricing-overlay.d.ts +1 -1
  30. package/dist/pricing-overlay.d.ts.map +1 -1
  31. package/dist/pricing-overlay.js +11 -0
  32. package/dist/pricing-overlay.js.map +1 -1
  33. package/dist/pricing.d.ts.map +1 -1
  34. package/dist/pricing.js +38 -0
  35. package/dist/pricing.js.map +1 -1
  36. package/dist/receipt.d.ts +38 -4
  37. package/dist/receipt.d.ts.map +1 -1
  38. package/dist/receipt.js +19 -1
  39. package/dist/receipt.js.map +1 -1
  40. package/dist/repeats.d.ts.map +1 -1
  41. package/dist/repeats.js +3 -2
  42. package/dist/repeats.js.map +1 -1
  43. package/dist/rollup.d.ts.map +1 -1
  44. package/dist/rollup.js +4 -0
  45. package/dist/rollup.js.map +1 -1
  46. package/dist/session-cost.d.ts.map +1 -1
  47. package/dist/session-cost.js +4 -2
  48. package/dist/session-cost.js.map +1 -1
  49. package/dist/store.d.ts +5 -0
  50. package/dist/store.d.ts.map +1 -1
  51. package/dist/store.js +4 -0
  52. package/dist/store.js.map +1 -1
  53. package/dist/truncation-retry.d.ts.map +1 -1
  54. package/dist/truncation-retry.js +3 -2
  55. package/dist/truncation-retry.js.map +1 -1
  56. package/dist/types.d.ts +13 -0
  57. package/dist/types.d.ts.map +1 -1
  58. package/dist/usage.d.ts +34 -0
  59. package/dist/usage.d.ts.map +1 -1
  60. package/dist/usage.js +34 -3
  61. package/dist/usage.js.map +1 -1
  62. package/package.json +1 -1
  63. package/src/anthropic-cost.ts +46 -12
  64. package/src/anthropic-usage.ts +24 -2
  65. package/src/billing.ts +15 -0
  66. package/src/claude-code.ts +16 -1
  67. package/src/connector.ts +56 -3
  68. package/src/csv.ts +11 -0
  69. package/src/gateway.ts +16 -0
  70. package/src/pricing-overlay.ts +15 -0
  71. package/src/pricing.ts +39 -0
  72. package/src/receipt.ts +53 -6
  73. package/src/repeats.ts +3 -2
  74. package/src/rollup.ts +4 -0
  75. package/src/session-cost.ts +4 -2
  76. package/src/store.ts +9 -0
  77. package/src/truncation-retry.ts +3 -2
  78. package/src/types.ts +13 -0
  79. package/src/usage.ts +68 -3
package/src/connector.ts CHANGED
@@ -178,6 +178,12 @@ export interface UsageBucket {
178
178
  /** False when the provider reported writes without saying which TTL. */
179
179
  writeTtlKnown: boolean;
180
180
  outputTokens: number;
181
+ /**
182
+ * Web searches the bucket's requests ran, billed per search on top of the
183
+ * tokens: Anthropic's `server_tool_use.web_search_requests`. Absent is none,
184
+ * which is also what a pull stored before 2.7.5 reads as.
185
+ */
186
+ webSearchRequests?: number;
181
187
  /** Whatever the provider grouped by beyond the model — workspace, key, tier. */
182
188
  group: Record<string, string>;
183
189
  }
@@ -198,7 +204,9 @@ export interface PullGap {
198
204
  | 'unreadable-entry'
199
205
  | 'unreadable-field'
200
206
  /** Usage at a tier no catalogue rate prices, left out and named. */
201
- | 'unpriced-tier';
207
+ | 'unpriced-tier'
208
+ /** Web searches on a model whose row publishes no per-search fee, left out and named. */
209
+ | 'unpriced-web-search';
202
210
  detail: string;
203
211
  }
204
212
 
@@ -241,6 +249,9 @@ function collect(buckets: UsageBucket[]): UsageBucket[] {
241
249
  seen.cacheWrite5mTokens += bucket.cacheWrite5mTokens;
242
250
  seen.cacheWrite1hTokens += bucket.cacheWrite1hTokens;
243
251
  seen.outputTokens += bucket.outputTokens;
252
+ if ((bucket.webSearchRequests ?? 0) > 0) {
253
+ seen.webSearchRequests = (seen.webSearchRequests ?? 0) + bucket.webSearchRequests!;
254
+ }
244
255
  seen.writeTtlKnown = seen.writeTtlKnown && bucket.writeTtlKnown;
245
256
  // A count merged with an absent count is still absent: adding a number to
246
257
  // "unknown" produces a number that describes only part of the traffic.
@@ -308,6 +319,8 @@ export function normalizeAnthropicUsage(payload: unknown): ConnectorPull {
308
319
  const write1h = num(creation.ephemeral_1h_input_tokens) ?? 0;
309
320
  const flatWrite = num(r.cache_creation_input_tokens) ?? 0;
310
321
  const ttlKnown = !(flatWrite > 0 && write5m === 0 && write1h === 0);
322
+ /* Billed per search, $10 per 1,000 on Claude: the one count here that is not tokens. */
323
+ const searches = num((r.server_tool_use as Record<string, unknown> | undefined)?.web_search_requests) ?? 0;
311
324
  buckets.push({
312
325
  fromMs,
313
326
  toMs,
@@ -320,6 +333,7 @@ export function normalizeAnthropicUsage(payload: unknown): ConnectorPull {
320
333
  cacheWrite1hTokens: ttlKnown ? write1h : 0,
321
334
  writeTtlKnown: ttlKnown,
322
335
  outputTokens: num(r.output_tokens) ?? 0,
336
+ ...(searches > 0 ? { webSearchRequests: searches } : {}),
323
337
  group: groupOf(r, ['workspace_id', 'api_key_id', 'service_tier', 'context_window', 'speed', 'inference_geo']),
324
338
  });
325
339
  }
@@ -461,6 +475,13 @@ export interface BucketedSlice {
461
475
  tierCeilingBuckets: number;
462
476
  tierCeilingUsd: number;
463
477
  tierFloorUsd: number;
478
+ /**
479
+ * Web searches, billed per search at the model's fee, flat: the Batch API,
480
+ * fast mode and US-only inference move token rates, not this. Part of
481
+ * `totalUsd`.
482
+ */
483
+ webSearchRequests: number;
484
+ webSearchUsd: number;
464
485
  }
465
486
 
466
487
  export interface BucketedReport {
@@ -476,6 +497,9 @@ export interface BucketedReport {
476
497
  cacheReadTokens: number;
477
498
  cacheWriteTokens: number;
478
499
  outputTokens: number;
500
+ /** Web searches billed, and what they came to: already inside `totalUsd`. */
501
+ webSearchRequests: number;
502
+ webSearchUsd: number;
479
503
  };
480
504
  byModel: BucketedSlice[];
481
505
  /** Spend per UTC day, oldest first — the shape a total hides. */
@@ -521,6 +545,8 @@ export function bucketedProfile(
521
545
  + bucket.outputTokens;
522
546
  leftOut.set(key, seen);
523
547
  };
548
+ /* Searches on a model with no per-search fee, per model, so the gap names it. */
549
+ const searchesLeftOut = new Map<string, number>();
524
550
 
525
551
  for (const bucket of pull.buckets) {
526
552
  const model = catalogue.byId.get(bucket.model);
@@ -613,6 +639,17 @@ export function bucketedProfile(
613
639
  const ifAssumed1h = bucket.writeTtlKnown
614
640
  ? cacheWriteUsd
615
641
  : per(writeTokens, inputPerMTok * rates.cacheWrite1h);
642
+ /*
643
+ * Searches at the row's fee, flat, read off the model and not out of
644
+ * `effectivePricing`: none of the multipliers `how` carries reaches a
645
+ * search. A model with no fee leaves them out, named below.
646
+ */
647
+ const searches = bucket.webSearchRequests ?? 0;
648
+ const fee = model.webSearchPerThousandUsd;
649
+ const searchUsd = searches > 0 && fee !== undefined ? (searches / 1_000) * fee : 0;
650
+ if (searches > 0 && fee === undefined) {
651
+ searchesLeftOut.set(bucket.model, (searchesLeftOut.get(bucket.model) ?? 0) + searches);
652
+ }
616
653
 
617
654
  const slice = slices.get(bucket.model) ?? {
618
655
  model: bucket.model,
@@ -632,6 +669,8 @@ export function bucketedProfile(
632
669
  tierCeilingBuckets: 0,
633
670
  tierCeilingUsd: 0,
634
671
  tierFloorUsd: 0,
672
+ webSearchRequests: 0,
673
+ webSearchUsd: 0,
635
674
  };
636
675
  slice.calls = slice.calls === null || bucket.calls === null ? null : slice.calls + bucket.calls;
637
676
  slice.inputTokens += bucket.inputTokens;
@@ -642,7 +681,11 @@ export function bucketedProfile(
642
681
  slice.cacheReadUsd += cacheReadUsd;
643
682
  slice.cacheWriteUsd += cacheWriteUsd;
644
683
  slice.outputUsd += outputUsd;
645
- slice.totalUsd += inputUsd + cacheReadUsd + cacheWriteUsd + outputUsd;
684
+ slice.totalUsd += inputUsd + cacheReadUsd + cacheWriteUsd + outputUsd + searchUsd;
685
+ if (fee !== undefined) {
686
+ slice.webSearchRequests += searches;
687
+ slice.webSearchUsd += searchUsd;
688
+ }
646
689
  slice.cachedTokensAtInputRateUsd += atInputRate;
647
690
  slice.cacheWriteUsdIfAssumed1h += ifAssumed1h;
648
691
  slice.writeTtlKnown = slice.writeTtlKnown && bucket.writeTtlKnown;
@@ -655,7 +698,7 @@ export function bucketedProfile(
655
698
 
656
699
  const day = new Date(bucket.fromMs).toISOString().slice(0, 10);
657
700
  const entry = days.get(day) ?? { usd: 0, calls: bucket.calls === null ? null : 0 };
658
- entry.usd += inputUsd + cacheReadUsd + cacheWriteUsd + outputUsd;
701
+ entry.usd += inputUsd + cacheReadUsd + cacheWriteUsd + outputUsd + searchUsd;
659
702
  entry.calls = entry.calls === null || bucket.calls === null ? null : entry.calls + bucket.calls;
660
703
  days.set(day, entry);
661
704
  }
@@ -675,6 +718,8 @@ export function bucketedProfile(
675
718
  cacheReadTokens: byModel.reduce((sum, s) => sum + s.cacheReadTokens, 0),
676
719
  cacheWriteTokens: byModel.reduce((sum, s) => sum + s.cacheWriteTokens, 0),
677
720
  outputTokens: byModel.reduce((sum, s) => sum + s.outputTokens, 0),
721
+ webSearchRequests: byModel.reduce((sum, s) => sum + s.webSearchRequests, 0),
722
+ webSearchUsd: byModel.reduce((sum, s) => sum + s.webSearchUsd, 0),
678
723
  },
679
724
  byModel,
680
725
  byDay: [...days.entries()]
@@ -693,6 +738,14 @@ export function bucketedProfile(
693
738
  + `and ${left.tokens.toLocaleString('en-US')} token(s) were left out rather than priced at the standard rate`,
694
739
  }),
695
740
  ),
741
+ ...[...searchesLeftOut.entries()].map(
742
+ ([model, searches]): PullGap => ({
743
+ kind: 'unpriced-web-search',
744
+ detail:
745
+ `${searches.toLocaleString('en-US')} web search(es) on ${model}, whose row publishes no per-search fee, `
746
+ + 'were left out rather than billed at another provider\'s',
747
+ }),
748
+ ),
696
749
  ],
697
750
  unavailable: pull.unavailable,
698
751
  };
package/src/csv.ts CHANGED
@@ -45,6 +45,13 @@ export const PROFILE_CSV_COLUMNS = [
45
45
  'cache_write_usd',
46
46
  'output_usd',
47
47
  'total_usd',
48
+ /*
49
+ * Appended, never inserted, so a reader that addresses columns by position
50
+ * keeps reading the same twelve. Web searches are billed per search, so
51
+ * `total_usd` is the four token columns plus `web_search_usd`.
52
+ */
53
+ 'web_search_requests',
54
+ 'web_search_usd',
48
55
  ] as const;
49
56
 
50
57
  /**
@@ -164,6 +171,8 @@ export function profileToCsv(report: UsageProfileReport, options: ProfileCsvOpti
164
171
  usd(breakdown.cacheWriteUsd),
165
172
  usd(breakdown.outputUsd),
166
173
  usd(breakdown.totalUsd),
174
+ String(breakdown.webSearchRequests),
175
+ usd(breakdown.webSearchUsd),
167
176
  ].join(','),
168
177
  );
169
178
  }
@@ -193,6 +202,8 @@ export function profileToCsv(report: UsageProfileReport, options: ProfileCsvOpti
193
202
  '',
194
203
  '',
195
204
  '',
205
+ String(row.breakdown.webSearchRequests),
206
+ '',
196
207
  ].join(','),
197
208
  );
198
209
  }
package/src/gateway.ts CHANGED
@@ -523,8 +523,18 @@ export interface GatewayUsage {
523
523
  serviceTier?: string;
524
524
  /** Anthropic's `usage.inference_geo`, the geography that ran: "us" bills 1.1x on Claude 4.6 and later. */
525
525
  inferenceGeo?: string;
526
+ /** Anthropic's `usage.server_tool_use.web_search_requests`: each search bills $10 per 1,000 on top. */
527
+ webSearchRequests?: number;
526
528
  }
527
529
 
530
+ /** The searches a usage object counts, when it counts a readable number of them. */
531
+ const webSearchesIn = (usage: Record<string, unknown>): number | undefined => {
532
+ const tools = usage.server_tool_use;
533
+ if (typeof tools !== 'object' || tools === null) return undefined;
534
+ const searches = (tools as Record<string, unknown>).web_search_requests;
535
+ return typeof searches === 'number' && Number.isFinite(searches) && searches >= 0 ? searches : undefined;
536
+ };
537
+
528
538
  /**
529
539
  * OpenAI's cache writes, inside `prompt_tokens` like its cached reads.
530
540
  *
@@ -693,6 +703,8 @@ export function streamingUsageReader(
693
703
  usage.outputTokens = num(start.output_tokens);
694
704
  if (typeof start.speed === 'string' && start.speed !== '') usage.speed = start.speed;
695
705
  if (typeof start.inference_geo === 'string' && start.inference_geo !== '') usage.inferenceGeo = start.inference_geo;
706
+ const searches = webSearchesIn(start);
707
+ if (searches !== undefined) usage.webSearchRequests = searches;
696
708
  seen = true;
697
709
  }
698
710
  }
@@ -711,6 +723,9 @@ export function streamingUsageReader(
711
723
  if (typeof d.input_tokens === 'number') usage.inputTokens = num(d.input_tokens);
712
724
  if (typeof d.speed === 'string' && d.speed !== '') usage.speed = d.speed;
713
725
  if (typeof d.inference_geo === 'string' && d.inference_geo !== '') usage.inferenceGeo = d.inference_geo;
726
+ // Cumulative like the output count: the last delta's searches are the call's.
727
+ const searches = webSearchesIn(d);
728
+ if (searches !== undefined) usage.webSearchRequests = searches;
714
729
  seen = true;
715
730
  }
716
731
  return;
@@ -814,6 +829,7 @@ export function usageFromResponse(
814
829
  ...cacheWriteBreakdown(u),
815
830
  ...(typeof u.speed === 'string' && u.speed !== '' ? { speed: u.speed } : {}),
816
831
  ...(typeof u.inference_geo === 'string' && u.inference_geo !== '' ? { inferenceGeo: u.inference_geo } : {}),
832
+ ...(webSearchesIn(u) === undefined ? {} : { webSearchRequests: webSearchesIn(u) }),
817
833
  };
818
834
  }
819
835
  if (shape === 'openai') {
@@ -36,6 +36,7 @@ export const PRICING_MODEL_KEYS = [
36
36
  'promo',
37
37
  'multipliers',
38
38
  'inferenceGeoMultipliers',
39
+ 'webSearchPerThousandUsd',
39
40
  ] as const;
40
41
 
41
42
  /** The geographies a provider prices differently, as `InferenceGeo` names them. */
@@ -281,6 +282,20 @@ function parseModel(
281
282
  model.inferenceGeoMultipliers = {};
282
283
  if (geo.us !== undefined) model.inferenceGeoMultipliers.us = positiveNumber(geo.us, `${label}.us`, source);
283
284
  }
285
+ /*
286
+ * A per-search fee, in dollars per 1,000 searches, as the catalogue carries
287
+ * it on every Claude row. Accepted for the same two reasons: a copied row
288
+ * stays valid, and a contract price for searches can be stated. Zero and
289
+ * negatives are refused like every other rate; a row with no searches to
290
+ * price simply leaves the key out.
291
+ */
292
+ if (raw.webSearchPerThousandUsd !== undefined) {
293
+ model.webSearchPerThousandUsd = positiveNumber(
294
+ raw.webSearchPerThousandUsd,
295
+ `models.${id}.webSearchPerThousandUsd`,
296
+ source,
297
+ );
298
+ }
284
299
 
285
300
  return model;
286
301
  }
package/src/pricing.ts CHANGED
@@ -323,6 +323,25 @@ const MISTRAL_CACHE_NOTE =
323
323
  */
324
324
  const US_ONLY_INFERENCE = Object.freeze({ us: 1.1 });
325
325
 
326
+ /**
327
+ * Anthropic's web search, per 1,000 searches.
328
+ *
329
+ * platform.claude.com/docs/en/about-claude/pricing, "Web search tool", and
330
+ * the web search tool's own page, read 2026-11-05: "Web search is available on
331
+ * the Claude API for **$10 USD per 1,000 searches**, plus standard token costs
332
+ * for search-generated content", "Each web search counts as one use,
333
+ * regardless of the number of results returned. If an error occurs during web
334
+ * search, the web search will not be billed", and "Web search tool is
335
+ * available on every model". The tool page also says searches through the
336
+ * Messages Batches API "are priced the same as those in regular Messages API
337
+ * requests", so the Batch API ratio never reaches this fee; the 1.1x of
338
+ * US-only inference is stated for "all token pricing categories", and a
339
+ * search is not a token, so it does not either. Web fetch has "no additional
340
+ * charges beyond standard token costs" and carries no fee. `price-drift.mjs`
341
+ * reads the sentence weekly.
342
+ */
343
+ const ANTHROPIC_WEB_SEARCH_USD_PER_1K = 10;
344
+
326
345
  export const MODELS: ModelPricing[] = [
327
346
  {
328
347
  /*
@@ -334,6 +353,7 @@ export const MODELS: ModelPricing[] = [
334
353
  */
335
354
  id: 'claude-fable-5-1',
336
355
  provider: 'anthropic',
356
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
337
357
  inferenceGeoMultipliers: US_ONLY_INFERENCE,
338
358
  displayName: 'Claude Fable 5.1',
339
359
  inputPerMTok: 10,
@@ -353,6 +373,7 @@ export const MODELS: ModelPricing[] = [
353
373
  */
354
374
  id: 'claude-mythos-5-1',
355
375
  provider: 'anthropic',
376
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
356
377
  inferenceGeoMultipliers: US_ONLY_INFERENCE,
357
378
  displayName: 'Claude Mythos 5.1',
358
379
  recommendable: false,
@@ -370,6 +391,7 @@ export const MODELS: ModelPricing[] = [
370
391
  {
371
392
  id: 'claude-fable-5',
372
393
  provider: 'anthropic',
394
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
373
395
  inferenceGeoMultipliers: US_ONLY_INFERENCE,
374
396
  displayName: 'Claude Fable 5',
375
397
  inputPerMTok: 10,
@@ -383,6 +405,7 @@ export const MODELS: ModelPricing[] = [
383
405
  {
384
406
  id: 'claude-mythos-5',
385
407
  provider: 'anthropic',
408
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
386
409
  inferenceGeoMultipliers: US_ONLY_INFERENCE,
387
410
  displayName: 'Claude Mythos 5',
388
411
  recommendable: false,
@@ -405,6 +428,7 @@ export const MODELS: ModelPricing[] = [
405
428
  */
406
429
  id: 'claude-opus-5-5',
407
430
  provider: 'anthropic',
431
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
408
432
  inferenceGeoMultipliers: US_ONLY_INFERENCE,
409
433
  displayName: 'Claude Opus 5.5',
410
434
  inputPerMTok: 4,
@@ -428,6 +452,7 @@ export const MODELS: ModelPricing[] = [
428
452
  {
429
453
  id: 'claude-opus-5',
430
454
  provider: 'anthropic',
455
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
431
456
  inferenceGeoMultipliers: US_ONLY_INFERENCE,
432
457
  displayName: 'Claude Opus 5',
433
458
  inputPerMTok: 5,
@@ -443,6 +468,7 @@ export const MODELS: ModelPricing[] = [
443
468
  {
444
469
  id: 'claude-opus-4-8',
445
470
  provider: 'anthropic',
471
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
446
472
  inferenceGeoMultipliers: US_ONLY_INFERENCE,
447
473
  displayName: 'Claude Opus 4.8',
448
474
  inputPerMTok: 5,
@@ -462,6 +488,7 @@ export const MODELS: ModelPricing[] = [
462
488
  {
463
489
  id: 'claude-opus-4-7',
464
490
  provider: 'anthropic',
491
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
465
492
  inferenceGeoMultipliers: US_ONLY_INFERENCE,
466
493
  displayName: 'Claude Opus 4.7',
467
494
  inputPerMTok: 5,
@@ -474,6 +501,7 @@ export const MODELS: ModelPricing[] = [
474
501
  {
475
502
  id: 'claude-opus-4-6',
476
503
  provider: 'anthropic',
504
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
477
505
  inferenceGeoMultipliers: US_ONLY_INFERENCE,
478
506
  displayName: 'Claude Opus 4.6',
479
507
  inputPerMTok: 5,
@@ -495,6 +523,7 @@ export const MODELS: ModelPricing[] = [
495
523
  id: 'claude-opus-4-5',
496
524
  aliases: ['claude-opus-4-5-20251101'],
497
525
  provider: 'anthropic',
526
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
498
527
  displayName: 'Claude Opus 4.5',
499
528
  inputPerMTok: 5,
500
529
  outputPerMTok: 25,
@@ -519,6 +548,7 @@ export const MODELS: ModelPricing[] = [
519
548
  */
520
549
  id: 'claude-opus-4-1-20250805',
521
550
  provider: 'anthropic',
551
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
522
552
  displayName: 'Claude Opus 4.1',
523
553
  recommendable: false,
524
554
  inputPerMTok: 15,
@@ -539,6 +569,7 @@ export const MODELS: ModelPricing[] = [
539
569
  */
540
570
  id: 'claude-opus-4-20250514',
541
571
  provider: 'anthropic',
572
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
542
573
  displayName: 'Claude Opus 4',
543
574
  recommendable: false,
544
575
  inputPerMTok: 15,
@@ -559,6 +590,7 @@ export const MODELS: ModelPricing[] = [
559
590
  */
560
591
  id: 'claude-sonnet-5-5',
561
592
  provider: 'anthropic',
593
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
562
594
  inferenceGeoMultipliers: US_ONLY_INFERENCE,
563
595
  displayName: 'Claude Sonnet 5.5',
564
596
  inputPerMTok: 2,
@@ -573,6 +605,7 @@ export const MODELS: ModelPricing[] = [
573
605
  {
574
606
  id: 'claude-sonnet-5',
575
607
  provider: 'anthropic',
608
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
576
609
  inferenceGeoMultipliers: US_ONLY_INFERENCE,
577
610
  displayName: 'Claude Sonnet 5',
578
611
  inputPerMTok: 2,
@@ -588,6 +621,7 @@ export const MODELS: ModelPricing[] = [
588
621
  {
589
622
  id: 'claude-sonnet-4-6',
590
623
  provider: 'anthropic',
624
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
591
625
  inferenceGeoMultipliers: US_ONLY_INFERENCE,
592
626
  displayName: 'Claude Sonnet 4.6',
593
627
  inputPerMTok: 3,
@@ -610,6 +644,7 @@ export const MODELS: ModelPricing[] = [
610
644
  id: 'claude-sonnet-4-5',
611
645
  aliases: ['claude-sonnet-4-5-20250929'],
612
646
  provider: 'anthropic',
647
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
613
648
  displayName: 'Claude Sonnet 4.5',
614
649
  recommendable: false,
615
650
  inputPerMTok: 3,
@@ -632,6 +667,7 @@ export const MODELS: ModelPricing[] = [
632
667
  */
633
668
  id: 'claude-sonnet-4-20250514',
634
669
  provider: 'anthropic',
670
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
635
671
  displayName: 'Claude Sonnet 4',
636
672
  recommendable: false,
637
673
  inputPerMTok: 3,
@@ -663,6 +699,7 @@ export const MODELS: ModelPricing[] = [
663
699
  */
664
700
  id: 'claude-haiku-5-5',
665
701
  provider: 'anthropic',
702
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
666
703
  inferenceGeoMultipliers: US_ONLY_INFERENCE,
667
704
  displayName: 'Claude Haiku 5.5',
668
705
  inputPerMTok: 0.1,
@@ -691,6 +728,7 @@ export const MODELS: ModelPricing[] = [
691
728
  // not derived: see `aliases` in types.ts.
692
729
  aliases: ['claude-haiku-4-5-20251001'],
693
730
  provider: 'anthropic',
731
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
694
732
  displayName: 'Claude Haiku 4.5',
695
733
  inputPerMTok: 1,
696
734
  outputPerMTok: 5,
@@ -711,6 +749,7 @@ export const MODELS: ModelPricing[] = [
711
749
  */
712
750
  id: 'claude-3-5-haiku-20241022',
713
751
  provider: 'anthropic',
752
+ webSearchPerThousandUsd: ANTHROPIC_WEB_SEARCH_USD_PER_1K,
714
753
  displayName: 'Claude Haiku 3.5',
715
754
  recommendable: false,
716
755
  inputPerMTok: 0.8,
package/src/receipt.ts CHANGED
@@ -97,12 +97,18 @@ export interface ReceiptPricing {
97
97
  reviewedOn: string | null;
98
98
  }
99
99
 
100
- /** Where a line's money went. The four add to `ReceiptLine.usd`. */
100
+ /** Where a line's money went. The five add to `ReceiptLine.usd`. */
101
101
  export interface ReceiptMoney {
102
102
  inputUsd: number;
103
103
  cacheReadUsd: number;
104
104
  cacheWriteUsd: number;
105
105
  outputUsd: number;
106
+ /**
107
+ * Web searches, billed per search rather than per token, so no token count
108
+ * divides it: `ReceiptLine.webSearchRequests` does. Zero on a line that ran
109
+ * none, which is most of them.
110
+ */
111
+ webSearchUsd: number;
106
112
  }
107
113
 
108
114
  /** One slice of a bill: a label's calls to one model. */
@@ -143,9 +149,10 @@ export interface ReceiptLine {
143
149
  * recomputed.
144
150
  *
145
151
  * This is the field that makes a receipt checkable. `usd` alone can only be
146
- * believed; these four can be added up, and each can be divided by its own
147
- * token count to recover the rate that was really charged -- including the
148
- * one for cached reads, which no published rate names.
152
+ * believed; these five can be added up, and each can be divided by its own
153
+ * count to recover the rate that was really charged -- including the one for
154
+ * cached reads, which no published rate names, and the per-search fee,
155
+ * divided by `webSearchRequests`.
149
156
  */
150
157
  money: ReceiptMoney;
151
158
  /** The catalogue's published rates, as provenance. */
@@ -178,6 +185,12 @@ export interface ReceiptLine {
178
185
  * and a reader is entitled to know which slices carry it.
179
186
  */
180
187
  assumedWriteTtlCalls: number;
188
+ /**
189
+ * Web searches these calls ran, each billed at the provider's per-search
190
+ * fee. The count only: what was searched for never reaches a usage log, and
191
+ * so never reaches this.
192
+ */
193
+ webSearchRequests: number;
181
194
  }
182
195
 
183
196
  /** Everything a receipt refuses to answer, typed rather than left implicit. */
@@ -222,6 +235,15 @@ export type ReceiptGap =
222
235
  * cheaper rate; the true figure for them is between the two.
223
236
  */
224
237
  | { kind: 'tier-ceiling'; calls: number; models: string[]; ceilingUsd: number; floorUsd: number }
238
+ /**
239
+ * Web searches counted on models whose row publishes no per-search fee.
240
+ *
241
+ * Reported because the total is then a **floor**: the searches ran, the
242
+ * provider presumably charged for them, and no rate here says what. Left out
243
+ * and named, the same as a model the catalogue does not know, rather than
244
+ * billed at another provider's fee.
245
+ */
246
+ | { kind: 'unpriced-web-search'; requests: number; models: string[] }
225
247
  /**
226
248
  * Calls a time window had to leave out because they carry no timestamp.
227
249
  *
@@ -256,7 +278,13 @@ export interface ReceiptDocument {
256
278
  */
257
279
  counting: 'counted';
258
280
  lines: ReceiptLine[];
259
- total: { calls: number; usd: number };
281
+ /**
282
+ * The whole receipt. `batchUsd` (calls priced at the Batch API rate, their
283
+ * tokens) and `webSearchUsd` (searches, per search) are parts of `usd`, said
284
+ * apart since 2.7.5 so `reconcile` can set each against the provider's own
285
+ * batch and non-token charges instead of taking those out whole.
286
+ */
287
+ total: { calls: number; usd: number; batchUsd: number; webSearchUsd: number };
260
288
  /**
261
289
  * What this receipt cannot say, and why.
262
290
  *
@@ -301,6 +329,7 @@ const RECEIPT_LINE_FIELD_MAP = {
301
329
  pricing: true,
302
330
  maxCallInputTokens: true,
303
331
  assumedWriteTtlCalls: true,
332
+ webSearchRequests: true,
304
333
  } satisfies Record<keyof ReceiptLine, true>;
305
334
 
306
335
  /**
@@ -348,6 +377,7 @@ const lineFrom = (
348
377
  cacheReadUsd: breakdown.cacheReadUsd,
349
378
  cacheWriteUsd: breakdown.cacheWriteUsd,
350
379
  outputUsd: breakdown.outputUsd,
380
+ webSearchUsd: breakdown.webSearchUsd,
351
381
  },
352
382
  pricing: {
353
383
  provider: priced.provider ?? 'unknown',
@@ -360,6 +390,9 @@ const lineFrom = (
360
390
  their TTL is not visible in a token total. */
361
391
  maxCallInputTokens: breakdown.maxCallInputTokens,
362
392
  assumedWriteTtlCalls: breakdown.assumedWriteTtlCalls,
393
+ /* A count of uses, the divisor of `money.webSearchUsd`. It says how many
394
+ searches ran and nothing about what was searched for. */
395
+ webSearchRequests: breakdown.webSearchRequests,
363
396
  };
364
397
  };
365
398
 
@@ -424,6 +457,15 @@ export function receiptFrom(
424
457
  });
425
458
  }
426
459
 
460
+ const unpricedSearches = report.byModel.filter((row) => row.breakdown.webSearchUnpricedRequests > 0);
461
+ if (unpricedSearches.length > 0) {
462
+ gaps.push({
463
+ kind: 'unpriced-web-search',
464
+ requests: report.total.webSearchUnpricedRequests,
465
+ models: unpricedSearches.map((row) => row.model),
466
+ });
467
+ }
468
+
427
469
  return {
428
470
  schemaVersion: 1,
429
471
  emittedAt: options.emittedAt?.toISOString() ?? null,
@@ -437,7 +479,12 @@ export function receiptFrom(
437
479
  * separation rather than re-deriving it, and `gaps` carries the size of
438
480
  * what is missing.
439
481
  */
440
- total: { calls: report.total.calls, usd: report.total.totalUsd },
482
+ total: {
483
+ calls: report.total.calls,
484
+ usd: report.total.totalUsd,
485
+ batchUsd: report.total.batchUsd,
486
+ webSearchUsd: report.total.webSearchUsd,
487
+ },
441
488
  gaps,
442
489
  };
443
490
  }
package/src/repeats.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { effectivePricing, multipliersFor } from './pricing.js';
2
- import { billedAt, promptSizeOf } from './billing.js';
2
+ import { billedAt, promptSizeOf, webSearchUsdOf } from './billing.js';
3
3
  import { UNLABELLED } from './usage.js';
4
4
  import type { PricingCatalogue } from './pricing.js';
5
5
  import type { UsageRecord } from './usage.js';
@@ -130,7 +130,8 @@ export function createRepeatsTracker(options: RepeatsOptions): RepeatsTracker {
130
130
  per(record.cacheReadTokens, inputPerMTok * rates.cacheRead) +
131
131
  per(record.cacheWrite5mTokens, inputPerMTok * rates.cacheWrite5m) +
132
132
  per(record.cacheWrite1hTokens, inputPerMTok * rates.cacheWrite1h) +
133
- per(record.outputTokens, outputPerMTok);
133
+ per(record.outputTokens, outputPerMTok) +
134
+ webSearchUsdOf(record, model);
134
135
  };
135
136
 
136
137
  const finish = (): RepeatedTurns[] => {
package/src/rollup.ts CHANGED
@@ -319,6 +319,10 @@ const BREAKDOWN_SUM = [
319
319
  'tierCeilingCalls',
320
320
  'tierCeilingUsd',
321
321
  'tierFloorUsd',
322
+ 'webSearchRequests',
323
+ 'webSearchUsd',
324
+ 'webSearchUnpricedRequests',
325
+ 'batchUsd',
322
326
  ] as const;
323
327
 
324
328
  /** Fields whose combination is a maximum, because a sum would invent a call. */
@@ -1,5 +1,5 @@
1
1
  import { effectivePricing, multipliersFor } from './pricing.js';
2
- import { billedAt, promptSizeOf } from './billing.js';
2
+ import { billedAt, promptSizeOf, webSearchUsdOf } from './billing.js';
3
3
  import { UNLABELLED } from './usage.js';
4
4
  import type { PricingCatalogue } from './pricing.js';
5
5
  import type { UsageRecord } from './usage.js';
@@ -86,7 +86,9 @@ export function costOf(record: UsageRecord, catalogue: PricingCatalogue, on: Dat
86
86
  per(record.cacheReadTokens, inputPerMTok * rates.cacheRead) +
87
87
  per(record.cacheWrite5mTokens, inputPerMTok * rates.cacheWrite5m) +
88
88
  per(record.cacheWrite1hTokens, inputPerMTok * rates.cacheWrite1h) +
89
- per(record.outputTokens, outputPerMTok)
89
+ per(record.outputTokens, outputPerMTok) +
90
+ // And its web searches, per search: billed dollars too.
91
+ webSearchUsdOf(record, model)
90
92
  );
91
93
  }
92
94
 
package/src/store.ts CHANGED
@@ -56,6 +56,11 @@ export interface StoreRecord {
56
56
  /** False when the source reported writes without saying which TTL. */
57
57
  ttlKnown: boolean;
58
58
  output: number;
59
+ /**
60
+ * Web searches, billed per search on top of the tokens. Absent is none, so
61
+ * a store written before the field existed reads the same as it did.
62
+ */
63
+ webSearch?: number;
59
64
  /**
60
65
  * The account's own opaque identifiers — workspace, key, tier — as the
61
66
  * provider served them.
@@ -179,6 +184,7 @@ export function recordsFromBuckets(
179
184
  write1h: bucket.cacheWrite1hTokens,
180
185
  ttlKnown: bucket.writeTtlKnown,
181
186
  output: bucket.outputTokens,
187
+ ...((bucket.webSearchRequests ?? 0) > 0 ? { webSearch: bucket.webSearchRequests } : {}),
182
188
  group: bucket.group,
183
189
  pulledAtMs,
184
190
  }));
@@ -197,6 +203,9 @@ export function bucketsFromRecords(records: readonly StoreRecord[]): UsageBucket
197
203
  cacheWrite1hTokens: record.write1h,
198
204
  writeTtlKnown: record.ttlKnown,
199
205
  outputTokens: record.output,
206
+ ...(typeof record.webSearch === 'number' && Number.isFinite(record.webSearch) && record.webSearch > 0
207
+ ? { webSearchRequests: record.webSearch }
208
+ : {}),
200
209
  group: record.group,
201
210
  }));
202
211
  }
@@ -1,5 +1,5 @@
1
1
  import { effectivePricing, multipliersFor } from './pricing.js';
2
- import { billedAt, promptSizeOf } from './billing.js';
2
+ import { billedAt, promptSizeOf, webSearchUsdOf } from './billing.js';
3
3
  import { UNLABELLED } from './usage.js';
4
4
  import type { PricingCatalogue } from './pricing.js';
5
5
  import type { UsageRecord } from './usage.js';
@@ -100,7 +100,8 @@ export function createTruncationRetryTracker(options: TruncationRetryOptions): T
100
100
  per(record.cacheReadTokens, inputPerMTok * rates.cacheRead) +
101
101
  per(record.cacheWrite5mTokens, inputPerMTok * rates.cacheWrite5m) +
102
102
  per(record.cacheWrite1hTokens, inputPerMTok * rates.cacheWrite1h) +
103
- per(record.outputTokens, outputPerMTok)
103
+ per(record.outputTokens, outputPerMTok) +
104
+ webSearchUsdOf(record, model)
104
105
  );
105
106
  };
106
107