70640e7e81052acca0efa59affeaedd03b02c809
💰 ComfyUI-ModalCredits
Track your Modal GPU credits in real-time with an iPhone-style battery indicator in the ComfyUI header!
✨ Features
- 🔋 iPhone-style battery indicator in ComfyUI header
- ⚡ Real-time credit tracking - updates every second
- 💾 Persistent data - survives server restarts
- 🎮 Auto GPU detection - detects A10G, A100, H100, T4, L4, L40S
- 🔄 Token change detection - auto-resets when switching Modal accounts
- 🎨 Color-coded alerts - Green (>50%), Yellow (20-50%), Red (<20%)
- 📊 Detailed stats - Click icon for GPU type, cost/hour, estimated time remaining
📦 Installation
Quick Install (Recommended)
cd ComfyUI/custom_nodes/
git clone https://github.com/yourusername/ComfyUI-ModalCredits.git
Then restart ComfyUI server.
Manual Install
- Create directory:
cd ComfyUI/custom_nodes/
mkdir ComfyUI-ModalCredits
cd ComfyUI-ModalCredits
mkdir web
-
Copy these files:
__init__.pymodal_credits_node.pyroutes.pyweb/modal_credits.js
-
Restart ComfyUI
⚙️ Configuration
Step 1: Update GPU Costs
Edit modal_credits_node.py and update prices to match your Modal plan:
GPU_COSTS = {
"A10G": 1.10, # ← Update these
"A100-40GB": 3.00,
"A100-80GB": 4.00,
"H100": 8.00,
"T4": 0.60,
"L4": 0.80,
"L40S": 2.50,
"UNKNOWN": 1.00
}
Step 2: Set Initial Credits
Default is $80. Change it by:
- Adding the "Modal Credits Monitor" node to your workflow
- Setting
initial_creditsparameter - Or editing the default in the code
🚀 Usage
After Installation
- Start ComfyUI - Battery icon appears automatically in header
- View credits - See remaining balance next to battery
- Click icon - See detailed breakdown
- Monitor usage - Watch it decrease in real-time
Node Parameters
initial_credits(default: 80.0) - Your starting credit amountreset_credits(default: False) - Toggle to reset countergpu_override(default: AUTO) - Manual GPU selection if auto-detect fails
Battery Colors
- 🟢 Green - More than 50% remaining (healthy)
- 🟡 Yellow - 20-50% remaining (caution)
- 🔴 Red - Less than 20% remaining (low, pulses)
📊 What You'll See
Click the battery icon to view:
💰 Modal Credits Details
━━━━━━━━━━━━━━━━━━━━━━━━
💵 Remaining: $45.50
📊 Used: $34.50
💳 Initial: $80.00
🔋 Battery: 57%
🎮 GPU: A100-40GB
💲 Cost: $3.00/hour
⏱️ Session: 11.50 hours
🧮 Estimated time remaining:
15.17 hours
💾 Data Storage
Credits are saved to:
ComfyUI/output/modal_credits_data.json
This file stores:
- Initial credit amount
- Total credits used
- Session start time
- Modal token ID (for account detection)
- Last save timestamp
🔄 Resetting Credits
Method 1: Using the Node
Add node to workflow → Set reset_credits to True → Run
Method 2: Delete Data File
rm ComfyUI/output/modal_credits_data.json
Method 3: API Call
curl -X POST http://localhost:8188/modal_credits/reset \
-H "Content-Type: application/json" \
-d '{"initial_credits": 80.0}'
🔧 Troubleshooting
Battery icon not showing up?
- ✅ Check all files are in correct locations
- ✅ Clear browser cache (Ctrl+Shift+R)
- ✅ Check browser console for errors (F12)
- ✅ Restart ComfyUI server completely
GPU not detected?
- ✅ Verify nvidia-smi works:
nvidia-smi - ✅ Use
gpu_overridein node settings - ✅ Check server console for detection messages
Credits not saving?
- ✅ Check permissions on
ComfyUI/output/directory - ✅ Look for
modal_credits_data.jsonfile - ✅ Check server logs for write errors
Wrong GPU detected?
- Use the
gpu_overridedropdown in the node to manually select
📁 File Structure
ComfyUI/custom_nodes/ComfyUI-ModalCredits/
├── __init__.py # Package initialization
├── modal_credits_node.py # Main node & credit logic
├── routes.py # API endpoints
├── web/
│ └── modal_credits.js # Web interface & battery UI
└── README.md # This file
🎯 How It Works
- GPU Detection: Uses
nvidia-smito detect your GPU - Cost Calculation: Calculates cost per second based on GPU
- Real-time Updates: Updates every second in the background
- Data Persistence: Saves to JSON file every 10 seconds
- Token Detection: Reads Modal config to detect account changes
💡 Pro Tips
- 📌 Update GPU costs monthly to match Modal's pricing
- 👀 Click battery icon regularly to check estimated time remaining
- ⚠️ Set alerts when credits drop below 20%
- 💾 Backup
modal_credits_data.jsonto preserve history - 🔄 Reset credits when you add funds to your Modal account
📝 Requirements
- ComfyUI
- Python 3.8+
- NVIDIA GPU (for GPU detection)
- Modal CLI configured (optional, for token detection)
🤝 Contributing
Issues and PRs welcome! Feel free to:
- Report bugs
- Suggest features
- Improve documentation
- Add support for more GPUs
📄 License
MIT License - Free to use and modify
⭐ Support
If this helps you track your Modal credits, give it a star! ⭐
Made with ❤️ for the ComfyUI community
Languages
JavaScript
78.5%
Python
21.5%