> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getmuster.io/llms.txt
> Use this file to discover all available pages before exploring further.

# n8n

> Monitor your n8n workflows with Muster using a single HTTP Request node.

<Note>
  n8n workflows are best monitored via Muster's HTTP webhook. The n8n scanner requires network access to your n8n instance and won't work for locally-hosted setups.
</Note>

## Overview

Add a single **HTTP Request** node at the end of your n8n workflow. This sends quality signals to Muster after every execution.

## Setup

### 1. Register the workflow in Muster

In your Muster dashboard → **Add Agent**:

* Name: your workflow name (e.g. `invoice-processing-n8n`)
* Framework: `N8N`
* Owner email and department

### 2. Add an HTTP Request node

In your n8n workflow, add an **HTTP Request** node as the last step:

**Node settings:**

| Setting           | Value                                                                |
| ----------------- | -------------------------------------------------------------------- |
| Method            | POST                                                                 |
| URL               | `https://app.getmuster.io/api/v1/jobs/{{ $now.toMillis() }}/quality` |
| Authentication    | None                                                                 |
| Send Body         | Enabled                                                              |
| Body Content Type | JSON                                                                 |

**JSON body:**

```json theme={null}
{
  "agent_id": "invoice-processing-n8n",
  "job_id": "{{ $now.toMillis() }}",
  "overall_passed": true,
  "checks": [
    {
      "check_id": "output_not_empty",
      "severity": "HIGH",
      "passed": {{ $json.output ? true : false }}
    }
  ]
}
```

### 3. Handle errors

To report failures, use an **Error Trigger** node connected to a second HTTP Request node:

```json theme={null}
{
  "agent_id": "invoice-processing-n8n",
  "job_id": "{{ $now.toMillis() }}",
  "overall_passed": false,
  "checks": [
    {
      "check_id": "output_not_empty",
      "severity": "HIGH",
      "passed": false,
      "message": "{{ $json.message }}"
    }
  ]
}
```

## Dynamic checks

For more detailed monitoring, build the checks array dynamically using n8n's **Code** node before the HTTP Request:

```javascript theme={null}
// Code node
const output = $input.first().json;

const checks = [
  {
    check_id: "output_not_empty",
    severity: "HIGH",
    passed: !!output.result
  },
  {
    check_id: "required_fields_present",
    severity: "HIGH",
    passed: !!(output.vendor && output.total && output.date),
    expected: "vendor,total,date",
    actual: Object.keys(output).filter(k => ["vendor","total","date"].includes(k)).join(",")
  }
];

return [{
  json: {
    agent_id: "invoice-processing-n8n",
    job_id: $now.toMillis().toString(),
    overall_passed: checks.every(c => c.passed),
    checks
  }
}];
```

Then connect this node's output to an HTTP Request node posting to Muster.

## Tracking token usage

If your n8n workflow calls OpenAI or Anthropic, pass token counts to Muster for cost tracking:

```json theme={null}
{
  "agent_id": "invoice-processing-n8n",
  "job_id": "{{ $now.toMillis() }}",
  "overall_passed": true,
  "token_input": {{ $node["OpenAI"].data.usage.prompt_tokens }},
  "token_output": {{ $node["OpenAI"].data.usage.completion_tokens }},
  "model": "gpt-4o",
  "checks": []
}
```
