Skip to main content
This guide provides a comprehensive walkthrough for integrating Nevermined Payment Libraries into your AI services. We’ll cover setup, core components, and the different patterns you can use to add a payment layer to your AI agents.

The Nevermined Payment Libraries

The Nevermined Payment Libraries are software components that enable programmatic interaction with the Nevermined ecosystem. Payment Libraries allow AI Builders and developers to monetize their AI Applications (such as AI Agents or Services) and integrate them seamlessly. The Payment Libraries are designed for two main scenarios:
  1. Human to Agent: The libraries can be used in browser or CLI environments, allowing human users to interact with AI Agents. They support registering and listing AI Agents, purchasing access, and querying agents as subscribers.
  2. Agent to Agent: The libraries can be embedded within AI Agents, enabling them to interact with other AI Agents, purchase access to APIs, and query them programmatically.
The libraries are provided in Python and TypeScript. Both language implementations provide the same API but the Python one is more suited for AI Builders, Data Scientists, and Data Engineers.
The TypeScript implementation can be used for building AI Agents and also for building Web applications like AI Marketplaces.

Main Features

  • Register AI Agents
  • Create Pricing Plans defining the conditions (price & usage) for subscribers
  • Associate Pricing Plans to AI Agents, so when a subscriber purchases a payment plan they can query all the agents associated to it
  • Order Pricing Plans (payments in Fiat & Crypto) giving access to the AI Agents
  • Query AI Agents programmatically
  • Build AI Agents able to process tasks sent by users
  • Easy integration with Agent orchestration frameworks like Google A2A and MCP

Prerequisites

Before you begin, make sure you have:
1

Development Environment

  • Node.js 16+ and npm/yarn (for TypeScript)
  • Python 3.8+ (for Python)
  • A code editor (VS Code recommended)
2

Blockchain Wallet

  • MetaMask or compatible wallet
  • Some test tokens for the testing environment
3

Nevermined API Key

Get your API key from the Nevermined App

Installation

npm install @nevermined-io/payments
# or
yarn add @nevermined-io/payments

Getting Your API Key

  1. Go to the Nevermined App
  2. Log in with your wallet
  3. Navigate to the Settings section in the user menu
  4. Click on the API Keys tab
  5. Generate a new key, give it a descriptive name, and copy it
  6. Store this key securely as an environment variable (e.g., NVM_API_KEY)
Never expose your API key in client-side code or commit it to version control. Always use environment variables.

Initialize the SDK

import { Payments } from '@nevermined-io/payments'

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

Environment Configuration

Choose the appropriate environment for your use case:
  • Network: Base Sepolia testnet
  • Use case: Development and testing
  • Tokens: Test tokens (free)
  • Environment: 'testing'
  • Network: Base Mainnet
  • Use case: Live applications
  • Tokens: Real tokens (paid)
  • Environment: 'production'

Basic Configuration Example

Here’s a complete example of setting up the Payments client:
import { Payments } from '@nevermined-io/payments'
import dotenv from 'dotenv'

// Load environment variables
dotenv.config()

// Initialize the Payments client
const payments = Payments.getInstance({
  nvmApiKey: process.env.NVM_API_KEY!,
  environment: 'testing', // Start with testing
  // Optional: specify custom RPC endpoints
  // web3ProviderUri: 'https://your-custom-rpc-endpoint.com'
})

// Verify the connection
console.log('Payments client initialized successfully')

Environment Variables Setup

Create a .env file in your project root:
# Required
NVM_API_KEY=your_api_key_here

# Optional - for custom configurations
WEB3_PROVIDER_URI=https://your-custom-rpc-endpoint.com
BUILDER_ADDRESS=your_wallet_address_here

Verification

Test your setup with a simple verification:
async function verifySetup() {
  try {
    // Test the connection by checking if the client is properly initialized
    const config = await payments.getConfig()
    console.log('Setup verified! Environment:', config.environment)
    return true
  } catch (error) {
    console.error('Setup verification failed:', error)
    return false
  }
}

verifySetup()

Common Issues

Make sure your API key is correctly set in your environment variables and has the proper permissions.
Check that you’re using the correct environment (‘testing’ or ‘production’) and that your network connection is stable.
Ensure your wallet has some test tokens for the testing environment or real tokens for production.

Need Help?

If you have questions about Nevermined Payment Libraries, you’re always welcome to ask our community on Discord or Twitter. If you encounter any issues, check our Troubleshooting Guide or reach out to our community.

Next Steps

Now that you have the Nevermined Payment Libraries set up, explore the integration workflow: