Billing and Credits
Product Factory includes a complete billing system powered by the worker-billing service. It supports a credits-based usage model, subscription plans, and order management.
Credits System
Credits are the internal currency for consuming services (primarily AI completions). Users receive credits through:
| Source | Mechanism |
|---|---|
| Daily check-in | Free credits awarded once per day via /checkin |
| Subscription plan | Monthly credit allocation based on plan tier |
| One-time purchase | Direct credit purchase through checkout flow |
Credit Deduction
When a user makes an AI request, the flow is:
worker-aicallsworker-billingto perform a credits preflight check.- If sufficient credits exist, the AI request proceeds.
- After completion,
worker-aireports actual token usage. worker-billingdeducts the calculated credit cost.
Subscription Plans
Plans are defined by admins and stored in D1. Each plan specifies:
| Field | Description |
|---|---|
name | Display name (e.g., “Pro”, “Enterprise”) |
price | Monthly price |
credits | Monthly credit allocation |
features | JSON array of feature descriptions |
Users subscribe through the checkout flow. The gateway handles subscription lifecycle events.
Orders
Every credit purchase or subscription payment creates an order record in D1:
| Field | Description |
|---|---|
order_id | Unique identifier |
user_id | Buyer |
type | credits or subscription |
amount | Payment amount |
status | pending, completed, failed, refunded |
API Endpoints
See the Billing API Reference for the complete endpoint documentation.