Skip to main content
This guide covers the x402 payment protocol for verifying permissions and settling payments.

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
The protocol is named after HTTP status code 402 (Payment Required).

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:
  1. Navigate to the permissions page
  2. Select your plan and agent
  3. Configure limits (optional)
  4. Generate the access token

From SDK

Card-Delegation Token Generation

For fiat plans using nvm:card-delegation, pass X402TokenOptions with a DelegationConfig:

Auto Scheme Resolution

Use resolve_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

The X402PaymentRequired object specifies what payment is required. The scheme and network fields vary by payment type:

Using the Helpers

For a single plan, 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

  1. Always verify before processing: Don’t do expensive work without verification
  2. Only settle on success: Don’t burn credits if processing fails
  3. Use agent_request_id: Include request IDs for tracking and debugging
  4. Handle 402 responses: Return proper payment required responses with scheme info
  5. 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