Skip to main content

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

  1. Top Up: Add credits to your account via payment intent
  2. Use API: Make requests to paid endpoints (e.g., x402 protected routes)
  3. Auto Deduct: Credits are automatically deducted when you settle x402 payments
  4. Track Usage: View your balance, top-ups, and usage in real-time

Balance Calculation

Your balance is computed from the credit ledger:
Source Reference: /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

Source Reference: /home/daytona/workspace/source/api/src/db/schema.ts:18-28

Creating a Payment Intent

Top up your account:
Request Constraints:
  • Minimum: 100 cents ($1.00 USD)
  • Maximum: 100,000 cents ($1,000.00 USD)
Response:
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:
Response:
Intents are sorted by creation date (newest first), limited to 50 results.

Credit Ledger

The credit ledger is a double-entry accounting log of all balance changes.

Ledger Entry Structure

Database Schema

Source Reference: /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

Source Reference: /home/daytona/workspace/source/api/src/db/schema.ts:60-72

Usage Tracking

Usage events are created when x402 payments are consumed:
This enables:
  • Detailed usage analytics
  • Cost attribution per API key
  • Usage trends over time
  • Billing dispute resolution

Billing Summary

Get an overview of your billing status:
Response:

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 overview
  • topUp(request, payload): Add credits to account
  • paymentIntents(request): List top-up history
Source Reference: /home/daytona/workspace/source/api/src/modules/billing/service.ts

Validation

Top-up amounts are validated:

Credits Service

The CreditsService computes balances:
Source Reference: /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:
Usage events will show which key incurred 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

  1. Transaction Atomicity: All ledger entries are created in database transactions
  2. Idempotency: Payment intents use unique IDs to prevent double-charging
  3. User Isolation: All queries filter by userId to prevent cross-user access
  4. Audit Trail: The ledger provides immutable financial history
  5. 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