Skip to main content
This guide provides a quick path to integrating Nevermined, whether you’re an AI Builder looking to monetize an AI agent or service, or a User wanting to access one. You can interact with Nevermined through our user-friendly Web App or programmatically via our SDKs.

For AI Builders: Monetize Your Agent

Using the Nevermined Web App (No Code)

The easiest way to get started is by using the Nevermined App to register your agent and create payment plans through a visual interface.
  1. Log In: Access the app via Web3Auth (socials or wallet).
  2. Register Agent: Navigate to the “Agents” tab to “Register New Agent”. Fill in your agent’s metadata (name, description) and register all API endpoints.
  3. Create Pricing Plan: Define one or more pricing plans for your agent, specifying price, payment currency (fiat or crypto), and usage terms (per-request pricing).
  4. Done!: Your agent is now discoverable and ready to accept payments.

Using the SDKs (Programmatic)

For developers who need to automate and integrate directly, our SDKs are the perfect tool.
1

1. Get Your API Key

To interact with the Nevermined API, you need an API key. Follow the Get Your API Key guide to create one, then store it as an environment variable:
export NVM_API_KEY="sandbox:your-api-key-here"
2

2. Install and Initialize the Payments Library

Install the PaymentsLibrary and initialize the Payments client with your API key.
npm install @nevermined-io/payments
import { Payments } from '@nevermined-io/payments'

const payments = Payments.getInstance({
  nvmApiKey: process.env.NVM_API_KEY,
  environment: 'sandbox' // or 'live'
})
3

3. Register Your AI Agent

Define your agent’s metadata, API endpoints, and payment plan. Then register it with a single call.
// Define agent metadata
const agentMetadata = {
  name: 'My AI Assistant',
  tags: ['ai', 'assistant'],
  dateCreated: new Date(),
};

// Define API endpoints
const agentApi = {
  endpoints: [{ POST: 'https://api.myservice.com/query' }],
  agentDefinitionUrl: 'https://api.myservice.com/openapi.json' // URL to OpenAPI spec, MCP Manifest, or A2A agent card
};

// Define plan metadata
const planMetadata = {
  name: 'Basic Plan',
  description: '100 queries per month',
  dateCreated: new Date(),
};

// Configure pricing (e.g., 10 USDC)
const priceConfig = payments.plans.getERC20PriceConfig(
  10_000_000n, // 10 USDC (6 decimals)
  '0xA0b86a33E6441c41F4F2B8Bf4F2B0f1B0F1C1C1C', // USDC address
  process.env.BUILDER_ADDRESS
);

// Configure credits (e.g., 100 queries)
const creditsConfig = payments.plans.getFixedCreditsConfig(100n, 1n);

// Register agent and plan together
const { agentId, planId } = await payments.agents.registerAgentAndPlan(
  agentMetadata,
  agentApi,
  planMetadata,
  priceConfig,
  creditsConfig
);

console.log(`Agent registered: ${agentId}`);
4

4. Accept Payments

In your agent’s backend, add payment protection to your routes. The paymentMiddleware handles the full x402 flow automatically: it returns 402 with payment requirements when no token is present, verifies permissions, executes your handler, and settles (burns) credits.
import express from 'express'
import { Payments } from '@nevermined-io/payments'
import { paymentMiddleware } from '@nevermined-io/payments/express'

const app = express()
app.use(express.json())

const payments = Payments.getInstance({
  nvmApiKey: process.env.NVM_API_KEY!,
  environment: 'sandbox'
})

const PLAN_ID = process.env.NVM_PLAN_ID!

// Add payment protection — 1 credit per request to /api/query
app.use(paymentMiddleware(payments, {
  'POST /api/query': { planId: PLAN_ID, credits: 1 }
}))

app.post('/api/query', async (req, res) => {
  // If we reach here, payment is already verified
  const result = await processAIQuery(req.body.prompt)
  res.json(result)
})

app.listen(3000)
Your package.json must include "type": "module" for the @nevermined-io/payments/express subpath import to work.
This flow protects your agent and automates billing.

For Users (Subscribers): Access an AI Agent

Using the Nevermined Web App

  1. Discover: Find agents in the Nevermined App or other marketplaces.
  2. Purchase: Select a pricing plan and purchase it with crypto or a credit card.
  3. Get Credentials: Once purchased, you’ll receive API credentials to access the agent.

Using the SDKs

// 1. Discover the agent and its plans
const agent = await payments.agents.getAgent('AGENT_ID');
const plan = agent.plans[0];

// 2. Purchase the plan
// Option A: Crypto payment
const orderResult = await payments.plans.orderPlan(plan.planId);
console.log('Order transaction:', orderResult.transactionHash);

// Option B: Fiat payment (credit card)
const { sessionId, url } = await payments.plans.orderFiatPlan(plan.planId);
window.location.href = url; // Redirect to Stripe

// 3. Get X402 access token
const { accessToken } = await payments.x402.getX402AccessToken(
  plan.planId,
  agent.agentId
);

// 4. Query the agent using the access token
// Extract URL from endpoint object (endpoints have HTTP method as key)
const endpoint = agent.endpoints[0]
const method = Object.keys(endpoint)[0]
const url = endpoint[method]

const response = await fetch(url, {
  method: method,
  headers: {
    'Content-Type': 'application/json',
    'payment-signature': accessToken
  },
  body: JSON.stringify({
    prompt: "Hello, how can you help me?"
  })
});

const result = await response.json();
console.log('Agent response:', result);