How I track per-customer LLM costs in production
Description and use
The author describes a solution for tracking LLM costs per customer in multi-tenant applications. Instead of relying on aggregate provider invoices, the approach involves passing tenant_id in request metadata and using a stack of Next.js, Supabase, and Inngest to build a real-time pipeline with budget overrun alerts. An open-source tool, LLMeter, is introduced.
Problem
Standard billing dashboards show total LLM spend but fail to attribute costs to specific customers or tenants, making it difficult to monitor margins and prevent budget overruns by power users.
Outcome
The implementation allows for real-time tracking of LLM costs per tenant, enabling proactive budget alerts and accurate margin analysis without over-engineering the billing stack.
Workflow
- Pass user_id or tenant_id as metadata in every LLM API request (e.g., OpenAI 'user' field, Anthropic custom headers).
- Proxy requests or capture token usage post-request to extract cost data.
- Fire an event to an async worker (Inngest) containing tenant_id, model, and token counts.
- Write usage data to a time-series database (Supabase).
- Trigger alerts when cumulative costs exceed defined budget limits for a tenant.
- Visualize data using a dashboard (LLMeter) for per-model, per-user, and per-day tracking.
Evidence
Pass the user_id or tenant_id directly to the provider... This simple line changes everything.
We ended up building a pipeline for this: Next.js edge functions for ingestion, Supabase for fast time-series queries, and Inngest for async budget checking.
- Record date: 2026-09-07T19:07:43.072Z