ComfyUI Extension: ComfyUI-Kontext-API
A custom ComfyUI node for integrating with the Fal Kontext API for advanced image editing and generation.
Custom Nodes (0)
README
ComfyUI-Kontext-API
A custom ComfyUI node for integrating with the Fal Kontext API for advanced image editing and generation.
Features
- Image-to-Image Generation: Transform images based on text prompts using Fal's Kontext model
- Single Image Output: Generates one image per request for optimal ComfyUI compatibility
- Seed Control: Use specific seeds for reproducible results or -1 for random
- Prompt Enhancement: Optional AI prompt enhancement (can be disabled)
Installation
- Clone this repository into your ComfyUI custom nodes directory:
cd ComfyUI/custom_nodes
git clone https://github.com/SanDiegoDude/ComfyUI-Kontext-API.git
- Install required dependencies:
cd ComfyUI-Kontext-API
pip install -r requirements.txt
- Set up your Fal API key (REQUIRED):
Getting a Fal API Key
- Sign up at https://fal.ai/
- Go to your dashboard
- Generate an API key
Setting up the API Key
Choose one of these methods:
Option 1: Create a .fal_key file (Recommended)
- Create a file named
.fal_key
in theComfyUI-Kontext-API
directory - Put your Fal API key in this file (just the key, nothing else)
- The file should contain only your API key, for example:
fal_1234567890abcdef
- Note: The
.fal_key
file is already in.gitignore
for security
Option 2: Set environment variable
export FAL_KEY="your_fal_api_key_here"
Usage
- Find the Fal Kontext API node in the
image/generation
category - Connect an input image to the
image
input - Enter your prompt describing the desired transformation
- Adjust settings:
- seed: Specific seed for reproducibility (-1 for random)
- disable_prompt_enhancement: Turn off AI prompt enhancement if needed
Node Inputs
- prompt (STRING): Text description of the desired image transformation
- image (IMAGE): Input image to transform
- seed (INT): Random seed (-1 for random, default: -1)
- disable_prompt_enhancement (BOOLEAN): Disable AI prompt enhancement (default: False)
Node Outputs
- image (IMAGE): Generated image as a single tensor
- info (STRING): API response information including:
- Request ID
- Seed used for generation
- Safety check status (✓ passed or ⚠️ blocked)
- Any error messages or warnings
- passed_nsfw_filtering (BOOLEAN): True if content passed safety checks, False if blocked
- Designed to work with "save on true" nodes in ComfyUI
- Returns True for safe content that should be saved
- Returns False for blocked content that should be skipped
Example Prompts
- "Change the car color to red"
- "Convert to pencil sketch with natural graphite lines"
- "Transform to oil painting with visible brushstrokes"
- "It's now snowing, everything is covered in snow"
- "Using this style, a bunny, a dog and a cat are having a tea party"
Troubleshooting
Debug Mode
The node includes detailed debug logging to help diagnose issues. To disable debug output once everything is working:
- Open
nodes.py
- Change
DEBUG = True
toDEBUG = False
at the top of the file
Image Handling Errors
The node properly handles ComfyUI's tensor format (B, H, W, C) and converts between PIL images and tensors automatically.
API Key Issues
Ensure your Fal API key is properly set either as an environment variable or in the .fal_key
file.
If you see an error like "FAL API KEY NOT FOUND!", follow these steps:
- Make sure you have created the
.fal_key
file in theComfyUI-Kontext-API
directory (not in ComfyUI root) - Check that the file contains only your API key with no extra spaces or quotes
- Verify the key is valid by testing it on fal.ai
Dependencies
Make sure you have installed all required packages:
pip install fal-client Pillow numpy torch
License
This project is licensed under the MIT License - see the LICENSE file for details.