Skip to main content
All types are exported from @key0ai/key0 and are available as TypeScript imports:

ChallengeState

The state machine for a challenge record. All transitions are atomic and go through IChallengeStore.transition().
State transitions:

AccessRequest

Sent by the client agent to initiate a payment flow. The requestId serves as an idempotency key.
Provide either planId or routeId, not both. The resource field is only used for standalone route-based calls when proxyTo or fetchResource is set on SellerConfig. After payment Key0 proxies to the specified method + path and returns a ResourceResponse instead of an AccessGrant.
Used in: A2A Executor message/send (as a data part), x402 HTTP request parsing. Subscription example:
Route-based standalone example:

X402Challenge

Returned by the server after receiving an AccessRequest. Contains all information the client needs to make a USDC payment.
Used in: A2A Executor response, ChallengeEngine.requestAccess() return value. Example:

PaymentProof

Sent by the client after completing an on-chain USDC transfer. Contains the transaction hash for verification.
Used in: A2A Executor message/send (as a data part), ChallengeEngine.submitProof() input. Example:

ResourceResponse

Returned instead of AccessGrant for route-based standalone calls. Contains the proxied backend API response — no JWT is issued.
Used in: x402 HTTP 200 response body for standalone route calls; A2A Executor and MCP request_access tool result for route purchases. Example:
If the backend returns a non-2xx status, the challenge stays in PAID state (pending refund). The resource.status and resource.body reflect the backend’s error response. For free routes, txHash and explorerUrl are omitted.

PaymentInfo

Available as req.key0Payment in embedded per-request route handlers and as params.paymentInfo in fetchResource callbacks.

AccessGrant

Returned after successful payment verification for subscription plans. Contains the bearer token for accessing protected resources.
Used in: A2A Executor response, x402 HTTP 200 response body, MCP tool result. Example:

ChallengeRecord

The internal record stored in IChallengeStore. Contains all challenge state, timestamps, and the access grant once delivered. Not directly exposed in API responses, but useful for understanding the storage layer.
Key invariants:
  • state transitions are atomic via IChallengeStore.transition(id, fromState, toState, updates?, meta?).
  • amountRaw is the USDC amount in 6-decimal micro-units (e.g., 100000n = $0.10).
  • accessGrant is persisted durably in the PAID state before the DELIVERED transition, using an outbox pattern.

NetworkConfig

Configuration for a supported blockchain network.
Built-in configurations:

NetworkName

The two supported network identifiers.

Plan

Defines a pricing plan in the seller’s catalog.
Subscription plan example:

Route

Defines a callable API route in the seller’s route catalog. Routes are how you model free endpoints and pay-per-call endpoints.
Paid route example:

X402PaymentRequiredResponse

The x402 v2 payment-required response. Sent in 402 response bodies and the payment-required header (base64-encoded).

X402PaymentPayload

The payment payload sent by the client, either in the PAYMENT-SIGNATURE HTTP header (base64url-encoded) or in MCP _meta["x402/payment"].

X402SettleResponse

The settlement receipt, returned in the payment-response HTTP header (base64-encoded) and in MCP _meta["x402/payment-response"].

Error Codes

Complete reference of all Key0ErrorCode values and HTTP status codes.

State Machine

Visual guide to ChallengeState transitions and invariants.

ChallengeEngine

The engine that orchestrates these data models through the payment lifecycle.

POST /x402/access

The x402 HTTP endpoint that produces and consumes these types.