Building Credit-Based Pricing Systems for AI Platforms: How to Monetize Your AI Business with Step-by-Step Implementation Using Chimoney
Developers
How To
Product Knowledge

Building Credit-Based Pricing Systems for AI Platforms: How to Monetize Your AI Business with Step-by-Step Implementation Using Chimoney

Uchi Uchibeke

Introduction

Billing and monetization are key factors that can determine the business success of AI platforms. The challenge lies in finding a pricing model that is scalable, easy for customers to understand, and simple for engineers to implement. One standout model that has gained popularity in AI services and SaaS businesses is the credit-based system. This article will explain how to create a credit-based pricing system tailored for AI platforms and organizers, examining different approaches and showing how to build this system using Chimoney.

A credit-based model offers flexibility and simplicity, making it suitable for various applications, including AI-driven SaaS, collaborative platforms with human and AI contributors, AI agent marketplaces, or products that charge based on task usage. This approach benefits both your company and your customers by providing a clear and manageable pricing structure.

This guide includes detailed, practical examples to help you implement this system so let's dive in!


What Is a Credit-Based Pricing Model?

A credit-based pricing model allows users to pre-purchase units (credits) that they can use for various services or tasks on your platform. Unlike traditional pay-per-use models, this approach offers flexibility for users to buy credits in bulk, use them as needed, and manage costs more effectively. It also provides a clear, predictable revenue stream for businesses.

Why Is It Ideal for AI Platforms?

AI platforms, whether for automation, data processing, or collaborative work, often perform tasks with variable complexity and cost. Charging per task directly can be complicated, as tasks might have different levels of AI involvement and resource consumption. With a credit-based model:

  • Users know exactly how many credits a task costs before committing.
  • Credits can be scaled to represent any unit of value, such as the complexity or type of AI service being used.
  • Bulk credit purchases incentivize higher spending and user commitment.

Options for Implementing a Credit-Based Model

Before diving into the specifics, let’s explore the different options for implementing a credit system:

  1. Native Accounting System: Build your own internal system to track user credits.
  • Pros: Full control over credit logic, expiration, and special features.
  • Cons: Complex, time-consuming, and requires strict security measures.
  1. Third-Party Payment Processors: Use systems like Stripe to handle payments and credit purchases.
  • Pros: Good for one-time credit purchases with seamless checkout experiences.
  • Cons: Might require custom tracking systems to manage credits after purchase.
  1. Chimoney for Multi-Currency Wallet and Credit Management: Use Chimoney’s API to leverage multi-currency wallets and transaction metadata to manage credits securely.
  • Pros: Simplifies the process, integrates with existing wallet infrastructure, and provides robust tracking and audit capabilities.
  • Cons: Limited to Chimoney’s transaction and metadata management capabilities.

While a native system gives you full control, it comes with heavy development overhead. Third-party processors like Stripe are great for payment handling but fall short on integrated credit tracking. Chimoney strikes a balance by allowing you to handle credit purchases and tracking through its multi-currency wallet and metadata features.


Step-by-Step Guide to Building a Credit-Based Pricing System with Chimoney

Step 1: Understanding Chimoney’s Capabilities

Chimoney offers a powerful API for managing wallets and multi-currency transactions, making it an excellent choice for building a credit-based system without heavy custom development. Here’s what you can use:

  • Wallets: Each user can have a wallet to hold balances.
  • Transactions: Securely handle deposits, withdrawals, and metadata.
  • Metadata: Attach custom data to transactions for tracking credits.

For more details, refer to the Chimoney API Documentation


Step 2: Setting Up User Wallets and Managing Credits

1. Create a User Wallet

Each user or business will need a Chimoney wallet for credit purchases. Chimoney’s Multicurrency Wallet allows users to hold value and transact in multiple currencies. Credits purchased by users will not be held as traditional currency but represented through transaction metadata.

Code Example: Issue a Multi-currency Wallet

Checkout the Create Multi-currency Wallet endpoint on Chimoney API Docs here

carbon (4).png

2. Purchase Credits:

Credits can be bought in two ways:

  • Directly Debit User Wallets: Deduct USD balances and track the transaction via metadata.

  • Initiate a Payment Request: Allow users to pay via cards, Interac, or Mobile Money, with the amount settling in your Chimoney account.

Code Example: Initiate a Payment Request

Checkout the Initiate Payment Request endpoint on Chimoney API Docs here

carbon (5).png

3. Direct Transfer from their Wallet to your Wallet

Another option is to facilitate a direct Transfer of funds from their Wallet to your Wallet.

Code Example: Direct Debit to the Platform Wallet

carbon (6).png

The example you chose above depends on several factors:

  1. If your platform allows users to earn money or rewards to their Chimoney Wallet, then they should be able to convert this to AI credits.
  2. If you want to give users the flexibility to pay for Credit using multiple options including local currency, payment rails like Interac and alternative payment methods like Mobile Money.

Step 3: Tracking and Deducting Credits

Credit Structure

To manage credits, mantain a credit ledger in your system with entries referencing Chimoney transaction IDs and tracking creditsPurchased and creditUsed.

Code Example: Credit Entry

carbon (7).png

Deducting Credits (LIFO Approach)

When users spend credits, use the "Last In, First Out" (LIFO) approach; start deducting from the most recent credit purchase. This ensures newer credits, which customers often expect to use first, are consumed before older ones.

Code Example: Deduct Credit

carbon (8).png


Step 4: Implementing Top-Ups and Balance Management

Top-Up Workflow:

  1. The client initiates a top-up request.
  2. The corresponding amount is deducted from their Chimoney wallet.
  3. A new record is created in the credit ledger to track the transaction.

API for Adding Credit Entries

This process updates the user’s balance by logging the credits purchased into the system. The credit ledger is updated with a new entry, associating the transaction ID with the credits purchased.

Code Example: Top-up credit

carbon (9).png


Step 5: Displaying Credit Balance to Users

To show users their credit balance, follow these two steps:

1. Calculate the Total Remaining Credits

For each credit entry, subtract creditsUsed from creditsPurchased and sum up all the remaining credits across entries to get the total.

Code Example: Calculate Credit Balance

carbon (10).png

2. Create an Endpoint to Display Credit Balance

Use an API endpoint to fetch the calculated credit balance for a specific user and respond with the user's available credits.

Code Example: Credit Balance Endpoint

carbon (11).png


Step 6: Ensuring Security and Auditability

To maintain a secure and reliable credit system, follow these practices:

1. Maintain an Audit Trail:

  • Use Chimoney’s chiRef in your CreditEntry to tie credit purchases to secure transactions.
  • Regularly reconcile credit entries with Chimoney’s transaction logs for consistency.

2. Ensure Data Integrity:

  • Implement atomic updates to ensure that creditsUsed changes are safe and conflict-free.

3. Integrate Real-time Webhooks:

  • Set up webhooks to handle real-time updates when payments are made, ensuring your credit ledger stays up-to-date.
  • Chimoney offers Webhooks to notify you of transaction states.

Code Example: Monitor Chimoney Webhooks

carbon (12).png


Comparing Chimoney to Other Credit Management Approaches

When deciding on a credit management solution, here’s how Chimoney stacks up against other common approaches:

1. Building a Native System:

  • Pros: Full control over the system, allowing you to define custom rules and workflows.
  • Cons: Complex to build, high maintenance, security risks.

2. Using Third-Party Payment Processors:

  • Pros: Great for handling payments, limited credit management capabilities.
  • Cons: Often requires custom solutions for credit tracking.

3. Chimoney-Based Approach:

  • Pros: Simplifies credit handling with wallet management, secure transactions, and metadata capabilities. Easy integration for auditing and tracking.
  • Cons: Dependent on Chimoney’s services, but highly reliable for businesses.

Conclusion

Building a credit-based pricing system for your AI platform doesn’t have to be daunting. By leveraging Chimoney’s multi-currency wallet infrastructure, you can implement a secure, scalable, and easy-to-manage credit system without building everything from scratch. The key is understanding how to integrate Chimoney’s transaction metadata and wallet management to track credit purchases and deductions seamlessly.

For platforms monetizing task-based AI services, collaborative AI-human interactions, or SaaS products that benefit from flexible billing structures, this guide and Chimoney’s integration steps provide a solid foundation to create a robust solution that scales with your business.

Ready to build your credit-based pricing system with Chimoney? Check out the Chimoney API documentation or book a demo with us to get started today!


Appendix: Code Snippets

Below are the code snippets referenced in this guide. You can copy them directly into your implementation.

Code Example: Issue them a Multi-currency Wallet

const fetch = require('node-fetch');
const chimoneyAPIBase = 'https://api-v2-sandbox.chimoney.io/v0.2'; // Sandbox
const chimoneyAPISecret = process.env.CHIMONEY_API_SECRET;

try {
  const url = `${chimoneyAPIBase}/multicurrency-wallets/create`;
  const options = {
    method: 'POST',
    headers: {
      accept: 'application/json',
      'content-type': 'application/json',
      'X-API-KEY': chimoneyAPISecret,
    },
    body: JSON.stringify({
      name: 'Jane AI Doe',
    }),
  };

  const response = await fetch(url, options);
  const json = await response.json();
  console.log(json);
} catch (error) {
  console.error('error:', error);
}

Code Example: Initiate a Payment Request

const fetch = require('node-fetch');
const chimoneyAPIBase = 'https://api-v2-sandbox.chimoney.io/v0.2'; // Sandbox
const chimoneyAPISecret = process.env.CHIMONEY_API_SECRET;

try {
  const url = `${chimoneyAPIBase}/payment/initiate`;
  const options = {
    method: 'POST',
    headers: {
      accept: 'application/json',
      'content-type': 'application/json',
      'X-API-KEY': chimoneyAPISecret,
    },
    body: JSON.stringify({
      amount: 'AMOUNT_YOU_CHARGE_FOR_N_NUMBER_OF_CREDITS', // decided by your pricing plan
      currency,
      payerEmail,
      redirect_url,
      meta: {
        orulyType: 'credit_purchase',
        userId: 'your_platform_user_id',
        credits: 'NUMBER_OF_CREDITS_TO_PURCHASE',
      },
    }),
  };

  const response = await fetch(url, options);
  const json = await response.json();
  console.log(json);
} catch (error) {
  console.error('error:', error);
}

Code Example: Direct Debit their Platform Wallet

const chimoneyAPIBase = "https://api-v2-sandbox.chimoney.io/v0.2"; // Sandbox
const chimoneyAPISecret = process.env.CHIMONEY_API_SECRET;

try {
  const url = `${chimoneyAPIBase}/payment/initiate`;
  const options = {
    method: "POST",
    headers: {
      accept: "application/json",
      "content-type": "application/json",
      "X-API-KEY": chimoneyAPISecret,
    },
    body: JSON.stringify({
      subAccount: "THE_USERS_MULTICURRENCY_ACCOUNT_ID",
      amountToSend: "10",
      originCurrency: "USD",
      receiver: "YOUR_CHIMONEY_ACCOUNT_EMAIL",
      destinationCurrency: "USD",
      narration: "AI Credit purchase",
      meta: {
        orulyType: "credit_purchase",
        userId: "your_platform_user_id",
        credits: "NUMBER_OF_CREDITS_TO_PURCHASE",
      },
    }),
  };

  const response = await fetch(url, options);
  const json = await response.json();
  console.log(json);
} catch (error) {
  console.error("error:", error);
}const fetch = require("node-fetch");

Code Example: Credit Entry

interface CreditEntry {
  transactionId: string;
  creditsPurchased: number;
  creditsUsed: number;
}

let userCredits: CreditEntry[] = [];

Code Example: Deduct Credit

function deductCredits(
  userCredits: CreditEntry[],
  creditsToDeduct: number
): boolean {
  let remainingCredits = creditsToDeduct;

  for (let i = userCredits.length - 1; i >= 0 && remainingCredits > 0; i--) {
    const entry = userCredits[i];
    const availableCredits = entry.creditsPurchased - entry.creditsUsed;

    if (availableCredits > 0) {
      const creditsUsed = Math.min(availableCredits, remainingCredits);
      entry.creditsUsed += creditsUsed;
      remainingCredits -= creditsUsed;
    }
  }

  return remainingCredits === 0;
}

Code Example: Top-up credit

function addCreditEntry(
  userCredits: CreditEntry[],
  transactionId: string,
  creditsPurchased: number
) {
  userCredits.push({ transactionId, creditsPurchased, creditsUsed: 0 });
}

Code Example: Calculate Credit Balance

function calculateTotalCredits(userCredits: CreditEntry[]): number {
  return userCredits.reduce((total, entry) => {
    return total + Math.max(0, entry.creditsPurchased - entry.creditsUsed);
  }, 0);

Code Example: Credit Balance Endpoint

app.get('/api/user/credits', (req, res) => {
  const userId = req.query.userId;
  const credits = calculateTotalCredits(getUserCredits(userId));
  res.json({ availableCredits: credits });
});

Code Example: Monitor Chimoney Webhooks

app.post('/webhook/credits', (req, res) => {
  const { transactionId, creditsPurchased } = req.body;
  addCreditEntry(getUserCredits(req.userId), transactionId, creditsPurchased);
  res.sendStatus(200);
});
}
Last edited on:
Share Post
instagramtwitterlinkedin

Check out these other posts