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
- Go to
/my-credits - Scroll down to "Transaction History"
- View all credit transactions
- 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/pingendpoint - 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 pagesrc/models/credit.ts- Credit data modelsrc/services/credit.ts- Credit business logicsrc/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
- Go to
/my-credits - Scroll to "Transaction History"
- Browse through transactions
- Use pagination for older records
Purchase More Credits
- Go to
/pricing - Choose a credit package
- Click Get Chameleon
- Complete Stripe checkout
- 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:
- Refresh the page
- Check transaction history
- Verify payment success in
/my-orders - Contact support if payment succeeded but credits not added
Transaction not showing
Problem: Transaction not appearing in history
Solution:
- Check transaction was successful
- Verify transaction type is correct
- Check for database issues
- Contact support with transaction details
Credits expired
Problem: Credits show as expired
Solution:
- Check expiration dates in transaction history
- Purchase new credits if needed
- Use credits before they expire
- Consider subscription for automatic renewal
Next Steps
- Credit System - Detailed credit system documentation
- Pricing - Learn about credit packages
- Referral System - Earn credits through referrals