Summary
Update all tutorial agents to use the new x402 access token flow instead of the legacy JWT-based flow. The x402 implementation provides a simpler developer experience with delegated session keys that enable auto-ordering of credits.
Important: Tutorials should follow the x402 transport specifications for each integration type.
Background
The Nevermined API has migrated from the old protocol module (initializeAgentRequest / redeemCredits with JWT tokens) to a new x402-based solution. The SDKs (@nevermined-io/payments and payments-py) have been updated with the necessary functionality.
Key x402 Advantages
- No pre-purchase required: Subscribers don't need to check balance or order plans in advance
- Delegated permissions: x402 tokens include "order" (auto top-up) and "burn" (redeem credits) session keys
- Smart Account integration: Uses ERC-4337 Account Abstraction for seamless transactions
x402 Transport Specifications
Each tutorial type should follow the corresponding x402 transport spec:
Migration Details
Old Flow (to be replaced)
// Client
const credentials = await payments.agents.getAgentAccessToken(planId, agentId);
// Server
const agentRequest = await payments.requests.startProcessingRequest(agentId, authHeader, url, httpVerb);
if (!agentRequest.balance.isSubscriber || agentRequest.balance.balance < 1n) {
return res.status(402).json({ error: "Payment Required" });
}
await payments.requests.redeemCreditsFromRequest(requestId, token, credits);
New x402 Flow
// Client - much simpler, no balance check needed
const result = await payments.x402.getX402AccessToken(planId, agentId);
const x402Token = result.accessToken;
// Server
import { decodeAccessToken } from '@nevermined-io/payments'
const x402Token = authHeader.replace(/^Bearer\s+/i, "");
const decoded = decodeAccessToken(x402Token);
const verification = await payments.facilitator.verifyPermissions({
planId,
x402AccessToken: x402Token,
subscriberAddress: decoded.subscriberAddress,
maxAmount: BigInt(expectedCredits),
});
if (!verification.success) {
return res.status(402).json({ error: "Payment Required" });
}
// ... do work ...
const settlement = await payments.facilitator.settlePermissions({
planId,
x402AccessToken: x402Token,
subscriberAddress: decoded.subscriberAddress,
maxAmount: BigInt(actualCreditsUsed),
});
Tutorials to Update
Phase 1: HTTP Tutorials (follow http.md)
Phase 2: A2A Tutorial (follow a2a.md)
Phase 3: MCP Tutorials (follow mcp.md)
Reference Code & E2E Tests
TypeScript SDK (@nevermined-io/payments)
Python SDK (payments-py)
API Implementation (nvm-monorepo)
- Controller spec:
apps/api/src/x402/x402.controller.external.spec.ts
- Service:
apps/api/src/x402/x402.service.ts
- Controller:
apps/api/src/x402/x402.controller.ts
Key SDK Methods
Subscriber (Client-side)
| Method |
TypeScript |
Python |
| Get x402 token |
payments.x402.getX402AccessToken(planId, agentId) |
payments.x402.get_x402_access_token(plan_id, agent_id) |
Agent (Server-side)
| Method |
TypeScript |
Python |
| Decode token |
decodeAccessToken(token) |
decode_access_token(token) |
| Verify |
payments.facilitator.verifyPermissions({...}) |
payments.facilitator.verify_permissions(...) |
| Settle |
payments.facilitator.settlePermissions({...}) |
payments.facilitator.settle_permissions(...) |
Optional Parameters
The getX402AccessToken method supports optional parameters:
redemptionLimit: Max number of interactions allowed
orderLimit: Max spend limit in token units (wei)
expiration: ISO 8601 expiration date (e.g., "2025-02-01T10:00:00Z")
Acceptance Criteria
Related Documentation
Summary
Update all tutorial agents to use the new x402 access token flow instead of the legacy JWT-based flow. The x402 implementation provides a simpler developer experience with delegated session keys that enable auto-ordering of credits.
Important: Tutorials should follow the x402 transport specifications for each integration type.
Background
The Nevermined API has migrated from the old
protocolmodule (initializeAgentRequest / redeemCredits with JWT tokens) to a new x402-based solution. The SDKs (@nevermined-io/paymentsandpayments-py) have been updated with the necessary functionality.Key x402 Advantages
x402 Transport Specifications
Each tutorial type should follow the corresponding x402 transport spec:
Migration Details
Old Flow (to be replaced)
New x402 Flow
Tutorials to Update
Phase 1: HTTP Tutorials (follow http.md)
financial-agent/agent/index_nevermined.ts- Server-sidefinancial-agent/client/index_nevermined.ts- Client-sidemedical-agent/agent/index_nevermined.ts- Server-sidemedical-agent/client/index_nevermined.ts- Client-sidePhase 2: A2A Tutorial (follow a2a.md)
a2a-examples/a2a-agent-client-example/- Full migrationPhase 3: MCP Tutorials (follow mcp.md)
mcp-examples/weather-mcp/- TypeScript MCP servermcp-examples/weather-mcp-py/- Python MCP serverReference Code & E2E Tests
TypeScript SDK (
@nevermined-io/payments)tests/e2e/test_x402_e2e.test.tssrc/x402/facilitator-api.tssrc/x402/token.tssrc/utils.tsPython SDK (
payments-py)tests/e2e/test_x402_e2e.pytests/e2e/test_pay_as_you_go_x402_e2e.pypayments_py/x402/facilitator_api.pypayments_py/x402/token.pyAPI Implementation (
nvm-monorepo)apps/api/src/x402/x402.controller.external.spec.tsapps/api/src/x402/x402.service.tsapps/api/src/x402/x402.controller.tsKey SDK Methods
Subscriber (Client-side)
payments.x402.getX402AccessToken(planId, agentId)payments.x402.get_x402_access_token(plan_id, agent_id)Agent (Server-side)
decodeAccessToken(token)decode_access_token(token)payments.facilitator.verifyPermissions({...})payments.facilitator.verify_permissions(...)payments.facilitator.settlePermissions({...})payments.facilitator.settle_permissions(...)Optional Parameters
The
getX402AccessTokenmethod supports optional parameters:redemptionLimit: Max number of interactions allowedorderLimit: Max spend limit in token units (wei)expiration: ISO 8601 expiration date (e.g., "2025-02-01T10:00:00Z")Acceptance Criteria
facilitator.verifyPermissions()andsettlePermissions()Related Documentation