Chameleon

Credits Management

Manage your credits and transactions

Credits Management

Learn how to view your credit balance, transaction history, and understand credit sources in the user center.

Overview

The Credits page provides a comprehensive view of your credit balance, transaction history, and credit sources. You can track how you earn and spend credits, view expiration dates, and monitor your account activity.

Credit Balance

Current Balance

The credits page displays:

  • Left Credits: Current available balance
  • Total Credits: Lifetime earned credits
  • Expired Credits: Credits that have expired

Balance Calculation

// Credit balance calculation
const balance = {
  left_credits: 850,      // Currently available
  total_credits: 1100,    // Lifetime earned
  expired_credits: 250    // Expired credits
};

Credit Display

The balance is shown in multiple locations:

  • Header: Top right of user center
  • AI Generator: Shows cost and remaining credits
  • My Credits page: Detailed breakdown

Transaction History

Viewing Transactions

  1. Go to /my-credits
  2. Scroll down to "Transaction History"
  3. View all credit transactions
  4. Use pagination to browse older transactions

Transaction Information

Each transaction shows:

  • Type: Transaction type (purchase, usage, reward)
  • Amount: Credits added (+) or deducted (-)
  • Date: Transaction timestamp
  • Description: Additional details
  • Expiration: When credits expire (if applicable)

Transaction Types

enum CreditsTransType {
  NewUser = "new_user",           // New user bonus
  OrderPay = "order_pay",         // Purchased credits
  SystemAdd = "system_add",       // Admin added
  Ping = "ping",                  // Daily check-in
  AIGeneration = "ai_generation", // AI usage
  Referral = "referral"           // Referral rewards
}

Credit Sources

New User Bonus

  • Amount: 100 credits
  • When: Automatically added on account creation
  • Expiration: 1 year from signup
  • Type: new_user

Daily Check-In

  • Amount: 1 credit per day
  • How: Visit /api/ping endpoint
  • Limit: Maximum 1 credit per day
  • Expiration: 1 year from earning
  • Type: ping

Purchase Credits

  • Amount: Varies by package
  • How: Buy through pricing page
  • Expiration: 1 year from purchase
  • Type: order_pay

Referral Rewards

  • Amount: 5-30% commission
  • How: When referred users purchase
  • Expiration: 1 year from earning
  • Type: referral

Admin Added Credits

  • Amount: Custom amount
  • How: Added by administrators
  • Expiration: Custom (set by admin)
  • Type: system_add

Credit Usage

AI Generation Costs

const AI_GENERATION_CREDITS = {
  image: {
    openai: 5,      // DALL-E 3
    replicate: 3,   // Flux
    kling: 4        // Kling AI
  },
  video: {
    kling: 10,      // Kling AI
    seedance: 10    // Seedance
  }
};

Credit Deduction

Credits are deducted when:

  • AI generation completes successfully
  • Premium features are used
  • Note: Credits are NOT deducted on task creation, only on successful completion

Insufficient Credits

When you don't have enough credits:

  • Warning message appears
  • Link to pricing page is shown
  • Current balance is displayed
  • Generation is blocked

File Locations

  • src/app/[locale]/(console)/my-credits/page.tsx - Credits page
  • src/models/credit.ts - Credit data model
  • src/services/credit.ts - Credit business logic
  • src/app/api/get-user-credits/route.ts - Credits API

Common Tasks

Check Credit Balance

// API call to get credits
const response = await fetch("/api/get-user-credits", {
  method: "POST",
});

const { data } = await response.json();
console.log("Credits:", data.left_credits);

View Transaction History

  1. Go to /my-credits
  2. Scroll to "Transaction History"
  3. Browse through transactions
  4. Use pagination for older records

Purchase More Credits

  1. Go to /pricing
  2. Choose a credit package
  3. Click Get Chameleon
  4. Complete Stripe checkout
  5. Credits added automatically

Daily Check-In

// Daily check-in API call
const response = await fetch("/api/ping", {
  method: "POST",
});

const { message } = await response.json();
console.log(message); // "Ping success, 1 credit added"

Troubleshooting

Credits not updating

Problem: Balance doesn't change after purchase

Solution:

  1. Refresh the page
  2. Check transaction history
  3. Verify payment success in /my-orders
  4. Contact support if payment succeeded but credits not added

Transaction not showing

Problem: Transaction not appearing in history

Solution:

  1. Check transaction was successful
  2. Verify transaction type is correct
  3. Check for database issues
  4. Contact support with transaction details

Credits expired

Problem: Credits show as expired

Solution:

  1. Check expiration dates in transaction history
  2. Purchase new credits if needed
  3. Use credits before they expire
  4. Consider subscription for automatic renewal

Next Steps