ComfyUI_LiteLLM is an addon for ComfyUI that provides nodes for interacting with various language models using the LiteLLM library directly within the ComfyUI interface. This addon serves as a bridge between ComfyUI and LiteLLM, allowing you to leverage any model supported by LiteLLM in your ComfyUI workflows.
This addon provides ComfyUI nodes that interface with LiteLLM's functionality, including:
LiteLLMModelProvider
: Selects LiteLLM-supported models for use in other nodesLiteLLMCompletion
: Generates completions using any LiteLLM-supported modelLiteLLMCompletionPrePend
: Similar to LiteLLMCompletion but with a pre-pended promptLiteLLMCompletionListOfPrompts
: Generates completions for a list of promptsCreateReflectionFilter
andFirstCodeBlockReflectionFilter
: Creates reflection filters for use withLiteLLMCompletionWithReflectionFilter
LiteLLMCompletionWithReflectionFilter
: Generates completions with a reflection filterLiteLLMCompletionProvider
: Provides a completion function for use in other nodesLiteLLMMessage
: Creates LiteLLM messagesShowLastMessage
andShowMessages
: Display message content in the UIListToMessages
andMessagesToList
: Convert between list and message formatsAppendMessages
: Combine multiple message setsMessagesToText
andTextToMessages
: Convert between text and message formatsLLLMInterpretUrl
: Fetch and process content from URLs
Complete graph-based Retrieval-Augmented Generation with any LiteLLM model:
- DocumentProcessor: Process documents using LightRAG with any LiteLLM-supported model
- QueryNode: Query LightRAG knowledge graphs with multiple retrieval modes (naive, local, global, hybrid)
- AgentMemoryProvider: Create memory functions for LiteLLM agents
- LinuxMemoryDirectory: High-performance memory directory for faster processing
- Local Embeddings: Uses high-quality Stella 1.5B model locally (no OpenAI dependency)
- Automatic Compatibility: LiteLLM completion providers work seamlessly with LightRAG's async interface
This addon supports all models that LiteLLM can interface with. This includes, but is not limited to:
- OpenAI models
- Anthropic models (Claude)
- Google models (PaLM, Gemini)
- Azure OpenAI
- AWS Bedrock models
- Cohere models
- AI21 models
- And many more
For the most up-to-date list of supported models, please refer to the LiteLLM documentation.
This addon features a production-ready integration between LightRAG (Graph-based Retrieval-Augmented Generation) and LiteLLM completion providers. Use any LiteLLM-supported model with LightRAG's powerful graph-based knowledge indexing and retrieval.
- π Universal Model Support: Use any LiteLLM model (OpenAI, Anthropic, Google, Kluster, etc.) with LightRAG
- π Local Embeddings: High-quality Stella 1.5B model runs locally (no OpenAI API calls)
- π Graph-Based Knowledge: Build intelligent knowledge graphs from documents with entity and relationship extraction
- π Incremental Processing: Add documents progressively while maintaining graph relationships
- π Multiple Query Modes: naive, local, global, and hybrid retrieval strategies
- πΎ Persistent Storage: Working directories maintain state across sessions
- π§ Agent Memory: Seamless integration with LiteLLM agents for contextual memory
- β‘ High Performance: Linux memory directory support for faster processing
The integration includes an automatic compatibility wrapper that bridges the gap between:
- LiteLLM: Synchronous
completion_function(prompt)
- LightRAG: Async
llm_func(prompt, system_prompt, history_messages, **kwargs)
The wrapper intelligently combines system prompts, conversation history, and user prompts into the format expected by your chosen LLM.
Node | Purpose | Key Features |
---|---|---|
DocumentProcessor | Process documents into knowledge graphs | Chunking, entity extraction, relationship mapping |
QueryNode | Query the knowledge graph | 4 retrieval modes, contextual responses |
AgentMemoryProvider | Memory for LiteLLM agents | Query refinement, context retrieval |
LinuxMemoryDirectory | High-speed storage | /dev/shm for faster processing |
Basic Document Processing:
LiteLLMModelProvider β LiteLLMCompletionProvider β DocumentProcessor
Complete RAG Pipeline:
LiteLLMModelProvider β LiteLLMCompletionProvider β DocumentProcessor β QueryNode
Agent with Memory:
DocumentProcessor β AgentMemoryProvider β [Your Agent Workflow]
- β Real API Integration: Tested with actual Kluster API calls
- β Multi-Document Processing: Handles incremental document addition
- β Cross-Document Queries: Finds relationships across multiple documents
- β State Persistence: Working directories maintain state across sessions
- β Error Handling: Robust error recovery and informative messages
- β No OpenAI Dependencies: Local embeddings eliminate authentication errors
Requirements:
pip install sentence-transformers
DocumentProcessor Configuration:
embedding_provider
: "local" (default - uses Stella 1.5B model)embedding_model
: "NovaSearch/stella_en_1.5B_v5" (default)embedding_dimension
: 1024 (recommended, options: 256-8192)override_callable
: REQUIRED - Connect your LiteLLM completion provider
Benefits:
- β High-quality embeddings (state-of-the-art MTEB scores)
- β Complete privacy - no data sent to external APIs
- β Fast local inference after initial model download (~3GB)
- β No API costs for embeddings
- β Works offline after setup
- Clone this repository into your
custom_nodes
directory in your ComfyUI installation. - Install the required dependencies by running
pip install -r requirements.txt
. - Restart ComfyUI.
- Add this addon's repository URL to your ComfyUI-Manager configuration.
- Install the addon through ComfyUI-Manager.
- Restart ComfyUI.
For production use in ComfyUI, set your API keys as system environment variables:
export OPENAI_API_KEY="your-openai-api-key"
export ANTHROPIC_API_KEY="your-anthropic-api-key"
export KLUSTER_API_KEY="your-kluster-api-key"
# ... other API keys as needed
The addon uses a clean architecture that separates configuration from secrets:
config.yaml
: Contains non-sensitive settings like base URLs and paths. Never put API keys here..env
: Used only for testing and development. Not used in production ComfyUI.
This addon follows best practices for environment management:
- β Never pollutes global environment variables - won't interfere with other ComfyUI custom nodes
- β
Reads environment variables safely - uses system environment first, falls back to
.env
for testing - β No API keys in config files - keeps secrets separate from configuration
- β Compatible with other node packs - won't override API keys that other packages expect
If you're developing or testing, you can create a .env
file in the addon directory:
# ComfyUI_LiteLLM/.env
OPENAI_API_KEY=your-test-key
KLUSTER_API_KEY=your-test-key
# etc.
This .env
file is only used when system environment variables aren't available, making it perfect for development without affecting production deployments.
After installation, the LiteLLM nodes will be available in the ComfyUI node editor under the "ETK/LLM/LiteLLM" category. You can use these nodes to integrate any LiteLLM-supported language model into your ComfyUI workflows.
- Set up your API keys as system environment variables (see Configuration section above)
- Select the desired model in the
LiteLLMModelProvider
node - Connect the nodes in your workflow
- Install sentence-transformers:
pip install sentence-transformers
- Create workflow:
LiteLLMModelProvider
βLiteLLMCompletionProvider
βDocumentProcessor
- Connect completion provider to DocumentProcessor's
override_callable
input (REQUIRED) - Set embedding provider to "local" for high-quality local embeddings
- First run downloads Stella model (~3GB), then cached for future use
The addon will automatically use your environment variables for authentication without interfering with other ComfyUI custom nodes that may also use the same API services.
Contributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request.
The addon includes comprehensive tests that can be run with:
cd ComfyUI_LiteLLM
python3 -m pytest tests/ -v
Tests use the .env
file for API keys when available, or skip tests requiring real API calls if keys aren't configured.
This addon is released under the MIT License.
- pyyaml
- addict
- litellm
- boto3
- lightrag-hku (for LightRAG graph-based RAG integration)
- sentence-transformers (for local embeddings with Stella 1.5B model)
For the full list of dependencies, please refer to the requirements.txt
file.