Overview
x402 is a payment protocol that enables:- Permission Generation: Subscribers create access tokens for agents
- Permission Verification: Agents verify tokens without burning credits
- Permission Settlement: Agents burn credits after completing work
Supported Schemes
Nevermined supports two x402 payment schemes:
The scheme is determined by the plan’s pricing configuration. Plans with
isCrypto: false use nvm:card-delegation; all others use nvm:erc4337. For card-delegation plans, the network is derived from the plan’s fiatPaymentProvider metadata ('stripe' or 'braintree'). The SDK auto-detects both via resolve_scheme() / resolve_network().
Generate Payment Permissions
From Nevermined App
The easiest way to generate permissions is through the Nevermined App Permissions page:- Navigate to the permissions page
- Select your plan and agent
- Configure limits (optional)
- Generate the access token
From SDK
Card-Delegation Token Generation
For fiat plans usingnvm:card-delegation, pass X402TokenOptions with a DelegationConfig:
Auto Scheme Resolution
Useresolve_scheme() to auto-detect the correct scheme from plan metadata:
DelegationAPI
Create delegations and list enrolled payment methods:PaymentMethodSummary fields:
Token Structure
The x402 token is a base64-encoded JSON document:Verify Payment Permissions
Verification checks if a subscriber has valid permissions without burning credits:Verification Response
Settle Payment Permissions
Settlement burns credits after successfully processing a request:Settlement Response
Payment Required Object
TheX402PaymentRequired object specifies what payment is required. The scheme and network fields vary by payment type:
Using the Helpers
build_payment_required_for_plans delegates to build_payment_required internally. When scheme is omitted, the network defaults to eip155:84532 (Base Sepolia). When scheme="nvm:card-delegation", the network is auto-resolved from the plan’s fiatPaymentProvider metadata — either "stripe" or "braintree".
Complete Workflow Example
HTTP Flow
Best Practices
- Always verify before processing: Don’t do expensive work without verification
- Only settle on success: Don’t burn credits if processing fails
- Use agent_request_id: Include request IDs for tracking and debugging
- Handle 402 responses: Return proper payment required responses with scheme info
- Cache verifications carefully: Tokens can be used multiple times until limits are reached
Error Codes
Next Steps
Request Validation
More validation patterns
MCP Integration
x402 with MCP servers