📝 (docs): update implementation status and README to reflect new settings integration 🔧 (docs): create SETTINGS_INTEGRATION.md and SETTINGS_INTEGRATION_SUMMARY.md for detailed implementation overview ✨ (civitai_service.py, config_api.py, gemini_util_options.py, nodes.py): implement API key management through ComfyUI settings instead of environment variables to enhance security and usability ♻️ (gemini_options_security.js): disable outdated security extension for API key handling as it is no longer needed ⬆️ (pyproject.toml): bump version to 2.9.0 to reflect recent changes and improvements ✨ (swiss-army-knife.js): update extension version to 2.8.11 for consistency ✨ (swiss-army-knife.js): add helper functions to retrieve API keys from settings ✨ (swiss-army-knife.js): implement sync function to send API keys to backend 💡 (swiss-army-knife.js): update comments to reflect changes in API key handling ✨ (swiss-army-knife.js): register settings for Gemini and Civitai API keys with sync functionality
3.9 KiB
3.9 KiB
ComfyUI Settings Integration
Overview
As of version 2.8.11+, ComfyUI-SwissArmyKnife integrates with ComfyUI's native settings system to manage API keys securely. This replaces the previous approach of using text input widgets for API keys.
Settings Configuration
Gemini API Key
- Setting ID:
swiss_army_knife.gemini.api_key - Location: ComfyUI Settings → Swiss Army Knife → Gemini API Key
- Purpose: Used by GeminiUtilOptions and related media description nodes
CivitAI API Key
- Setting ID:
swiss_army_knife.civitai.api_key - Location: ComfyUI Settings → Swiss Army Knife → Civitai API Key
- Purpose: Used by LoRAInfoExtractor for metadata lookup
Benefits of Settings Integration
Security
- API keys are stored securely in ComfyUI's settings system
- Keys are never saved in workflow JSON files
- Settings are stored separately from shareable workflows
User Experience
- Configure once, use everywhere
- No need to enter API keys in individual nodes
- Settings persist across ComfyUI sessions
Workflow Sharing
- Workflows can be shared without exposing API keys
- Recipients can use their own API keys from settings
- No risk of accidentally sharing sensitive information
Node Changes
GeminiUtilOptions Node
Before: Had a gemini_api_key text input widget
After: Automatically retrieves API key from ComfyUI settings
LoRAInfoExtractor Node
Before: Had a civitai_api_key text input widget
After: Automatically retrieves API key from ComfyUI settings
Technical Implementation
Frontend (JavaScript)
- Settings are registered using ComfyUI's settings API
onChangehandlers automatically sync settings to backend- Helper functions provide easy access to settings values
Backend (Python)
- Settings are cached from frontend via API endpoint
- Fallback to environment variables if settings unavailable
- Nodes access API keys via centralized function
API Endpoints
GET /swissarmyknife/config- Retrieve current configurationPOST /swissarmyknife/set_api_keys- Update cached API keys
Migration Guide
For Users
- Open ComfyUI Settings (gear icon)
- Navigate to "Swiss Army Knife" section
- Enter your API keys:
- Gemini API Key: Your Google AI Studio API key
- CivitAI API Key: Your CivitAI API key
- Existing workflows will automatically use the new settings
For Developers
- Nodes should use
get_setting_value()function instead of input parameters - JavaScript widgets can access settings via
app.extensionManager.setting.get() - Settings changes are automatically synced between frontend and backend
Fallback Behavior
If ComfyUI settings are not available, the system falls back to:
- Environment variables (
GEMINI_API_KEY,CIVITAI_API_KEY) - Empty string (will cause API operations to fail gracefully)
This ensures backward compatibility and graceful degradation.
Files Modified
JavaScript
web/js/swiss-army-knife.js- Settings registration and syncweb/js/gemini_options_security.js- Disabled (no longer needed)
Python
nodes/config_api.py- Settings caching and API endpointsnodes/media_describe/gemini_util_options.py- Removed API key widgetnodes/nodes.py- Removed CivitAI API key widget from LoRAInfoExtractor
Troubleshooting
Settings Not Working
- Check ComfyUI version supports settings API
- Verify settings are entered correctly (no extra spaces)
- Check browser console for JavaScript errors
- Restart ComfyUI if settings seem stuck
API Keys Not Being Used
- Verify settings are entered in ComfyUI Settings panel
- Check server logs for caching messages
- Ensure fallback environment variables are not interfering
- Try refreshing the page to force settings sync
Workflow Compatibility
- Existing workflows will work automatically
- Shared workflows will use recipient's API keys from settings
- No migration of existing workflow files needed