From 19440c420999d788e6fbf7fafe4796cc775dc003 Mon Sep 17 00:00:00 2001 From: Matias Date: Thu, 19 Feb 2026 11:27:08 -0300 Subject: [PATCH] feat: add custom paymentFetch option to proxy --- src/proxy.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/proxy.ts b/src/proxy.ts index 4ac1882..d3be8a4 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -788,6 +788,18 @@ export type ProxyOptions = { /** Port to listen on (default: 8402) */ port?: number; routingConfig?: Partial; + /** + * Custom payment-enabled fetch function. When provided, replaces the built-in + * x402 payment handler. Use this to integrate alternative payment systems + * (e.g., spend limits, budget enforcement, or custom payment flows). + * + * If not provided, uses built-in createPaymentFetch with walletKey. + */ + paymentFetch?: ( + input: RequestInfo | URL, + init?: RequestInit, + preAuth?: PreAuthParams, + ) => Promise; /** Request timeout in ms (default: 180000 = 3 minutes). Covers on-chain tx + LLM response. */ requestTimeoutMs?: number; /** Skip balance checks (for testing only). Default: false */ @@ -956,9 +968,10 @@ export async function startProxy(options: ProxyOptions): Promise { }; } - // Create x402 payment-enabled fetch from wallet private key + // Create x402 payment-enabled fetch from wallet private key (or use custom paymentFetch) const account = privateKeyToAccount(options.walletKey as `0x${string}`); - const { fetch: payFetch } = createPaymentFetch(options.walletKey as `0x${string}`); + const payFetch = + options.paymentFetch ?? createPaymentFetch(options.walletKey as `0x${string}`).fetch; // Create balance monitor for pre-request checks const balanceMonitor = new BalanceMonitor(account.address);