Skip to main content

Errors

BillPay uses HTTP status codes. 2xx means it worked, 4xx means something is wrong with your request, and 5xx means something went wrong at BillPay.

Error format​

Errors use the same envelope as successful responses. For validation errors, body lists each field that failed:

{
"statusCode": 400,
"message": "Validation error",
"body": {
"merchantReference": "must not be blank",
"amount": "must not be null"
},
"timestamp": "2026-10-29T09:19:16.968+00:00"
}

For other errors, there's no body:

{
"statusCode": 401,
"message": "Invalid API key",
"timestamp": "2026-10-29T09:19:16.968+00:00"
}
warning

Build your logic on the HTTP status, not on message. The wording of messages can change.

Status codes​

StatusMeaningWhat to doRetry?
400A field failed validation, the JSON is invalid, or Idempotency-Key is missing.Fix the fields listed in body.No
401The API key is missing, unknown, revoked, or from the other environment.Check the key and the base URL.No
403The key is valid but isn't allowed to do this.Check what the endpoint allows.No
404It doesn't exist, or it belongs to another merchant.Check the ID.No
405The path exists, but not with this HTTP method.Check the method.No
409Conflicts with something that exists, such as a used merchantReference or a reused Idempotency-Key.Use a new reference, or send the original body.No
413The body or file is too large.Send less.No
422A business rule refused it, for example a refund larger than what's left, or an account that isn't live yet.Read message.No
429Too many requests.Wait for Retry-After.Yes
500Unexpected error at BillPay.Contact support with the X-Request-Id.No
503A service BillPay depends on is down.Wait and retry.Yes
504A service BillPay depends on didn't answer in time.Wait and retry.Yes

When you retry, send the same Idempotency-Key. See Idempotency.

Handling errors in code​

One small wrapper keeps the error handling in one place:

billpay.js
export async function billpay(path, {method = 'GET', body, idempotencyKey} = {}) {
const res = await fetch(`${process.env.BILLPAY_BASE_URL}${path}`, {
method,
headers: {
'x-api-key': process.env.BILLPAY_API_KEY,
'Content-Type': 'application/json',
...(idempotencyKey && {'Idempotency-Key': idempotencyKey}),
},
body: body && JSON.stringify(body),
});

const result = await res.json().catch(() => null);
if (res.ok) return result.body;

const error = new Error(result?.message ?? `HTTP ${res.status}`);
error.status = res.status;
error.fields = result?.body ?? null; // which fields failed, on a 400
error.requestId = res.headers.get('X-Request-Id'); // send this to support
error.retryable = [429, 503, 504].includes(res.status);
throw error;
}
Usage
try {
const payment = await billpay('/api/v1/checkout/payments', {
method: 'POST',
body: paymentBody,
idempotencyKey: order.id,
});
} catch (err) {
console.error(`BillPay ${err.status} (${err.requestId}): ${err.message}`, err.fields);
}

Getting help​

Every response has an X-Request-Id header. Log it next to your errors. When you contact support, include it so we can find the exact request.