Skip to main content
This guide gets you from zero to a working payment integration in 5 minutes. By the end, you’ll have a monetizable service set up with Nevermined — typically an agent API, but the same flow applies to MCP tools/servers and protected assets.
In the code below we use “agent” terminology because it maps to the underlying object model, but you can think of it as the service/resource you’re charging for.

Prerequisites

1

Get Your API Key

Open nevermined.app, sign in, then go to Settings > Global NVM API Keys and click + New API Key. Copy the key and set it as an environment variable:
Keys are environment-specific — the prefix matches the SDK environment value you must pass at init.Use sandbox for testing and live for production. If you see auth errors that look unrelated to the key, double-check that prefix and environment match — a sandbox: key against environment: 'live' lands at the wrong backend and fails with confusing 4xx errors.
2

Install the SDK

Register Your Agent

Create a script to register your agent and a payment plan.
You can register your agent and any payment plan using the following code OR using the Nevermined App. No need to code this — just follow the steps in the app to create your agents and plans.
If you’re monetizing an agent, MCP tool/server or a protected resource, you’ll still register the monetizable unit and attach a plan — only the delivery step changes.
Run it:

Add Payment Validation in the Agent

Add this middleware to your agent to validate if a request is valid (have a payment attached) before delivering your response/resource. The example shows an HTTP API route; the same check can be used before calling an MCP tool handler or before serving a protected asset:

Integrate the validation code in your agent/server

Integrate the above validation code into your agent/server code at the very beginning of your request handling logic. The payment validation should occur before any processing of the request and can be complemented by any other authorization logic you may have.

Test It

1) Try without payment (should fail)
Response:
2) Purchase a plan and get an access token
3) Query with payment
Response:
Want subscribers to pay with a regular credit card instead of stablecoins? Card delegation lets subscribers enroll a Visa, Stripe, or Braintree card and create spending delegations that agents charge directly.

What’s Next?

Express Integration

Complete Express.js integration guide

FastAPI Integration

Complete FastAPI integration guide

Payment Patterns

Advanced validation and charging patterns

x402 Protocol

Implement HTTP 402 payment flows