N8N Custom Nodes
N8N Custom Nodes
Section titled “N8N Custom Nodes”UniCraft provides custom N8N nodes that make it easy to integrate AI model routing into your N8N workflows.
Overview
Section titled “Overview”N8N is a powerful workflow automation tool that allows you to connect different services and automate processes. UniCraft’s custom N8N nodes provide:
- Chat Completions: Generate text using AI models
- Model Selection: Automatically choose the best model for your task
- Cost Optimization: Route requests to the most cost-effective models
- Provider Management: Handle multiple AI providers seamlessly
Installation
Section titled “Installation”Method 1: N8N CLI
Section titled “Method 1: N8N CLI”# Install the UniCraft custom nodesn8n install @cloudcraftlabs/unicraft-nodesMethod 2: N8N Interface
Section titled “Method 2: N8N Interface”- Open your N8N instance
- Go to Settings → Community Nodes
- Click Install a community node
- Enter:
@cloudcraftlabs/unicraft-nodes - Click Install
Method 3: Manual Installation
Section titled “Method 3: Manual Installation”# Clone the repositorygit clone https://github.com/cloudcraftlabs/unicraft-n8n-nodes.git
# Install dependenciescd unicraft-n8n-nodesnpm install
# Build the nodesnpm run build
# Copy to N8N nodes directorycp -r dist/* /path/to/n8n/nodes/Configuration
Section titled “Configuration”1. Set Up Credentials
Section titled “1. Set Up Credentials”- Go to Credentials in N8N
- Click Add Credential
- Select UniCraft API
- Enter your UniCraft API key
- Test the connection
2. Configure Providers
Section titled “2. Configure Providers”Set up your AI providers in the UniCraft dashboard:
// Example provider configurationconst providers = [ { name: "OpenAI Production", type: "openai", api_key: process.env.OPENAI_API_KEY, models: ["gpt-4", "gpt-3.5-turbo"], priority: 1, }, { name: "Anthropic Production", type: "anthropic", api_key: process.env.ANTHROPIC_API_KEY, models: ["claude-3-sonnet", "claude-3-haiku"], priority: 2, },];Available Nodes
Section titled “Available Nodes”1. Chat Completion Node
Section titled “1. Chat Completion Node”The Chat Completion node allows you to generate text using AI models.
Parameters
Section titled “Parameters”- Messages: Array of message objects
- Model: AI model to use (or “auto” for smart routing)
- Max Tokens: Maximum number of tokens to generate
- Temperature: Controls randomness (0.0 to 1.0)
- Top P: Controls diversity (0.0 to 1.0)
- Frequency Penalty: Reduces repetition (-2.0 to 2.0)
- Presence Penalty: Encourages new topics (-2.0 to 2.0)
Example Usage
Section titled “Example Usage”{ "name": "Chat Completion", "type": "@cloudcraftlabs/unicraft-nodes.chatCompletion", "parameters": { "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "{{ $json.prompt }}" } ], "model": "auto", "max_tokens": 100, "temperature": 0.7 }}2. Model Selection Node
Section titled “2. Model Selection Node”The Model Selection node helps you choose the best model for your task.
Parameters
Section titled “Parameters”- Task Type: Type of task (text, code, analysis, etc.)
- Quality Requirement: Quality level needed (low, medium, high)
- Cost Preference: Cost preference (low, medium, high)
- Response Time: Maximum acceptable response time
Example Usage
Section titled “Example Usage”{ "name": "Model Selection", "type": "@cloudcraftlabs/unicraft-nodes.modelSelection", "parameters": { "task_type": "text_generation", "quality_requirement": "high", "cost_preference": "medium", "response_time": 5000 }}3. Provider Status Node
Section titled “3. Provider Status Node”The Provider Status node checks the status of your AI providers.
Parameters
Section titled “Parameters”- Provider: Specific provider to check (optional)
- Include Models: Whether to include model information
Example Usage
Section titled “Example Usage”{ "name": "Provider Status", "type": "@cloudcraftlabs/unicraft-nodes.providerStatus", "parameters": { "provider": "openai", "include_models": true }}Workflow Examples
Section titled “Workflow Examples”1. Content Generation Workflow
Section titled “1. Content Generation Workflow”{ "name": "Content Generation", "nodes": [ { "name": "Webhook", "type": "n8n-nodes-base.webhook", "parameters": { "path": "content-request", "httpMethod": "POST" } }, { "name": "Generate Content", "type": "@cloudcraftlabs/unicraft-nodes.chatCompletion", "parameters": { "messages": [ { "role": "system", "content": "You are a professional content writer." }, { "role": "user", "content": "Write a blog post about: {{ $json.topic }}" } ], "model": "auto", "max_tokens": 1000, "temperature": 0.7 } }, { "name": "Save to Google Docs", "type": "n8n-nodes-base.googleDocs", "parameters": { "operation": "create", "title": "{{ $json.topic }} - Blog Post", "content": "{{ $json.choices[0].message.content }}" } } ]}2. Customer Support Automation
Section titled “2. Customer Support Automation”{ "name": "Customer Support", "nodes": [ { "name": "Support Request", "type": "n8n-nodes-base.webhook", "parameters": { "path": "support", "httpMethod": "POST" } }, { "name": "Classify Request", "type": "@cloudcraftlabs/unicraft-nodes.chatCompletion", "parameters": { "messages": [ { "role": "system", "content": "Classify this support request: billing, technical, general, complaint" }, { "role": "user", "content": "{{ $json.message }}" } ], "model": "gpt-3.5-turbo", "max_tokens": 50 } }, { "name": "Generate Response", "type": "@cloudcraftlabs/unicraft-nodes.chatCompletion", "parameters": { "messages": [ { "role": "system", "content": "You are a helpful customer support agent." }, { "role": "user", "content": "Respond to this {{ $json.choices[0].message.content }} request: {{ $('Support Request').item.json.message }}" } ], "model": "auto", "max_tokens": 200 } }, { "name": "Send Email", "type": "n8n-nodes-base.emailSend", "parameters": { "toEmail": "{{ $('Support Request').item.json.email }}", "subject": "Re: {{ $('Support Request').item.json.subject }}", "message": "{{ $json.choices[0].message.content }}" } } ]}3. Data Analysis Workflow
Section titled “3. Data Analysis Workflow”{ "name": "Data Analysis", "nodes": [ { "name": "Data Source", "type": "n8n-nodes-base.googleSheets", "parameters": { "operation": "read", "sheetId": "your-sheet-id" } }, { "name": "Analyze Data", "type": "@cloudcraftlabs/unicraft-nodes.chatCompletion", "parameters": { "messages": [ { "role": "system", "content": "You are a data analyst. Analyze the provided data and provide insights." }, { "role": "user", "content": "Analyze this data: {{ JSON.stringify($json) }}" } ], "model": "gpt-4", "max_tokens": 500 } }, { "name": "Generate Report", "type": "@cloudcraftlabs/unicraft-nodes.chatCompletion", "parameters": { "messages": [ { "role": "system", "content": "You are a business analyst. Create a professional report." }, { "role": "user", "content": "Create a report based on: {{ $json.choices[0].message.content }}" } ], "model": "gpt-4", "max_tokens": 1000 } } ]}Advanced Features
Section titled “Advanced Features”1. Smart Routing
Section titled “1. Smart Routing”Use smart routing to automatically select the best model:
{ "name": "Smart Routing", "type": "@cloudcraftlabs/unicraft-nodes.chatCompletion", "parameters": { "messages": [ { "role": "user", "content": "{{ $json.prompt }}" } ], "model": "auto", "routing_strategy": "cost_optimized", "max_cost_per_request": 0.01, "quality_threshold": 0.8 }}2. Batch Processing
Section titled “2. Batch Processing”Process multiple requests together:
{ "name": "Batch Processing", "type": "@cloudcraftlabs/unicraft-nodes.batchCompletion", "parameters": { "requests": [ { "messages": [ { "role": "user", "content": "{{ $json.prompt1 }}" } ] }, { "messages": [ { "role": "user", "content": "{{ $json.prompt2 }}" } ] } ], "model": "auto", "max_tokens": 100 }}3. Cost Monitoring
Section titled “3. Cost Monitoring”Monitor costs in real-time:
{ "name": "Cost Monitor", "type": "@cloudcraftlabs/unicraft-nodes.costMonitor", "parameters": { "time_range": "1h", "alert_threshold": 10.0, "alert_channels": ["email", "slack"] }}Error Handling
Section titled “Error Handling”1. Retry Logic
Section titled “1. Retry Logic”Implement retry logic for failed requests:
{ "name": "Retry Logic", "type": "n8n-nodes-base.function", "parameters": { "functionCode": "const maxRetries = 3; let retries = 0; while (retries < maxRetries) { try { return $input.all(); } catch (error) { retries++; if (retries >= maxRetries) throw error; await new Promise(resolve => setTimeout(resolve, 1000 * retries)); } }" }}2. Fallback Handling
Section titled “2. Fallback Handling”Set up fallback providers:
{ "name": "Fallback Handler", "type": "@cloudcraftlabs/unicraft-nodes.chatCompletion", "parameters": { "messages": [ { "role": "user", "content": "{{ $json.prompt }}" } ], "model": "auto", "fallback_enabled": true, "fallback_providers": ["anthropic", "google"] }}Best Practices
Section titled “Best Practices”1. Model Selection
Section titled “1. Model Selection”- Use “auto” for most cases to leverage smart routing
- Specify models only when you need specific capabilities
- Consider cost vs. quality trade-offs
2. Error Handling
Section titled “2. Error Handling”- Always implement error handling
- Use retry logic for transient failures
- Set up fallback providers
3. Performance
Section titled “3. Performance”- Use appropriate max_tokens values
- Implement caching where possible
- Monitor response times
4. Security
Section titled “4. Security”- Store API keys securely
- Validate input data
- Monitor for unusual activity
Troubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues”-
Authentication Errors
- Check API key configuration
- Verify credentials in N8N
- Test connection
-
Model Not Available
- Check provider configuration
- Verify model availability
- Use “auto” for smart routing
-
Rate Limiting
- Implement rate limiting
- Use batch processing
- Monitor usage
-
High Costs
- Use cost-optimized routing
- Set cost limits
- Monitor spending
Debug Tips
Section titled “Debug Tips”- Use N8N execution log
- Add logging nodes
- Test with simple requests
- Check UniCraft dashboard
Support
Section titled “Support”For support with UniCraft N8N nodes:
- Documentation: UniCraft Docs
- GitHub: UniCraft N8N Nodes
- Community: UniCraft Community
- Support: support@unicraft.com
Next Steps
Section titled “Next Steps”After setting up UniCraft N8N nodes:
- Test Workflows: Test your workflows with various inputs
- Monitor Performance: Set up monitoring for workflow execution
- Optimize Costs: Monitor and optimize AI usage costs
- Scale Gradually: Start with simple workflows and add complexity
- Document Processes: Document your workflows for team use