Overview
The token management system enables:- User balance tracking
- Usage quotas and limits
- Credit-based access control
- Transaction history
- Automated balance deduction
Add Balance
Add tokens/credits to user accounts
Set Balance
Set specific balance amounts
List Balances
View all user balances
Balance Configuration
Configure the balance system
Enabling Balance System
Enable the balance system inlibrechat.yaml:
librechat.yaml
The balance system must be enabled in
librechat.yaml before using token management commands.Add Balance
Add tokens/credits to a user’s account.Usage
Interactive Mode
- Email: User’s email address
- Amount: Number of tokens to add (default: 1000)
Examples
Transaction Record
Each balance addition creates a transaction record with:- User ID
- Amount added
- Context: “admin”
- Timestamp
- New balance
Balance additions are tracked in the transaction history, which can be useful for billing, auditing, and user support.
Set Balance
Set a user’s balance to a specific amount (overwriting the current balance).Usage
Interactive Mode
Examples
List Balances
View token balances for all users.Usage
Output Format
Displays:- Email address
- Current balance
- Last transaction date
- Total tokens used
Example Output
Configuration
Configure the balance system inlibrechat.yaml:
Basic Settings
Enable or disable the balance system
Starting balance for new users
Minimum balance required to use features
Allow users to have negative balances
Token Costs
Define costs per model:librechat.yaml
Usage Limits
Implement daily or monthly limits:librechat.yaml
Balance Tiers
Create different user tiers:librechat.yaml
Transaction History
View a user’s transaction history:Using MongoDB
Transaction Fields
user- User IDtokenType- Type of tokens (credits, tokens, etc.)rawAmount- Amount of transactionrate- Exchange rate (if applicable)context- Context (admin, usage, refund, etc.)model- AI model used (for usage transactions)conversationId- Related conversationbalance- Balance after transactioncreatedAt- Transaction timestamp
Automated Balance Deduction
LibreChat automatically deducts tokens based on usage:Insufficient Balance
When a user has insufficient balance:- Block Request
- Allow Negative
- Use Free Model
Environment Variables
Optional environment variables for balance system:Enable balance checking before processing requests
Force balance check even for admin users
Best Practices
Set Reasonable Initial Balances
Give new users enough tokens to meaningfully try the service without excessive free usage.
Implement Refill Policies
Consider monthly refills for subscription users or balance expiration for free tiers.
Troubleshooting
Error: Balance is not enabled
Error: Balance is not enabled
Enable the balance system in
librechat.yaml:Balances not deducting
Balances not deducting
- Verify
CHECK_BALANCEis set totruein.env - Check
librechat.yamlhas token costs defined - Ensure database transactions are working
- Review server logs for errors
Transaction not created
Transaction not created
- Verify MongoDB connection
- Check user ID is valid
- Ensure balance configuration is correct
- Review database permissions
Incorrect token costs
Incorrect token costs
- Verify model names match exactly in
librechat.yaml - Check for typos in model names
- Ensure costs are per 1000 tokens (standard format)
- Update configuration and restart server
Related Documentation
- User Management - Create and manage users
- Configuration - YAML configuration reference
- Monitoring - Track usage and costs