@trazum/core 2.7.3 → 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.
- package/dist/anthropic-cost.d.ts +22 -5
- package/dist/anthropic-cost.d.ts.map +1 -1
- package/dist/anthropic-cost.js +33 -10
- package/dist/anthropic-cost.js.map +1 -1
- package/dist/anthropic-usage.d.ts +15 -2
- package/dist/anthropic-usage.d.ts.map +1 -1
- package/dist/anthropic-usage.js +41 -5
- package/dist/anthropic-usage.js.map +1 -1
- package/dist/batch-results.d.ts +77 -0
- package/dist/batch-results.d.ts.map +1 -0
- package/dist/batch-results.js +145 -0
- package/dist/batch-results.js.map +1 -0
- package/dist/billing.d.ts +10 -0
- package/dist/billing.d.ts.map +1 -1
- package/dist/billing.js +15 -0
- package/dist/billing.js.map +1 -1
- package/dist/claude-code.d.ts +4 -0
- package/dist/claude-code.d.ts.map +1 -1
- package/dist/claude-code.js +14 -1
- package/dist/claude-code.js.map +1 -1
- package/dist/connector.d.ts +19 -1
- package/dist/connector.d.ts.map +1 -1
- package/dist/connector.js +46 -6
- package/dist/connector.js.map +1 -1
- package/dist/csv.d.ts +1 -1
- package/dist/csv.d.ts.map +1 -1
- package/dist/csv.js +11 -0
- package/dist/csv.js.map +1 -1
- package/dist/gateway.d.ts +2 -0
- package/dist/gateway.d.ts.map +1 -1
- package/dist/gateway.js +16 -0
- package/dist/gateway.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/openai-usage.d.ts +5 -1
- package/dist/openai-usage.d.ts.map +1 -1
- package/dist/openai-usage.js +20 -4
- package/dist/openai-usage.js.map +1 -1
- package/dist/pricing-overlay.d.ts +1 -1
- package/dist/pricing-overlay.d.ts.map +1 -1
- package/dist/pricing-overlay.js +11 -0
- package/dist/pricing-overlay.js.map +1 -1
- package/dist/pricing.d.ts +8 -0
- package/dist/pricing.d.ts.map +1 -1
- package/dist/pricing.js +74 -17
- package/dist/pricing.js.map +1 -1
- package/dist/receipt.d.ts +38 -4
- package/dist/receipt.d.ts.map +1 -1
- package/dist/receipt.js +19 -1
- package/dist/receipt.js.map +1 -1
- package/dist/repeats.d.ts.map +1 -1
- package/dist/repeats.js +3 -2
- package/dist/repeats.js.map +1 -1
- package/dist/rollup.d.ts.map +1 -1
- package/dist/rollup.js +4 -0
- package/dist/rollup.js.map +1 -1
- package/dist/session-cost.d.ts.map +1 -1
- package/dist/session-cost.js +4 -2
- package/dist/session-cost.js.map +1 -1
- package/dist/store.d.ts +5 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +4 -0
- package/dist/store.js.map +1 -1
- package/dist/truncation-retry.d.ts.map +1 -1
- package/dist/truncation-retry.js +3 -2
- package/dist/truncation-retry.js.map +1 -1
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/usage.d.ts +42 -0
- package/dist/usage.d.ts.map +1 -1
- package/dist/usage.js +42 -3
- package/dist/usage.js.map +1 -1
- package/package.json +1 -1
- package/src/anthropic-cost.ts +46 -12
- package/src/anthropic-usage.ts +54 -7
- package/src/batch-results.ts +174 -0
- package/src/billing.ts +16 -0
- package/src/claude-code.ts +16 -1
- package/src/connector.ts +68 -8
- package/src/csv.ts +11 -0
- package/src/gateway.ts +16 -0
- package/src/index.ts +2 -0
- package/src/openai-usage.ts +24 -5
- package/src/pricing-overlay.ts +15 -0
- package/src/pricing.ts +83 -17
- package/src/receipt.ts +53 -6
- package/src/repeats.ts +3 -2
- package/src/rollup.ts +4 -0
- package/src/session-cost.ts +4 -2
- package/src/store.ts +9 -0
- package/src/truncation-retry.ts +3 -2
- package/src/types.ts +13 -0
- package/src/usage.ts +84 -3
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,
|
|
@@ -2467,6 +2506,8 @@ interface Rates {
|
|
|
2467
2506
|
serviceTier?: ServiceTier;
|
|
2468
2507
|
/** The geography whose published multiplier priced the call, when it was not global. */
|
|
2469
2508
|
inferenceGeo?: InferenceGeo;
|
|
2509
|
+
/** True when the call was billed at the row's batch ratio. */
|
|
2510
|
+
batch?: true;
|
|
2470
2511
|
}
|
|
2471
2512
|
|
|
2472
2513
|
/**
|
|
@@ -2501,6 +2542,12 @@ export interface PromptSize {
|
|
|
2501
2542
|
* only a geography the row publishes a multiplier for changes the price.
|
|
2502
2543
|
*/
|
|
2503
2544
|
inferenceGeo?: string;
|
|
2545
|
+
/**
|
|
2546
|
+
* The call ran on the provider's Batch API: Anthropic's `usage.service_tier`
|
|
2547
|
+
* `"batch"`, a batch result file's line, or a usage report's batch row.
|
|
2548
|
+
* Billed at the row's batch ratio.
|
|
2549
|
+
*/
|
|
2550
|
+
batch?: boolean;
|
|
2504
2551
|
}
|
|
2505
2552
|
|
|
2506
2553
|
/**
|
|
@@ -2517,6 +2564,26 @@ export function inferenceGeoOf(value: unknown): InferenceGeo | undefined {
|
|
|
2517
2564
|
/** Rounded to a billionth of a dollar per million tokens, so 1.1x of $5 is $5.5 and not $5.500000000000001. */
|
|
2518
2565
|
const scaled = (rate: number, factor: number): number => Math.round(rate * factor * 1e9) / 1e9;
|
|
2519
2566
|
|
|
2567
|
+
/** Every rate a call is billed at, multiplied by one published factor: the floor of an undecided band too. */
|
|
2568
|
+
function scaleRates(rates: Rates, factor: number): Rates {
|
|
2569
|
+
return {
|
|
2570
|
+
...rates,
|
|
2571
|
+
inputPerMTok: scaled(rates.inputPerMTok, factor),
|
|
2572
|
+
outputPerMTok: scaled(rates.outputPerMTok, factor),
|
|
2573
|
+
...(rates.tier?.floor !== undefined
|
|
2574
|
+
? {
|
|
2575
|
+
tier: {
|
|
2576
|
+
...rates.tier,
|
|
2577
|
+
floor: {
|
|
2578
|
+
inputPerMTok: scaled(rates.tier.floor.inputPerMTok, factor),
|
|
2579
|
+
outputPerMTok: scaled(rates.tier.floor.outputPerMTok, factor),
|
|
2580
|
+
},
|
|
2581
|
+
},
|
|
2582
|
+
}
|
|
2583
|
+
: {}),
|
|
2584
|
+
};
|
|
2585
|
+
}
|
|
2586
|
+
|
|
2520
2587
|
/**
|
|
2521
2588
|
* A response's `service_tier` as the tier whose table prices it, or
|
|
2522
2589
|
* `undefined` for the standard one.
|
|
@@ -2688,23 +2755,22 @@ export function effectivePricing(
|
|
|
2688
2755
|
const geo = inferenceGeoOf(inferenceGeo);
|
|
2689
2756
|
const factor = geo === undefined ? undefined : model.inferenceGeoMultipliers?.[geo];
|
|
2690
2757
|
if (geo === undefined || factor === undefined) return rates;
|
|
2691
|
-
return {
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
};
|
|
2758
|
+
return { ...scaleRates(rates, factor), inferenceGeo: geo };
|
|
2759
|
+
}
|
|
2760
|
+
/*
|
|
2761
|
+
* A call the provider ran on its Batch API is billed at the row's batch
|
|
2762
|
+
* ratio, on input and output alike, and the cache multipliers apply on top
|
|
2763
|
+
* of the batch input rate, as both providers' pages say. The ratio is the
|
|
2764
|
+
* one the batch advisory quotes and `price-drift.mjs` checks against each
|
|
2765
|
+
* batch table every week. A row with no batch API (`batch: null`) cannot
|
|
2766
|
+
* have run one, so such a call keeps the standard price: a ceiling.
|
|
2767
|
+
*/
|
|
2768
|
+
if (context.batch === true) {
|
|
2769
|
+
const { batch: _batch, ...rest } = context;
|
|
2770
|
+
const rates = effectivePricing(model, on, rest);
|
|
2771
|
+
const ratio = multipliersFor(model, on).batch;
|
|
2772
|
+
if (ratio === null) return rates;
|
|
2773
|
+
return { ...scaleRates(rates, ratio), batch: true };
|
|
2708
2774
|
}
|
|
2709
2775
|
/* A call before a published price change is priced as it was billed then. */
|
|
2710
2776
|
if (model.history !== undefined) {
|
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
|
|
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
|
|
147
|
-
*
|
|
148
|
-
*
|
|
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
|
-
|
|
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: {
|
|
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. */
|
package/src/session-cost.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';
|
|
@@ -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
|
}
|
package/src/truncation-retry.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';
|
|
@@ -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
|
|
package/src/types.ts
CHANGED
|
@@ -414,6 +414,19 @@ export interface ModelPricing {
|
|
|
414
414
|
* here: a row without the field prices every geography at its own rate.
|
|
415
415
|
*/
|
|
416
416
|
inferenceGeoMultipliers?: Partial<Record<InferenceGeo, number>>;
|
|
417
|
+
/**
|
|
418
|
+
* What one thousand web searches cost, in US dollars, billed per search on
|
|
419
|
+
* top of the tokens.
|
|
420
|
+
*
|
|
421
|
+
* Anthropic charges $10 per 1,000 searches on every model and counts them in
|
|
422
|
+
* `usage.server_tool_use.web_search_requests`. The fee is flat: the Batch
|
|
423
|
+
* API prices searches "the same as those in regular Messages API requests",
|
|
424
|
+
* and US-only inference and fast mode multiply token rates, which a search
|
|
425
|
+
* is not. Absent on a row whose provider publishes no such fee, and then a
|
|
426
|
+
* search the log counts is named as unpriced rather than billed at a rate
|
|
427
|
+
* borrowed from somewhere else.
|
|
428
|
+
*/
|
|
429
|
+
webSearchPerThousandUsd?: number;
|
|
417
430
|
/**
|
|
418
431
|
* Other ids that bill at exactly this rate.
|
|
419
432
|
*
|