This workflow corresponds to n8n.io template #4876 — we link there as the canonical source.
This workflow follows the Chainllm → Gmail recipe pattern — see all workflows that pair these two integrations.
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 →
{
"meta": {
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "37166e51-ffb6-43fe-8bd5-fe5eb1249366",
"name": "OpenRouter Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
"position": [
540,
540
],
"parameters": {
"model": "google/gemini-2.5-flash-preview-05-20",
"options": {}
},
"credentials": {
"openRouterApi": {
"name": "<your credential>"
}
},
"typeVersion": 1
},
{
"id": "067f6b55-dc4c-4757-b19e-2d539b8b2526",
"name": "Aggregate Gmail Messages",
"type": "n8n-nodes-base.aggregate",
"position": [
-360,
220
],
"parameters": {
"options": {},
"aggregate": "aggregateAllItemData"
},
"typeVersion": 1
},
{
"id": "7807ff72-49f7-4a7b-9d75-24746d0dfdb7",
"name": "Merge Labels & Messages",
"type": "n8n-nodes-base.merge",
"position": [
240,
320
],
"parameters": {
"mode": "combine",
"options": {},
"combineBy": "combineAll"
},
"typeVersion": 3.1
},
{
"id": "8c51f04b-3415-4d53-8624-ce8d484145b9",
"name": "Classify Email with AI",
"type": "@n8n/n8n-nodes-langchain.chainLlm",
"position": [
520,
320
],
"parameters": {
"text": "=You are an email classification assistant. Your task is to analyze Gmail email snippets and categorize them into one of the following labels:\n\n1. To respond - Emails requiring a direct personal response from you (questions from individuals, personal conversations, NOT automated feedback requests)\n2. FYI - Emails requesting you to take action, reminders, or alerts about issues (add money requests, payment failures, action needed)\n3. Comment - Emails specifically asking for your feedback, review, or opinion in a professional/collaborative context\n4. Notification - Automated updates about completed or ongoing events (successful payments, transfers sent, deployments, shipments, security alerts)\n5. Meeting update - Calendar invites, meeting changes, or meeting-related communications\n6. Awaiting reply - Follow-up emails or reminders about your pending responses\n7. Actioned - Confirmations of actions YOU specifically took (not automated system actions)\n8. Marketing - Promotional content, sales emails, feature announcements, newsletters, or automated customer feedback surveys\n\nKey classification rules:\n- Automated status updates (deployments, transfers, payments processed) \u2192 Notification\n- Requests to add money or take action \u2192 FYI\n- Payment failure alerts \u2192 FYI\n- Security alert digests \u2192 Notification\n- Shipment updates \u2192 Notification\n- Direct Debit payment confirmations \u2192 Notification\n- Balance update confirmations \u2192 Notification\n- Customer satisfaction surveys or feedback requests \u2192 Marketing\n- Automated \"how was your experience\" emails \u2192 Marketing\n- Only use \"Actioned\" for confirmations of YOUR manual actions\n- Only use \"Marketing\" for promotional content, including feedback surveys\n\nInstructions:\n1. Read the email snippet carefully\n2. Note the sender (if provided) for context\n3. Choose the single most appropriate label based on the rules above\n4. IMPORTANT: Respond ONLY with the number and label (e.g., \"2. FYI\")\n5. Do not include any other text, explanation, or repeat the email content\n\nEmail From:\n{{ $json.From }}\nEmail To:\n{{ $json.To }}\nEmail subject:\n{{ $json.Subject }}\nEmail snippet:\n{{ $json.snippet }}\n\nYour response must be exactly one of these 8 options:\n1. To respond\n2. FYI\n3. Comment\n4. Notification\n5. Meeting update\n6. Awaiting reply\n7. Actioned\n8. Marketing",
"batching": {},
"promptType": "define"
},
"typeVersion": 1.7
},
{
"id": "ddbdc31a-ea27-415e-b9e2-954959cfcb7a",
"name": "New Gmail Email Received",
"type": "n8n-nodes-base.gmailTrigger",
"position": [
-560,
340
],
"parameters": {
"filters": {},
"pollTimes": {
"item": [
{
"hour": 12
}
]
}
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 1.2
},
{
"id": "52b3a1d8-3be8-4f57-8759-7ae9abcdb5cb",
"name": "Fetch Available Gmail Labels",
"type": "n8n-nodes-base.gmail",
"position": [
-140,
220
],
"parameters": {
"resource": "label",
"returnAll": true
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 2.1
},
{
"id": "2d15670f-5735-4110-a1eb-d5b6b8abef89",
"name": "Map Label Names to IDs",
"type": "n8n-nodes-base.code",
"position": [
60,
220
],
"parameters": {
"jsCode": "const items = $input.all();\nconst combinedObject = items.reduce((acc, item) => {\n return { ...acc, [item.json.name]: item.json.id };\n}, {});\n\nreturn { combinedObject };\n"
},
"typeVersion": 2
},
{
"id": "4c5d1e4a-93ce-4f78-b0ce-8b94aff99498",
"name": "Apply Classification Label",
"type": "n8n-nodes-base.gmail",
"position": [
960,
320
],
"parameters": {
"labelIds": "={{ $('Map Label Names to IDs').item.json.combinedObject[$json.text] }}",
"messageId": "={{ $('Merge Labels & Messages').item.json.id }}",
"operation": "addLabels"
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 2.1
}
],
"connections": {
"OpenRouter Chat Model": {
"ai_languageModel": [
[
{
"node": "Classify Email with AI",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Classify Email with AI": {
"main": [
[
{
"node": "Apply Classification Label",
"type": "main",
"index": 0
}
]
]
},
"Map Label Names to IDs": {
"main": [
[
{
"node": "Merge Labels & Messages",
"type": "main",
"index": 0
}
]
]
},
"Merge Labels & Messages": {
"main": [
[
{
"node": "Classify Email with AI",
"type": "main",
"index": 0
}
]
]
},
"Aggregate Gmail Messages": {
"main": [
[
{
"node": "Fetch Available Gmail Labels",
"type": "main",
"index": 0
}
]
]
},
"New Gmail Email Received": {
"main": [
[
{
"node": "Aggregate Gmail Messages",
"type": "main",
"index": 0
},
{
"node": "Merge Labels & Messages",
"type": "main",
"index": 1
}
]
]
},
"Fetch Available Gmail Labels": {
"main": [
[
{
"node": "Map Label Names to IDs",
"type": "main",
"index": 0
}
]
]
}
}
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
gmailOAuth2openRouterApi
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
Professionals and individuals who receive high volumes of emails, those who want to automatically organize their Gmail inbox using AI classification.
Source: https://n8n.io/workflows/4876/ — 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 workflow contains community nodes that are only compatible with the self-hosted version of n8n.
This n8n template shows you how to automate customer support email triage with a sovereign AI. By combining Gmail for inbox monitoring and the IONOS AI Model Hub, every customer email is classified an
NTF 03: Email Triage Agent. Uses gmailTrigger, lmChatAnthropic, chainLlm, gmail. Event-driven trigger; 9 nodes.
What it does
This workflow is for contractors, freelancers, local service businesses, and small teams that receive leads and customer requests through Gmail but do not have a dedicated sales or admin team.