Overview
Custom nodes in ComfyUI allow you to extend the platform with new functionality, from simple image processing operations to complex model integrations. This guide covers the complete workflow for creating, registering, and distributing custom nodes.Basic Node Structure
Custom nodes are Python classes that inherit fromio.ComfyNode and implement specific class methods:
Defining Node Schema
Thedefine_schema() method specifies the node’s identity and interface:
The
node_id must be unique across all installed custom nodes. Use descriptive names to avoid conflicts.Input Types
ComfyUI supports various input types through theio module:
- Basic Types
- Model Types
- Data Types
Output Types
Outputs are defined similarly using the.Output() variant:
Multiple outputs are supported. Return values in the same order as defined in the schema.
Execute Method
Theexecute() method contains your node’s main logic:
Lazy Evaluation
Lazy inputs are only evaluated when needed, improving performance for conditional workflows.Marking Inputs as Lazy
Controlling Lazy Evaluation
Implementcheck_lazy_status() to specify which lazy inputs should be evaluated:
1
Initial Call
Called with non-lazy inputs evaluated, lazy inputs as
None2
Request Evaluation
Return list of input names that need evaluation
3
Subsequent Calls
Called again once requested inputs are available
4
Complete
When empty list returned, proceed to
execute()Fingerprinting (Cache Control)
Control when your node should re-execute using fingerprinting:Creating an Extension
Wrap your nodes in aComfyExtension to register them:
Adding Custom API Routes
Extend the ComfyUI server with custom endpoints:Custom routes are useful for integrating external tools, providing status endpoints, or enabling webhooks.
Frontend Extensions
Add custom JavaScript to enhance the UI:.js file in that directory will be loaded by the frontend.
Example: Image Processing Node
Here’s a complete example of a custom image processing node:Example: Model Processing Node
Example of working with models:Best Practices
Type Hints
Use proper type hints for better IDE support and error detection
Error Handling
Add try-except blocks and provide meaningful error messages
Memory Management
Clean up large tensors and models when done processing
Documentation
Write clear docstrings and comments for complex logic
Lazy Inputs
Use lazy evaluation for expensive or conditional operations
Unique IDs
Ensure node_id is unique and descriptive
Debugging Tips
Node Not Appearing
Node Not Appearing
- Check that
comfy_entrypoint()is defined - Verify the extension is in the
custom_nodesdirectory - Look for errors in the ComfyUI console on startup
- Ensure
node_idis unique
Execution Errors
Execution Errors
- Add print statements to track execution flow
- Check that parameter names match between schema and execute
- Verify input/output tensor shapes and types
- Use try-except to catch and log exceptions
Performance Issues
Performance Issues
- Profile your code to find bottlenecks
- Use lazy evaluation for expensive operations
- Consider async operations for I/O
- Monitor memory usage with
torch.cuda.memory_summary()
Distribution
To distribute your custom node:1
Create Repository
Create a Git repository with your extension code
2
Add README
Document installation instructions and usage
3
Include Requirements
Add
requirements.txt for dependencies4
Add Examples
Include example workflows demonstrating your nodes
5
Submit to Registry
Submit to ComfyUI custom node registry for discoverability
Related
Memory Management
Learn about VRAM optimization for your custom nodes
Quantization
Work with quantized models in your nodes
Model Merging
Understand model merging techniques