Overview
ActumX uses a credit-based prepaid billing system. You add credits to your account, then credits are automatically deducted as you use paid API endpoints.Key Concepts
- Credits: Prepaid balance stored in cents (USD)
- Payment Intents: Top-up transactions that add credits
- Credit Ledger: Double-entry accounting log of all credits/debits
- Usage Events: Records of API usage and costs
- x402 Transactions: Payment records for paid requests
All monetary values in ActumX are stored in cents (USD) to avoid floating-point precision issues.
Credit-Based Model
How It Works
- Top Up: Add credits to your account via payment intent
- Use API: Make requests to paid endpoints (e.g., x402 protected routes)
- Auto Deduct: Credits are automatically deducted when you settle x402 payments
- Track Usage: View your balance, top-ups, and usage in real-time
Balance Calculation
Your balance is computed from the credit ledger:/home/daytona/workspace/source/api/src/services/credits.service.ts (inferred from usage in billing/service.ts:88)
Payment Intents
Payment intents represent top-up transactions.Payment Intent Structure
Database Schema
/home/daytona/workspace/source/api/src/db/schema.ts:18-28
Creating a Payment Intent
Top up your account:- Minimum: 100 cents ($1.00 USD)
- Maximum: 100,000 cents ($1,000.00 USD)
Currently, ActumX uses a dummy payment provider for development. In production, this would integrate with Stripe, PayPal, or similar.
Payment Intent Flow
Listing Payment Intents
View your top-up history:Credit Ledger
The credit ledger is a double-entry accounting log of all balance changes.Ledger Entry Structure
Database Schema
/home/daytona/workspace/source/api/src/db/schema.ts:30-40
Ledger Entry Types
Credit Entry (Top-Up)
Debit Entry (API Usage)
Balance Calculation
Your current balance is computed by summing all ledger entries:The ledger provides an immutable audit trail of all financial transactions.
Usage Events
Usage events record each API request and its cost.Usage Event Structure
Database Schema
/home/daytona/workspace/source/api/src/db/schema.ts:60-72
Usage Tracking
Usage events are created when x402 payments are consumed:- Detailed usage analytics
- Cost attribution per API key
- Usage trends over time
- Billing dispute resolution
Billing Summary
Get an overview of your billing status:Summary Calculations
Pricing
Current Costs
- x402 Quote Request: 10 cents ($0.10 USD)
Pricing is configured in
/home/daytona/workspace/source/api/src/config/constants.ts via X402_PAID_REQUEST_COST_CENTS.Future Pricing Model
ActumX may introduce tiered pricing:Payment Flow Diagram
Implementation Details
Service Layer
The billing service handles all financial operations: Key Functions:summary(request): Get billing overviewtopUp(request, payload): Add credits to accountpaymentIntents(request): List top-up history
/home/daytona/workspace/source/api/src/modules/billing/service.ts
Validation
Top-up amounts are validated:Credits Service
TheCreditsService computes balances:
/home/daytona/workspace/source/api/src/services/credits.service.ts (inferred)
Best Practices
1. Monitor Your Balance
Regularly check your balance to avoid service interruptions:2. Set Balance Alerts
Implement client-side alerts when balance drops below a threshold:3. Track Usage by API Key
Use different API keys for different services to track costs:4. Automate Top-Ups
Set up automatic top-ups when balance is low:5. Review Usage Events
Periodically audit usage events for unexpected costs:Error Handling
Common billing errors:Example Error Response
Security Considerations
- Transaction Atomicity: All ledger entries are created in database transactions
- Idempotency: Payment intents use unique IDs to prevent double-charging
- User Isolation: All queries filter by
userIdto prevent cross-user access - Audit Trail: The ledger provides immutable financial history
- Balance Validation: Settlement checks balance before debiting
Next Steps
Billing & Credits Guide
Step-by-step guide to managing your credits
Dashboard - Billing
View billing details in the web dashboard
API Reference
View detailed billing API endpoints
x402 Protocol
Learn how x402 payments deduct credits