# How Do I Count Each Client's n8n Workflow Runs for Their Monthly Invoice? An Automation Agency's Month-End Run

An automation agency runs an agent at month end that counts each client's n8n workflow executions by status and writes the totals to a data table for invoicing.

[Run this on Rush](https://cloud.getrush.ai/run/count-each-clients-workflow-runs-for-billing/n8n/). Opens the console with this prompt ready to send. Connect n8n there first.

## What the agent does

This is for an automation agency that builds and hosts n8n workflows for its clients on one n8n instance: lead routing for a law firm, order syncing for an online store, invoice reminders for a cleaning company. Most of its contracts charge a monthly fee that includes a set number of workflow runs, plus a rate for runs above it. At month end someone has to count, per client, how many runs each workflow made, and how many of them failed through no fault of the client. Clicking through the executions list for thirty clients takes most of a day. The agent does the counting and writes the totals to an n8n data table; the agency's account manager reads the table and writes the invoices.

The agency tags every workflow with its client, such as `client:harbor-law`, and turns on instance-level MCP under Settings in n8n. The operations lead connects it once with `POST /me/connections {"type": "mcp", "name": "n8n", "url": "https://agency.app.n8n.cloud/mcp-server/http", "auth": {"mode": "oauth"}}` and approves Rush on n8n's own redirect page. n8n's docs say each OAuth client gets only the permissions granted when it connects, and that an owner or admin must have turned MCP access on first.

On a run the agent calls `list_workflow_tags` to find every tag that starts with `client:`, then `search_workflows` with that tag in `tags` for each client. n8n's reference notes that `search_workflows` lists every workflow the user can see, whatever its Available in MCP setting, so a client workflow nobody exposed to MCP is still counted. For each workflow it calls `search_workflow_executions` with `startedAfter` and `startedBefore` set to the first instant of the month and of the next month, `limit` 200, and follows `nextCursor` until it comes back null. It counts each execution by `status` (`success`, `error`, `crashed`, `canceled`) and by `mode`.

The mode matters for the bill. An execution with `mode` set to `manual` is someone at the agency pressing Execute while building or fixing a workflow, and the agency does not charge clients for its own testing, so the agent counts those separately. A `retry` is a rerun of a failed execution. The agent then calls `search_data_tables` for the table `client_run_counts` and writes one row per workflow with `add_data_table_rows`: month, client tag, workflow id and name, billable runs (trigger, webhook and the other automatic modes), manual runs, retries, failed runs and the share that failed. n8n accepts at most 1,000 rows per call and only the column names the table already has, so the agency creates the table once with those columns.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Count n8n workflow executions per client for October 2026 (2026-10-01T00:00:00Z to 2026-11-01T00:00:00Z). Use the n8n connection. Call list_workflow_tags and keep the tags that start with 'client:'. For each, call search_workflows with tags [that tag]. For each workflow, call search_workflow_executions with workflowId, startedAfter and startedBefore as above and limit 200, following nextCursor until it is null. Count executions by status (success, error, crashed, canceled, other) and by mode. Billable runs are every execution whose mode is not manual and not retry. Then call search_data_tables with query 'client_run_counts' and add one row per workflow with add_data_table_rows (at most 1000 rows per call), using exactly these columns: month ('2026-10'), client, workflow_id, workflow_name, billable_runs, manual_runs, retries, failed_runs, failure_rate. Also write billing.md: one section per client with its total billable runs, a table of its workflows, and any workflow whose failure_rate is above 5% or which had no executions at all. Do not call execute_workflow, test_workflow, publish_workflow or unpublish_workflow, and change no workflow.",
  "connections": [
    "n8n"
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

`billing.md` gives each client's workflow runs billable for the month, a table of its workflows, and anything odd in them. The `client_run_counts` data table in n8n also gets one row per client workflow for the month, which the agency's own invoicing workflow can read later with n8n's Data Table node. The file is among the session's artifacts, and its odd items are a workflow with a high share of failed runs, or one that never ran at all during the month.

The account manager checks two things before an invoice goes out. Failed runs: a client who was billed for runs that failed because the agency's credentials expired will ask why, so the agency decides per contract whether `error` and `crashed` runs count. And workflows with no client tag, which the run cannot place; the prompt can ask for those too. The counts are n8n's own execution records, so an instance that prunes old executions before month end will undercount, and the agency should keep at least 40 days of history.

## Run it on every first day of each month

In the console, a Project automation with a `schedule` trigger at `0 7 1 * *` and the agency's `timezone` runs a saved agent whose connections name `n8n`, with the counting rules above in its instructions. A schedule fills no dates into the prompt, so the instructions say "the previous calendar month in UTC" and the agent writes the month it counted into every row.

An agency whose clients pay in arrears on different days can instead start the runs from its billing system: one `POST /o/{org}/sessions` per client on the client's billing day, with that client's tag and dates in `input`, and a `request_id` that is a UUID v5 of the client tag and the month so a retried job does not write the rows twice.

## Why run it on Rush?

The n8n sign-in lives in Rush's connection, with the scope the operations lead approved, rather than in a personal access token pasted into a script on someone's laptop. n8n's docs note that a new personal token revokes the previous one, so a script that shares one token with other tools breaks without warning; the OAuth client Rush holds is listed under Connected clients in n8n and can be revoked there on its own.

Each month's run has its own computer and a record of every `search_workflow_executions` call it made, with the time window it used. When a client disputes a count, the agency opens that month's session and shows exactly which executions were counted. The session also records its `total_cost_usd`, so the agency knows what its month-end billing costs to produce.

## Frequently asked questions

### Which n8n version does this need?

n8n's tools reference lists `search_workflow_executions` from 2.20.0, tag filtering in `search_workflows` from 2.27.0, and the data table tools from 2.16.0. An instance older than 2.27.0 can still be counted if the prompt finds client workflows by name with the `query` parameter instead of by tag.

### Can the agent read the data table back next month?

Not with the tools n8n's MCP reference lists today: it has tools to search, create and add rows to data tables, but none to read their rows, though n8n's source has added a `get_data_table_rows` tool that a later release may document. Until then, the agency's own n8n workflow reads the table with the Data Table node, and the agent compares months from the `billing.md` files of earlier sessions instead.

### Does the run trigger any of the client's workflows?

No. The prompt forbids `execute_workflow`, `test_workflow`, `publish_workflow` and `unpublish_workflow`, and the only write it makes is adding rows to the agency's own data table. n8n's docs say `execute_workflow` runs the published version by default, which is exactly what a billing count must never do.

### What if the executions list is very long?

`search_workflow_executions` returns at most 200 at a time with a `nextCursor`, and the agent follows it to the end for each workflow. n8n may report `count` as `-1` or `estimated` on large instances, which is why the agent counts the executions it pages through rather than trusting the total.

## More n8n jobs

- [Which n8n Workflows Stopped Running Without Failing? A Property Manager's Weekly Check of Its Scheduled Automations](https://getrush.ai/run/find-scheduled-workflows-that-stopped-running/n8n/)
- [What Changed in Our n8n Automations This Week? An Accounting Firm's Friday Change Log](https://getrush.ai/run/log-weekly-n8n-workflow-changes/n8n/)
- [Review Yesterday's Failed n8n Workflow Runs Before the Store Opens](https://getrush.ai/run/review-failed-workflow-runs/n8n/)

## More jobs like this: Produce a report or file, no repo

- [Write a Linear Cycle Report](https://getrush.ai/run/cycle-report/linear/)
- [Get a Daily Sales Summary From Square](https://getrush.ai/run/daily-sales-summary/square/)
- [Review a Supabase Database Schema](https://getrush.ai/run/database-schema-review/supabase/)

## Keep reading

- [Connect n8n to Rush once, then name it on any run](https://getrush.ai/integrations/n8n/)
- [Start your first run from the developer API quickstart](https://getrush.ai/docs/quickstart/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
