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.
The Nevermined x402 programmable extension
Nevermined extends x402 with thenvm: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 a402 response with a payment-required header:
PaymentPayload (Client Response)
The client responds with apayment-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 a402 Payment Required response with the payment-required header containing the payment requirements.
- TypeScript
- Python
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 withcreateDelegation (provider and currency are required), then request access tokens by passing its delegationId. Reuse the delegation until it expires or is exhausted.
- TypeScript
- Python
Step 3: Retry request with payment header
Send the x402 access token in thepayment-signature header:
- TypeScript
- Python
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 with402 and set the payment-required header with your payment requirements:
- TypeScript
- Python
Step 2: Verify with the facilitator
Verify the x402 token with the facilitator. The facilitator extractsplanId and subscriber address from the token:
- TypeScript
- Python
Step 3: Execute Workload
Step 4: Settle Payment
Settle after work is complete and return the settlement receipt in thepayment-response header:
- TypeScript
- Python
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