Skip to content

N8N Custom Nodes

UniCraft provides custom N8N nodes that make it easy to integrate AI model routing into your N8N workflows.

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
Terminal window
# Install the UniCraft custom nodes
n8n install @cloudcraftlabs/unicraft-nodes
  1. Open your N8N instance
  2. Go to SettingsCommunity Nodes
  3. Click Install a community node
  4. Enter: @cloudcraftlabs/unicraft-nodes
  5. Click Install
Terminal window
# Clone the repository
git clone https://github.com/cloudcraftlabs/unicraft-n8n-nodes.git
# Install dependencies
cd unicraft-n8n-nodes
npm install
# Build the nodes
npm run build
# Copy to N8N nodes directory
cp -r dist/* /path/to/n8n/nodes/
  1. Go to Credentials in N8N
  2. Click Add Credential
  3. Select UniCraft API
  4. Enter your UniCraft API key
  5. Test the connection

Set up your AI providers in the UniCraft dashboard:

// Example provider configuration
const 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,
},
];

The Chat Completion node allows you to generate text using AI models.

  • 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)
{
"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
}
}

The Model Selection node helps you choose the best model for your task.

  • 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
{
"name": "Model Selection",
"type": "@cloudcraftlabs/unicraft-nodes.modelSelection",
"parameters": {
"task_type": "text_generation",
"quality_requirement": "high",
"cost_preference": "medium",
"response_time": 5000
}
}

The Provider Status node checks the status of your AI providers.

  • Provider: Specific provider to check (optional)
  • Include Models: Whether to include model information
{
"name": "Provider Status",
"type": "@cloudcraftlabs/unicraft-nodes.providerStatus",
"parameters": {
"provider": "openai",
"include_models": true
}
}
{
"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 }}"
}
}
]
}
{
"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 }}"
}
}
]
}
{
"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
}
}
]
}

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
}
}

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
}
}

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"]
}
}

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)); } }"
}
}

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"]
}
}
  • Use “auto” for most cases to leverage smart routing
  • Specify models only when you need specific capabilities
  • Consider cost vs. quality trade-offs
  • Always implement error handling
  • Use retry logic for transient failures
  • Set up fallback providers
  • Use appropriate max_tokens values
  • Implement caching where possible
  • Monitor response times
  • Store API keys securely
  • Validate input data
  • Monitor for unusual activity
  1. Authentication Errors

    • Check API key configuration
    • Verify credentials in N8N
    • Test connection
  2. Model Not Available

    • Check provider configuration
    • Verify model availability
    • Use “auto” for smart routing
  3. Rate Limiting

    • Implement rate limiting
    • Use batch processing
    • Monitor usage
  4. High Costs

    • Use cost-optimized routing
    • Set cost limits
    • Monitor spending
  1. Use N8N execution log
  2. Add logging nodes
  3. Test with simple requests
  4. Check UniCraft dashboard

For support with UniCraft N8N nodes:

After setting up UniCraft N8N nodes:

  1. Test Workflows: Test your workflows with various inputs
  2. Monitor Performance: Set up monitoring for workflow execution
  3. Optimize Costs: Monitor and optimize AI usage costs
  4. Scale Gradually: Start with simple workflows and add complexity
  5. Document Processes: Document your workflows for team use