The SDK throws typed errors for payment failures, API errors, and configuration issues.
SDK error classes
import { SDKError, APIError, PaymentRequiredSDKError } from "@galliun/sdk";
try {
const response = await client.fetch("/p/demo/summarize", {
method: "POST",
body: JSON.stringify({ text: "..." }),
});
} catch (error) {
if (error instanceof PaymentRequiredSDKError) {
// Payment rejected after retry
console.log(error.code); // "payment_required"
}
if (error instanceof APIError) {
console.log(error.statusCode, error.responseBody);
const body = error.responseBody as { error?: string };
if (body.error === "endpoint_unavailable") {
console.log("The endpoint is temporarily unavailable.");
}
if (body.error === "payment_verification_failed") {
console.log("Payment could not be verified.");
}
}
if (error instanceof SDKError) {
console.log(error.message); // missing wallet, auth failures, etc.
}
}
Common API error codes
| Code | HTTP | Meaning |
|---|---|---|
payment_required |
402 | Payment missing or invalid |
payment_verification_failed |
402/400 | On-chain verification failed |
payment_expired |
402 | Requirement past expiresAt |
payment_reused / payment_replay |
402 | Transaction or nonce already used |
unsupported_chain |
402 | Chain not in accepts array |
insufficient_amount |
402 | Paid amount below required |
endpoint_unavailable |
503 | Endpoint disabled or unhealthy |
execution_failed_after_payment |
502 | Upstream failed after capture; refund may be recommended to the provider |
refund_recommended |
502 | Galliun recorded a refund recommendation — provider refunds from their wallet |
Recovery guidance
payment_expired— retry the original request to get a fresh 402payment_reused— submit a new on-chain transactionendpoint_unavailable— wait for endpoint health recovery; no payment attemptedunsupported_chain— switch clientchainor configure payment rail