For the complete technical specification, see the x402 Smart Accounts Extension Spec.
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 with the required session keys:- 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
| Error | HTTP Status | Cause |
|---|---|---|
| Missing payment header | 402 | No payment-signature header |
| Invalid signature | 402 | Signature verification failed |
| Insufficient balance | 402 | User needs to purchase more credits |
| Expired session | 402 | Session key has expired |
| Settlement failed | 500 | On-chain transaction failed |