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
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
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 |
subscriber_address | str | Subscriber’s wallet address |
plan_id | str | Plan being used |
balance | int | Current credit balance |
error | str | Error message if invalid |
Settle Payment Permissions
Settlement burns credits after successfully processing a request:Settlement Response
| Field | Type | Description |
|---|---|---|
success | bool | Whether settlement succeeded |
credits_redeemed | int | Credits that were burned |
tx_hash | str | Blockchain transaction hash |
remaining_balance | int | Credits remaining |
Payment Required Object
TheX402PaymentRequired object specifies what payment is required:
Using the Helper
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 |