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.
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. Token generation requires a delegationConfig that controls spending limits and duration. You can either auto-create a delegation inline or reuse an existing one.

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