Skip to main content

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 from io.ComfyNode and implement specific class methods:

Defining Node Schema

The define_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 the io module:

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

The execute() method contains your node’s main logic:
Parameter names in execute() must exactly match the input names defined in define_schema().

Lazy Evaluation

Lazy inputs are only evaluated when needed, improving performance for conditional workflows.

Marking Inputs as Lazy

Controlling Lazy Evaluation

Implement check_lazy_status() to specify which lazy inputs should be evaluated:
1

Initial Call

Called with non-lazy inputs evaluated, lazy inputs as None
2

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:
The core LoadImage node uses fingerprinting to re-execute when the source image file changes on disk.

Creating an Extension

Wrap your nodes in a ComfyExtension 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:
Any .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

  • Check that comfy_entrypoint() is defined
  • Verify the extension is in the custom_nodes directory
  • Look for errors in the ComfyUI console on startup
  • Ensure node_id is unique
  • 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
  • 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 dependencies
4

Add Examples

Include example workflows demonstrating your nodes
5

Submit to Registry

Submit to ComfyUI custom node registry for discoverability

Memory Management

Learn about VRAM optimization for your custom nodes

Quantization

Work with quantized models in your nodes

Model Merging

Understand model merging techniques