Faremeter API / fetch/src
fetch/src
Namespaces
Classes
WrappedFetchError
Defined in: packages/fetch/src/fetch.ts:14 Error thrown when payment fails after exhausting all retry attempts. Contains the final 402 response for inspection.Extends
Error
Constructors
Constructor
new WrappedFetchError(Defined in: packages/fetch/src/fetch.ts:15message,response):WrappedFetchError
Parameters
message
string
response
Response
The final 402 response after all retry attempts failed.
Returns
WrappedFetchError
Overrides
Error.constructor
Properties
response
response: Response
Defined in: packages/fetch/src/fetch.ts:18
The final 402 response after all retry attempts failed.
Type Aliases
WrapOpts
WrapOpts =Defined in: packages/fetch/src/fetch.ts:27 Configuration options for wrapping a fetch function with x402 payment handling.ProcessPaymentRequiredResponseOpts&object
Type declaration
initialRetryDelay?
Initial delay between retries in milliseconds. Doubles after each attempt. Defaults to 100.optionalinitialRetryDelay:number
phase1Fetch?
Optional fetch function for the initial request (phase 1). Defaults to phase2Fetch.optionalphase1Fetch: typeoffetch
retryCount?
Number of retry attempts after initial failure. Defaults to 2.optionalretryCount:number
returnPaymentFailure?
If true, returns the 402 response instead of throwing on payment failure.optionalreturnPaymentFailure:boolean
Functions
wrap()
wrap(Defined in: packages/fetch/src/fetch.ts:49 Wraps a fetch function with automatic x402 payment handling. When a 402 Payment Required response is received, the wrapper automatically processes the payment requirements, executes payment via the configured handlers, and retries the request with the payment header attached.phase2Fetch,options): (input,init) =>Promise<Response>
Parameters
phase2Fetch
{(input, init?): Promise<Response>; (input, init?): Promise<Response>; }
The fetch function to use for the paid request (phase 2)
options
WrapOpts
Configuration including payment handlers and retry settings
Returns
A wrapped fetch function with the same signature as native fetch(input,init):Promise<Response>
Parameters
input
RequestInfo | URL
init
RequestInit = {}
Returns
Promise<Response>