Error Codes
All errors raised by the Key0 SDK use theKey0Error class, which extends the native Error with a machine-readable error code, an HTTP status code, and optional structured details.
Key0Error Class
| Property | Type | Description |
|---|---|---|
code | Key0ErrorCode | Machine-readable error code (see table below). |
httpStatus | number | Suggested HTTP status code for the response. |
message | string | Human-readable description of the error. |
details | Record<string, unknown> | Optional structured data. Present on PROOF_ALREADY_REDEEMED (contains cached grant). |
name | string | Always "Key0Error". |
toJSON()
Returns a serializable object suitable for HTTP response bodies. Thedetails field is only included when present.
Error Codes Reference
| Code | HTTP Status | When Thrown |
|---|---|---|
TIER_NOT_FOUND | 400 | The planId in the request does not match any plan in SellerConfig.plans. |
CHALLENGE_NOT_FOUND | 404 | The challengeId does not exist in the challenge store. |
CHALLENGE_EXPIRED | 401 / 410 | The challenge TTL has elapsed, or the access token exp claim is in the past. |
CHAIN_MISMATCH | 400 | The on-chain transaction was executed on a different chain than expected. |
AMOUNT_MISMATCH | 400 | The on-chain transfer amount is less than the required unitAmount. |
TX_UNCONFIRMED | 400 | The transaction has not yet been mined (no receipt available). |
TX_ALREADY_REDEEMED | 409 | The txHash has already been used for a different challenge. Prevents double-spend. |
PROOF_ALREADY_REDEEMED | 409 | The payment proof for this request has already been submitted. The cached AccessGrant is returned in details.grant. |
INVALID_REQUEST | 400 / 401 | Malformed request body, missing required fields, or invalid/missing access token. |
INVALID_PROOF | 400 | The payment proof failed on-chain verification (wrong recipient, wrong token, etc.). |
PAYMENT_FAILED | 402 | On-chain settlement failed after verification. |
ADAPTER_ERROR | 500 | The payment adapter (X402Adapter) encountered an internal error during verification. |
TOKEN_ISSUE_FAILED | 502 | The fetchResourceCredentials callback threw an error or the remote endpoint returned a non-2xx response. |
TOKEN_ISSUE_TIMEOUT | 504 | The fetchResourceCredentials callback (or remote token endpoint) did not respond within the configured timeout. |
INTERNAL_ERROR | 500 | An unexpected internal error occurred. Catch-all for unhandled exceptions. |
JSON Error Response
All Key0 HTTP integrations (Express, Hono, Fastify) serialize errors usingKey0Error.toJSON(). The response body follows this shape:
details is present (e.g., PROOF_ALREADY_REDEEMED):

