Split and rebill AI API costs per client in n8n
Short answer: give each client its own n8n credential whose Base URL points at a local meter with that client's name in the address. The same API key can go in every one. Each Claude or OpenAI call is then recorded under the client's name, with the token counts from the provider's own response, and month end is one export.
This works when n8n runs on the same computer as the meter, started with npm or npx, or in Docker with one opt-in setting (below). It doesn't work with n8n Cloud. A free option that needs no app is at the end.
Why n8n's own numbers aren't enough for an invoice
People who build automations for several clients describe the same month-end chore on the n8n forum: working
out what each client cost in OpenAI and Anthropic calls means
a lot of manual digging.
In another thread,
a builder who quotes AI costs to clients reported that n8n's estimatedTokens came out about 46% below
the input tokens their provider billed. That's one person's test, but the advice in both threads is the same:
charge clients from the provider's usage numbers, with every call tagged by client.
The two usual ways to do that:
- One API key per client. The provider's usage page splits by key. Clean for the bill, but you manage a key per client, and it doesn't show which workflow or which call cost what.
- A logging step in every workflow. One database row per AI call. Detailed, but you add it to every workflow by hand and keep a price table yourself.
The setup: one credential per client, pointed at a local meter
n8n's Anthropic and OpenAI credentials both have a Base URL field
(Anthropic,
default https://api.anthropic.com;
OpenAI,
default https://api.openai.com/v1). Point that field at a local meter, and every call made with
the credential goes through the meter, which records the provider's usage block from the response and passes
everything else through unchanged.
With NeverPayTwice's live meter (it listens on 127.0.0.1:8098):
- Add one entry per client in the app. Open Add usage, then Add another AI company under
“Live meter: any AI company”. For a client called Acme on Claude: short name
acme-anthropic, nameClient: Acme, addresshttps://api.anthropic.com. For Acme on OpenAI:acme-openaiandhttps://api.openai.com. - Make one credential per client in n8n. Same API key if you like. Set the Base URL to:
Credential Base URL Anthropic, client Acme http://127.0.0.1:8098/acme-anthropicOpenAI, client Acme http://127.0.0.1:8098/acme-openai/v1 - Use that client's credential in that client's workflows. Nothing else in the workflow changes.
Every call is now a receipt labelled Client: Acme: model, request ID, new input, cache writes,
cache reads, output and cost at list prices. Retries are separate receipts, because each one is a separate
billed response, and a request you already paid for once is flagged as a repeat.
If n8n runs in Docker
Inside a container, 127.0.0.1 is the container itself, and the meter listens on
127.0.0.1 only. Since version 1.3.0 you can open it on one extra private address. It's off by default.
- Docker Desktop (Mac, Windows): first try a Base URL of
http://host.docker.internal:8098/acme-anthropicwith the meter as it is. If n8n says it can't connect, start the meter on your computer's own network address (for examplepython3 start.py --gateway-host 192.168.1.20) and use that address in the Base URL. - Docker on Linux: start the meter on the Docker bridge address, usually
172.17.0.1(ip -4 addr show docker0shows yours):python3 start.py --gateway-host 172.17.0.1. Then usehttp://172.17.0.1:8098/acme-anthropicas the Base URL, or addextra_hosts: ["host.docker.internal:host-gateway"]to the n8n service and usehost.docker.internalas on Docker Desktop. If ufw or another firewall is on, allow port 8098 from Docker's networks.
To keep it on, add "listen": ["172.17.0.1"] to data/gateway.json and restart, so
double-click starts use it too. The meter's window then shows ALSO listening on ….
What turning it on means: anything that can reach that address can send AI calls through the meter, and
they show up in your records. They still need their own API key, because the meter passes keys through and
never stores them. The meter refuses 0.0.0.0 (“every address”) and public addresses, and turns away
calls coming from public internet addresses. Remove the address when you don't need it.
We tested this on November 23, 2026 by opening the meter on a second address on the same Mac (its network
address, and ::1 in the automated tests) and sending metered calls through it. We haven't run it
from inside a Docker container yet. If something on your setup doesn't connect, tell us and we'll fix this page.
Month end
In Receipts, pick Last month at the top, pick the client in the tools menu and press For your accountant. You get two CSV files:
- a summary with one row per month, client and model: billed responses, tokens and amount;
- every charge: date, model, request ID, the four token counts, amount, and whether it was a repeat charge. No prompt text is included, so it can go to a client as it is.
The amounts are calculated from token counts at published prices. Your provider's invoice is still the official record, and the request IDs let you match any line to it.
We tested the meter side on November 23, 2026 with two clients against a test API: four calls were recorded under the two client names, filtering by client narrowed the totals and receipts, and the export's per-call amount ($0.0052 for 1,200 input, 3,000 cache-read and 250 output tokens on Claude Sonnet 5.5) matched a hand calculation at Anthropic's list prices. The n8n side is the standard Base URL field shown in n8n's source; if your version labels it differently, tell us and we'll update this page.
Limits, before you rely on it
- Same computer only. By default the meter only accepts connections from programs on the computer it runs on. n8n started with npm or npx there works. n8n in Docker needs the opt-in address above. n8n Cloud: its calls come from n8n's servers, so a meter on your computer never sees them.
- If you turned on n8n's SSRF protection (
N8N_SSRF_PROTECTION_ENABLED, off by default), its default block list includes127.0.0.0/8. Allow the meter withN8N_SSRF_ALLOWED_IP_RANGES=127.0.0.1/32. In Docker, allow the address you use instead, for example172.17.0.1/32. - The date ranges are 7, 30 and 90 days, last month, this year, last year and all. For any other month, pick a range that covers it and use that month's row in the summary file.
The free way, without an app
Make an API key (OpenAI: a project) per client, then read usage per key on the provider's side. Anthropic's Usage and Cost Analytics API can group cost by API key (it needs an Admin API key and isn't available to individual Console accounts), and OpenAI's usage page can be narrowed to a project and key. That gives you a total per client per day, not per workflow or per call.
Questions people ask
Can n8n track AI API costs per client?
Not on its own. The usual ways are one API key per client, read on the provider's usage page, or a logging step after every AI call. A third way is one n8n credential per client whose Base URL points at a local meter, which records each call under that client's name from the provider's own usage numbers.
Does the n8n Anthropic or OpenAI credential support a custom base URL?
Yes. n8n's Anthropic and OpenAI credentials both have a Base URL field, with defaults https://api.anthropic.com and https://api.openai.com/v1. The Google Gemini credential has a Host field instead.
Does per-client metering work with n8n Cloud?
No. n8n Cloud's API calls come from n8n's servers, so a meter on your own computer never sees them. It works with self-hosted n8n on the same computer as the meter. For n8n in Docker, NeverPayTwice 1.3.0 and later can open the meter on an address the container can reach (off by default); that setup hasn't been tested inside a real container yet.
Is n8n's estimatedTokens accurate enough to invoice clients?
One builder on the n8n community forum measured n8n's estimatedTokens at about 46% below the input tokens Google billed, on n8n 2.36.7. Whatever you use, the safer basis for an invoice is the provider's own usage numbers, with each call tagged by client.
Or let the meter keep the receipts
NeverPayTwice is a small app we make. The live meter runs on your own computer, never blocks or changes a request, and never stores your API keys. Mac, Windows or Linux. $9.99 to start, then $2.99 a month to keep (your first month is included).
Try it on your own n8n workflows, free for 7 days. No card needed.
Sources: n8n's credential source files for Anthropic and OpenAI (Base URL fields), n8n's SSRF protection settings, the two n8n forum threads linked above, and Anthropic's Usage and Cost Analytics API page, checked November 23, 2026. n8n changes often; check the current fields if something doesn't match.