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.
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 fee | Offer checkout can use | What you receive |
|---|---|---|
| You | Smaller, while the shortfall, counted as spread, keeps the total within your max fee | Less than the order amount. |
| Buyer | Larger, while the buyer's total stays within the order amount plus your max fee | The full order amount. Peer keeps the difference above its fee. |
| Split | Smaller, while Peer's fee can cover the shortfall | Your 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
| Property | Type | Required | Description |
|---|---|---|---|
amount | string | Yes | Positive decimal string, in the units of quoteMode |
quoteMode | CheckoutModeType | Yes | 'exact-token' or 'exact-fiat', see below |
enabledRails | string[] | No | Non-empty list of supported rails. Defaults to your account's rails. See rail-scoped availability |
destinationChainId | string | number | Yes | Payout 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 |
destinationToken | string | Yes | Payout token, for example 'USDC' |
destinationAddress | string | Yes | Payout address |
fiatCurrency | string | No | Defaults to your account's Default currency, then USD |
nearbyQuotesCount | number | No | Suggestions 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:amountis the order principal in USDC. When the buyer pays the fee, this is the USDC you want to receive.CheckoutMode.EXACT_FIAT:amountis the order principal infiatCurrency.
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;
};
| Property | Type | Description |
|---|---|---|
available | boolean | Whether at least one quote on the checked rails can currently fill amount under your fee settings |
quoteCount | number | How many quotes matched |
nearbySuggestions | object | null | Alternative amounts. Always null when available is true |
Each suggestion:
| Property | Type | Description |
|---|---|---|
suggestedAmount | string | The alternative order principal, in your quoteMode units. Under SPLIT it excludes the buyer's share of fees |
percentDifference | string | Signed difference from your requested amount |
rail | string | Payment rail that can fill it, for example 'venmo' |
paymentAmount | string | What 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 |
paymentCurrency | string | Currency of paymentAmount |
tokenAmount | string | Under SPLIT, the order principal in USDC after sharing quote costs by your fee share; otherwise the USDC from the quote |
conversionRate | string | Rate 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: falsedoes not guarantee suggestions. You can getnearbySuggestions: nullor{ below: [], above: [] }. Both mean there is nothing to offer, so check for both.nearbyQuotesCountis per direction.nearbyQuotesCount: 10can return up to 20 suggestions.- The order and per-payment limits apply. An
amountabove 10,000 USDC, after conversion inexact-fiatmode, fails with400 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 returnavailable: false. Suggestions stay within both limits. See order amount limits. available: trueis 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.
| Status | Error | Cause |
|---|---|---|
400 | Invalid request: nearbyQuotesCount: Number must be less than or equal to 10 | A field failed validation. The message summarizes the field errors; the full detail is on fieldErrors and formErrors |
400 | Merchant config not found | The account has no checkout configuration yet. Finish onboarding in the dashboard |
400 | AMOUNT_ABOVE_MAX | The amount, converted to USDC in exact-fiat mode, is above 10,000 USDC |
401 | Missing API key, Invalid API key | The X-API-Key header is missing or wrong |
403 | IP_NOT_ALLOWED | The request came from an address outside your IP allowlist |
428 | MERCHANT_WALLET_NOT_DELEGATED | Your 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 |
429 | Too many requests | Rate limited. See retries |
502 | Unable to resolve exchange rate for <CUR> | No exchange rate for that currency right now |
502 | Quote provider unavailable | Quotes could not be fetched. Retry |
502 | Unable to price non-Base payout for quote availability | The payout to another chain or token could not be priced |
500 | Internal server error | Unexpected 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:
| Message | Meaning |
|---|---|
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 response | The 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.