@trazum/core 2.7.1 → 2.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/billing.d.ts.map +1 -1
- package/dist/billing.js +5 -2
- package/dist/billing.js.map +1 -1
- package/dist/gateway.d.ts +8 -0
- package/dist/gateway.d.ts.map +1 -1
- package/dist/gateway.js +14 -1
- package/dist/gateway.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/pricing.d.ts +22 -1
- package/dist/pricing.d.ts.map +1 -1
- package/dist/pricing.js +460 -9
- package/dist/pricing.js.map +1 -1
- package/dist/types.d.ts +37 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/usage.d.ts +8 -0
- package/dist/usage.d.ts.map +1 -1
- package/dist/usage.js +9 -0
- package/dist/usage.js.map +1 -1
- package/package.json +1 -1
- package/src/billing.ts +5 -2
- package/src/gateway.ts +21 -2
- package/src/index.ts +1 -0
- package/src/pricing.ts +475 -10
- package/src/types.ts +39 -0
- package/src/usage.ts +17 -0
package/src/pricing.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ModelPricing, PricingTier, TierCondition } from './types.js';
|
|
1
|
+
import type { ModelPricing, PricingTier, ServiceTier, TierCondition } from './types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Model and pricing catalogue (USD per million tokens).
|
|
@@ -41,10 +41,12 @@ export const PROVIDER_REVIEWED: Readonly<Record<string, string>> = Object.freeze
|
|
|
41
41
|
* which bills Opus 5.5 at $8/$40 and Opus 5 and 4.8 at $10/$50 and which
|
|
42
42
|
* every response records in `usage.speed`, so fast calls had been priced at
|
|
43
43
|
* half their cost; and Claude Sonnet 4.5, deprecated but still served until
|
|
44
|
-
* 2026-11-30, which read as unpriced. Both are here now.
|
|
45
|
-
* 4.1, Opus 4, Sonnet 4 and Haiku 3.5
|
|
46
|
-
*
|
|
47
|
-
*
|
|
44
|
+
* 2026-11-30, which read as unpriced. Both are here now. So are the
|
|
45
|
+
* retired Opus 4.1, Opus 4, Sonnet 4 and Haiku 3.5, still on the pricing
|
|
46
|
+
* page and in every log from before their retirement: their own model pages
|
|
47
|
+
* are gone, and the context-windows page gives each the 200k window every
|
|
48
|
+
* Claude model outside its 1M list has. Claude Sonnet 3.7 and Haiku 3 are
|
|
49
|
+
* retired and absent from the pricing page, so they stay unpriced.
|
|
48
50
|
*/
|
|
49
51
|
anthropic: '2026-11-05',
|
|
50
52
|
/*
|
|
@@ -269,6 +271,18 @@ const NO_PUBLISHED_CACHE_MINIMUM =
|
|
|
269
271
|
*/
|
|
270
272
|
const OPENAI_CACHE_TTL = Object.freeze({ writeMs: 30 * 60_000, longerMs: 12 * 60 * 60_000 });
|
|
271
273
|
|
|
274
|
+
/**
|
|
275
|
+
* OpenAI's service-tier tables, read from developers.openai.com/api/docs/pricing.md
|
|
276
|
+
* on 2026-11-05: the Flex, Fast and Ultrafast tables beside the Standard one,
|
|
277
|
+
* each model's row as printed, and its "Long context" columns where the table
|
|
278
|
+
* publishes them ("Short context: <=272K input tokens. Long context: >272K").
|
|
279
|
+
* A row whose long columns read "-" gets no long band here: GPT-5.5 and 5.4 in
|
|
280
|
+
* Fast, GPT-5.5 pro in Flex. See `ModelPricing.serviceTiers`.
|
|
281
|
+
*/
|
|
282
|
+
const openAiLongBand = (inputPerMTok: number, outputPerMTok: number): PricingTier[] => [
|
|
283
|
+
{ id: 'over-272k', when: { kind: 'input-tokens-above', tokens: 272_000 }, inputPerMTok, outputPerMTok },
|
|
284
|
+
];
|
|
285
|
+
|
|
272
286
|
const OPENAI_CURRENT_NOTE =
|
|
273
287
|
'Priced per request by prompt length: over 272,000 input tokens, 2x input and cache and 1.5x output for'
|
|
274
288
|
+ ' the whole request. Cache writes cost 1.25x input for the default 30-minute entry and 2.5x for a'
|
|
@@ -282,6 +296,10 @@ const OPENAI_EARLIER_LONG_NOTE =
|
|
|
282
296
|
+ OPENAI_EARLIER_NOTE;
|
|
283
297
|
const OPENAI_EARLIER_NO_CACHE_NOTE = 'OpenAI publishes no cached-input price for this model, so caching is not priced.';
|
|
284
298
|
const OPENAI_DEPRECATED_SUFFIX = ' Deprecated by OpenAI: priced for the logs that hold it, never recommended.';
|
|
299
|
+
const OPENAI_SHUT_DOWN_SUFFIX = ' Shut down by OpenAI: priced for the logs that hold it, never recommended.';
|
|
300
|
+
const OPENAI_CODEX_NOTE =
|
|
301
|
+
'Caching is automatic; a write costs what input costs. Responses API only, and no batch. OpenAI says the minimum for'
|
|
302
|
+
+ ' models before GPT-5.6 varies by request settings, so 1,024 here is the nearest published floor.';
|
|
285
303
|
|
|
286
304
|
const OPENAI_GPT5_NOTE =
|
|
287
305
|
'Caching is automatic, with no cache_control to set. OpenAI says the minimum for models before GPT-5.6 varies by'
|
|
@@ -464,6 +482,53 @@ export const MODELS: ModelPricing[] = [
|
|
|
464
482
|
tier: 'opus',
|
|
465
483
|
notes: '200K context window and a 64K output cap.',
|
|
466
484
|
},
|
|
485
|
+
{
|
|
486
|
+
/*
|
|
487
|
+
* Retired on the Claude API on 2026-08-05 (the deprecations page, read
|
|
488
|
+
* 2026-11-05) and still served on Claude Models on Google Cloud (Google
|
|
489
|
+
* managed) and on Bedrock. Priced because a year of logs carries it and,
|
|
490
|
+
* unpriced, every one of those calls read as a gap. The pricing page, read
|
|
491
|
+
* the same day: $15/$75, writes $18.75 and $30, cache hits $1.50, batch
|
|
492
|
+
* $7.50/$37.50, which are the default multipliers. Its model page is gone;
|
|
493
|
+
* the context-windows page gives every Claude model outside its 1M list a
|
|
494
|
+
* 200k window, and the prompt-caching page a 1,024-token cache minimum.
|
|
495
|
+
* The dated id is the one the deprecations page names and what a log
|
|
496
|
+
* carries; no shorter alias is on any page read, so none is declared.
|
|
497
|
+
*/
|
|
498
|
+
id: 'claude-opus-4-1-20250805',
|
|
499
|
+
provider: 'anthropic',
|
|
500
|
+
displayName: 'Claude Opus 4.1',
|
|
501
|
+
recommendable: false,
|
|
502
|
+
inputPerMTok: 15,
|
|
503
|
+
outputPerMTok: 75,
|
|
504
|
+
contextWindow: 200_000,
|
|
505
|
+
cacheMinTokens: 1024,
|
|
506
|
+
capability: 'large',
|
|
507
|
+
tier: 'opus',
|
|
508
|
+
notes:
|
|
509
|
+
'Retired on the Claude API on 2026-08-05; still served on Google Cloud (Google managed) and Bedrock.'
|
|
510
|
+
+ ' Anthropic names Claude Opus 4.8 as the replacement.',
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
/*
|
|
514
|
+
* Retired on the Claude API on 2026-06-15; still served on Claude Models
|
|
515
|
+
* on Google Cloud (Google managed). The same pages and the same figures as
|
|
516
|
+
* Opus 4.1 above: $15/$75, 200k context, a 1,024-token cache minimum.
|
|
517
|
+
*/
|
|
518
|
+
id: 'claude-opus-4-20250514',
|
|
519
|
+
provider: 'anthropic',
|
|
520
|
+
displayName: 'Claude Opus 4',
|
|
521
|
+
recommendable: false,
|
|
522
|
+
inputPerMTok: 15,
|
|
523
|
+
outputPerMTok: 75,
|
|
524
|
+
contextWindow: 200_000,
|
|
525
|
+
cacheMinTokens: 1024,
|
|
526
|
+
capability: 'large',
|
|
527
|
+
tier: 'opus',
|
|
528
|
+
notes:
|
|
529
|
+
'Retired on the Claude API on 2026-06-15; still served on Google Cloud (Google managed).'
|
|
530
|
+
+ ' Anthropic names Claude Opus 4.8 as the replacement.',
|
|
531
|
+
},
|
|
467
532
|
{
|
|
468
533
|
/*
|
|
469
534
|
* The pricing page and the Sonnet 5.5 model page, read 2026-10-10. The
|
|
@@ -530,6 +595,30 @@ export const MODELS: ModelPricing[] = [
|
|
|
530
595
|
tier: 'sonnet',
|
|
531
596
|
notes: 'Deprecated; retires 2026-11-30. Recommended replacement: Claude Sonnet 5.5.',
|
|
532
597
|
},
|
|
598
|
+
{
|
|
599
|
+
/*
|
|
600
|
+
* Retired on the Claude API on 2026-06-15 (the deprecations page, read
|
|
601
|
+
* 2026-11-05); still served on Claude Models on Google Cloud (Google
|
|
602
|
+
* managed) and on Bedrock. The pricing page, read the same day: $3/$15,
|
|
603
|
+
* writes $3.75 and $6, cache hits $0.30, batch $1.50/$7.50. 200k context
|
|
604
|
+
* from the context-windows page, a 1,024-token cache minimum from the
|
|
605
|
+
* prompt-caching page. The pricing page publishes one rate for it and no
|
|
606
|
+
* long-context band, so every call is priced at that rate.
|
|
607
|
+
*/
|
|
608
|
+
id: 'claude-sonnet-4-20250514',
|
|
609
|
+
provider: 'anthropic',
|
|
610
|
+
displayName: 'Claude Sonnet 4',
|
|
611
|
+
recommendable: false,
|
|
612
|
+
inputPerMTok: 3,
|
|
613
|
+
outputPerMTok: 15,
|
|
614
|
+
contextWindow: 200_000,
|
|
615
|
+
cacheMinTokens: 1024,
|
|
616
|
+
capability: 'mid',
|
|
617
|
+
tier: 'sonnet',
|
|
618
|
+
notes:
|
|
619
|
+
'Retired on the Claude API on 2026-06-15; still served on Google Cloud (Google managed) and Bedrock.'
|
|
620
|
+
+ ' Anthropic names Claude Sonnet 5.5 as the replacement.',
|
|
621
|
+
},
|
|
533
622
|
{
|
|
534
623
|
/*
|
|
535
624
|
* The pricing page, the models overview and the prompt-caching page, read
|
|
@@ -585,6 +674,29 @@ export const MODELS: ModelPricing[] = [
|
|
|
585
674
|
tier: 'haiku',
|
|
586
675
|
notes: '200K context window and a 64K output cap, smaller than the rest.',
|
|
587
676
|
},
|
|
677
|
+
{
|
|
678
|
+
/*
|
|
679
|
+
* Retired on the Claude API on 2026-02-19 (the deprecations page, read
|
|
680
|
+
* 2026-11-05); still served on Claude Models on Google Cloud (Google
|
|
681
|
+
* managed). The pricing page, read the same day: $0.80/$4, writes $1 and
|
|
682
|
+
* $1.60, cache hits $0.08, batch $0.40/$2, the default multipliers. 200k
|
|
683
|
+
* context from the context-windows page, and the prompt-caching page's
|
|
684
|
+
* 2,048-token cache minimum.
|
|
685
|
+
*/
|
|
686
|
+
id: 'claude-3-5-haiku-20241022',
|
|
687
|
+
provider: 'anthropic',
|
|
688
|
+
displayName: 'Claude Haiku 3.5',
|
|
689
|
+
recommendable: false,
|
|
690
|
+
inputPerMTok: 0.8,
|
|
691
|
+
outputPerMTok: 4,
|
|
692
|
+
contextWindow: 200_000,
|
|
693
|
+
cacheMinTokens: 2048,
|
|
694
|
+
capability: 'small',
|
|
695
|
+
tier: 'haiku',
|
|
696
|
+
notes:
|
|
697
|
+
'Retired on the Claude API on 2026-02-19; still served on Google Cloud (Google managed).'
|
|
698
|
+
+ ' Anthropic names Claude Haiku 4.5 as the replacement.',
|
|
699
|
+
},
|
|
588
700
|
|
|
589
701
|
// ------------------------------------------------------------------------
|
|
590
702
|
// OpenAI
|
|
@@ -645,6 +757,11 @@ export const MODELS: ModelPricing[] = [
|
|
|
645
757
|
outputPerMTok: 75,
|
|
646
758
|
},
|
|
647
759
|
],
|
|
760
|
+
serviceTiers: {
|
|
761
|
+
flex: { inputPerMTok: 5, outputPerMTok: 25, tiers: openAiLongBand(10, 37.5) },
|
|
762
|
+
fast: { inputPerMTok: 20, outputPerMTok: 100, tiers: openAiLongBand(40, 150) },
|
|
763
|
+
ultrafast: { inputPerMTok: 60, outputPerMTok: 300, tiers: openAiLongBand(120, 450) },
|
|
764
|
+
},
|
|
648
765
|
capability: 'frontier',
|
|
649
766
|
tier: 'frontier',
|
|
650
767
|
notes: OPENAI_CURRENT_NOTE,
|
|
@@ -668,6 +785,11 @@ export const MODELS: ModelPricing[] = [
|
|
|
668
785
|
outputPerMTok: 15,
|
|
669
786
|
},
|
|
670
787
|
],
|
|
788
|
+
serviceTiers: {
|
|
789
|
+
flex: { inputPerMTok: 1, outputPerMTok: 5, tiers: openAiLongBand(2, 7.5) },
|
|
790
|
+
fast: { inputPerMTok: 4, outputPerMTok: 20, tiers: openAiLongBand(8, 30) },
|
|
791
|
+
ultrafast: { inputPerMTok: 12, outputPerMTok: 60, tiers: openAiLongBand(24, 90) },
|
|
792
|
+
},
|
|
671
793
|
capability: 'large',
|
|
672
794
|
tier: 'opus',
|
|
673
795
|
notes: OPENAI_CURRENT_NOTE,
|
|
@@ -697,6 +819,10 @@ export const MODELS: ModelPricing[] = [
|
|
|
697
819
|
outputPerMTok: 7.5,
|
|
698
820
|
},
|
|
699
821
|
],
|
|
822
|
+
serviceTiers: {
|
|
823
|
+
flex: { inputPerMTok: 0.5, outputPerMTok: 2.5, tiers: openAiLongBand(1, 3.75) },
|
|
824
|
+
fast: { inputPerMTok: 2, outputPerMTok: 10, tiers: openAiLongBand(4, 15) },
|
|
825
|
+
},
|
|
700
826
|
capability: 'mid',
|
|
701
827
|
tier: 'sonnet',
|
|
702
828
|
notes: OPENAI_CURRENT_NOTE,
|
|
@@ -720,6 +846,10 @@ export const MODELS: ModelPricing[] = [
|
|
|
720
846
|
outputPerMTok: 15,
|
|
721
847
|
},
|
|
722
848
|
],
|
|
849
|
+
serviceTiers: {
|
|
850
|
+
flex: { inputPerMTok: 1, outputPerMTok: 5, tiers: openAiLongBand(2, 7.5) },
|
|
851
|
+
fast: { inputPerMTok: 4, outputPerMTok: 20, tiers: openAiLongBand(8, 30) },
|
|
852
|
+
},
|
|
723
853
|
capability: 'large',
|
|
724
854
|
tier: 'opus',
|
|
725
855
|
notes: OPENAI_CURRENT_NOTE,
|
|
@@ -743,12 +873,30 @@ export const MODELS: ModelPricing[] = [
|
|
|
743
873
|
outputPerMTok: 0.75,
|
|
744
874
|
},
|
|
745
875
|
],
|
|
876
|
+
serviceTiers: {
|
|
877
|
+
flex: { inputPerMTok: 0.05, outputPerMTok: 0.25, tiers: openAiLongBand(0.1, 0.375) },
|
|
878
|
+
fast: { inputPerMTok: 0.2, outputPerMTok: 1, tiers: openAiLongBand(0.4, 1.5) },
|
|
879
|
+
},
|
|
746
880
|
capability: 'small',
|
|
747
881
|
tier: 'haiku',
|
|
748
882
|
notes: OPENAI_CURRENT_NOTE,
|
|
749
883
|
},
|
|
750
884
|
{
|
|
885
|
+
/*
|
|
886
|
+
* Its model page, read 2026-11-05: "The `gpt-5.6` alias routes requests
|
|
887
|
+
* to GPT-5.6 Sol", so a log that names the alias is this model; and
|
|
888
|
+
* "$4 per million input tokens and $20 per million output tokens, a 20%
|
|
889
|
+
* reduction in input pricing and a 33% reduction in output pricing ...
|
|
890
|
+
* promotional pricing is available until November 30, 2026". The price
|
|
891
|
+
* after the promotion is not published as a figure, and deriving one
|
|
892
|
+
* from two rounded percentages would be a price nobody quoted, so the row
|
|
893
|
+
* carries what the page charges today. When the page changes,
|
|
894
|
+
* `scripts/price-drift.mjs` reports it on the next weekly run; until a
|
|
895
|
+
* person reads the new figure, a call after 2026-11-30 may be priced low,
|
|
896
|
+
* and the note says so to anyone reading the row.
|
|
897
|
+
*/
|
|
751
898
|
id: 'gpt-5.6-sol',
|
|
899
|
+
aliases: ['gpt-5.6'],
|
|
752
900
|
provider: 'openai',
|
|
753
901
|
displayName: 'GPT-5.6 Sol',
|
|
754
902
|
inputPerMTok: 4,
|
|
@@ -766,9 +914,15 @@ export const MODELS: ModelPricing[] = [
|
|
|
766
914
|
outputPerMTok: 30,
|
|
767
915
|
},
|
|
768
916
|
],
|
|
917
|
+
serviceTiers: {
|
|
918
|
+
flex: { inputPerMTok: 2, outputPerMTok: 10, tiers: openAiLongBand(4, 15) },
|
|
919
|
+
fast: { inputPerMTok: 8, outputPerMTok: 40, tiers: openAiLongBand(16, 60) },
|
|
920
|
+
},
|
|
769
921
|
capability: 'large',
|
|
770
922
|
tier: 'opus',
|
|
771
|
-
notes:
|
|
923
|
+
notes:
|
|
924
|
+
OPENAI_CURRENT_NOTE
|
|
925
|
+
+ ' $4/$20 is promotional until 2026-11-30, and OpenAI has not published the price after it as a figure.',
|
|
772
926
|
},
|
|
773
927
|
{
|
|
774
928
|
id: 'gpt-5.6-terra',
|
|
@@ -789,6 +943,10 @@ export const MODELS: ModelPricing[] = [
|
|
|
789
943
|
outputPerMTok: 18,
|
|
790
944
|
},
|
|
791
945
|
],
|
|
946
|
+
serviceTiers: {
|
|
947
|
+
flex: { inputPerMTok: 1, outputPerMTok: 6, tiers: openAiLongBand(2, 9) },
|
|
948
|
+
fast: { inputPerMTok: 4, outputPerMTok: 24, tiers: openAiLongBand(8, 36) },
|
|
949
|
+
},
|
|
792
950
|
capability: 'mid',
|
|
793
951
|
tier: 'sonnet',
|
|
794
952
|
notes: OPENAI_CURRENT_NOTE,
|
|
@@ -812,56 +970,111 @@ export const MODELS: ModelPricing[] = [
|
|
|
812
970
|
outputPerMTok: 1.8,
|
|
813
971
|
},
|
|
814
972
|
],
|
|
973
|
+
serviceTiers: {
|
|
974
|
+
flex: { inputPerMTok: 0.1, outputPerMTok: 0.6, tiers: openAiLongBand(0.2, 0.9) },
|
|
975
|
+
fast: { inputPerMTok: 0.4, outputPerMTok: 2.4, tiers: openAiLongBand(0.8, 3.6) },
|
|
976
|
+
},
|
|
815
977
|
capability: 'small',
|
|
816
978
|
tier: 'haiku',
|
|
817
979
|
notes: OPENAI_CURRENT_NOTE,
|
|
818
980
|
},
|
|
981
|
+
{
|
|
982
|
+
/*
|
|
983
|
+
* The pricing page's "Cyber models" table and the model's own page
|
|
984
|
+
* (developers.openai.com/api/docs/models/gpt-5.6-cyber.md), read
|
|
985
|
+
* 2026-11-05: $12.50/$75, cached input $1.25, the 30-minute write $15.625
|
|
986
|
+
* and the 12-hour one $31.25, the same 0.1x, 1.25x and 2.5x as the rest of
|
|
987
|
+
* GPT-5.6. A 400,000-token context window with at most 272,000 input
|
|
988
|
+
* tokens, so the long-prompt band the model page mentions can never be
|
|
989
|
+
* reached and none is modelled; the pricing page lists none either. The
|
|
990
|
+
* Batch endpoint is "Not supported", so there is no batch price.
|
|
991
|
+
*
|
|
992
|
+
* Found by `scripts/price-drift.mjs` on its first run, as a model on the
|
|
993
|
+
* pricing page that read as unpriced. It needs Daybreak programme
|
|
994
|
+
* approval, so it is priced for the logs of people who have it and never
|
|
995
|
+
* recommended to anyone else.
|
|
996
|
+
*/
|
|
997
|
+
id: 'gpt-5.6-cyber',
|
|
998
|
+
provider: 'openai',
|
|
999
|
+
displayName: 'GPT-5.6 Cyber',
|
|
1000
|
+
recommendable: false,
|
|
1001
|
+
inputPerMTok: 12.5,
|
|
1002
|
+
outputPerMTok: 75,
|
|
1003
|
+
contextWindow: 400_000,
|
|
1004
|
+
cacheMinTokens: 1024,
|
|
1005
|
+
caching: 'automatic',
|
|
1006
|
+
multipliers: { cacheRead: 0.1, cacheWrite5m: 1.25, cacheWrite1h: 2.5, batch: null },
|
|
1007
|
+
cacheTtl: OPENAI_CACHE_TTL,
|
|
1008
|
+
capability: 'large',
|
|
1009
|
+
tier: 'opus',
|
|
1010
|
+
notes:
|
|
1011
|
+
'Needs approval through the Daybreak programme. At most 272,000 input tokens, Responses API only, no batch.'
|
|
1012
|
+
+ ' Cache writes cost 1.25x input for the default 30-minute entry and 2.5x for a 12-hour one.',
|
|
1013
|
+
},
|
|
819
1014
|
|
|
820
1015
|
// ------------------------------------------------------------------------
|
|
1016
|
+
// GPT-5, mini and nano. Each model page, read 2026-11-05, opens with
|
|
1017
|
+
// "Status: Deprecated", and the catalogue still offered all three as
|
|
1018
|
+
// cheaper alternatives, nano as the cheapest OpenAI model there is. Priced
|
|
1019
|
+
// for the logs that hold them; never recommended.
|
|
821
1020
|
{
|
|
822
1021
|
id: 'gpt-5',
|
|
823
1022
|
aliases: ['gpt-5-2025-08-07'],
|
|
824
1023
|
provider: 'openai',
|
|
825
1024
|
displayName: 'GPT-5',
|
|
1025
|
+
recommendable: false,
|
|
826
1026
|
inputPerMTok: 1.25,
|
|
827
1027
|
outputPerMTok: 10,
|
|
828
1028
|
contextWindow: 400_000,
|
|
829
1029
|
cacheMinTokens: 1024,
|
|
830
1030
|
caching: 'automatic',
|
|
831
1031
|
multipliers: { cacheRead: 0.1, cacheWrite5m: 1, cacheWrite1h: 1, batch: 0.5 },
|
|
1032
|
+
serviceTiers: {
|
|
1033
|
+
flex: { inputPerMTok: 0.625, outputPerMTok: 5 },
|
|
1034
|
+
fast: { inputPerMTok: 2.5, outputPerMTok: 20 },
|
|
1035
|
+
},
|
|
832
1036
|
capability: 'frontier',
|
|
833
1037
|
tier: 'frontier',
|
|
834
|
-
notes: OPENAI_GPT5_NOTE,
|
|
1038
|
+
notes: OPENAI_GPT5_NOTE + OPENAI_DEPRECATED_SUFFIX,
|
|
835
1039
|
},
|
|
836
1040
|
{
|
|
837
1041
|
id: 'gpt-5-mini',
|
|
838
1042
|
aliases: ['gpt-5-mini-2025-08-07'],
|
|
839
1043
|
provider: 'openai',
|
|
840
1044
|
displayName: 'GPT-5 mini',
|
|
1045
|
+
recommendable: false,
|
|
841
1046
|
inputPerMTok: 0.25,
|
|
842
1047
|
outputPerMTok: 2,
|
|
843
1048
|
contextWindow: 400_000,
|
|
844
1049
|
cacheMinTokens: 1024,
|
|
845
1050
|
caching: 'automatic',
|
|
846
1051
|
multipliers: { cacheRead: 0.1, cacheWrite5m: 1, cacheWrite1h: 1, batch: 0.5 },
|
|
1052
|
+
serviceTiers: {
|
|
1053
|
+
flex: { inputPerMTok: 0.125, outputPerMTok: 1 },
|
|
1054
|
+
fast: { inputPerMTok: 0.45, outputPerMTok: 3.6 },
|
|
1055
|
+
},
|
|
847
1056
|
capability: 'mid',
|
|
848
1057
|
tier: 'sonnet',
|
|
849
|
-
notes: OPENAI_GPT5_NOTE,
|
|
1058
|
+
notes: OPENAI_GPT5_NOTE + OPENAI_DEPRECATED_SUFFIX,
|
|
850
1059
|
},
|
|
851
1060
|
{
|
|
852
1061
|
id: 'gpt-5-nano',
|
|
853
1062
|
aliases: ['gpt-5-nano-2025-08-07'],
|
|
854
1063
|
provider: 'openai',
|
|
855
1064
|
displayName: 'GPT-5 nano',
|
|
1065
|
+
recommendable: false,
|
|
856
1066
|
inputPerMTok: 0.05,
|
|
857
1067
|
outputPerMTok: 0.4,
|
|
858
1068
|
contextWindow: 400_000,
|
|
859
1069
|
cacheMinTokens: 1024,
|
|
860
1070
|
caching: 'automatic',
|
|
861
1071
|
multipliers: { cacheRead: 0.1, cacheWrite5m: 1, cacheWrite1h: 1, batch: 0.5 },
|
|
1072
|
+
serviceTiers: {
|
|
1073
|
+
flex: { inputPerMTok: 0.025, outputPerMTok: 0.2 },
|
|
1074
|
+
},
|
|
862
1075
|
capability: 'small',
|
|
863
1076
|
tier: 'haiku',
|
|
864
|
-
notes: OPENAI_GPT5_NOTE,
|
|
1077
|
+
notes: OPENAI_GPT5_NOTE + OPENAI_DEPRECATED_SUFFIX,
|
|
865
1078
|
},
|
|
866
1079
|
|
|
867
1080
|
// ------------------------------------------------------------------------
|
|
@@ -899,6 +1112,10 @@ export const MODELS: ModelPricing[] = [
|
|
|
899
1112
|
outputPerMTok: 45,
|
|
900
1113
|
},
|
|
901
1114
|
],
|
|
1115
|
+
serviceTiers: {
|
|
1116
|
+
flex: { inputPerMTok: 2.5, outputPerMTok: 15, tiers: openAiLongBand(5, 22.5) },
|
|
1117
|
+
fast: { inputPerMTok: 12.5, outputPerMTok: 75 },
|
|
1118
|
+
},
|
|
902
1119
|
capability: 'frontier',
|
|
903
1120
|
tier: 'frontier',
|
|
904
1121
|
notes: OPENAI_EARLIER_LONG_NOTE,
|
|
@@ -922,6 +1139,9 @@ export const MODELS: ModelPricing[] = [
|
|
|
922
1139
|
outputPerMTok: 270,
|
|
923
1140
|
},
|
|
924
1141
|
],
|
|
1142
|
+
serviceTiers: {
|
|
1143
|
+
flex: { inputPerMTok: 15, outputPerMTok: 90 },
|
|
1144
|
+
},
|
|
925
1145
|
capability: 'frontier',
|
|
926
1146
|
tier: 'frontier',
|
|
927
1147
|
notes: OPENAI_EARLIER_LONG_NOTE,
|
|
@@ -945,6 +1165,10 @@ export const MODELS: ModelPricing[] = [
|
|
|
945
1165
|
outputPerMTok: 22.5,
|
|
946
1166
|
},
|
|
947
1167
|
],
|
|
1168
|
+
serviceTiers: {
|
|
1169
|
+
flex: { inputPerMTok: 1.25, outputPerMTok: 7.5, tiers: openAiLongBand(2.5, 11.25) },
|
|
1170
|
+
fast: { inputPerMTok: 5, outputPerMTok: 30 },
|
|
1171
|
+
},
|
|
948
1172
|
capability: 'frontier',
|
|
949
1173
|
tier: 'frontier',
|
|
950
1174
|
notes: OPENAI_EARLIER_LONG_NOTE,
|
|
@@ -968,6 +1192,9 @@ export const MODELS: ModelPricing[] = [
|
|
|
968
1192
|
outputPerMTok: 270,
|
|
969
1193
|
},
|
|
970
1194
|
],
|
|
1195
|
+
serviceTiers: {
|
|
1196
|
+
flex: { inputPerMTok: 15, outputPerMTok: 90, tiers: openAiLongBand(30, 135) },
|
|
1197
|
+
},
|
|
971
1198
|
capability: 'frontier',
|
|
972
1199
|
tier: 'frontier',
|
|
973
1200
|
notes: OPENAI_EARLIER_LONG_NOTE,
|
|
@@ -983,6 +1210,10 @@ export const MODELS: ModelPricing[] = [
|
|
|
983
1210
|
cacheMinTokens: 1024,
|
|
984
1211
|
caching: 'automatic',
|
|
985
1212
|
multipliers: { cacheRead: 0.1, cacheWrite5m: 1, cacheWrite1h: 1, batch: 0.5 },
|
|
1213
|
+
serviceTiers: {
|
|
1214
|
+
flex: { inputPerMTok: 0.375, outputPerMTok: 2.25 },
|
|
1215
|
+
fast: { inputPerMTok: 1.5, outputPerMTok: 9 },
|
|
1216
|
+
},
|
|
986
1217
|
capability: 'mid',
|
|
987
1218
|
tier: 'sonnet',
|
|
988
1219
|
notes: OPENAI_EARLIER_NOTE,
|
|
@@ -999,6 +1230,9 @@ export const MODELS: ModelPricing[] = [
|
|
|
999
1230
|
cacheMinTokens: 1024,
|
|
1000
1231
|
caching: 'automatic',
|
|
1001
1232
|
multipliers: { cacheRead: 0.1, cacheWrite5m: 1, cacheWrite1h: 1, batch: 0.5 },
|
|
1233
|
+
serviceTiers: {
|
|
1234
|
+
flex: { inputPerMTok: 0.1, outputPerMTok: 0.625 },
|
|
1235
|
+
},
|
|
1002
1236
|
capability: 'small',
|
|
1003
1237
|
tier: 'haiku',
|
|
1004
1238
|
notes: OPENAI_EARLIER_NOTE + OPENAI_DEPRECATED_SUFFIX,
|
|
@@ -1014,6 +1248,10 @@ export const MODELS: ModelPricing[] = [
|
|
|
1014
1248
|
cacheMinTokens: 1024,
|
|
1015
1249
|
caching: 'automatic',
|
|
1016
1250
|
multipliers: { cacheRead: 0.1, cacheWrite5m: 1, cacheWrite1h: 1, batch: 0.5 },
|
|
1251
|
+
serviceTiers: {
|
|
1252
|
+
flex: { inputPerMTok: 0.875, outputPerMTok: 7 },
|
|
1253
|
+
fast: { inputPerMTok: 3.5, outputPerMTok: 28 },
|
|
1254
|
+
},
|
|
1017
1255
|
capability: 'frontier',
|
|
1018
1256
|
tier: 'frontier',
|
|
1019
1257
|
notes: OPENAI_EARLIER_NOTE,
|
|
@@ -1045,6 +1283,10 @@ export const MODELS: ModelPricing[] = [
|
|
|
1045
1283
|
cacheMinTokens: 1024,
|
|
1046
1284
|
caching: 'automatic',
|
|
1047
1285
|
multipliers: { cacheRead: 0.1, cacheWrite5m: 1, cacheWrite1h: 1, batch: 0.5 },
|
|
1286
|
+
serviceTiers: {
|
|
1287
|
+
flex: { inputPerMTok: 0.625, outputPerMTok: 5 },
|
|
1288
|
+
fast: { inputPerMTok: 2.5, outputPerMTok: 20 },
|
|
1289
|
+
},
|
|
1048
1290
|
capability: 'frontier',
|
|
1049
1291
|
tier: 'frontier',
|
|
1050
1292
|
notes: OPENAI_EARLIER_NOTE + OPENAI_DEPRECATED_SUFFIX,
|
|
@@ -1077,6 +1319,9 @@ export const MODELS: ModelPricing[] = [
|
|
|
1077
1319
|
cacheMinTokens: 1024,
|
|
1078
1320
|
caching: 'automatic',
|
|
1079
1321
|
multipliers: { cacheRead: 0.25, cacheWrite5m: 1, cacheWrite1h: 1, batch: 0.5 },
|
|
1322
|
+
serviceTiers: {
|
|
1323
|
+
fast: { inputPerMTok: 3.5, outputPerMTok: 14 },
|
|
1324
|
+
},
|
|
1080
1325
|
capability: 'large',
|
|
1081
1326
|
tier: 'opus',
|
|
1082
1327
|
notes: OPENAI_EARLIER_NOTE + OPENAI_DEPRECATED_SUFFIX,
|
|
@@ -1093,6 +1338,9 @@ export const MODELS: ModelPricing[] = [
|
|
|
1093
1338
|
cacheMinTokens: 1024,
|
|
1094
1339
|
caching: 'automatic',
|
|
1095
1340
|
multipliers: { cacheRead: 0.25, cacheWrite5m: 1, cacheWrite1h: 1, batch: 0.5 },
|
|
1341
|
+
serviceTiers: {
|
|
1342
|
+
fast: { inputPerMTok: 0.7, outputPerMTok: 2.8 },
|
|
1343
|
+
},
|
|
1096
1344
|
capability: 'mid',
|
|
1097
1345
|
tier: 'sonnet',
|
|
1098
1346
|
notes: OPENAI_EARLIER_NOTE + OPENAI_DEPRECATED_SUFFIX,
|
|
@@ -1109,6 +1357,9 @@ export const MODELS: ModelPricing[] = [
|
|
|
1109
1357
|
cacheMinTokens: 1024,
|
|
1110
1358
|
caching: 'automatic',
|
|
1111
1359
|
multipliers: { cacheRead: 0.5, cacheWrite5m: 1, cacheWrite1h: 1, batch: 0.5 },
|
|
1360
|
+
serviceTiers: {
|
|
1361
|
+
fast: { inputPerMTok: 4.25, outputPerMTok: 17 },
|
|
1362
|
+
},
|
|
1112
1363
|
capability: 'large',
|
|
1113
1364
|
tier: 'opus',
|
|
1114
1365
|
notes: OPENAI_EARLIER_NOTE + OPENAI_DEPRECATED_SUFFIX,
|
|
@@ -1125,6 +1376,9 @@ export const MODELS: ModelPricing[] = [
|
|
|
1125
1376
|
cacheMinTokens: 1024,
|
|
1126
1377
|
caching: 'automatic',
|
|
1127
1378
|
multipliers: { cacheRead: 0.5, cacheWrite5m: 1, cacheWrite1h: 1, batch: 0.5 },
|
|
1379
|
+
serviceTiers: {
|
|
1380
|
+
fast: { inputPerMTok: 0.25, outputPerMTok: 1 },
|
|
1381
|
+
},
|
|
1128
1382
|
capability: 'small',
|
|
1129
1383
|
tier: 'haiku',
|
|
1130
1384
|
notes: OPENAI_EARLIER_NOTE + OPENAI_DEPRECATED_SUFFIX,
|
|
@@ -1141,6 +1395,10 @@ export const MODELS: ModelPricing[] = [
|
|
|
1141
1395
|
cacheMinTokens: 1024,
|
|
1142
1396
|
caching: 'automatic',
|
|
1143
1397
|
multipliers: { cacheRead: 0.25, cacheWrite5m: 1, cacheWrite1h: 1, batch: 0.5 },
|
|
1398
|
+
serviceTiers: {
|
|
1399
|
+
flex: { inputPerMTok: 1, outputPerMTok: 4 },
|
|
1400
|
+
fast: { inputPerMTok: 3.5, outputPerMTok: 14 },
|
|
1401
|
+
},
|
|
1144
1402
|
capability: 'frontier',
|
|
1145
1403
|
tier: 'frontier',
|
|
1146
1404
|
notes: OPENAI_EARLIER_NOTE + OPENAI_DEPRECATED_SUFFIX,
|
|
@@ -1161,6 +1419,143 @@ export const MODELS: ModelPricing[] = [
|
|
|
1161
1419
|
tier: 'frontier',
|
|
1162
1420
|
notes: OPENAI_EARLIER_NO_CACHE_NOTE + OPENAI_DEPRECATED_SUFFIX,
|
|
1163
1421
|
},
|
|
1422
|
+
// ------------------------------------------------------------------------
|
|
1423
|
+
// The Codex models and chat-latest. Codex CLI sessions name these, and none
|
|
1424
|
+
// was priced, so every such call read as unpriced. Each from its own model
|
|
1425
|
+
// page (developers.openai.com/api/docs/models/<id>.md), read 2026-11-05,
|
|
1426
|
+
// and gpt-5.3-codex and chat-latest also from the pricing page's
|
|
1427
|
+
// "Specialized models" table. Every page says Batch is "Not supported", so
|
|
1428
|
+
// none has a batch price. gpt-5.3-codex is deprecated and the rest of the
|
|
1429
|
+
// Codex line is shut down; all are priced for the logs that hold them and
|
|
1430
|
+
// never recommended. chat-latest is served and not recommended either: it
|
|
1431
|
+
// points at whatever model ChatGPT uses, so a recommendation would not name
|
|
1432
|
+
// a fixed model. Cache reads are 0.1x everywhere but codex-mini-latest,
|
|
1433
|
+
// whose page gives $0.375 on $1.50, 0.25x. gpt-5-search-api is on the
|
|
1434
|
+
// pricing page too and its model page returns 404, so it has no context
|
|
1435
|
+
// window and is left unpriced (see scripts/price-drift.mjs).
|
|
1436
|
+
// ------------------------------------------------------------------------
|
|
1437
|
+
{
|
|
1438
|
+
id: 'gpt-5.3-codex',
|
|
1439
|
+
provider: 'openai',
|
|
1440
|
+
displayName: 'GPT-5.3-Codex',
|
|
1441
|
+
recommendable: false,
|
|
1442
|
+
inputPerMTok: 1.75,
|
|
1443
|
+
outputPerMTok: 14,
|
|
1444
|
+
contextWindow: 400_000,
|
|
1445
|
+
cacheMinTokens: 1024,
|
|
1446
|
+
caching: 'automatic',
|
|
1447
|
+
multipliers: { cacheRead: 0.1, cacheWrite5m: 1, cacheWrite1h: 1, batch: null },
|
|
1448
|
+
// The pricing page's specialized "Fast" table: $3.50/$28, cached $0.35.
|
|
1449
|
+
serviceTiers: { fast: { inputPerMTok: 3.5, outputPerMTok: 28 } },
|
|
1450
|
+
capability: 'frontier',
|
|
1451
|
+
tier: 'frontier',
|
|
1452
|
+
notes: OPENAI_CODEX_NOTE + ' At most 272,000 input tokens.' + OPENAI_DEPRECATED_SUFFIX,
|
|
1453
|
+
},
|
|
1454
|
+
{
|
|
1455
|
+
id: 'gpt-5.2-codex',
|
|
1456
|
+
provider: 'openai',
|
|
1457
|
+
displayName: 'GPT-5.2-Codex',
|
|
1458
|
+
recommendable: false,
|
|
1459
|
+
inputPerMTok: 1.75,
|
|
1460
|
+
outputPerMTok: 14,
|
|
1461
|
+
contextWindow: 400_000,
|
|
1462
|
+
cacheMinTokens: 1024,
|
|
1463
|
+
caching: 'automatic',
|
|
1464
|
+
multipliers: { cacheRead: 0.1, cacheWrite5m: 1, cacheWrite1h: 1, batch: null },
|
|
1465
|
+
capability: 'frontier',
|
|
1466
|
+
tier: 'frontier',
|
|
1467
|
+
notes: OPENAI_CODEX_NOTE + ' At most 272,000 input tokens.' + OPENAI_SHUT_DOWN_SUFFIX,
|
|
1468
|
+
},
|
|
1469
|
+
{
|
|
1470
|
+
id: 'gpt-5.1-codex',
|
|
1471
|
+
provider: 'openai',
|
|
1472
|
+
displayName: 'GPT-5.1-Codex',
|
|
1473
|
+
recommendable: false,
|
|
1474
|
+
inputPerMTok: 1.25,
|
|
1475
|
+
outputPerMTok: 10,
|
|
1476
|
+
contextWindow: 400_000,
|
|
1477
|
+
cacheMinTokens: 1024,
|
|
1478
|
+
caching: 'automatic',
|
|
1479
|
+
multipliers: { cacheRead: 0.1, cacheWrite5m: 1, cacheWrite1h: 1, batch: null },
|
|
1480
|
+
capability: 'frontier',
|
|
1481
|
+
tier: 'frontier',
|
|
1482
|
+
notes: OPENAI_CODEX_NOTE + OPENAI_SHUT_DOWN_SUFFIX,
|
|
1483
|
+
},
|
|
1484
|
+
{
|
|
1485
|
+
id: 'gpt-5.1-codex-max',
|
|
1486
|
+
provider: 'openai',
|
|
1487
|
+
displayName: 'GPT-5.1-Codex-Max',
|
|
1488
|
+
recommendable: false,
|
|
1489
|
+
inputPerMTok: 1.25,
|
|
1490
|
+
outputPerMTok: 10,
|
|
1491
|
+
contextWindow: 400_000,
|
|
1492
|
+
cacheMinTokens: 1024,
|
|
1493
|
+
caching: 'automatic',
|
|
1494
|
+
multipliers: { cacheRead: 0.1, cacheWrite5m: 1, cacheWrite1h: 1, batch: null },
|
|
1495
|
+
capability: 'frontier',
|
|
1496
|
+
tier: 'frontier',
|
|
1497
|
+
notes: OPENAI_CODEX_NOTE + OPENAI_SHUT_DOWN_SUFFIX,
|
|
1498
|
+
},
|
|
1499
|
+
{
|
|
1500
|
+
id: 'gpt-5.1-codex-mini',
|
|
1501
|
+
provider: 'openai',
|
|
1502
|
+
displayName: 'GPT-5.1-Codex Mini',
|
|
1503
|
+
recommendable: false,
|
|
1504
|
+
inputPerMTok: 0.25,
|
|
1505
|
+
outputPerMTok: 2,
|
|
1506
|
+
contextWindow: 400_000,
|
|
1507
|
+
cacheMinTokens: 1024,
|
|
1508
|
+
caching: 'automatic',
|
|
1509
|
+
multipliers: { cacheRead: 0.1, cacheWrite5m: 1, cacheWrite1h: 1, batch: null },
|
|
1510
|
+
capability: 'mid',
|
|
1511
|
+
tier: 'sonnet',
|
|
1512
|
+
notes: OPENAI_CODEX_NOTE + OPENAI_SHUT_DOWN_SUFFIX,
|
|
1513
|
+
},
|
|
1514
|
+
{
|
|
1515
|
+
id: 'gpt-5-codex',
|
|
1516
|
+
provider: 'openai',
|
|
1517
|
+
displayName: 'GPT-5-Codex',
|
|
1518
|
+
recommendable: false,
|
|
1519
|
+
inputPerMTok: 1.25,
|
|
1520
|
+
outputPerMTok: 10,
|
|
1521
|
+
contextWindow: 400_000,
|
|
1522
|
+
cacheMinTokens: 1024,
|
|
1523
|
+
caching: 'automatic',
|
|
1524
|
+
multipliers: { cacheRead: 0.1, cacheWrite5m: 1, cacheWrite1h: 1, batch: null },
|
|
1525
|
+
capability: 'frontier',
|
|
1526
|
+
tier: 'frontier',
|
|
1527
|
+
notes: OPENAI_CODEX_NOTE + ' At most 272,000 input tokens.' + OPENAI_SHUT_DOWN_SUFFIX,
|
|
1528
|
+
},
|
|
1529
|
+
{
|
|
1530
|
+
id: 'codex-mini-latest',
|
|
1531
|
+
provider: 'openai',
|
|
1532
|
+
displayName: 'codex-mini-latest',
|
|
1533
|
+
recommendable: false,
|
|
1534
|
+
inputPerMTok: 1.5,
|
|
1535
|
+
outputPerMTok: 6,
|
|
1536
|
+
contextWindow: 200_000,
|
|
1537
|
+
cacheMinTokens: 1024,
|
|
1538
|
+
caching: 'automatic',
|
|
1539
|
+
multipliers: { cacheRead: 0.25, cacheWrite5m: 1, cacheWrite1h: 1, batch: null },
|
|
1540
|
+
capability: 'mid',
|
|
1541
|
+
tier: 'sonnet',
|
|
1542
|
+
notes: OPENAI_CODEX_NOTE + ' A cache read costs 0.25x input.' + OPENAI_SHUT_DOWN_SUFFIX,
|
|
1543
|
+
},
|
|
1544
|
+
{
|
|
1545
|
+
id: 'chat-latest',
|
|
1546
|
+
provider: 'openai',
|
|
1547
|
+
displayName: 'Chat Latest',
|
|
1548
|
+
recommendable: false,
|
|
1549
|
+
inputPerMTok: 5,
|
|
1550
|
+
outputPerMTok: 30,
|
|
1551
|
+
contextWindow: 400_000,
|
|
1552
|
+
cacheMinTokens: 1024,
|
|
1553
|
+
caching: 'automatic',
|
|
1554
|
+
multipliers: { cacheRead: 0.1, cacheWrite5m: 1, cacheWrite1h: 1, batch: null },
|
|
1555
|
+
capability: 'large',
|
|
1556
|
+
tier: 'opus',
|
|
1557
|
+
notes: 'Points at the model ChatGPT currently uses, so it is priced and never recommended. Caching is automatic; a write costs what input costs. At most 272,000 input tokens, and no batch.',
|
|
1558
|
+
},
|
|
1164
1559
|
|
|
1165
1560
|
// ------------------------------------------------------------------------
|
|
1166
1561
|
// Google
|
|
@@ -2042,6 +2437,8 @@ interface Rates {
|
|
|
2042
2437
|
*/
|
|
2043
2438
|
floor?: { inputPerMTok: number; outputPerMTok: number };
|
|
2044
2439
|
} | null;
|
|
2440
|
+
/** The service tier whose table priced the call, when it was not the standard one. */
|
|
2441
|
+
serviceTier?: ServiceTier;
|
|
2045
2442
|
}
|
|
2046
2443
|
|
|
2047
2444
|
/**
|
|
@@ -2064,6 +2461,61 @@ export interface PromptSize {
|
|
|
2064
2461
|
inputTokensAtMost?: number;
|
|
2065
2462
|
/** The response's `usage.speed`, when the log kept it: `"fast"` or `"standard"`. */
|
|
2066
2463
|
speed?: string;
|
|
2464
|
+
/**
|
|
2465
|
+
* The response's `service_tier`, when the log kept it: OpenAI's `"flex"`,
|
|
2466
|
+
* `"priority"` or `"fast"`, `"ultrafast"`, or `"default"`. Normalised by
|
|
2467
|
+
* `serviceTierOf`; anything else prices at the standard rate.
|
|
2468
|
+
*/
|
|
2469
|
+
serviceTier?: string;
|
|
2470
|
+
}
|
|
2471
|
+
|
|
2472
|
+
/**
|
|
2473
|
+
* A response's `service_tier` as the tier whose table prices it, or
|
|
2474
|
+
* `undefined` for the standard one.
|
|
2475
|
+
*
|
|
2476
|
+
* OpenAI renamed Priority processing to Fast mode on 2026-07-30, and its guide
|
|
2477
|
+
* says "for GPT-5.6 and earlier models, the response returns `priority`
|
|
2478
|
+
* whether the request specifies `priority` or `fast`", so both spellings are
|
|
2479
|
+
* the Fast table. `"default"` is the standard tier, and is also what a Fast
|
|
2480
|
+
* request downgraded under the ramp-rate limit returns, "and charge standard
|
|
2481
|
+
* rates". `"auto"` and `"scale"`, or a value this table has never seen, are
|
|
2482
|
+
* priced at the standard rate rather than guessed into another tier.
|
|
2483
|
+
*/
|
|
2484
|
+
export function serviceTierOf(value: unknown): ServiceTier | undefined {
|
|
2485
|
+
if (typeof value !== 'string') return undefined;
|
|
2486
|
+
const tier = value.trim().toLowerCase();
|
|
2487
|
+
if (tier === 'flex') return 'flex';
|
|
2488
|
+
if (tier === 'fast' || tier === 'priority') return 'fast';
|
|
2489
|
+
if (tier === 'ultrafast') return 'ultrafast';
|
|
2490
|
+
return undefined;
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2493
|
+
/**
|
|
2494
|
+
* The row as one service tier prices it: that tier's rates and long band, the
|
|
2495
|
+
* row's own cache and batch ratios. Built once per row and tier.
|
|
2496
|
+
*/
|
|
2497
|
+
const serviceTierMemo = new WeakMap<ModelPricing, Map<ServiceTier, ModelPricing>>();
|
|
2498
|
+
|
|
2499
|
+
function serviceTierRow(model: ModelPricing, tier: ServiceTier): ModelPricing | undefined {
|
|
2500
|
+
const sheet = model.serviceTiers?.[tier];
|
|
2501
|
+
if (sheet === undefined) return undefined;
|
|
2502
|
+
let rows = serviceTierMemo.get(model);
|
|
2503
|
+
if (rows === undefined) {
|
|
2504
|
+
rows = new Map();
|
|
2505
|
+
serviceTierMemo.set(model, rows);
|
|
2506
|
+
}
|
|
2507
|
+
let row = rows.get(tier);
|
|
2508
|
+
if (row === undefined) {
|
|
2509
|
+
const { history: _history, promo: _promo, tiers: _tiers, serviceTiers: _serviceTiers, ...rest } = model;
|
|
2510
|
+
row = Object.freeze({
|
|
2511
|
+
...rest,
|
|
2512
|
+
inputPerMTok: sheet.inputPerMTok,
|
|
2513
|
+
outputPerMTok: sheet.outputPerMTok,
|
|
2514
|
+
...(sheet.tiers !== undefined ? { tiers: sheet.tiers } : {}),
|
|
2515
|
+
});
|
|
2516
|
+
rows.set(tier, row);
|
|
2517
|
+
}
|
|
2518
|
+
return row;
|
|
2067
2519
|
}
|
|
2068
2520
|
|
|
2069
2521
|
const pricingMemo = new WeakMap<
|
|
@@ -2084,7 +2536,8 @@ function pricedAt(model: ModelPricing, on: Date): ModelPricing {
|
|
|
2084
2536
|
let periods = periodMemo.get(model);
|
|
2085
2537
|
if (periods === undefined) {
|
|
2086
2538
|
periods = history.map((period) => {
|
|
2087
|
-
|
|
2539
|
+
// A period's own price only: the service tiers below are today's tables.
|
|
2540
|
+
const { history: _history, promo: _promo, tiers: _tiers, multipliers: _multipliers, serviceTiers: _serviceTiers, ...rest } = model;
|
|
2088
2541
|
const row: ModelPricing = Object.freeze({
|
|
2089
2542
|
...rest,
|
|
2090
2543
|
inputPerMTok: period.inputPerMTok,
|
|
@@ -2181,6 +2634,18 @@ export function effectivePricing(
|
|
|
2181
2634
|
const period = pricedAt(model, on);
|
|
2182
2635
|
if (period !== model) return effectivePricing(period, on, context);
|
|
2183
2636
|
}
|
|
2637
|
+
/*
|
|
2638
|
+
* A response that names another service tier is priced by that tier's own
|
|
2639
|
+
* table, long band included, and by nothing composed out of two.
|
|
2640
|
+
*/
|
|
2641
|
+
if (context.serviceTier !== undefined && model.serviceTiers !== undefined) {
|
|
2642
|
+
const named = serviceTierOf(context.serviceTier);
|
|
2643
|
+
const row = named === undefined ? undefined : serviceTierRow(model, named);
|
|
2644
|
+
if (row !== undefined) {
|
|
2645
|
+
const { serviceTier: _serviceTier, ...size } = context;
|
|
2646
|
+
return { ...effectivePricing(row, on, size), serviceTier: named };
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2184
2649
|
const memo = pricingMemo.get(model) ?? cache(model);
|
|
2185
2650
|
|
|
2186
2651
|
/**
|