Skip to main content

Quote Availability

checkQuoteAvailability tells your backend whether an amount can be paid right now, before you create an order. When it cannot, the response carries nearby amounts that can.

Server-side only

This call sends your merchant API key in the X-API-Key header. Call it only from a trusted backend.

Basic usage​

Set BASE_PAYOUT_ADDRESS to your own Base payout address for these examples.

import { checkQuoteAvailability, CheckoutMode } from '@zkp2p/pay-sdk';

const availability = await checkQuoteAvailability(
{
amount: '25.00',
quoteMode: CheckoutMode.EXACT_TOKEN,
enabledRails: ['venmo'],
destinationChainId: 8453,
destinationToken: 'USDC',
destinationAddress: process.env.BASE_PAYOUT_ADDRESS!,
},
{
apiBaseUrl: 'https://api.pay.peer.xyz',
apiKey: process.env.ZKPAY_API_KEY!,
signal: AbortSignal.timeout(8_000),
},
);

if (availability.available) {
// Create the order with the same enabledRails: ['venmo'] selection.
}

Pass a signal so a slow response cannot block your own request handler.

Rail-scoped availability​

Availability means at least one of the checked rails can fill the amount. Only fiat rails are checked.

By default the API checks every rail enabled on your account, which says nothing about any one payment method: a Venmo-only checkout can pass on Cash App or PayPal liquidity while Venmo has no quote inside your fee cap. To scope the check, send the same non-empty enabledRails, amount, quote mode, currency and payout destination you will send to createCheckout. An explicit enabledRails replaces your account's rails here exactly as it does at order creation.

Executable amounts and fee buffers​

Checkout can fill an order from a peer offer slightly smaller or larger than the amount, without changing the order. Such an offer counts toward quoteCount and can make available true; it is not a nearby suggestion. Who absorbs the difference depends on who pays the fee:

Who pays the feeOffer checkout can useWhat you receive
YouSmaller, while the shortfall, counted as spread, keeps the total within your max feeLess than the order amount.
BuyerLarger, while the buyer's total stays within the order amount plus your max feeThe full order amount. Peer keeps the difference above its fee.
SplitSmaller, while Peer's fee can cover the shortfallYour usual net; Peer takes less fee.

On all-in pricing, and in exact-token checks when you pay the fee, Peer covers a small shortfall from its fee. The cap itself is explained in how the cap is checked.

Parameters​

params: QuoteAvailabilityRequest​

PropertyTypeRequiredDescription
amountstringYesPositive decimal string, in the units of quoteMode
quoteModeCheckoutModeTypeYes'exact-token' or 'exact-fiat', see below
enabledRailsstring[]NoNon-empty list of supported rails. Defaults to your account's rails. See rail-scoped availability
destinationChainIdstring | numberYesPayout chain as a positive decimal integer: 8453 or '8453' for Base. Hex ('0x2105'), signed ('+8453') and zero values throw a TypeError before any request is made
destinationTokenstringYesPayout token, for example 'USDC'
destinationAddressstringYesPayout address
fiatCurrencystringNoDefaults to your account's Default currency, then USD
nearbyQuotesCountnumberNoSuggestions per direction, an integer from 1 to 10. Default 3

CheckoutModeType is the type; CheckoutMode is the const object you read values from (CheckoutMode.EXACT_TOKEN).

exact-token vs exact-fiat​

  • CheckoutMode.EXACT_TOKEN: amount is the order principal in USDC. When the buyer pays the fee, this is the USDC you want to receive.
  • CheckoutMode.EXACT_FIAT: amount is the order principal in fiatCurrency.

Use the mode you will use at order creation; suggestions come back in its units. The check uses your account's current fee payer and buyer share and takes no per-order fee override, so its result applies to orders created with your account's fee settings. Under SPLIT, it includes the buyer's share of fees when probing liquidity.

Response​

type QuoteAvailability = {
available: boolean;
quoteCount: number;
nearbySuggestions: {
below: QuoteAvailabilitySuggestion[];
above: QuoteAvailabilitySuggestion[];
} | null;
};
PropertyTypeDescription
availablebooleanWhether at least one quote on the checked rails can currently fill amount under your fee settings
quoteCountnumberHow many quotes matched
nearbySuggestionsobject | nullAlternative amounts. Always null when available is true

Each suggestion:

PropertyTypeDescription
suggestedAmountstringThe alternative order principal, in your quoteMode units. Under SPLIT it excludes the buyer's share of fees
percentDifferencestringSigned difference from your requested amount
railstringPayment rail that can fill it, for example 'venmo'
paymentAmountstringWhat the customer pays, including the fee and spread they bear: all of it when the buyer pays, their share under split. When you pay the fee and check exact-token, it is the peer's price for the USDC, with the spread but not the fee, while checkout charges suggestedAmount at the market rate. See what the quoted price includes
paymentCurrencystringCurrency of paymentAmount
tokenAmountstringUnder SPLIT, the order principal in USDC after sharing quote costs by your fee share; otherwise the USDC from the quote
conversionRatestringRate used for the quote

below holds amounts smaller than you asked for, above larger. An exact-token check always returns USDC suggestions, even when the liquidity is quoted in another fiat currency. Under SPLIT, create or resize the order with suggestedAmount, never the gross paymentAmount, or the buyer's share of fees is added twice; tokenAmount there is principal, not what settles to you.

Behavior notes​

  • available: false does not guarantee suggestions. You can get nearbySuggestions: null or { below: [], above: [] }. Both mean there is nothing to offer, so check for both.
  • nearbyQuotesCount is per direction. nearbyQuotesCount: 10 can return up to 20 suggestions.
  • The order and per-payment limits apply. An amount above 10,000 USDC, after conversion in exact-fiat mode, fails with 400 AMOUNT_ABOVE_MAX, as at order creation. A quote whose payment would settle more than 10,000 USDC onchain, fees included, does not count, so a buyer-pays amount near the limit can return available: false. Suggestions stay within both limits. See order amount limits.
  • available: true is advisory. The check reserves nothing. Liquidity can move before you create the order, so always handle order-creation failure.

Where the destination fields come from​

All three destination fields are required here, even though createCheckout treats them as optional and falls back to your account settings.

getMerchant supplies two of them:

import { getMerchant } from '@zkp2p/pay-sdk';

const merchant = await getMerchant({ apiBaseUrl, apiKey });

if (merchant.merchantConfig === null) {
throw new Error('Merchant config is not set up yet.');
}

const { destinationChainId, destinationToken } = merchant.merchantConfig;

merchantConfig has no destinationAddress. Pass the same destinationAddress you pass to createCheckout; if you leave it out there, use your payout wallet from Settings, Account, Payout wallets. Re-read these per checkout flow rather than caching them, because payout settings can change.

Worked example​

Check first, then either create the order or offer the customer an amount that works:

import { checkQuoteAvailability, createCheckout, CheckoutMode } from '@zkp2p/pay-sdk';

const params = {
amount: '25.00',
quoteMode: CheckoutMode.EXACT_TOKEN,
enabledRails: ['venmo'],
destinationChainId: 8453,
destinationToken: 'USDC',
destinationAddress: process.env.BASE_PAYOUT_ADDRESS!,
};

// A fresh signal per call: AbortSignal.timeout starts counting when it is created.
const opts = () => ({
apiBaseUrl: 'https://api.pay.peer.xyz',
checkoutBaseUrl: 'https://pay.peer.xyz',
apiKey: process.env.ZKPAY_API_KEY!,
signal: AbortSignal.timeout(8_000),
});

export async function startCheckout(merchantOrderId: string) {
const availability = await checkQuoteAvailability(params, opts());

if (availability.available) {
const checkout = await createCheckout(
{
requestedUsdcAmount: params.amount,
enabledRails: params.enabledRails,
destinationChainId: params.destinationChainId,
destinationToken: params.destinationToken,
destinationAddress: params.destinationAddress,
notes: { merchantOrderId },
},
opts(),
);
return { status: 'ready', checkoutUrl: checkout.checkoutUrl };
}

const alternatives = [
...(availability.nearbySuggestions?.below ?? []),
...(availability.nearbySuggestions?.above ?? []),
];

if (alternatives.length === 0) {
return { status: 'no_liquidity' };
}

return {
status: 'alternatives',
options: alternatives.map((option) => ({
amount: option.suggestedAmount,
rail: option.rail,
customerPays: `${option.paymentAmount} ${option.paymentCurrency}`,
})),
};
}

checkQuoteAvailability ignores checkoutBaseUrl, so one options object serves both calls.

Common errors​

The SDK throws a PayApiError carrying the HTTP status as statusCode, the errorCode when there is one, and the server message. This table covers what you are most likely to hit; it is not exhaustive.

StatusErrorCause
400Invalid request: nearbyQuotesCount: Number must be less than or equal to 10A field failed validation. The message summarizes the field errors; the full detail is on fieldErrors and formErrors
400Merchant config not foundThe account has no checkout configuration yet. Finish onboarding in the dashboard
400AMOUNT_ABOVE_MAXThe amount, converted to USDC in exact-fiat mode, is above 10,000 USDC
401Missing API key, Invalid API keyThe X-API-Key header is missing or wrong
403IP_NOT_ALLOWEDThe request came from an address outside your IP allowlist
428MERCHANT_WALLET_NOT_DELEGATEDYour account signs its own payments, and its merchant wallet has not given Peer permission to sign for it. Checkout cannot quote or take payments until it does; the owner sets this up by signing in to the dashboard. If it persists, contact Peer support
429Too many requestsRate limited. See retries
502Unable to resolve exchange rate for <CUR>No exchange rate for that currency right now
502Quote provider unavailableQuotes could not be fetched. Retry
502Unable to price non-Base payout for quote availabilityThe payout to another chain or token could not be priced
500Internal server errorUnexpected server error

Retries​

PayApiError carries the HTTP status but not the response headers. To read the rate-limit headers, pass a custom fetcher and inspect the response before returning it:

const fetcher: typeof fetch = async (input, init) => {
const response = await fetch(input, init);

if (response.status === 429) {
// Seconds until you may retry. There is no standard Retry-After header.
recordRetryAfter(Number(response.headers.get('x-retry-after')));
}

return response;
};

Malformed responses​

The SDK never hands back a partly valid object. If a response does not match the documented shape it throws, and the message says which layer rejected it:

MessageMeaning
Malformed API response envelope: …The outer { success, responseObject } envelope was wrong or missing, usually a proxy or gateway answering instead of the API
Malformed quote availability responseThe envelope was fine but the payload was not, for example a bad quoteCount or a suggestion missing a field

Both are plain Errors, not PayApiError.