How we meter AI usage in a multi-tenant SaaS
AI API costs are per-token and unpredictable. Here is how we built usage metering that gives tenants visibility, enforces quotas fairly, and prevents one tenant from running up everyone else's costs.
The problem
AI API costs are a function of token usage — which varies dramatically by use case, tenant, and conversation pattern. A tenant running complex multi-step AI workflows uses 10x the tokens of a tenant doing simple FAQ lookups. In a flat-pricing model, power users subsidise light users (fine) — but if a single tenant spikes unexpectedly, the platform owner absorbs the cost.
The solution: metered billing with per-tenant quotas, real-time usage visibility, and graceful enforcement.
What we meter
We meter three things: - AI tokens consumed (input + output), per model tier - Messages processed (incoming + AI-generated), per channel - Knowledge base queries (vector search operations per month)
Each is tracked in a usage_events table with tenant ID, event type, quantity, and timestamp. This table is append-only and feeds both billing and the tenant dashboard.
Quota enforcement
Each plan defines a monthly quota per metric. At 80% of quota, we send an email alert. At 100%, we have two options:
- 1.Hard stop — block further AI processing, serve a fallback "our AI is temporarily unavailable" response to customers.
- 2.Overage billing — continue processing, charge the overage at a per-unit rate.
Enterprise tenants get overage by default; SMB plans get hard stop with an option to upgrade. This is a business decision, not just a technical one — and it is important to communicate clearly in the plan terms.
Preventing abuse
The most common abuse pattern: a tenant enables public-facing AI with no rate limiting on the widget, a bot hits the widget endpoint continuously, usage spikes to 100x normal. We prevent this with:
- Per-session rate limiting on the widget endpoint (10 messages per minute per session)
- Per-tenant daily soft cap (alert at 5x daily average, hard stop at 10x)
- Anomaly detection that compares rolling 24h usage to the tenant's historical baseline
Visibility
Tenants can see their usage in real time in the dashboard: tokens today, this month, vs. quota. Graphs show usage by channel and by AI model tier. This visibility reduces support tickets ("am I about to hit my limit?") and helps tenants make informed plan upgrade decisions.
The investment in metering infrastructure paid back in the first month: one tenant's runaway bot would have cost us $4,000 in API fees. The anomaly detection caught it in 20 minutes.