Skip to main content
This guide explains the end-to-end x402 flow from both the subscriber (client) and resource server (API/agent) perspectives.
For the complete technical specification, see the x402 Smart Accounts Extension Spec.
This page covers the x402 protocol. The Payments Facilitator also speaks MPP (Merchant Payment Protocol) against the same plans and credits — see Accepting MPP payments for the seller side and Paying an MPP-protected service for the buyer side.
If you’re new to the programmable extension concepts, see:

The Nevermined x402 programmable extension

Nevermined extends x402 with the nvm:erc4337 scheme, enabling programmable settlement (credits/subscriptions/PAYG) using ERC-4337 smart accounts and session keys.

PaymentRequired Response (402)

When a server requires payment, it returns a 402 response with a payment-required header:

PaymentPayload (Client Response)

The client responds with a payment-signature header containing the x402 access token:

Subscriber flow (client side)

Step 1: Discover payment requirements (HTTP 402)

When calling a protected endpoint, the server returns a 402 Payment Required response with the payment-required header containing the payment requirements.

Step 2: Generate x402 access token

Use the Nevermined SDK to generate an x402 access token. The supported flow is create-first: create a delegation once with createDelegation (provider and currency are required), then request access tokens by passing its delegationId. Reuse the delegation until it expires or is exhausted.
Inline create-on-the-fly is deprecated. Passing creation fields (spendingLimitCents, durationSecs, providerPaymentMethodId, cardId, currency) directly in delegationConfig instead of a delegationId still works but emits a runtime deprecation warning. Create the delegation first, then pass only { delegationId }.

Step 3: Retry request with payment header

Send the x402 access token in the payment-signature header:

Resource server flow (API/agent side)

Recommended: For Express.js applications, use the paymentMiddleware which handles all of this automatically with one line of code.

Step 1: Return 402 when payment is missing

If the payment header is not present, respond with 402 and set the payment-required header with your payment requirements:

Step 2: Verify with the facilitator

Verify the x402 token with the facilitator. The facilitator extracts planId and subscriber address from the token:

Step 3: Execute Workload

Step 4: Settle Payment

Settle after work is complete and return the settlement receipt in the payment-response header:

Complete Request Lifecycle

Error Handling

Next Steps

Express.js Integration

One-line payment protection with Express middleware

Payment Models

Configure credits, subscriptions, and dynamic pricing

x402 Integration

Complete integration guide with code examples

Technical Spec

Full x402 Smart Accounts specification