Skip to main content

Payments and Balance

This guide explains how subscribers purchase payment plans and check their credit balances. These operations are typically performed by users who want to access AI agents.

Overview

The payment flow consists of:
  1. Discovering Plans: Browse available payment plans for agents
  2. Ordering Plans: Purchase a plan to receive credits
  3. Checking Balance: Monitor available credits and subscription status

Get Plan Balance

Subscribers can check their available credits for a specific plan:

Balance Response Structure

The balance response contains:

Working with Balance

Order a Plan

Subscribers purchase plans to receive credits:

Crypto Payment

For plans priced in cryptocurrency:

Fiat Payment (Stripe)

For plans priced in fiat currency, use orderFiatPlan to get a Stripe checkout URL:

CLI

Note: When using X402 card-delegation tokens (nvm:card-delegation scheme), the payment is handled automatically through the delegated card — no separate checkout URL is needed. See Querying an Agent for details on card-delegation tokens.

Complete Purchase Flow

Waiting for Balance Updates

After ordering a plan, credits are allocated on-chain, which may take a few seconds:

Check Multiple Plan Balances

If a subscriber has multiple plans:

Stripe Checkout Integration

Stripe checkout for fiat-priced plans is managed through the Nevermined App dashboard. Visit nevermined.app to configure Stripe payments for your plans.

Plan Information

Before ordering, subscribers might want to view plan details:

Complete Example: Purchase Flow with UI

Best Practices

  1. Check Balance First: Always check existing balance before ordering
  2. Wait for Settlement: Allow time for on-chain credit allocation after purchase
  3. Handle Errors: Wrap order operations in try-catch blocks
  4. User Feedback: Provide clear feedback during the purchase process
  5. Balance Monitoring: Check balance before each agent request
  6. Stripe Redirects: Use absolute URLs for Stripe success/cancel URLs

Source References:
  • src/api/plans-api.ts (orderPlan, getPlanBalance methods)
  • tests/e2e/test_payments_e2e.test.ts (ordering and balance verification)