nevermined-paymentsIntegrates Nevermined payment infrastructure into AI agents, MCP servers, Google A2A agents, and REST APIs. Handles x402 protocol, credit billing, payment plans, and SDK integration for TypeScript (@nevermined-io/payments) and Python (payments-py).
Install via ClawdBot CLI:
clawdbot install aaitor/nevermined-paymentsNevermined provides financial rails for AI agents β real-time monetization, access control, and payments. This skill gives you everything needed to:
The x402 protocol uses HTTP 402 responses to advertise payment requirements. Clients acquire an access token and retry the request. The server verifies permissions, executes the workload, then settles (burns credits).
npm install @nevermined-io/payments or pip install payments-py)references/payment-plans.md)| Variable | Required | Description |
|---|---|---|
| NVM_API_KEY | Yes | Your Nevermined API key (get it at nevermined.app β Settings β API Keys) |
| NVM_ENVIRONMENT | Yes | sandbox for testing, live for production |
| NVM_PLAN_ID | Yes | The plan ID from registration |
| NVM_AGENT_ID | Sometimes | Required for MCP servers and plans with multiple agents |
| BUILDER_ADDRESS | For registration | Wallet address to receive payments |
.env Template# Required
NVM_API_KEY=your-api-key-here
NVM_ENVIRONMENT=sandbox
NVM_PLAN_ID=your-plan-id-here
# Required for MCP servers or multi-agent plans
NVM_AGENT_ID=your-agent-id-here
# Required for registration
BUILDER_ADDRESS=0xYourWalletAddress
package.json must include "type": "module" for the @nevermined-io/payments/express subpath import to work.pip install payments-py[fastapi] β the [fastapi] extra is required for the middleware.npm install @nevermined-io/payments
import { Payments } from '@nevermined-io/payments'
const payments = Payments.getInstance({
nvmApiKey: process.env.NVM_API_KEY!,
environment: 'sandbox'
})
pip install payments-py
import os
from payments_py import Payments, PaymentOptions
payments = Payments.get_instance(
PaymentOptions(
nvm_api_key=os.environ["NVM_API_KEY"],
environment="sandbox"
)
)
Every Nevermined payment integration follows this 5-step pattern:
payment-required header (base64-encoded JSON with plan info)payments.x402.getX402AccessToken(planId, agentId)payment-signature header containing the tokenpayment-response headerChoose the integration that matches your stack:
| Framework | Language | Reference | Key Import |
|---|---|---|---|
| Express.js | TypeScript/JS | references/express-integration.md | paymentMiddleware from @nevermined-io/payments/express |
| FastAPI | Python | references/fastapi-integration.md | PaymentMiddleware from payments_py.x402.fastapi |
| Strands Agent | Python | references/strands-integration.md | @requires_payment from payments_py.x402.strands |
| MCP Server | TypeScript | references/mcp-paywall.md | payments.mcp.start() / payments.mcp.registerTool() |
| Google A2A | TS / Python | references/a2a-integration.md | payments.a2a.start() / payments.a2a.buildPaymentAgentCard() |
| Any HTTP | Any | references/x402-protocol.md | Manual verify/settle via facilitator API |
| Client-side | TS / Python | references/client-integration.md | payments.x402.getX402AccessToken() |
@nevermined-io/payments)// Initialize
const payments = Payments.getInstance({ nvmApiKey, environment })
// Register agent + plan
const { agentId, planId } = await payments.agents.registerAgentAndPlan(
agentMetadata, agentApi, planMetadata, priceConfig, creditsConfig
)
// Subscriber: order plan and get token
await payments.plans.orderPlan(planId)
const balance = await payments.plans.getPlanBalance(planId)
const { accessToken } = await payments.x402.getX402AccessToken(planId, agentId)
// Server: verify and settle
const verification = await payments.facilitator.verifyPermissions({
paymentRequired, x402AccessToken: token, maxAmount: BigInt(credits)
})
const settlement = await payments.facilitator.settlePermissions({
paymentRequired, x402AccessToken: token, maxAmount: BigInt(creditsUsed)
})
// Helpers
import { buildPaymentRequired } from '@nevermined-io/payments'
import { paymentMiddleware, X402_HEADERS } from '@nevermined-io/payments/express'
// MCP server
payments.mcp.registerTool(name, config, handler, { credits: 5n })
const { info, stop } = await payments.mcp.start({ port, agentId, serverName })
// A2A server
const agentCard = payments.a2a.buildPaymentAgentCard(baseCard, { paymentType, credits, planId, agentId })
const server = await payments.a2a.start({ port, basePath: '/a2a/', agentCard, executor })
// A2A client
const client = payments.a2a.getClient({ agentBaseUrl, agentId, planId })
await client.sendMessage("Hello", accessToken)
payments-py)# Initialize
payments = Payments.get_instance(PaymentOptions(nvm_api_key=key, environment="sandbox"))
# Register agent + plan
result = payments.agents.register_agent_and_plan(
agent_metadata, agent_api, plan_metadata, price_config, credits_config
)
# Subscriber: order plan and get token
payments.plans.order_plan(plan_id)
balance = payments.plans.get_plan_balance(plan_id)
token_res = payments.x402.get_x402_access_token(plan_id, agent_id)
# Server: verify and settle
verification = payments.facilitator.verify_permissions(
payment_required=pr, x402_access_token=token, max_amount=str(credits)
)
settlement = payments.facilitator.settle_permissions(
payment_required=pr, x402_access_token=token, max_amount=str(credits_used)
)
# Helpers
from payments_py.x402.helpers import build_payment_required
from payments_py.x402.fastapi import PaymentMiddleware
from payments_py.x402.strands import requires_payment
# A2A server
from payments_py.a2a.agent_card import build_payment_agent_card
from payments_py.a2a.server import PaymentsA2AServer
agent_card = build_payment_agent_card(base_card, { ... })
server = PaymentsA2AServer.start(agent_card=agent_card, executor=executor, payments_service=payments, port=3005)
# A2A client
client = payments.a2a.get_client(agent_base_url=url, agent_id=agent_id, plan_id=plan_id)
All x402 v2 integrations use these three HTTP headers:
| Header | Direction | Description |
|---|---|---|
| payment-signature | Client β Server | x402 access token |
| payment-required | Server β Client (402) | Base64-encoded JSON with plan requirements |
| payment-response | Server β Client (200) | Base64-encoded JSON settlement receipt |
The payment-required payload structure:
{
"x402Version": 2,
"accepts": [{
"scheme": "nvm:erc4337",
"network": "eip155:84532",
"planId": "<plan-id>",
"extra": { "agentId": "<agent-id>" }
}]
}
Nevermined supports several plan types:
See references/payment-plans.md for plan registration code.
import { paymentMiddleware } from '@nevermined-io/payments/express'
app.use(paymentMiddleware(payments, {
'POST /ask': { planId: PLAN_ID, credits: 1 },
'POST /generate': { planId: PLAN_ID, credits: 5 }
}))
from payments_py.x402.fastapi import PaymentMiddleware
app.add_middleware(
PaymentMiddleware,
payments=payments,
routes={
"POST /ask": {"plan_id": PLAN_ID, "credits": 1},
"POST /generate": {"plan_id": PLAN_ID, "credits": 5}
}
)
paymentMiddleware(payments, {
'POST /generate': {
planId: PLAN_ID,
credits: (req, res) => {
const tokens = res.locals.tokenCount || 100
return Math.ceil(tokens / 100)
}
}
})
async def calculate_credits(request: Request) -> int:
body = await request.json()
max_tokens = body.get("max_tokens", 100)
return max(1, max_tokens // 100)
app.add_middleware(
PaymentMiddleware,
payments=payments,
routes={"POST /generate": {"plan_id": PLAN_ID, "credits": calculate_credits}}
)
payments.mcp.registerTool(
"weather.today",
{ title: "Today's Weather", inputSchema: z.object({ city: z.string() }) },
async (args, extra, context) => ({
content: [{ type: "text", text: `Weather in ${args.city}: Sunny, 25C` }]
}),
{ credits: 5n }
)
const { info, stop } = await payments.mcp.start({
port: 3000,
agentId: process.env.NVM_AGENT_ID!,
serverName: "my-server"
})
from strands import Agent, tool
from payments_py.x402.strands import requires_payment
@tool(context=True)
@requires_payment(payments=payments, plan_id=PLAN_ID, credits=1)
def analyze_data(query: str, tool_context=None) -> dict:
return {"status": "success", "content": [{"text": f"Analysis: {query}"}]}
agent = Agent(tools=[analyze_data])
const agentCard = payments.a2a.buildPaymentAgentCard(baseAgentCard, {
paymentType: "dynamic",
credits: 1,
planId: process.env.NVM_PLAN_ID!,
agentId: process.env.NVM_AGENT_ID!,
})
const server = await payments.a2a.start({
port: 3005,
basePath: '/a2a/',
agentCard,
executor: new MyExecutor(),
})
from payments_py.a2a.agent_card import build_payment_agent_card
from payments_py.a2a.server import PaymentsA2AServer
agent_card = build_payment_agent_card(base_agent_card, {
"paymentType": "dynamic",
"credits": 1,
"planId": os.environ["NVM_PLAN_ID"],
"agentId": os.environ["NVM_AGENT_ID"],
})
server = PaymentsA2AServer.start(
agent_card=agent_card,
executor=MyExecutor(),
payments_service=payments,
port=3005,
base_path="/a2a/",
)
const client = payments.a2a.getClient({
agentBaseUrl: 'http://localhost:3005/a2a/',
agentId: AGENT_ID,
planId: PLAN_ID,
})
const { accessToken } = await payments.x402.getX402AccessToken(PLAN_ID, AGENT_ID)
const response = await client.sendMessage("Analyze this data", accessToken)
When a developer asks you to integrate Nevermined payments, gather ALL required information in a single question before generating code. This avoids multiple back-and-forth interactions.
Ask the developer once for:
POST /chat = 1 credit, POST /generate = 5 credits)NVM_API_KEY? If not, direct them to nevermined.app β Settings β API KeysNVM_PLAN_ID? If not, do they need a registration script too?sandbox (testing) or live (production)?If they need plan registration, also ask:
BUILDER_ADDRESS): The wallet that receives paymentsExample combined prompt to offer the developer:
I need to set up Nevermined payments. Here's my info:
- Framework: Express.js
- Routes: POST /chat (1 credit), POST /summarize (3 credits)
- I need a registration script too
- Plan: "Starter Plan", 100 credits for 10 USDC
- Environment: sandbox
- My API key is in the NVM_API_KEY env var
- My wallet: 0x1234...
With this information, generate both the registration script and the payment-protected server in a single response.
Register your agent and plan programmatically β see references/payment-plans.md for complete code.
// TypeScript
const { agentId, planId } = await payments.agents.registerAgentAndPlan(
{ name: 'My Agent', description: 'AI service', tags: ['ai'], dateCreated: new Date() },
{ endpoints: [{ POST: 'https://your-api.com/query' }] },
{ name: 'Starter Plan', description: '100 requests for $10', dateCreated: new Date() },
payments.plans.getERC20PriceConfig(10_000_000n, USDC_ADDRESS, process.env.BUILDER_ADDRESS!),
payments.plans.getFixedCreditsConfig(100n, 1n)
)
# Python
result = payments.agents.register_agent_and_plan(
agent_metadata={'name': 'My Agent', 'description': 'AI service', 'tags': ['ai']},
agent_api={'endpoints': [{'POST': 'https://your-api.com/query'}]},
plan_metadata={'name': 'Starter Plan', 'description': '100 requests for $10'},
price_config=get_erc20_price_config(10_000_000, USDC_ADDRESS, os.environ['BUILDER_ADDRESS']),
credits_config=get_fixed_credits_config(100, 1)
)
agentId and planId for your .env file# 1. Install CLI
npm install -g @nevermined-io/cli
# 2. Configure (use sandbox for testing)
nvm config init --api-key "$NVM_API_KEY" --environment sandbox
# 3. Register agent and plan together
nvm agents register-agent-and-plan \
--agent-metadata '{"name":"My Agent","description":"AI service"}' \
--agent-api '{"endpoints":[{"POST":"https://your-api.com/query"}]}' \
--plan-metadata '{"name":"Starter Plan","description":"100 requests"}' \
--price-config '{"tokenAddress":"0x036CbD53842c5426634e7929541eC2318f3dCF7e","price":10000000,"amountOfCredits":100}' \
--credits-config '{"minCreditsRequired":1,"minCreditsToCharge":1,"maxCreditsToCharge":10}'
# 4. List your plans
nvm plans get-plans
# 5. As a subscriber: order a plan and get an x402 token
nvm plans order-plan $PLAN_ID
nvm x402token get-x402-access-token $PLAN_ID --agent-id $AGENT_ID
# 6. Test against your running server
curl -X POST http://localhost:3000/chat \
-H "Content-Type: application/json" \
-H "payment-signature: $TOKEN" \
-d '{"message": "Hello"}'
| Symptom | Cause | Fix |
|---|---|---|
| HTTP 402 returned | No payment-signature header or invalid/expired token | Generate a fresh token via getX402AccessToken |
| MCP error -32003 | Payment Required β no token, invalid token, or insufficient credits | Check subscriber has purchased plan and has credits remaining |
| MCP error -32002 | Server misconfiguration | Verify NVM_API_KEY, NVM_PLAN_ID, and NVM_AGENT_ID are set correctly |
| verification.isValid is false | Token expired, wrong plan, or insufficient credits | Re-order the plan or generate a new token |
| Credits not deducting | Settlement not called after request | Ensure you call settlePermissions after processing (middleware does this automatically) |
| payment-required header missing | Server not returning 402 properly | Use buildPaymentRequired() helper or framework middleware |
https://docs.nevermined.app/mcp β search Nevermined docs from any MCP client@nevermined-io/payments on npmpayments-py on PyPIAI Usage Analysis
Analysis is being generated⦠refresh in a few seconds.
Use the mcporter CLI to list, configure, auth, and call MCP servers/tools directly (HTTP or stdio), including ad-hoc servers, config edits, and CLI/type generation.
Connect to 100+ APIs (Google Workspace, Microsoft 365, GitHub, Notion, Slack, Airtable, HubSpot, etc.) with managed OAuth. Use this skill when users want to...
Build, debug, and deploy websites using HTML, CSS, JavaScript, and modern frameworks following production best practices.
YouTube Data API integration with managed OAuth. Search videos, manage playlists, access channel data, and interact with comments. Use this skill when users want to interact with YouTube. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway).
Scaffold, test, document, and debug REST and GraphQL APIs. Use when the user needs to create API endpoints, write integration tests, generate OpenAPI specs, test with curl, mock APIs, or troubleshoot HTTP issues.
Search for jobs across LinkedIn, Indeed, Glassdoor, ZipRecruiter, Google Jobs, Bayt, Naukri, and BDJobs using the JobSpy MCP server.