Overview
Virtual credits are a form of currency that enables pay-as-you-go pricing models where customers are charged based on their actual usage. Unlike subscriptions that provide access to features, credits are consumed when customers use specific services or resources. Credits are ideal for:- API call pricing: Charge per API request or batch of requests
- Compute resources: Bill for processing time, storage, or bandwidth
- Service units: Token-based access to services like support hours or consulting time
- Flexible top-ups: Allow customers to purchase credits as needed
Credit System Architecture
Frontier implements credits using a double-entry bookkeeping system:- Credit transactions: Add credits to customer accounts (purchases, awards)
- Debit transactions: Remove credits from accounts (usage consumption)
- Balance calculation: Sum of credits minus sum of debits
- Dual entries: Each transaction creates two entries (customer and system accounts)
Double-entry bookkeeping ensures balance accuracy and consistency. For example, when a customer purchases 100 credits, a credit transaction adds 100 to their account while a debit transaction removes 100 from the system account.
Transaction Types
Credit Transactions
Add credits to a customer account:| Source | Description |
|---|---|
system.buy | Credits purchased by customer |
system.awarded | Credits awarded by platform (promotions, rewards) |
system.starter | Onboarding credits for new customers |
system.revert | Credits restored from reversed usage |
system.overdraft | Overdraft credits (if enabled) |
Debit Transactions
Remove credits from a customer account:| Source | Description |
|---|---|
| Usage reporting | Credits consumed via usage APIs |
| Manual adjustments | Platform-initiated debits |
Purchasing Credits
Customers purchase credits by buying products withcredits behavior through checkout sessions.
Create Credit Product
Define a product that awards credits when purchased:Purchase Flow
Credits Awarded
Upon successful payment, credits are automatically added to the customer’s account.
Create Checkout for Credits
Consuming Credits
Report usage to consume credits from a customer’s account.Report Usage
amount: Number of credits to consume (required)source: Source application or event triggering usage (required)description: Human-readable description of usage (optional)user_id: ID of user who initiated usage (optional)metadata: Additional custom data (optional)
Usage Example
Here’s a real-world example of reporting credit usage:Checking Balance
Retrieve the current credit balance for a customer:Transaction History
List all credit transactions for a customer:start_time: Filter transactions from this time (ISO 8601)end_time: Filter transactions until this time (ISO 8601)
Reverting Usage
If usage was incorrectly reported or a service failed, you can revert the usage and restore credits.Full Revert
Revert the entire usage amount:Partial Revert
Revert only a portion of the usage:Reverted credits are added back to the customer’s account with source
system.revert. Each revert creates a new credit transaction.Revert Use Cases
- Service Failures: ML model fails to complete, API request times out
- Incorrect Billing: Usage was reported with wrong amount
- Customer Satisfaction: Goodwill credit restoration for issues
- Testing: Revert test usage in development environments
Awarding Credits
Platform administrators can award credits to customers for promotions, rewards, or compensation:Onboarding Credits
Automatically award credits when customers are created or subscribe to plans:Customer Onboarding Credits
Plan Starter Credits
Onboarding credits have source
system.starter and are awarded automatically by the system.Credit Balance Calculation
The balance is calculated as:| Transaction | Type | Amount | Balance |
|---|---|---|---|
| Initial | - | - | 0 |
| Purchase credits | Credit | +100 | 100 |
| Onboarding award | Credit | +50 | 150 |
| API usage | Debit | -20 | 130 |
| ML inference | Debit | -30 | 100 |
| Service failure revert | Credit | +30 | 130 |
Monitoring Credit Usage
Low Balance Alerts
Implement proactive notifications when customers are running low on credits:Usage Analytics
Track credit consumption patterns:Best Practices
Check Balance Before Usage
Always verify sufficient credits exist before allowing operations to prevent failures.
Implement Graceful Degradation
When credits are insufficient, guide users to purchase more rather than hard-failing.
Set Appropriate Credit Amounts
Price credit packages at amounts that align with typical usage patterns.
Use Descriptive Sources
Set meaningful source values to help customers understand where credits are consumed.
Troubleshooting
Insufficient Credits Error
Customer attempted to use more credits than available: Solution:- Check balance before reporting usage
- Guide customer to purchase more credits
- Consider enabling overdraft (if supported)
Balance Not Updating
Credit transactions not reflecting in balance: Solution:- Verify transaction was successfully created (check response)
- Ensure double-entry transactions completed
- Check for database synchronization issues
Credits Not Awarded After Purchase
Customer completed payment but credits not added: Solution:- Verify product has
creditsbehavior configured - Check
credit_amountis set in product config - Ensure webhook events from Stripe are being processed
- Review transaction logs for errors
Next Steps
Products and Plans
Create credit products with proper behavior configuration
Subscriptions
Award starter credits with subscriptions
Customers
Configure onboarding credits for new customers
Entitlements
Combine credits with feature access control