@dexterai/x402 3.18.1 → 4.1.0
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/README.md +19 -5
- package/dist/client/index.cjs +1 -1
- package/dist/client/index.d.cts +32 -70
- package/dist/client/index.d.ts +32 -70
- package/dist/client/index.js +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.d.cts +5 -107
- package/dist/react/index.d.ts +5 -107
- package/dist/react/index.js +1 -1
- package/dist/server/index.cjs +1 -286
- package/dist/server/index.d.cts +1 -724
- package/dist/server/index.d.ts +1 -724
- package/dist/server/index.js +1 -286
- package/dist/tab/adapters/solana/index.cjs +1 -1
- package/dist/tab/adapters/solana/index.d.cts +19 -24
- package/dist/tab/adapters/solana/index.d.ts +19 -24
- package/dist/tab/adapters/solana/index.js +1 -1
- package/dist/{x402-client-Ug0vrj74.d.ts → x402-client-BQKDeNxq.d.cts} +1 -123
- package/dist/{x402-client-DmRbvqoc.d.cts → x402-client-BQKDeNxq.d.ts} +1 -123
- package/package.json +2 -2
package/dist/server/index.d.ts
CHANGED
|
@@ -616,727 +616,4 @@ type DeclareDiscoveryConfig = Omit<Extract<DiscoveryConfig, {
|
|
|
616
616
|
*/
|
|
617
617
|
declare function declareDiscoveryExtension(config: DeclareDiscoveryConfig): Record<string, unknown>;
|
|
618
618
|
|
|
619
|
-
|
|
620
|
-
* x402 Browser Support Middleware
|
|
621
|
-
*
|
|
622
|
-
* @deprecated Slated for removal in `@dexterai/x402` 4.0. No replacement —
|
|
623
|
-
* the browser-paywall HTML page was a v1-era convenience that never picked
|
|
624
|
-
* up real consumers. Build a custom paywall page in your app if you need one.
|
|
625
|
-
*
|
|
626
|
-
* Express middleware that automatically renders a branded HTML paywall page
|
|
627
|
-
* when a browser (Accept: text/html) receives a 402 Payment Required response.
|
|
628
|
-
* API clients continue to receive the standard JSON response unchanged.
|
|
629
|
-
*
|
|
630
|
-
* Includes a functional "Pay" button using the Solana Wallet Standard --
|
|
631
|
-
* detects Phantom/Solflare/Backpack, constructs a USDC transfer, signs,
|
|
632
|
-
* and submits the payment automatically.
|
|
633
|
-
*
|
|
634
|
-
* @example
|
|
635
|
-
* ```typescript
|
|
636
|
-
* import express from 'express';
|
|
637
|
-
* import { x402Middleware, x402BrowserSupport } from '@dexterai/x402/server';
|
|
638
|
-
*
|
|
639
|
-
* const app = express();
|
|
640
|
-
* app.use(express.json());
|
|
641
|
-
* app.use(x402BrowserSupport());
|
|
642
|
-
*
|
|
643
|
-
* app.post('/api/data',
|
|
644
|
-
* x402Middleware({ payTo: '...', amount: '0.01' }),
|
|
645
|
-
* (req, res) => res.json({ data: 'protected' })
|
|
646
|
-
* );
|
|
647
|
-
* ```
|
|
648
|
-
*/
|
|
649
|
-
|
|
650
|
-
/**
|
|
651
|
-
* Configuration for x402BrowserSupport middleware.
|
|
652
|
-
*/
|
|
653
|
-
interface X402BrowserSupportConfig {
|
|
654
|
-
/** Custom title shown on the paywall page. @default 'Payment Required' */
|
|
655
|
-
title?: string;
|
|
656
|
-
/** Custom branding text. @default 'Powered by x402' */
|
|
657
|
-
branding?: string;
|
|
658
|
-
/** URL to link for SDK/documentation. @default 'https://docs.dexter.cash/docs/sdk/' */
|
|
659
|
-
sdkUrl?: string;
|
|
660
|
-
/** Whether to include the request method and path. @default true */
|
|
661
|
-
showEndpoint?: boolean;
|
|
662
|
-
/** Solana RPC URL for wallet transactions. @default 'https://api.dexter.cash/api/solana/rpc' */
|
|
663
|
-
rpcUrl?: string;
|
|
664
|
-
}
|
|
665
|
-
/** Escape HTML to prevent XSS from untrusted payment requirement fields */
|
|
666
|
-
declare function escapeHtml(s: string): string;
|
|
667
|
-
/**
|
|
668
|
-
* Create x402 browser support middleware.
|
|
669
|
-
*
|
|
670
|
-
* Wraps `res.json()` to intercept 402 Payment Required responses.
|
|
671
|
-
* When the request is from a browser (Accept: text/html) and no
|
|
672
|
-
* payment-signature header is present, renders a branded HTML paywall
|
|
673
|
-
* instead of raw JSON.
|
|
674
|
-
*
|
|
675
|
-
* API clients are completely unaffected -- they receive normal JSON.
|
|
676
|
-
*
|
|
677
|
-
* @deprecated Slated for removal in `@dexterai/x402` 4.0. No replacement —
|
|
678
|
-
* build a custom browser paywall page in your application if you need one.
|
|
679
|
-
*/
|
|
680
|
-
declare function x402BrowserSupport(config?: X402BrowserSupportConfig): RequestHandler;
|
|
681
|
-
|
|
682
|
-
/**
|
|
683
|
-
* x402 Access Pass Middleware
|
|
684
|
-
*
|
|
685
|
-
* @deprecated Slated for removal in `@dexterai/x402` 4.0. No replacement —
|
|
686
|
-
* Access Pass was a v1-era stopgap before x402 v2 dynamic pricing landed.
|
|
687
|
-
* The same product story is served better by per-request payments with
|
|
688
|
-
* `payAndFetch` on the client and `x402Middleware` on the server.
|
|
689
|
-
*
|
|
690
|
-
* Pay once, get a time-limited JWT for unlimited API requests.
|
|
691
|
-
* Supports both predefined tiers and custom durations.
|
|
692
|
-
*
|
|
693
|
-
* @example Tier-based pricing
|
|
694
|
-
* ```typescript
|
|
695
|
-
* app.use('/api', x402AccessPass({
|
|
696
|
-
* payTo: 'YourSolanaAddress...',
|
|
697
|
-
* tiers: {
|
|
698
|
-
* '1h': '0.50', // $0.50 for 1 hour
|
|
699
|
-
* '24h': '2.00', // $2.00 for 24 hours
|
|
700
|
-
* },
|
|
701
|
-
* }));
|
|
702
|
-
* ```
|
|
703
|
-
*
|
|
704
|
-
* @example Rate-based custom durations
|
|
705
|
-
* ```typescript
|
|
706
|
-
* app.use('/api', x402AccessPass({
|
|
707
|
-
* payTo: 'YourSolanaAddress...',
|
|
708
|
-
* ratePerHour: '0.50', // $0.50/hour, any duration
|
|
709
|
-
* }));
|
|
710
|
-
* ```
|
|
711
|
-
*
|
|
712
|
-
* @example Both tiers and custom durations
|
|
713
|
-
* ```typescript
|
|
714
|
-
* app.use('/api', x402AccessPass({
|
|
715
|
-
* payTo: 'YourSolanaAddress...',
|
|
716
|
-
* tiers: { '1h': '0.50', '24h': '2.00' },
|
|
717
|
-
* ratePerHour: '0.50', // fallback for custom durations
|
|
718
|
-
* }));
|
|
719
|
-
* ```
|
|
720
|
-
*/
|
|
721
|
-
|
|
722
|
-
/**
|
|
723
|
-
* Access pass middleware configuration
|
|
724
|
-
*/
|
|
725
|
-
interface X402AccessPassConfig {
|
|
726
|
-
/** Address to receive payments (Solana pubkey or EVM address) */
|
|
727
|
-
payTo: string;
|
|
728
|
-
/** CAIP-2 network identifier @default 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp' */
|
|
729
|
-
network?: string;
|
|
730
|
-
/** x402 facilitator URL @default 'https://x402.dexter.cash' */
|
|
731
|
-
facilitatorUrl?: string;
|
|
732
|
-
/** Asset config @default USDC on specified network */
|
|
733
|
-
asset?: {
|
|
734
|
-
address: string;
|
|
735
|
-
decimals: number;
|
|
736
|
-
};
|
|
737
|
-
/**
|
|
738
|
-
* Predefined pricing tiers.
|
|
739
|
-
* Keys are tier IDs (e.g., '5m', '1h', '24h').
|
|
740
|
-
* Values are prices in USD (e.g., '0.50').
|
|
741
|
-
* Duration is parsed from the ID: '5m' = 5 minutes, '1h' = 1 hour, '24h' = 24 hours, '7d' = 7 days.
|
|
742
|
-
*/
|
|
743
|
-
tiers?: Record<string, string>;
|
|
744
|
-
/**
|
|
745
|
-
* Rate per hour in USD for custom durations.
|
|
746
|
-
* When set, buyers can request any duration via ?duration=<seconds> query param.
|
|
747
|
-
*/
|
|
748
|
-
ratePerHour?: string;
|
|
749
|
-
/** HMAC secret for JWT signing. Auto-generated if not provided. */
|
|
750
|
-
secret?: Buffer;
|
|
751
|
-
/** Issuer string for JWT 'iss' claim @default 'x402-access-pass' */
|
|
752
|
-
issuer?: string;
|
|
753
|
-
/** Enable verbose logging */
|
|
754
|
-
verbose?: boolean;
|
|
755
|
-
/** Description shown in 402 response */
|
|
756
|
-
description?: string;
|
|
757
|
-
}
|
|
758
|
-
/**
|
|
759
|
-
* Extended request with access pass info
|
|
760
|
-
*/
|
|
761
|
-
interface X402AccessPassRequest extends Request {
|
|
762
|
-
/** Access pass info (present when request is authenticated via valid pass) */
|
|
763
|
-
accessPass?: {
|
|
764
|
-
tier: string;
|
|
765
|
-
duration: number;
|
|
766
|
-
expiresAt: string;
|
|
767
|
-
payer: string;
|
|
768
|
-
network: string;
|
|
769
|
-
};
|
|
770
|
-
/** x402 payment info (present when a new pass was just purchased) */
|
|
771
|
-
x402?: {
|
|
772
|
-
transaction: string;
|
|
773
|
-
payer: string;
|
|
774
|
-
network: string;
|
|
775
|
-
};
|
|
776
|
-
}
|
|
777
|
-
/**
|
|
778
|
-
* Create x402 access pass middleware for Express.
|
|
779
|
-
*
|
|
780
|
-
* Protects routes with time-limited access passes purchased via x402 payments.
|
|
781
|
-
* Supports predefined tiers, custom durations, or both.
|
|
782
|
-
*
|
|
783
|
-
* @deprecated Slated for removal in `@dexterai/x402` 4.0. No replacement —
|
|
784
|
-
* use per-request `x402Middleware` with `payAndFetch` clients.
|
|
785
|
-
*/
|
|
786
|
-
declare function x402AccessPass(config: X402AccessPassConfig): RequestHandler;
|
|
787
|
-
|
|
788
|
-
/**
|
|
789
|
-
* Dynamic Pricing for x402
|
|
790
|
-
*
|
|
791
|
-
* @deprecated Slated for removal in `@dexterai/x402` 4.0. Use x402 v2 dynamic
|
|
792
|
-
* pricing on the server (compute the amount per request and pass it to
|
|
793
|
-
* `x402Middleware`), which superseded this character-based v1 helper.
|
|
794
|
-
*
|
|
795
|
-
* Calculate prices based on input length (characters, tokens, etc.)
|
|
796
|
-
* Perfect for LLM/AI endpoints where cost scales with input size.
|
|
797
|
-
*
|
|
798
|
-
* @example
|
|
799
|
-
* ```typescript
|
|
800
|
-
* import { createDynamicPricing } from '@dexterai/x402/server';
|
|
801
|
-
*
|
|
802
|
-
* const pricing = createDynamicPricing({
|
|
803
|
-
* unitSize: 1000, // chars per billing unit
|
|
804
|
-
* ratePerUnit: 0.01, // $0.01 per unit
|
|
805
|
-
* minUsd: 0.01, // floor
|
|
806
|
-
* maxUsd: 10.00, // ceiling (optional)
|
|
807
|
-
* });
|
|
808
|
-
*
|
|
809
|
-
* // Calculate price from input
|
|
810
|
-
* const quote = pricing.calculate(userPrompt);
|
|
811
|
-
* // → { amountAtomic: '23000', usdAmount: 0.023, quoteHash: 'abc...', units: 2.3 }
|
|
812
|
-
*
|
|
813
|
-
* // Validate on retry (prevents prompt manipulation)
|
|
814
|
-
* const isValid = pricing.validateQuote(userPrompt, req.headers['x-quote-hash']);
|
|
815
|
-
* ```
|
|
816
|
-
*/
|
|
817
|
-
/**
|
|
818
|
-
* Configuration for dynamic pricing
|
|
819
|
-
*/
|
|
820
|
-
interface DynamicPricingConfig {
|
|
821
|
-
/**
|
|
822
|
-
* Characters per billing unit.
|
|
823
|
-
* Example: 1000 means every 1000 chars = 1 unit
|
|
824
|
-
*/
|
|
825
|
-
unitSize: number;
|
|
826
|
-
/**
|
|
827
|
-
* USD per unit.
|
|
828
|
-
* Example: 0.01 means $0.01 per unit
|
|
829
|
-
*/
|
|
830
|
-
ratePerUnit: number;
|
|
831
|
-
/**
|
|
832
|
-
* Minimum USD amount (floor).
|
|
833
|
-
* Recommended: 0.01 (practical minimum for settlement)
|
|
834
|
-
* @default 0.01
|
|
835
|
-
*/
|
|
836
|
-
minUsd?: number;
|
|
837
|
-
/**
|
|
838
|
-
* Maximum USD amount (ceiling).
|
|
839
|
-
* Optional - prevents unexpectedly large bills.
|
|
840
|
-
*/
|
|
841
|
-
maxUsd?: number;
|
|
842
|
-
/**
|
|
843
|
-
* Rounding mode for unit calculation.
|
|
844
|
-
* - 'ceil': Always round up (fair to seller)
|
|
845
|
-
* - 'floor': Always round down (fair to buyer)
|
|
846
|
-
* - 'round': Standard rounding
|
|
847
|
-
* @default 'ceil'
|
|
848
|
-
*/
|
|
849
|
-
roundingMode?: 'ceil' | 'floor' | 'round';
|
|
850
|
-
/**
|
|
851
|
-
* Token decimals for atomic conversion.
|
|
852
|
-
* @default 6 (USDC)
|
|
853
|
-
*/
|
|
854
|
-
decimals?: number;
|
|
855
|
-
}
|
|
856
|
-
/**
|
|
857
|
-
* Price quote returned by calculate()
|
|
858
|
-
*/
|
|
859
|
-
interface PriceQuote {
|
|
860
|
-
/** Amount in atomic units (for buildRequirements) */
|
|
861
|
-
amountAtomic: string;
|
|
862
|
-
/** Human-readable USD amount (for display) */
|
|
863
|
-
usdAmount: number;
|
|
864
|
-
/**
|
|
865
|
-
* Quote hash for validation.
|
|
866
|
-
* Includes input + config, so config changes invalidate quotes.
|
|
867
|
-
* Client should send this back as X-Quote-Hash header.
|
|
868
|
-
*/
|
|
869
|
-
quoteHash: string;
|
|
870
|
-
/** Number of billing units */
|
|
871
|
-
units: number;
|
|
872
|
-
/** Input length in characters */
|
|
873
|
-
inputLength: number;
|
|
874
|
-
}
|
|
875
|
-
/**
|
|
876
|
-
* Dynamic pricing calculator
|
|
877
|
-
*/
|
|
878
|
-
interface DynamicPricing {
|
|
879
|
-
/** Calculate price from input */
|
|
880
|
-
calculate(input: string): PriceQuote;
|
|
881
|
-
/** Validate quote hash (returns true if valid) */
|
|
882
|
-
validateQuote(input: string, quoteHash: string): boolean;
|
|
883
|
-
/** Get pricing config (for display) */
|
|
884
|
-
readonly config: Required<DynamicPricingConfig>;
|
|
885
|
-
}
|
|
886
|
-
/**
|
|
887
|
-
* Create a dynamic pricing calculator
|
|
888
|
-
*
|
|
889
|
-
* @deprecated Slated for removal in `@dexterai/x402` 4.0. Use x402 v2 dynamic
|
|
890
|
-
* pricing instead — compute the price per request in your handler and pass it
|
|
891
|
-
* to `x402Middleware`.
|
|
892
|
-
*/
|
|
893
|
-
declare function createDynamicPricing(config: DynamicPricingConfig): DynamicPricing;
|
|
894
|
-
/**
|
|
895
|
-
* Format pricing for display
|
|
896
|
-
* Example: "from $0.01 per 1,000 chars"
|
|
897
|
-
*/
|
|
898
|
-
declare function formatPricing(config: DynamicPricingConfig): string;
|
|
899
|
-
|
|
900
|
-
/**
|
|
901
|
-
* Token-Based Pricing for x402
|
|
902
|
-
*
|
|
903
|
-
* @deprecated Slated for removal in `@dexterai/x402` 4.0 (along with the
|
|
904
|
-
* underlying `model-registry.ts`). The hardcoded OpenAI pricing catalog goes
|
|
905
|
-
* stale within weeks; use x402 v2 dynamic pricing and price the request in
|
|
906
|
-
* your handler with live rates from your model provider.
|
|
907
|
-
*
|
|
908
|
-
* Accurate LLM pricing using tiktoken for token counting.
|
|
909
|
-
* Uses real OpenAI model rates for precise cost calculation.
|
|
910
|
-
*
|
|
911
|
-
* Pricing data is sourced from the Model Registry (model-registry.ts).
|
|
912
|
-
*
|
|
913
|
-
* @example
|
|
914
|
-
* ```typescript
|
|
915
|
-
* import { createTokenPricing, MODEL_PRICING } from '@dexterai/x402/server';
|
|
916
|
-
*
|
|
917
|
-
* const pricing = createTokenPricing({
|
|
918
|
-
* model: 'gpt-4o-mini',
|
|
919
|
-
* // Optional overrides:
|
|
920
|
-
* // minUsd: 0.001,
|
|
921
|
-
* // maxUsd: 50.0,
|
|
922
|
-
* });
|
|
923
|
-
*
|
|
924
|
-
* // Calculate price from input
|
|
925
|
-
* const quote = pricing.calculate(userPrompt);
|
|
926
|
-
* // → { amountAtomic: '1500', usdAmount: 0.0015, inputTokens: 100, quoteHash: 'abc...' }
|
|
927
|
-
*
|
|
928
|
-
* // Validate on retry (prevents prompt manipulation)
|
|
929
|
-
* const isValid = pricing.validateQuote(userPrompt, req.headers['x-quote-hash']);
|
|
930
|
-
* ```
|
|
931
|
-
*/
|
|
932
|
-
/**
|
|
933
|
-
* Pricing info for a model
|
|
934
|
-
*/
|
|
935
|
-
interface ModelPricing$1 {
|
|
936
|
-
/** USD per 1M input tokens */
|
|
937
|
-
input: number;
|
|
938
|
-
/** USD per 1M output tokens */
|
|
939
|
-
output: number;
|
|
940
|
-
/** USD per 1M cached input tokens (optional) */
|
|
941
|
-
cached?: number;
|
|
942
|
-
/** Default max output tokens for this model */
|
|
943
|
-
maxTokens: number;
|
|
944
|
-
/** Pricing tier */
|
|
945
|
-
tier: 'fast' | 'standard' | 'reasoning' | 'premium' | 'specialized' | 'custom';
|
|
946
|
-
}
|
|
947
|
-
/**
|
|
948
|
-
* OpenAI Model Pricing - USD per million tokens
|
|
949
|
-
*
|
|
950
|
-
* This is now sourced from the Model Registry (model-registry.ts).
|
|
951
|
-
* The registry is the single source of truth for all model information.
|
|
952
|
-
*
|
|
953
|
-
* Updated: January 2026
|
|
954
|
-
*
|
|
955
|
-
* @deprecated Slated for removal in `@dexterai/x402` 4.0. The catalog is a
|
|
956
|
-
* January 2026 snapshot and goes stale fast — price requests from your model
|
|
957
|
-
* provider's live API instead.
|
|
958
|
-
*/
|
|
959
|
-
declare const MODEL_PRICING: Record<string, ModelPricing$1>;
|
|
960
|
-
/**
|
|
961
|
-
* Configuration for token-based pricing
|
|
962
|
-
*/
|
|
963
|
-
interface TokenPricingConfig {
|
|
964
|
-
/**
|
|
965
|
-
* Model name. Used for display and to look up built-in pricing.
|
|
966
|
-
* If not in MODEL_PRICING and no custom rates provided, falls back to gpt-4o-mini rates.
|
|
967
|
-
*/
|
|
968
|
-
model?: string;
|
|
969
|
-
/**
|
|
970
|
-
* Custom input rate (USD per 1M tokens).
|
|
971
|
-
* Overrides built-in MODEL_PRICING for this model.
|
|
972
|
-
* Use this for Anthropic, Gemini, Mistral, or any custom model.
|
|
973
|
-
*/
|
|
974
|
-
inputRate?: number;
|
|
975
|
-
/**
|
|
976
|
-
* Custom output rate (USD per 1M tokens).
|
|
977
|
-
* Optional - used for display/info purposes.
|
|
978
|
-
*/
|
|
979
|
-
outputRate?: number;
|
|
980
|
-
/**
|
|
981
|
-
* Custom max output tokens.
|
|
982
|
-
* @default 4096
|
|
983
|
-
*/
|
|
984
|
-
maxTokens?: number;
|
|
985
|
-
/**
|
|
986
|
-
* Custom tier label.
|
|
987
|
-
* @default 'custom'
|
|
988
|
-
*/
|
|
989
|
-
tier?: 'fast' | 'standard' | 'reasoning' | 'premium' | 'specialized' | 'custom';
|
|
990
|
-
/**
|
|
991
|
-
* Custom tokenizer function.
|
|
992
|
-
* If not provided, uses tiktoken (cl100k_base encoding).
|
|
993
|
-
* Use this for models with different tokenization (e.g., Llama, Mistral).
|
|
994
|
-
*
|
|
995
|
-
* @example
|
|
996
|
-
* tokenizer: (text) => llamaTokenizer.encode(text).length
|
|
997
|
-
*/
|
|
998
|
-
tokenizer?: (text: string) => number | Promise<number>;
|
|
999
|
-
/**
|
|
1000
|
-
* Minimum USD amount (floor).
|
|
1001
|
-
* @default 0.001
|
|
1002
|
-
*/
|
|
1003
|
-
minUsd?: number;
|
|
1004
|
-
/**
|
|
1005
|
-
* Maximum USD amount (ceiling).
|
|
1006
|
-
* @default 50.0
|
|
1007
|
-
*/
|
|
1008
|
-
maxUsd?: number;
|
|
1009
|
-
/**
|
|
1010
|
-
* Token decimals for atomic conversion.
|
|
1011
|
-
* @default 6 (USDC)
|
|
1012
|
-
*/
|
|
1013
|
-
decimals?: number;
|
|
1014
|
-
}
|
|
1015
|
-
/**
|
|
1016
|
-
* Token price quote
|
|
1017
|
-
*/
|
|
1018
|
-
interface TokenPriceQuote {
|
|
1019
|
-
/** Amount in atomic units (for buildRequirements) */
|
|
1020
|
-
amountAtomic: string;
|
|
1021
|
-
/** Human-readable USD amount */
|
|
1022
|
-
usdAmount: number;
|
|
1023
|
-
/** Number of input tokens */
|
|
1024
|
-
inputTokens: number;
|
|
1025
|
-
/** Model used for pricing */
|
|
1026
|
-
model: string;
|
|
1027
|
-
/** Pricing tier */
|
|
1028
|
-
tier: string;
|
|
1029
|
-
/** Input rate per million tokens */
|
|
1030
|
-
inputRatePerMillion: number;
|
|
1031
|
-
/** Output rate per million tokens */
|
|
1032
|
-
outputRatePerMillion: number;
|
|
1033
|
-
/** Max output tokens for this model */
|
|
1034
|
-
maxOutputTokens: number;
|
|
1035
|
-
/**
|
|
1036
|
-
* Quote hash for validation.
|
|
1037
|
-
* Client should send this back as X-Quote-Hash header.
|
|
1038
|
-
*/
|
|
1039
|
-
quoteHash: string;
|
|
1040
|
-
}
|
|
1041
|
-
/**
|
|
1042
|
-
* Token pricing calculator
|
|
1043
|
-
*/
|
|
1044
|
-
interface TokenPricing {
|
|
1045
|
-
/** Calculate price from input text */
|
|
1046
|
-
calculate(input: string, systemPrompt?: string): Promise<TokenPriceQuote>;
|
|
1047
|
-
/** Validate quote hash (returns true if valid) */
|
|
1048
|
-
validateQuote(input: string, quoteHash: string): Promise<boolean>;
|
|
1049
|
-
/** Count tokens in a string (lazy-loads tiktoken on first call) */
|
|
1050
|
-
countTokens(input: string): Promise<number>;
|
|
1051
|
-
/** Get pricing config */
|
|
1052
|
-
readonly config: Required<TokenPricingConfig>;
|
|
1053
|
-
/** Get model info */
|
|
1054
|
-
readonly modelInfo: ModelPricing$1;
|
|
1055
|
-
}
|
|
1056
|
-
/**
|
|
1057
|
-
* Count tokens in a string using tiktoken.
|
|
1058
|
-
* Lazy-loads tiktoken on first call — no cost if never used.
|
|
1059
|
-
*/
|
|
1060
|
-
declare function countTokens(text: string, model?: string): Promise<number>;
|
|
1061
|
-
/**
|
|
1062
|
-
* Create a token-based pricing calculator
|
|
1063
|
-
*
|
|
1064
|
-
* @deprecated Slated for removal in `@dexterai/x402` 4.0. Price requests with
|
|
1065
|
-
* your model provider's live API and pass the amount to `x402Middleware`.
|
|
1066
|
-
*/
|
|
1067
|
-
declare function createTokenPricing(config?: TokenPricingConfig): TokenPricing;
|
|
1068
|
-
/**
|
|
1069
|
-
* Get list of available models with their pricing.
|
|
1070
|
-
*/
|
|
1071
|
-
declare function getAvailableModels(): Array<{
|
|
1072
|
-
model: string;
|
|
1073
|
-
inputRate: number;
|
|
1074
|
-
outputRate: number;
|
|
1075
|
-
maxTokens: number;
|
|
1076
|
-
tier: string;
|
|
1077
|
-
}>;
|
|
1078
|
-
/**
|
|
1079
|
-
* Check if a model exists in our pricing.
|
|
1080
|
-
*/
|
|
1081
|
-
declare function isValidModel(model: string): boolean;
|
|
1082
|
-
/**
|
|
1083
|
-
* Format token pricing for display
|
|
1084
|
-
* Example: "$0.15 per 1M tokens (gpt-4o-mini)"
|
|
1085
|
-
*/
|
|
1086
|
-
declare function formatTokenPricing(model?: string): string;
|
|
1087
|
-
|
|
1088
|
-
/**
|
|
1089
|
-
* OpenAI Model Registry
|
|
1090
|
-
*
|
|
1091
|
-
* @deprecated Slated for removal in `@dexterai/x402` 4.0 (bundled with the
|
|
1092
|
-
* `token-pricing.ts` removal — `MODEL_PRICING_MAP` here is the underlying
|
|
1093
|
-
* data source for token-pricing's `MODEL_PRICING` re-export). The hardcoded
|
|
1094
|
-
* January 2026 snapshot goes stale fast; use your model provider's live API
|
|
1095
|
-
* instead.
|
|
1096
|
-
*
|
|
1097
|
-
* The single source of truth for all OpenAI models.
|
|
1098
|
-
* Contains pricing, capabilities, API requirements, and constraints.
|
|
1099
|
-
*
|
|
1100
|
-
* Updated: January 2026
|
|
1101
|
-
* Source: https://platform.openai.com/docs/pricing
|
|
1102
|
-
*
|
|
1103
|
-
* @example
|
|
1104
|
-
* ```typescript
|
|
1105
|
-
* import { ModelRegistry, getModel, getModelsByTier } from '@dexterai/x402/server';
|
|
1106
|
-
*
|
|
1107
|
-
* // Get a specific model
|
|
1108
|
-
* const model = getModel('gpt-4o-mini');
|
|
1109
|
-
* console.log(model.pricing.input); // 0.15
|
|
1110
|
-
*
|
|
1111
|
-
* // Get all reasoning models
|
|
1112
|
-
* const reasoners = getModelsByTier('reasoning');
|
|
1113
|
-
* ```
|
|
1114
|
-
*/
|
|
1115
|
-
/**
|
|
1116
|
-
* Model capability tiers, ordered by general capability level
|
|
1117
|
-
*/
|
|
1118
|
-
type ModelTier = 'fast' | 'standard' | 'reasoning' | 'premium' | 'specialized';
|
|
1119
|
-
/**
|
|
1120
|
-
* What the model can process/generate
|
|
1121
|
-
*/
|
|
1122
|
-
type ModelModality = 'text' | 'vision' | 'audio' | 'realtime' | 'image' | 'video';
|
|
1123
|
-
/**
|
|
1124
|
-
* API endpoint type
|
|
1125
|
-
*/
|
|
1126
|
-
type ModelApiType = 'chat' | 'completion' | 'responses';
|
|
1127
|
-
/**
|
|
1128
|
-
* Pricing per 1M tokens (USD)
|
|
1129
|
-
*/
|
|
1130
|
-
interface ModelPricing {
|
|
1131
|
-
/** Input token cost per 1M */
|
|
1132
|
-
input: number;
|
|
1133
|
-
/** Output token cost per 1M */
|
|
1134
|
-
output: number;
|
|
1135
|
-
/** Cached input token cost per 1M (if supported) */
|
|
1136
|
-
cached?: number;
|
|
1137
|
-
}
|
|
1138
|
-
/**
|
|
1139
|
-
* What parameters the model accepts
|
|
1140
|
-
*/
|
|
1141
|
-
interface ModelParameters {
|
|
1142
|
-
/** Uses max_completion_tokens instead of max_tokens */
|
|
1143
|
-
usesMaxCompletionTokens: boolean;
|
|
1144
|
-
/** Supports temperature parameter */
|
|
1145
|
-
supportsTemperature: boolean;
|
|
1146
|
-
/** Supports top_p parameter */
|
|
1147
|
-
supportsTopP: boolean;
|
|
1148
|
-
/** Supports frequency_penalty */
|
|
1149
|
-
supportsFrequencyPenalty: boolean;
|
|
1150
|
-
/** Supports presence_penalty */
|
|
1151
|
-
supportsPresencePenalty: boolean;
|
|
1152
|
-
/** Supports reasoning_effort parameter */
|
|
1153
|
-
supportsReasoningEffort: boolean;
|
|
1154
|
-
/** Supports streaming */
|
|
1155
|
-
supportsStreaming: boolean;
|
|
1156
|
-
/** Supports system messages */
|
|
1157
|
-
supportsSystemMessage: boolean;
|
|
1158
|
-
/** Supports function/tool calling */
|
|
1159
|
-
supportsTools: boolean;
|
|
1160
|
-
/** Supports structured outputs (JSON mode) */
|
|
1161
|
-
supportsStructuredOutput: boolean;
|
|
1162
|
-
}
|
|
1163
|
-
/**
|
|
1164
|
-
* Complete model definition
|
|
1165
|
-
*/
|
|
1166
|
-
interface ModelDefinition {
|
|
1167
|
-
/** Model ID as used in API calls */
|
|
1168
|
-
id: string;
|
|
1169
|
-
/** Human-readable display name */
|
|
1170
|
-
displayName: string;
|
|
1171
|
-
/** Model family (gpt-4o, gpt-5, o1, o3, etc.) */
|
|
1172
|
-
family: string;
|
|
1173
|
-
/** Capability tier */
|
|
1174
|
-
tier: ModelTier;
|
|
1175
|
-
/** Capability rank within tier (1 = lowest, 10 = highest) */
|
|
1176
|
-
capabilityRank: number;
|
|
1177
|
-
/** What it can process */
|
|
1178
|
-
modalities: ModelModality[];
|
|
1179
|
-
/** API type */
|
|
1180
|
-
apiType: ModelApiType;
|
|
1181
|
-
/** Pricing per 1M tokens */
|
|
1182
|
-
pricing: ModelPricing;
|
|
1183
|
-
/** Context window size (tokens) */
|
|
1184
|
-
contextWindow: number;
|
|
1185
|
-
/** Default max output tokens */
|
|
1186
|
-
defaultMaxOutput: number;
|
|
1187
|
-
/** Maximum output tokens allowed */
|
|
1188
|
-
maxOutputTokens: number;
|
|
1189
|
-
/** Parameter support */
|
|
1190
|
-
parameters: ModelParameters;
|
|
1191
|
-
/** Is this model deprecated? */
|
|
1192
|
-
deprecated: boolean;
|
|
1193
|
-
/** Brief description */
|
|
1194
|
-
description: string;
|
|
1195
|
-
}
|
|
1196
|
-
/**
|
|
1197
|
-
* Complete registry of all OpenAI models
|
|
1198
|
-
* Ordered by tier, then by capability rank (ascending)
|
|
1199
|
-
*
|
|
1200
|
-
* @deprecated Slated for removal in `@dexterai/x402` 4.0. Hardcoded January
|
|
1201
|
-
* 2026 snapshot — use your model provider's live API instead.
|
|
1202
|
-
*/
|
|
1203
|
-
declare const MODEL_REGISTRY: ModelDefinition[];
|
|
1204
|
-
/**
|
|
1205
|
-
* Get a model by ID
|
|
1206
|
-
* @throws if model not found
|
|
1207
|
-
*/
|
|
1208
|
-
declare function getModel(modelId: string): ModelDefinition;
|
|
1209
|
-
/**
|
|
1210
|
-
* Get a model by ID, returns undefined if not found
|
|
1211
|
-
*/
|
|
1212
|
-
declare function findModel(modelId: string): ModelDefinition | undefined;
|
|
1213
|
-
/**
|
|
1214
|
-
* Check if a model ID is valid
|
|
1215
|
-
*/
|
|
1216
|
-
declare function isValidModelId(modelId: string): boolean;
|
|
1217
|
-
/**
|
|
1218
|
-
* Get all model IDs
|
|
1219
|
-
*/
|
|
1220
|
-
declare function getAvailableModelIds(): string[];
|
|
1221
|
-
/**
|
|
1222
|
-
* Get all models in a specific tier
|
|
1223
|
-
*/
|
|
1224
|
-
declare function getModelsByTier(tier: ModelTier): ModelDefinition[];
|
|
1225
|
-
/**
|
|
1226
|
-
* Get all models in a specific family
|
|
1227
|
-
*/
|
|
1228
|
-
declare function getModelsByFamily(family: string): ModelDefinition[];
|
|
1229
|
-
/**
|
|
1230
|
-
* Get all non-deprecated models, ordered by tier then capability
|
|
1231
|
-
*/
|
|
1232
|
-
declare function getActiveModels(): ModelDefinition[];
|
|
1233
|
-
/**
|
|
1234
|
-
* Get models suitable for text generation testing
|
|
1235
|
-
* (excludes realtime, audio-only, etc.)
|
|
1236
|
-
*/
|
|
1237
|
-
declare function getTextModels(): ModelDefinition[];
|
|
1238
|
-
/**
|
|
1239
|
-
* Get the cheapest model that meets minimum capability requirements
|
|
1240
|
-
*/
|
|
1241
|
-
declare function getCheapestModel(minTier?: ModelTier): ModelDefinition;
|
|
1242
|
-
/**
|
|
1243
|
-
* Estimate cost for a request
|
|
1244
|
-
*/
|
|
1245
|
-
declare function estimateCost(modelId: string, inputTokens: number, outputTokens: number, useCached?: boolean): number;
|
|
1246
|
-
/**
|
|
1247
|
-
* Format pricing for display
|
|
1248
|
-
*/
|
|
1249
|
-
declare function formatModelPricing(modelId: string): string;
|
|
1250
|
-
/**
|
|
1251
|
-
* Simple pricing map for token-pricing.ts compatibility
|
|
1252
|
-
*
|
|
1253
|
-
* @deprecated Slated for removal in `@dexterai/x402` 4.0 alongside
|
|
1254
|
-
* `token-pricing.ts`. Hardcoded snapshot — use live provider rates instead.
|
|
1255
|
-
*/
|
|
1256
|
-
declare const MODEL_PRICING_MAP: Record<string, {
|
|
1257
|
-
input: number;
|
|
1258
|
-
output: number;
|
|
1259
|
-
cached?: number;
|
|
1260
|
-
maxTokens: number;
|
|
1261
|
-
tier: string;
|
|
1262
|
-
}>;
|
|
1263
|
-
|
|
1264
|
-
/**
|
|
1265
|
-
* Stripe Machine Payments — PayTo Provider
|
|
1266
|
-
*
|
|
1267
|
-
* @deprecated Slated for removal in `@dexterai/x402` 4.0. No replacement —
|
|
1268
|
-
* the Stripe machine-payments path was a v1-era hypothesis aimed at merchants
|
|
1269
|
-
* who wanted to accept x402 with Stripe-as-acquirer. The current x402 audience
|
|
1270
|
-
* is agents paying USDC directly; integrate Stripe at your own application
|
|
1271
|
-
* layer if you still need it. The `getStripeProviderNetwork` helper and the
|
|
1272
|
-
* Stripe-network check in `x402Middleware` are removed alongside this file in
|
|
1273
|
-
* 4.0.
|
|
1274
|
-
*
|
|
1275
|
-
* Generates per-request Stripe deposit addresses via PaymentIntents.
|
|
1276
|
-
* Payments land in your Stripe Dashboard with full reporting, taxes, and refunds.
|
|
1277
|
-
*
|
|
1278
|
-
* Requires `stripe` npm package as a peer dependency.
|
|
1279
|
-
*
|
|
1280
|
-
* @example
|
|
1281
|
-
* ```typescript
|
|
1282
|
-
* import { x402Middleware, stripePayTo } from '@dexterai/x402/server';
|
|
1283
|
-
*
|
|
1284
|
-
* app.use('/api/data', x402Middleware({
|
|
1285
|
-
* amount: '0.01',
|
|
1286
|
-
* payTo: stripePayTo(process.env.STRIPE_SECRET_KEY),
|
|
1287
|
-
* }));
|
|
1288
|
-
* ```
|
|
1289
|
-
*
|
|
1290
|
-
* @see https://docs.stripe.com/payments/machine
|
|
1291
|
-
*/
|
|
1292
|
-
|
|
1293
|
-
/**
|
|
1294
|
-
* Configuration for the Stripe PayTo provider.
|
|
1295
|
-
*/
|
|
1296
|
-
interface StripePayToConfig {
|
|
1297
|
-
/** Stripe secret key (sk_test_... or sk_live_...) */
|
|
1298
|
-
secretKey: string;
|
|
1299
|
-
/**
|
|
1300
|
-
* Stripe API version to use.
|
|
1301
|
-
* @default '2026-01-28.clover'
|
|
1302
|
-
*/
|
|
1303
|
-
apiVersion?: string;
|
|
1304
|
-
/**
|
|
1305
|
-
* Target network for deposit addresses.
|
|
1306
|
-
* - 'base' → Base mainnet (eip155:8453)
|
|
1307
|
-
* - 'base-sepolia' → Base Sepolia testnet (eip155:84532)
|
|
1308
|
-
* @default 'base'
|
|
1309
|
-
*/
|
|
1310
|
-
network?: 'base' | 'base-sepolia';
|
|
1311
|
-
}
|
|
1312
|
-
/**
|
|
1313
|
-
* Create a Stripe-backed PayTo provider for x402 machine payments.
|
|
1314
|
-
*
|
|
1315
|
-
* On each new request, creates a Stripe PaymentIntent with a crypto deposit address.
|
|
1316
|
-
* When the agent sends USDC to that address, Stripe auto-captures the payment.
|
|
1317
|
-
* Payments appear in your Stripe Dashboard like any other transaction.
|
|
1318
|
-
*
|
|
1319
|
-
* **Important: Stripe crypto deposits only support Base (mainnet and Sepolia).**
|
|
1320
|
-
* This provider cannot be used with Solana, Polygon, Arbitrum, or other networks.
|
|
1321
|
-
* For multi-chain endpoints, use `stripePayTo` for Base and a static address for other chains:
|
|
1322
|
-
*
|
|
1323
|
-
* ```typescript
|
|
1324
|
-
* x402Middleware({
|
|
1325
|
-
* payTo: {
|
|
1326
|
-
* 'eip155:8453': stripePayTo('sk_...'), // Base → Stripe
|
|
1327
|
-
* 'solana:*': 'YourSolanaAddress...', // Solana → direct
|
|
1328
|
-
* 'eip155:*': '0xYourEvmAddress...', // Other EVM → direct
|
|
1329
|
-
* },
|
|
1330
|
-
* network: ['eip155:8453', 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp', 'eip155:137'],
|
|
1331
|
-
* })
|
|
1332
|
-
* ```
|
|
1333
|
-
*
|
|
1334
|
-
* @param secretKeyOrConfig - Stripe secret key string, or full config object
|
|
1335
|
-
* @returns A PayToProvider function with auto-configuration defaults
|
|
1336
|
-
*
|
|
1337
|
-
* @deprecated Slated for removal in `@dexterai/x402` 4.0. No replacement —
|
|
1338
|
-
* integrate Stripe at your application layer if still needed.
|
|
1339
|
-
*/
|
|
1340
|
-
declare function stripePayTo(secretKeyOrConfig: string | StripePayToConfig): PayToProvider;
|
|
1341
|
-
|
|
1342
|
-
export { type AssetConfig, type BodyDiscoveryConfig, type BuildRequirementsOptions, type DeclareDiscoveryConfig, type DiscoveryConfig, type DiscoveryExtension, type DynamicPricing, type DynamicPricingConfig, FacilitatorClient, MODEL_PRICING, MODEL_PRICING_MAP, MODEL_REGISTRY, type ModelApiType, type ModelDefinition, type ModelModality, type ModelParameters, type ModelPricing$1 as ModelPricing, type ModelTier, PayToProvider, PaymentAccept, PaymentRequired, type PaymentRequiredContext, type PriceQuote, type QueryDiscoveryConfig, type ModelPricing as RegistryModelPricing, type ResourceServerExtension, SettleResponse, type StripePayToConfig, type SupportedKind, type SupportedResponse, type TokenPriceQuote, type TokenPricing, type TokenPricingConfig, VerifyResponse, type X402AccessPassConfig, type X402AccessPassRequest, type X402BrowserSupportConfig, type X402MiddlewareConfig, type X402Request, type X402Server, type X402ServerConfig, bazaarExtension, countTokens, createDynamicPricing, createTokenPricing, createX402Server, declareDiscoveryExtension, escapeHtml, estimateCost, findModel, formatModelPricing, formatPricing, formatTokenPricing, getActiveModels, getAvailableModelIds, getAvailableModels, getCheapestModel, getModel, getModelsByFamily, getModelsByTier, getTextModels, isValidModel, isValidModelId, resolveDefaultAsset, stripePayTo, x402AccessPass, x402BrowserSupport, x402Middleware };
|
|
619
|
+
export { type AssetConfig, type BodyDiscoveryConfig, type BuildRequirementsOptions, type DeclareDiscoveryConfig, type DiscoveryConfig, type DiscoveryExtension, FacilitatorClient, PayToProvider, PaymentAccept, PaymentRequired, type PaymentRequiredContext, type QueryDiscoveryConfig, type ResourceServerExtension, SettleResponse, type SupportedKind, type SupportedResponse, VerifyResponse, type X402MiddlewareConfig, type X402Request, type X402Server, type X402ServerConfig, bazaarExtension, createX402Server, declareDiscoveryExtension, resolveDefaultAsset, x402Middleware };
|