Table of Contents
For SaaS products and internal multi-department AI deployments, you need to attribute infrastructure cost to tenants / customers / departments. Self-hosted has a different attribution model than per-token API billing — predictable monthly cost gets allocated based on usage proxies.
Three attribution models: per-token consumption (track tokens per tenant), per-request consumption (track API call count), flat allocation (split by users / department headcount). Most production: per-token attribution with the structured logs you're already capturing.
Attribution models
- Per-token: most accurate; needs token counting per request; matches hosted-API billing model
- Per-request: simpler; works when token counts are similar across tenants
- Per-active-user: simplest; useful for internal departmental allocation
- Time-based: GPU minutes consumed per tenant; useful for batch workloads
Data needed
Your structured JSON logs already capture this:
tenant_idper requestprompt_tokens+completion_tokensmodel+model_versionrequest_id+user_id
Aggregate via ClickHouse / Postgres window functions, output per-tenant per-month tokens consumed.
Billing
For a SaaS billing model on top of self-hosted AI:
- Compute monthly cost: server (£279) + ops engineering pro-rated + frontier API fallback
- Compute monthly tokens: from logs
- £/M tokens this month: total cost / total tokens
- Per-tenant bill: their tokens × £/M tokens (or with margin for SaaS pricing)
For internal departments: use the same per-token rate, charged back at cost.
Verdict
Per-token attribution from structured logs is the right default for multi-tenant self-hosted AI cost allocation. Matches hosted-API mental model; transparent to customers; supports usage-based pricing tiers. Build this from day one — retrofitting attribution after launch is painful.
Bottom line
Per-token attribution from logs. See structured logging.