Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,18 @@ export type ProxyOptions = {
/** Port to listen on (default: 8402) */
port?: number;
routingConfig?: Partial<RoutingConfig>;
/**
* 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<Response>;
/** Request timeout in ms (default: 180000 = 3 minutes). Covers on-chain tx + LLM response. */
requestTimeoutMs?: number;
/** Skip balance checks (for testing only). Default: false */
Expand Down Expand Up @@ -1069,9 +1081,10 @@ export async function startProxy(options: ProxyOptions): Promise<ProxyHandle> {
};
}

// 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);
Expand Down