This workflow corresponds to n8n.io template #13809 — we link there as the canonical source.
The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"id": "Le5YLLYsFuiH6UBT",
"name": "n8n Hugging Face \u2014 Open-Source AI Model Runner",
"tags": [],
"nodes": [
{
"id": "e5af3623-cb11-41bd-8823-c00d4578c342",
"name": "Main Overview",
"type": "n8n-nodes-base.stickyNote",
"position": [
-256,
-272
],
"parameters": {
"width": 1408,
"height": 1468,
"content": "# n8n Hugging Face Workflow\n## Run Open-Source AI Models Automatically\n\n---\n\n### Description\nThis workflow connects n8n to the Hugging Face Inference API, letting you run powerful open-source AI models for text generation, summarization, sentiment analysis, translation, and image generation \u2014 all fully automated, no GPU setup required. Simply POST a request and get AI-powered results back in seconds.\n\n---\n\n### What's the Goal?\nTo give developers, agencies, and businesses a plug-and-play automation for running any Hugging Face model without managing infrastructure. Replace expensive proprietary APIs with open-source alternatives that you control.\n\nTasks this workflow handles out of the box:\n- Text generation (GPT-style content writing)\n- Summarization (condense long documents)\n- Sentiment analysis (classify tone of any text)\n- Translation (multilingual content)\n- Image generation (text-to-image via Stable Diffusion)\n\n---\n\n### Why Does It Matter?\nHugging Face hosts over 400,000 open-source models \u2014 many matching or exceeding the quality of paid APIs at a fraction of the cost. This workflow:\n\n- Saves money: free tier available, paid plans start at $9/mo\n- Gives full control: swap any model by changing one field\n- Scales instantly: no GPU provisioning or DevOps needed\n- Works in automation: connects to any n8n trigger or pipeline\n- Produces billable output: agencies can resell AI services built on this\n\n---\n\n### How It Works\nStep 1 \u2014 Webhook receives the task request with input text and task type\nStep 2 \u2014 Set node stores your Hugging Face API key and normalizes all inputs\nStep 3 \u2014 Code node selects the right model and builds the correct API payload for the task\nStep 4 \u2014 HTTP Request calls the Hugging Face Inference API with the built payload\nStep 5 \u2014 Code node parses and formats the raw API response into clean structured output\nStep 6 \u2014 Respond node returns the final result as JSON to the caller\n\n---\n\n### Configuration Requirements\n- HUGGING_FACE_API_KEY \u2014 Get free at huggingface.co/settings/tokens\n- No other credentials needed for basic usage\n- Optional: Google Sheets credential for logging (node already included)\n\n---\n\n### Setup Guide\nStep 1: Import this workflow into your n8n instance\nStep 2: Open the Set API Config node and replace YOUR_HF_API_KEY with your token\nStep 3: Activate the workflow\nStep 4: POST to /webhook/hf-runner with your task payload\nStep 5: Swap models anytime by changing the model field in your request\n"
},
"typeVersion": 1
},
{
"id": "1a48bd5c-8f54-497b-a17a-92ec92a2e66e",
"name": "Flow Guide",
"type": "n8n-nodes-base.stickyNote",
"position": [
1216,
16
],
"parameters": {
"color": 3,
"width": 608,
"height": 536,
"content": "### 1. Request and builds the correct API\n\nWebhook receives the task request with input text and task type and stores your Hugging Face API key and normalizes all inputs then selects the right model and builds the correct API payload for the task"
},
"typeVersion": 1
},
{
"id": "e3956749-268d-4d66-bf66-75ef24ec1e46",
"name": "Receive Task Request",
"type": "n8n-nodes-base.webhook",
"position": [
1264,
352
],
"parameters": {
"path": "hf-runner",
"options": {},
"httpMethod": "POST",
"responseMode": "responseNode"
},
"typeVersion": 2
},
{
"id": "8ee44072-1067-4fb5-ad3a-e28886a402e8",
"name": "Set API Config",
"type": "n8n-nodes-base.set",
"position": [
1472,
352
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "a1",
"name": "task",
"type": "string",
"value": "={{ $json.body.task || $json.task || 'summarization' }}"
},
{
"id": "a2",
"name": "inputText",
"type": "string",
"value": "={{ $json.body.input || $json.input || '' }}"
},
{
"id": "a3",
"name": "customModel",
"type": "string",
"value": "={{ $json.body.model || $json.model || '' }}"
},
{
"id": "a4",
"name": "extraParams",
"type": "string",
"value": "={{ JSON.stringify($json.body.parameters || $json.parameters || {}) }}"
},
{
"id": "a5",
"name": "jobId",
"type": "string",
"value": "={{ 'HF-' + Date.now() }}"
},
{
"id": "a6",
"name": "HF_API_KEY",
"type": "string",
"value": "YOUR_HF_API_KEY"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "e767998b-63c4-4d9e-bff5-fe9d51c7da74",
"name": "Build Model Payload",
"type": "n8n-nodes-base.code",
"position": [
1696,
352
],
"parameters": {
"jsCode": "\nvar d = $input.first().json;\n\n// Default models per task\nvar defaultModels = {\n text_generation: 'mistralai/Mistral-7B-Instruct-v0.2',\n summarization: 'facebook/bart-large-cnn',\n sentiment_analysis: 'distilbert-base-uncased-finetuned-sst-2-english',\n translation: 'Helsinki-NLP/opus-mt-en-fr',\n image_generation: 'stabilityai/stable-diffusion-xl-base-1.0'\n};\n\nvar task = d.task || 'summarization';\nvar model = d.customModel || defaultModels[task] || defaultModels['summarization'];\nvar input = d.inputText || '';\n\nif (!input) {\n throw new Error('Missing input field. Please provide text in the input field.');\n}\n\n// Build payload per task type\nvar payload = {};\nif (task === 'text_generation') {\n payload = {\n inputs: input,\n parameters: { max_new_tokens: 512, temperature: 0.7, return_full_text: false }\n };\n} else if (task === 'summarization') {\n payload = {\n inputs: input,\n parameters: { max_length: 200, min_length: 50, do_sample: false }\n };\n} else if (task === 'sentiment_analysis') {\n payload = { inputs: input };\n} else if (task === 'translation') {\n payload = { inputs: input };\n} else if (task === 'image_generation') {\n payload = {\n inputs: input,\n parameters: { num_inference_steps: 30, guidance_scale: 7.5 }\n };\n} else {\n payload = { inputs: input };\n}\n\n// Merge any extra user params\ntry {\n var extra = JSON.parse(d.extraParams || '{}');\n if (extra && typeof extra === 'object') {\n payload.parameters = Object.assign(payload.parameters || {}, extra);\n }\n} catch(e) {}\n\nreturn [{ json: {\n jobId: d.jobId,\n task: task,\n model: model,\n payload: payload,\n payloadJson: JSON.stringify(payload),\n HF_API_KEY: d.HF_API_KEY,\n startedAt: new Date().toISOString()\n}}];\n"
},
"typeVersion": 2
},
{
"id": "87092f41-6704-462c-8a87-8ad047ca809c",
"name": "Call Hugging Face API",
"type": "n8n-nodes-base.httpRequest",
"position": [
1920,
352
],
"parameters": {
"url": "={{ 'https://api-inference.huggingface.co/models/' + $json.model }}",
"method": "POST",
"options": {
"timeout": 60000,
"response": {
"response": {
"responseFormat": "json"
}
}
},
"jsonBody": "={{ $json.payloadJson }}",
"sendBody": true,
"sendHeaders": true,
"specifyBody": "json",
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "={{ 'Bearer ' + $json.HF_API_KEY }}"
},
{
"name": "Content-Type",
"value": "application/json"
},
{
"name": "x-wait-for-model",
"value": "true"
}
]
}
},
"typeVersion": 4.2
},
{
"id": "6a285588-0068-4623-99ec-b46141d0e6c2",
"name": "Parse and Format Response",
"type": "n8n-nodes-base.code",
"position": [
2144,
352
],
"parameters": {
"jsCode": "\nvar raw = $('Call Hugging Face API').first().json;\nvar meta = $('Build Model Payload').first().json;\n\nvar task = meta.task || 'unknown';\nvar result = null;\nvar label = '';\nvar score = null;\n\ntry {\n // HF returns different shapes per task\n if (Array.isArray(raw)) {\n var first = raw[0];\n\n if (task === 'text_generation') {\n result = (first.generated_text || '').trim();\n\n } else if (task === 'summarization') {\n result = (first.summary_text || '').trim();\n\n } else if (task === 'sentiment_analysis') {\n // Can be nested array\n var item = Array.isArray(first) ? first[0] : first;\n label = item.label || '';\n score = item.score ? parseFloat(item.score.toFixed(4)) : null;\n result = label + ' (' + (score !== null ? (score * 100).toFixed(1) + '%' : '') + ' confidence)';\n\n } else if (task === 'translation') {\n result = (first.translation_text || '').trim();\n\n } else if (task === 'image_generation') {\n // Binary/blob \u2014 HF returns base64 in some endpoints\n result = '[Image generated \u2014 use binary output mode for image bytes]';\n\n } else {\n result = JSON.stringify(first);\n }\n\n } else if (raw && typeof raw === 'object') {\n // Some models return object directly\n result = raw.generated_text || raw.summary_text || raw.translation_text || JSON.stringify(raw);\n } else {\n result = String(raw);\n }\n} catch(e) {\n result = 'Parse error: ' + e.message;\n}\n\nreturn [{ json: {\n success: true,\n jobId: meta.jobId,\n task: task,\n model: meta.model,\n result: result,\n label: label || null,\n score: score,\n resultLength: (result || '').length,\n completedAt: new Date().toISOString()\n}}];\n"
},
"typeVersion": 2
},
{
"id": "d582c9bf-69aa-42ea-80d4-91188fd2c160",
"name": "Return Result",
"type": "n8n-nodes-base.respondToWebhook",
"position": [
2352,
352
],
"parameters": {
"options": {
"responseCode": 200
},
"respondWith": "json",
"responseBody": "={{ JSON.stringify({ success: $json.success, jobId: $json.jobId, task: $json.task, model: $json.model, result: $json.result, label: $json.label, score: $json.score, resultLength: $json.resultLength, completedAt: $json.completedAt }) }}"
},
"typeVersion": 1.1
},
{
"id": "6e67090c-d7f7-4a04-aad5-f5412e00d42e",
"name": "Flow Guide1",
"type": "n8n-nodes-base.stickyNote",
"position": [
1872,
16
],
"parameters": {
"color": 3,
"width": 608,
"height": 536,
"content": "### 2. API response\n\nHTTP Request calls the Hugging Face Inference API with the built payload then parses and formats the raw API response into clean structured output and returns the final result as JSON to the caller"
},
"typeVersion": 1
}
],
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "5c888e49-877e-4217-bdd7-d7620c2f3fc4",
"connections": {
"Set API Config": {
"main": [
[
{
"node": "Build Model Payload",
"type": "main",
"index": 0
}
]
]
},
"Build Model Payload": {
"main": [
[
{
"node": "Call Hugging Face API",
"type": "main",
"index": 0
}
]
]
},
"Receive Task Request": {
"main": [
[
{
"node": "Set API Config",
"type": "main",
"index": 0
}
]
]
},
"Call Hugging Face API": {
"main": [
[
{
"node": "Parse and Format Response",
"type": "main",
"index": 0
}
]
]
},
"Parse and Format Response": {
"main": [
[
{
"node": "Return Result",
"type": "main",
"index": 0
}
]
]
}
}
}
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
This workflow connects n8n to the Hugging Face Inference API, letting you run powerful open-source AI models for text generation, summarization, sentiment analysis, translation, and image generation — all fully automated, no GPU setup required. Simply POST a request and get…
Source: https://n8n.io/workflows/13809/ — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
This n8n template provides enterprise-level version control for your workflows using GitHub integration. Stop losing hours to broken workflows and manual exports – get proper commit history, visual di
This flow creates dummy files for every item added in your *Arrs (Radarr/Sonarr) with the tag .
This workflow acts as a central API gateway for all technical indicator agents in the Binance Spot Market Quant AI system. It listens for incoming webhook requests and dynamically routes them to the c
Sign PDF documents with legally-compliant digital signatures using X.509 certificates. Supports multiple PAdES signature levels (B, T, LT, LTA) with optional visible stamps.
📡 This workflow serves as the central Alpha Vantage API fetcher for Tesla trading indicators, delivering cleaned 20-point JSON outputs for three timeframes: , , and . It is required by the following a