Documentation
Credits

Credits and Top-Ups

Give users trial credits, create credit packages, and check top-ups and AI spending

Credits let users try your app and top up when they need more. Give a test account some credits first, confirm AI works, then connect paid top-ups.

Complete login and admin setup before you start. Selling packages also needs Stripe or Creem.

1. Enable credits

Open Admin → Settings → Credit Settings (/admin/config), enable credits, and save. Refresh the homepage and open the avatar menu. Account shows the balance; Usage shows credit records.

If an environment variable locks the setting, update its VITE_CREDIT_* value and restart or redeploy. Remove that override if you want to manage the setting in admin.

2. Give your test account credits

For your first test, open Admin → Users (/admin/users), find the account, and grant it credits. Sign in with that account and check the balance and records.

To give new users trial credits automatically, enable a bonus in Settings:

SettingWhat to enterWhen it arrives
Signup bonusEnable it, enter an amount above 0 and an expiry periodOnce for accounts created after you enable it
Daily bonusEnable it and enter an amount above 0When an eligible user checks their balance

Signup bonuses do not apply to existing accounts. Their expiry can be 1–3650 days. Daily bonuses become available 24 hours after the previous grant and expire 24 hours after collection.

3. Create your first package

Create a $9.90 one-time product with your payment provider. Save its Price ID for Stripe or Product ID for Creem.

Open Admin → Credit Packages (/admin/credit-packages) and add a package. Use the existing 100-credit copy for your first test:

FieldExample
Locale Keycredit_100
Credit amount100
Expiry days30; leave blank for no expiry
Price in cents990, which is USD $9.90
Price IDStripe's price_... or Creem's prod_...
Sort order0
ActiveOn

Enter the localization key once. The existing credit_100 key provides the “100 Credits / 100 积分” name and description. Wait for the validation message, then complete the remaining fields and save.

For different copy, ask your AI coding tool to edit content.creditPackages in src/i18n/dashboard/en.json and zh.json. A new key needs both name and description. Restart or rebuild before entering the new key in admin.

The top-up panel currently displays prices in USD. Keep VITE_CURRENCY=USD for your first setup and match the amount at the payment provider. Update package price IDs if you switch providers.

4. Let users top up

  1. To let free users purchase, enable “Allow free users to purchase credit packages” in Settings. With it off, the purchase API requires an active subscription.
  2. Sign in with an ordinary test account, open the avatar menu, and choose Top Up. Check the name, credit amount, and price.
  3. Complete a purchase in your provider's test mode and confirm successful webhook delivery.
  4. Check the paid order in Admin → Orders, then return to the homepage and check the balance and Usage.
  5. Follow the AI guide to run a priced chat or generation request and confirm a spending record appears.

The default payment return page still needs to be completed before launch. Give your AI coding tool this task:

Update the success and cancellation destinations in src/routes/api/payment/credit-checkout.ts to existing app pages. Complete a test purchase and check the paid order and the user's balance.

What users can expect

Expired credits do not count toward the balance. Daily credits are used first, followed by credits closest to expiry. Chat is charged after a reply finishes. Media generation reserves credits before starting and releases them if the job fails.

If AI returns a result without charging credits, check Admin → AI Prices. A working reply does not mean the model has a credit price.

Next: enable AI chat and generation.

On this page