The sub-workflow attribution problem has a second edge that’s worth naming, because it bites in a different place than the Sheets template.
$workflow.name logging gives you attribution for anything running inside n8n, but it can’t see calls made outside n8n. If a client’s tool, script, or a teammate’s local agent hits the same provider key directly, those tokens land on your bill with no execution ID to join against. So your attribution is only as complete as the perimeter of n8n itself.
Two things that held up for me in that situation:
Make the key per-client, not per-account. If each client’s workflows use their own virtual key, attribution stops being a join problem and becomes a lookup. The bill line and the client map 1:1, and revocation is one key instead of an archaeology exercise across workflows. This is also what makes the provider-cap point enforceable — a cap that lives in n8n can’t stop a loop n8n is running, but a cap on the key can.
Track requests, not just tokens, if you’re invoicing. Token counts are what the provider reports, but they’re a noisy basis for a markup because a 500-token call and a 50,000-token call both cost you one round trip of infrastructure regardless of the context size. For client invoicing, a request allowance is easier to explain and much harder for a client to argue with than a token statement with no unit price attached.
Concretely, the pattern I use: per-client key with a daily request ceiling, then log $execution.id + $workflow.name + the request count per execution. The key gives you the cap and the clean bill line, n8n gives you the per-workflow breakdown, and the two reconcile because the key is the shared identifier in both. It’s the same idea as client-owned keys (precision, no markup) without giving up the boundary enforcement that client-owned keys remove.
I run this on top of APIClaw (flat-rate, OpenAI-compatible endpoint, virtual keys per client) — that’s the setup where the boundary is the billing unit rather than an afterthought: https://apiclaw.biz
The part I’m still unsure about: at what client count does per-key management itself become the overhead? Curious whether you’ve hit that ceiling or whether it stays flat.