I went back and forth on a credential per client too. Separate keys are clean for the bill, but they don’t tell you which workflow or which step cost what, and they get messy once a workflow serves several clients.
What I ended up with is one row per AI call in Postgres: client_id, workflow, model, input and output tokens, cost. Cost is computed from a small price table, and the month-to-date total per client is one SQL query, which is what goes on the invoice. A few things that bit me:
- Pass client_id explicitly into every sub-workflow. Execute Workflow won’t carry it for you, and untagged calls are where the money disappears.
- Log per call, not per execution. One execution can make 1 call or 40.
- Check the client’s budget before the call, not after. If they’re over, stop there. It’s not atomic, so parallel runs can each slip one call past the limit, and setting max_tokens on every request keeps that overshoot small.
- Keep the price table updated, or the numbers slowly drift away from the real invoice.
On pricing, I’d pass usage through with a markup or put it in a flat fee with a cap, rather than at cost. At cost you’re absorbing the tracking work and any overage for free.
I put the workflow and schema up as a free template if it helps: n8n workflow: log each OpenAI call's cost per client, and stop when the monthly budget is used up · GitHub