> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.alephant.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.alephant.io/_mcp/server.

# n8n Workflow Governance

> Govern, trace, and measure n8n workflows that use AI models, tools, and paid endpoints

n8n is a strong workflow orchestration layer. Alephant adds the governance and finance layer around AI work inside those workflows.

Use Alephant with n8n when a workflow needs more than a model response. Common needs include cost per run, policy control before expensive branches, request-level audit trails, and a path to packaging a useful workflow as a paid endpoint.

## Workflow Pattern

```text
n8n trigger
-> prepare workflow context
-> Alephant Cost Control node
-> model/tool/workflow branch
-> Alephant AI Analytics node
-> cost, policy, and trace output
-> alert, approval, dashboard, or paid endpoint response
```

## Recommended Setup

1. Create an Agent for the n8n workflow in Alephant.
2. Copy the Agent's Virtual Key.
3. Configure the **Alephant Virtual Key** credential in n8n.
4. Send AI requests through the **Alephant Cost Control** node.
5. Pass `requestId` or `requestLogId` forward in the workflow.
6. Use **Alephant AI Analytics** to fetch request or usage context.
7. Route high-cost, failed, blocked, or abnormal cases to approval, alerting, or review steps.

For workflows that call Alephant Gateway through an HTTP Request node, include `Alephant-Agent-Id` and `Alephant-Run-Id` headers directly. For workflows that use the Alephant community nodes, preserve the returned `requestId` and `requestLogId` so later analytics steps can look up the gateway log.

## What To Track

| Workflow field       | Why it matters                                             |
| -------------------- | ---------------------------------------------------------- |
| Workflow name        | Groups cost and traces by automation                       |
| Run ID               | Connects all steps in one workflow execution               |
| Agent or Virtual Key | Identifies the governed actor                              |
| Model and provider   | Explains routing and cost decisions                        |
| Request log ID       | Links n8n output to Alephant logs                          |
| Cost and tokens      | Shows the financial footprint of the run                   |
| Policy decision      | Explains allowed, blocked, throttled, or escalated actions |

When possible, pass workflow context through Alephant gateway headers such as `x-request-id`, `alephant-session-id`, `alephant-session-name`, and `alephant-property-*`.

See [Agent IDs And Run IDs](/docs/overview/core-concepts/agent-i-ds-and-run-i-ds) for concrete header examples.

## Cost-Aware Branching

Alephant analytics can help a workflow decide what to do next:

* Continue if budget usage is healthy.
* Ask for approval before a high-cost branch.
* Switch to a cheaper model for low-risk work.
* Stop if the Virtual Key or agent budget is exhausted.
* Send a notification when a run exceeds expected cost.

## From Workflow To Paid Endpoint

Some n8n workflows become reusable capabilities: lead enrichment, research, compliance checks, support triage, or data transformation.

Alephant can help package that workflow as a governed paid endpoint:

1. Define the workflow capability.
2. Attach endpoint policy for access, budget, model, and rate limits.
3. Require payment when the endpoint is monetized.
4. Run the n8n workflow after payment and policy pass.
5. Record revenue, model cost, external spend, latency, and known margin.

## Related Pages

* [n8n Nodes](/n8n)
* [Agent Gateway](/docs/overview/core-concepts/agent-gateway)
* [Agent Run Tracing](/docs/overview/core-concepts/agent-run-tracing)
* [Paid Endpoints](/docs/overview/monetize/paid-endpoints)