Skip to main content
This flow is the other side of the market: instead of paying, your agent gets paid. Point a coding agent (Claude Code, Cursor, an OpenAI agent) at your existing service and the Nevermined SDK, and it wires an x402 paywall in front of the endpoints you choose — so every call costs credits.

Useful for

  • Monetizing an existing Express, FastAPI, MCP, or A2A agent without building billing yourself.
  • Charging per request (fixed or dynamic credits) with metering and settlement handled for you.
  • Generating the registration script + middleware + a test in one pass, so you go from unpaid to paid in minutes.

Try it yourself

Run this in your project with a coding agent that can read and edit your files:
My project is an Express (TypeScript) AI agent with an endpoint `POST /ask`. Add Nevermined payments so callers must pay 1 credit per request via the x402 protocol.

Use the @nevermined-io/payments SDK, following the Nevermined `nevermined-payments` skill (https://github.com/nevermined-io/docs/tree/main/skills/nevermined-payments) — its Track B and `references/` cover each framework. Produce:
1. A registration script that publishes my agent and a "Starter" plan granting 100 credits for $10 in USDC (my builder wallet: <your-builder-wallet>), printing the agentId and planId.
2. The payment middleware wiring that gates `POST /ask` at 1 credit, reading NVM_API_KEY, NVM_PLAN_ID, NVM_AGENT_ID from env.
3. A short test that calls `POST /ask` with no token (expect 402), then with a fresh x402 token (expect 200), in the sandbox environment.

Keep my existing handler logic intact. Use payment-signature / verifyPermissions / settlePermissions (not the deprecated isValidRequest).
Swap the framework line for your stack — guides exist for Express, FastAPI, Strands, and generic HTTP.

How it works

1

Register an agent and a plan

Publish the service and price it. The SDK helpers build the on-chain price/credits config for you:
const { agentId, planId } = await payments.agents.registerAgentAndPlan(
  { name: 'My Agent', description: 'AI service', tags: ['ai'], dateCreated: new Date() },
  { endpoints: [{ POST: 'https://your-api.com/ask' }] },
  { 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),
)
See Register a plan & agent for the full options (fiat pricing, time-based and pay-as-you-go plans).
2

Gate your routes with middleware

Add the payment middleware and list the routes to protect with their credit cost. Everything not listed stays public:
import { paymentMiddleware } from '@nevermined-io/payments/express'

app.use(paymentMiddleware(payments, {
  'POST /ask': { planId: process.env.NVM_PLAN_ID, credits: 1 },
}))
The middleware returns 402 with a payment-required challenge when the token is missing, verifies it when present, runs your handler, then settles (burns credits) and returns the receipt in payment-response.
3

Test the paywall

Call without a token (expect 402), then with a fresh token (expect 200):
# 1) No token → 402
curl -i -X POST http://localhost:3000/ask -d '{"q":"hi"}'

# 2) With an x402 token → 200 (mint one as a buyer would — see "Buy access")
curl -i -X POST http://localhost:3000/ask \
  -H "payment-signature: <accessToken>" -d '{"q":"hi"}'

Register a plan & agent

Publish and price the service you’re protecting.

Nevermined x402

The protocol behind the paywall: schemes, headers, verify/settle.

Check revenue

Once you’re charging, track what you earn.

Buy access

See the buyer side that mints the token your paywall checks.