n8n Integration Guide
Track what your n8n AI workflows cost — without changing how they work. You'll add one extra step at the end of a workflow that quietly sends OpsViz the model, token counts, and cost each time your agent runs. It takes about two minutes, and if OpsViz is ever down your workflow keeps running normally.
How it works in 30 seconds
- 1.Create an agent in OpsViz → get your webhook URL (10 seconds)
- 2.Add one step to your n8n workflow → paste the URL (2 minutes)
- 3.See costs, tokens, and alerts in real time (instantly)
Set up with AI — copy and paste
The fastest way to add OpsViz monitoring is to paste this prompt into your platform's AI assistant. It sets everything up automatically.
Using n8n's Ask AI (recommended)
- 1. In your workflow, click + to add a new step after your AI node
- 2. Search for HTTP Request and add it
- 3. Click on the HTTP Request node to open it
- 4. Click the Ask AI button (sparkle icon) in the node panel
- 5. Paste this prompt:
Add OpsViz cost monitoring to this workflow. After this node completes, add an HTTP Request node that sends a POST request to my OpsViz webhook URL with these details:
- URL: [WEBHOOK_URL]
- Method: POST
- Content-Type: application/json
- Body: {
"event_type": "task.completed",
"model": "{{ $json.model || 'unknown' }}",
"tokens_in": {{ $json.usage.prompt_tokens || $json.usage.input_tokens || 0 }},
"tokens_out": {{ $json.usage.completion_tokens || $json.usage.output_tokens || 0 }},
"cost_usd": {{ $json.usage.total_cost || 0 }},
"duration_ms": 0,
"agent_name": "My n8n Workflow"
}
Make the HTTP Request node run in the background (don't wait for response) and set it to never fail the workflow if OpsViz is unavailable.Note: duration_ms tracks how long the task took. n8n doesn't expose this directly — leave it as 0 for now, or ask your AI assistant to calculate it from start/end timestamps if you have them.
6. Click Generate — n8n will fill in the URL, method, and body fields automatically.
Using Claude Code (if you have it installed)
Paste this into Claude Code in your n8n project directory:
I'm using n8n and want to add OpsViz monitoring. Find my workflow JSON files and add an HTTP Request node after each AI node that POSTs to this webhook URL: [WEBHOOK_URL] The payload should include event_type, model name, token counts, cost, and duration from the preceding AI node's output. Make the request fire-and-forget (don't fail the workflow if OpsViz is unavailable).
Prerequisites
- An active n8n instance
- An OpsViz account with an agent created
- Your OpsViz webhook URL (from the Agents page)
Copy your OpsViz webhook URL
In OpsViz, go to Agents → Your Agent → Webhook URL. Copy the full URL — in these guides we show it as [WEBHOOK_URL]
Add an HTTP Request node after your AI node
In your n8n workflow, after the node that calls your AI (e.g. OpenAI, Claude), add an HTTP Request node.
- • Method:
POST - • URL: paste your OpsViz webhook URL
- • Body Content Type:
JSON
Configure the request body
Set the JSON body to extract data from the previous node:
{
"event_type": "task.completed",
"agent_name": "My n8n Workflow",
"model": "={{ $('OpenAI').item.json.model }}",
"tokens_in": "={{ $('OpenAI').item.json.usage.prompt_tokens }}",
"tokens_out": "={{ $('OpenAI').item.json.usage.completion_tokens }}",
"status": "success",
"metadata": {
"workflow": "={{ $workflow.name }}",
"execution_id": "={{ $execution.id }}"
}
}(Replace 'OpenAI' with the exact name of your AI node in your workflow.)
Add error handling
Add a second HTTP Request node on the error branch of your workflow with "event_type": "task.failed" and "status": "error".
Test the integration
Run your workflow once and check your OpsViz dashboard. The event should appear within a few seconds.
That's it!
Events will appear on your OpsViz dashboard as they arrive. Check the webhook reference for full payload options.