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!
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.
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:
Before diving into the specifics, let’s explore the different options for implementing a credit system:
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.
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:
For more details, refer to the Chimoney API Documentation
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
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
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
The example you chose above depends on several factors:
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
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
Top-Up Workflow:
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
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
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
To maintain a secure and reliable credit system, follow these practices:
1. Maintain an Audit Trail:
CreditEntry
to tie credit purchases to secure transactions.2. Ensure Data Integrity:
creditsUsed
changes are safe and conflict-free.3. Integrate Real-time Webhooks:
Code Example: Monitor Chimoney Webhooks
When deciding on a credit management solution, here’s how Chimoney stacks up against other common approaches:
1. Building a Native System:
2. Using Third-Party Payment Processors:
3. Chimoney-Based Approach:
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!
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);
});
}