Skip to content

N8N Workflows

This guide shows you how to integrate UniCraft with N8N workflows to automate AI-powered processes.

N8N is a powerful workflow automation tool that can be integrated with UniCraft to create sophisticated AI-powered automations. This integration allows you to:

  • Automate AI model selection and routing
  • Process data through AI models in workflows
  • Create intelligent decision-making processes
  • Build AI-powered business processes

Before setting up N8N workflows with UniCraft:

  1. N8N Instance: Have N8N running (self-hosted or cloud)
  2. UniCraft Account: Active UniCraft account with API access
  3. API Keys: UniCraft API key and configured providers
  4. N8N Custom Nodes: Install UniCraft custom nodes (if available)

If UniCraft provides custom N8N nodes:

Terminal window
# Install via N8N CLI
n8n install @cloudcraftlabs/unicraft-nodes
# Or install via N8N interface
# Go to Settings > Community Nodes > Install
# Add: @cloudcraftlabs/unicraft-nodes

Set up UniCraft credentials in N8N:

  1. Go to Credentials in N8N
  2. Click Add Credential
  3. Select UniCraft API
  4. Enter your UniCraft API key
  5. Test the connection

Create a simple workflow that uses UniCraft:

{
"name": "UniCraft Chat Completion",
"nodes": [
{
"name": "Start",
"type": "n8n-nodes-base.start",
"position": [240, 300]
},
{
"name": "UniCraft Chat",
"type": "@cloudcraftlabs/unicraft-nodes.chatCompletion",
"position": [460, 300],
"parameters": {
"messages": [
{
"role": "user",
"content": "{{ $json.prompt }}"
}
],
"model": "auto",
"max_tokens": 100
}
},
{
"name": "Process Response",
"type": "n8n-nodes-base.function",
"position": [680, 300],
"parameters": {
"functionCode": "return { response: $input.first().json.choices[0].message.content };"
}
}
],
"connections": {
"Start": {
"main": [["UniCraft Chat"]]
},
"UniCraft Chat": {
"main": [["Process Response"]]
}
}
}

Automate content generation with quality checks:

{
"name": "Content Generation Pipeline",
"nodes": [
{
"name": "Content Request",
"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": "gpt-4",
"max_tokens": 1000,
"temperature": 0.7
}
},
{
"name": "Quality Check",
"type": "@cloudcraftlabs/unicraft-nodes.chatCompletion",
"parameters": {
"messages": [
{
"role": "system",
"content": "You are a content quality reviewer."
},
{
"role": "user",
"content": "Rate the quality of this content (1-10): {{ $json.choices[0].message.content }}"
}
],
"model": "gpt-3.5-turbo",
"max_tokens": 50
}
},
{
"name": "Conditional Processing",
"type": "n8n-nodes-base.if",
"parameters": {
"conditions": {
"number": [
{
"value1": "{{ $json.choices[0].message.content }}",
"operation": "larger",
"value2": 7
}
]
}
}
},
{
"name": "Save Content",
"type": "n8n-nodes-base.googleSheets",
"parameters": {
"operation": "append",
"sheetId": "your-sheet-id",
"columns": {
"mappingMode": "defineBelow",
"value": {
"topic": "={{ $('Content Request').item.json.topic }}",
"content": "={{ $('Generate Content').item.json.choices[0].message.content }}",
"quality_score": "={{ $('Quality Check').item.json.choices[0].message.content }}"
}
}
}
}
]
}

Automate customer support with AI:

{
"name": "Customer Support Bot",
"nodes": [
{
"name": "Support Request",
"type": "n8n-nodes-base.webhook",
"parameters": {
"path": "support-request",
"httpMethod": "POST"
}
},
{
"name": "Classify Request",
"type": "@cloudcraftlabs/unicraft-nodes.chatCompletion",
"parameters": {
"messages": [
{
"role": "system",
"content": "Classify this customer support request into categories: billing, technical, general, complaint"
},
{
"role": "user",
"content": "{{ $json.message }}"
}
],
"model": "gpt-3.5-turbo",
"max_tokens": 50
}
},
{
"name": "Route by Category",
"type": "n8n-nodes-base.switch",
"parameters": {
"rules": {
"rules": [
{
"value1": "={{ $json.choices[0].message.content }}",
"operation": "contains",
"value2": "billing"
},
{
"value1": "={{ $json.choices[0].message.content }}",
"operation": "contains",
"value2": "technical"
},
{
"value1": "={{ $json.choices[0].message.content }}",
"operation": "contains",
"value2": "complaint"
}
]
}
}
},
{
"name": "Generate Response",
"type": "@cloudcraftlabs/unicraft-nodes.chatCompletion",
"parameters": {
"messages": [
{
"role": "system",
"content": "You are a helpful customer support agent. Provide a professional and helpful response."
},
{
"role": "user",
"content": "Customer message: {{ $('Support Request').item.json.message }}\nCategory: {{ $('Classify Request').item.json.choices[0].message.content }}"
}
],
"model": "gpt-3.5-turbo",
"max_tokens": 200
}
},
{
"name": "Send Response",
"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 }}"
}
}
]
}

Automate data analysis with AI:

{
"name": "Data Analysis Pipeline",
"nodes": [
{
"name": "Data Source",
"type": "n8n-nodes-base.googleSheets",
"parameters": {
"operation": "read",
"sheetId": "your-data-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 based on the analysis."
},
{
"role": "user",
"content": "Create a report based on this analysis: {{ $json.choices[0].message.content }}"
}
],
"model": "gpt-4",
"max_tokens": 1000
}
},
{
"name": "Save Report",
"type": "n8n-nodes-base.googleDocs",
"parameters": {
"operation": "create",
"title": "Data Analysis Report - {{ new Date().toISOString().split('T')[0] }}",
"content": "={{ $json.choices[0].message.content }}"
}
}
]
}

If custom nodes aren’t available, use the HTTP Request node:

{
"name": "UniCraft HTTP Request",
"type": "n8n-nodes-base.httpRequest",
"parameters": {
"url": "https://api.unicraft.com/v1/chat/completions",
"method": "POST",
"headers": {
"Authorization": "Bearer {{ $credentials.unicraftApi.apiKey }}",
"Content-Type": "application/json"
},
"body": {
"messages": [
{
"role": "user",
"content": "{{ $json.prompt }}"
}
],
"model": "auto",
"max_tokens": 100
}
}
}
{
"name": "UniCraft with Error Handling",
"type": "n8n-nodes-base.httpRequest",
"parameters": {
"url": "https://api.unicraft.com/v1/chat/completions",
"method": "POST",
"headers": {
"Authorization": "Bearer {{ $credentials.unicraftApi.apiKey }}",
"Content-Type": "application/json"
},
"body": {
"messages": [
{
"role": "user",
"content": "{{ $json.prompt }}"
}
],
"model": "auto",
"max_tokens": 100
},
"options": {
"retry": {
"enabled": true,
"maxRetries": 3
},
"timeout": 30000
}
}
}

Always implement error handling in your workflows:

{
"name": "Error Handler",
"type": "n8n-nodes-base.function",
"parameters": {
"functionCode": "if ($input.first().json.error) { throw new Error($input.first().json.error.message); } return $input.all();"
}
}

Implement rate limiting to avoid hitting API limits:

{
"name": "Rate Limiter",
"type": "n8n-nodes-base.wait",
"parameters": {
"amount": 1,
"unit": "seconds"
}
}

Validate input data before processing:

{
"name": "Validate Input",
"type": "n8n-nodes-base.function",
"parameters": {
"functionCode": "const input = $input.first().json; if (!input.prompt || input.prompt.length < 10) { throw new Error('Prompt too short'); } return $input.all();"
}
}

Add logging for debugging and monitoring:

{
"name": "Log Response",
"type": "n8n-nodes-base.function",
"parameters": {
"functionCode": "console.log('UniCraft Response:', JSON.stringify($input.first().json, null, 2)); return $input.all();"
}
}

Test workflows manually using the N8N interface:

  1. Click Execute Workflow
  2. Provide test data
  3. Monitor execution
  4. Check results

Set up automated testing for your workflows:

{
"name": "Test Workflow",
"nodes": [
{
"name": "Test Data",
"type": "n8n-nodes-base.function",
"parameters": {
"functionCode": "return [{ json: { prompt: 'Test prompt', expected: 'Test response' } }];"
}
},
{
"name": "UniCraft Request",
"type": "@cloudcraftlabs/unicraft-nodes.chatCompletion",
"parameters": {
"messages": [
{
"role": "user",
"content": "{{ $json.prompt }}"
}
],
"model": "gpt-3.5-turbo",
"max_tokens": 50
}
},
{
"name": "Validate Response",
"type": "n8n-nodes-base.function",
"parameters": {
"functionCode": "const response = $input.first().json.choices[0].message.content; if (!response || response.length < 10) { throw new Error('Invalid response'); } return $input.all();"
}
}
]
}

Set up different environments for development and production:

{
"development": {
"unicraft_api_url": "https://api-dev.unicraft.com",
"model": "gpt-3.5-turbo",
"max_tokens": 100
},
"production": {
"unicraft_api_url": "https://api.unicraft.com",
"model": "auto",
"max_tokens": 500
}
}
  • Use environment variables for API keys
  • Implement proper authentication
  • Validate all inputs
  • Monitor for unusual activity
  • Use appropriate models for tasks
  • Implement caching where possible
  • Batch requests when appropriate
  • Monitor response times
  1. Authentication Errors: Check API key configuration
  2. Rate Limiting: Implement proper rate limiting
  3. Model Selection: Ensure models are available
  4. Data Format: Validate input data format
  1. Use the N8N execution log
  2. Add logging nodes to workflows
  3. Test with simple requests first
  4. Check UniCraft API documentation

After setting up N8N workflows with UniCraft:

  1. Test Thoroughly: Test all 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