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:| Scheme | Network | Use Case | Settlement |
|---|---|---|---|
nvm:erc4337 | eip155:84532 | Crypto payments | ERC-4337 UserOps + session keys |
nvm:card-delegation | stripe | braintree | visa | Fiat/credit card | Provider charge + credit burn |
isCrypto: false use nvm:card-delegation; all others use nvm:erc4337. The SDK auto-detects the scheme via resolve_scheme(). The network value within nvm:card-delegation is determined by which provider issued the delegation being consumed (stripe, braintree, or visa).
Visa support
Visa delegations use the samenvm:card-delegation scheme and SDK surface as Stripe and Braintree, but two steps must happen in a browser before the SDK can consume them:
- Card enrolment — the cardholder enrols a Visa card through VGS Collect (PCI-compliant iframe) in the Nevermined webapp. The card is bound to a Visa Agentic Token via the VGS Credential Management Platform.
- Delegation creation — the cardholder approves a delegation via a WebAuthn/passkey (FIDO) device-binding ceremony embedded by Visa VTS. This produces a single-use
assuranceDatablob bound to the spending limit + duration + merchant context.
delegation_id to DelegationConfig and call get_x402_access_token as usual:
delegation_id reuse is the only supported pattern for Visa — create_delegation(provider="visa", ...) is rejected by the backend without the browser-only consumer_prompt + assurance_data blobs the SDK has no way to produce. When a Visa creation call fails this way, PaymentsError.code carries the backend BCK.VISA.0014 so consumers can branch programmatically.
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:list_payment_methods() accepts an optional provider keyword argument
('stripe' | 'braintree' | 'visa' | 'erc4337'). When set, it is forwarded as a
?provider= query string and only methods backed by that provider are returned.
Omit it (the default) to return methods from every provider.
PaymentMethodSummary fields:
| Field | Type | Description |
|---|---|---|
id | str | Payment method ID (e.g., pm_...) |
brand | str | Card brand (e.g., visa, mastercard) |
last4 | str | Last 4 digits of the card number |
exp_month | int | Card expiration month |
exp_year | int | Card expiration year |
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
| Field | Type | Description |
|---|---|---|
is_valid | bool | Whether verification passed |
invalid_reason | str | Reason for invalidity (if is_valid is false) |
payer | str | Payer’s wallet address |
agent_request_id | str | Agent request ID for observability tracking |
Settle Payment Permissions
Settlement burns credits after successfully processing a request:Settlement Response
| Field | Type | Description |
|---|---|---|
success | bool | Whether settlement succeeded |
error_reason | str | Reason for failure (if success is false) |
payer | str | Payer’s wallet address |
transaction | str | Blockchain transaction hash |
credits_redeemed | str | Credits that were burned |
remaining_balance | str | Credits remaining |
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 automatically set to stripe.
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
| Error | Description | Resolution |
|---|---|---|
invalid_token | Token is malformed | Generate a new token |
expired_token | Token has expired | Generate a new token |
insufficient_balance | Not enough credits | Order more credits |
invalid_plan | Plan ID mismatch | Use correct plan ID |
invalid_agent | Agent ID mismatch | Use correct agent ID |
Next Steps
Request Validation
More validation patterns
MCP Integration
x402 with MCP servers
MCP OAuth and x402 Discovery
Experimental MCP payment discovery metadata