This workflow corresponds to n8n.io template #15920 — 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": "CkPmWF2yQuj2X5l8",
"name": "Track AI agent costs and token usage with Alephant AI Gateway",
"tags": [],
"nodes": [
{
"id": "e4a9ecb0-d35a-47a4-8b45-b8651c4ed9f1",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
176,
-16
],
"parameters": {
"width": 480,
"height": 496,
"content": "## Track AI agent costs and token usage with Alephant AI Gateway\n\n### How it works\n\nThis workflow runs every Monday at 9 AM to collect AI cost and token usage data from Alephant AI Gateway. It adds report configuration, formats the usage summary into a readable report, and sends it by email through Gmail.\n\n### Setup steps\n\n1. Install the Alephant community node\n2. Create an Alephant Virtual Key credential (docs link below)\n3. Connect your Gmail credential\n4. Edit the 'Set Report Config' node - set your recipient email\n5. Adjust the Schedule Trigger if you want daily/hourly instead of weekly\n\n**Requirements**\n- Alephant account (free tier works) - https://alephant.io\n- Gmail account\n\nDocs: https://developers.alephant.io/\n"
},
"typeVersion": 1
},
{
"id": "83adfc10-10d2-4e4a-a678-04b2e0db6fc8",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
736,
-16
],
"parameters": {
"color": 7,
"width": 432,
"height": 336,
"content": "## Schedule usage fetch\n\nStarts the workflow on the weekly Monday morning schedule and retrieves the Alephant AI Gateway usage summary."
},
"typeVersion": 1
},
{
"id": "067b5a54-55d6-4c6f-959c-b6d78d79de91",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
1216,
-16
],
"parameters": {
"color": 7,
"width": 432,
"height": 336,
"content": "## Configure and format report\n\nSets the report recipient configuration, then formats the Alephant usage data into an email-ready report."
},
"typeVersion": 1
},
{
"id": "503da710-b1d3-410f-b46f-e5f1c6621b83",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
1696,
-16
],
"parameters": {
"color": 7,
"height": 336,
"content": "## Send report email\n\nDelivers the formatted weekly cost and token usage report through Gmail."
},
"typeVersion": 1
},
{
"id": "34486343-b066-491a-95b5-b318a311376a",
"name": "Weekly Monday Trigger",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
784,
144
],
"parameters": {
"rule": {
"interval": [
{
"field": "weeks",
"triggerAtDay": [
1
],
"triggerAtHour": 9
}
]
}
},
"typeVersion": 1.2
},
{
"id": "4a6cd5bb-7893-49bd-a172-1cce9ababd76",
"name": "Fetch Alephant Usage Summary",
"type": "@alephantai/n8n-nodes-alephant-analytics.alephantUsage",
"position": [
1024,
144
],
"parameters": {},
"credentials": {
"alephantVirtualKeyApi": {
"name": "<your credential>"
}
},
"typeVersion": 1
},
{
"id": "04bc6b5b-5bab-4f5b-a126-1951177d03cd",
"name": "Set Email Recipient",
"type": "n8n-nodes-base.set",
"position": [
1264,
144
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "f1+1234567890-+1234567890",
"name": "recipient_email",
"type": "string",
"value": "you@example.com"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "c3c09c8d-c5e7-43a1-965e-f45e1931aa7d",
"name": "Format Usage Report",
"type": "n8n-nodes-base.code",
"position": [
1504,
144
],
"parameters": {
"jsCode": "// Pull the Usage Summary output from the Alephant node\nconst d = $('Fetch Alephant Usage Summary').first().json.data;\n\n// Cost: total_cost_cents is in CENTS - convert to dollars\nconst costUSD = (d.total_cost_cents / 100).toFixed(2);\n\n// Round the week-over-week percentages (they come back as long floats)\nconst costPct = Math.round(d.vs_previous_period.cost_pct);\nconst reqPct = Math.round(d.vs_previous_period.requests_pct);\n\n// Helper: turn a +/- number into a readable trend phrase\nconst trend = (pct) => {\n if (pct > 0) return `up ${pct}% vs previous period`;\n if (pct < 0) return `down ${Math.abs(pct)}% vs previous period`;\n return `no change vs previous period`;\n};\n\nconst totalTokens = d.total_tokens.input + d.total_tokens.output;\n\n// Build the email body (plain text)\nconst body =\n`AI Agent Cost Report - Alephant AI Gateway\n\nPeriod: ${d.period.from} to ${d.period.to}\n\nTotal cost: $${costUSD} (${trend(costPct)})\nTotal requests: ${d.total_requests} (${trend(reqPct)})\nTotal tokens: ${totalTokens} (input ${d.total_tokens.input} / output ${d.total_tokens.output})\n\nData source: ${d.data_source}${d.degraded ? ' (WARNING: data may be degraded)' : ''}\n\nSent automatically by your Alephant AI Gateway workflow.`;\n\n// Pass the body + recipient on to the Gmail node\nreturn [{\n json: {\n email_subject: `AI Agent Cost Report (${d.period.from} to ${d.period.to})`,\n email_body: body,\n recipient_email: $('Set Email Recipient').first().json.recipient_email\n }\n}];"
},
"typeVersion": 2
},
{
"id": "6edadefb-9099-4db3-b45c-1be5c2a98e02",
"name": "Send Usage Summary Email",
"type": "n8n-nodes-base.gmail",
"position": [
1744,
144
],
"parameters": {
"sendTo": "={{ $json.recipient_email }}",
"message": "={{ $json.email_body }}",
"options": {},
"subject": "={{ $json.email_subject }}",
"emailType": "text"
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 2.1
},
{
"id": "1b7ae0bd-25d6-4f49-9a36-7f782152ffb1",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
736,
352
],
"parameters": {
"width": 880,
"height": 128,
"content": "## Who's it for\n\nTeams running production AI agents - autonomous workflows that call AI models on their own and can quietly rack up cost you only discover on the invoice. Also useful for solo developers and AI-first startups who want a regular read on AI spend."
},
"typeVersion": 1
}
],
"active": false,
"settings": {
"binaryMode": "separate",
"executionOrder": "v1"
},
"versionId": "d781daf7-b6d3-44ad-af06-8225e4e9ec2e",
"connections": {
"Format Usage Report": {
"main": [
[
{
"node": "Send Usage Summary Email",
"type": "main",
"index": 0
}
]
]
},
"Set Email Recipient": {
"main": [
[
{
"node": "Format Usage Report",
"type": "main",
"index": 0
}
]
]
},
"Weekly Monday Trigger": {
"main": [
[
{
"node": "Fetch Alephant Usage Summary",
"type": "main",
"index": 0
}
]
]
},
"Fetch Alephant Usage Summary": {
"main": [
[
{
"node": "Set Email Recipient",
"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.
alephantVirtualKeyApigmailOAuth2
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
This workflow runs every Monday at 9 AM to pull a 7‑day usage summary from Alephant AI Gateway, calculates key metrics for AI Agents like total cost and tokens, and emails a formatted cost and usage report to a recipient via Gmail. Runs on a weekly schedule (Monday at 9 AM).…
Source: https://n8n.io/workflows/15920/ — 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 runs every 6 hours to check an Alephant AI Gateway virtual key’s budget usage and, when live usage meets or exceeds the threshold, sends a detailed overspend alert email via Gmail. Runs
This automation includes order analysis, product comparison, management approval, and automated product deactivation, with full reporting and transparency. 1st of Every Month at 8 AM, it triggers a sc
BSW Growth Agent · Lite (Free Tier). Uses googleSheets, googleDrive, httpRequest, gmail. Scheduled trigger; 21 nodes.
Founder's Discovery Engine. Uses googleSheets, googleDrive, httpRequest, gmail. Scheduled trigger; 21 nodes.
It identifies SKUs with low inventory per source and sends daily alerts via: