Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

How I track per-customer LLM costs in production

Описание и применение

Автор описывает решение для отслеживания затрат на LLM по каждому клиенту в многопользовательских приложениях. Вместо использования общих счетов от провайдеров, предлагается передавать tenant_id в метаданных запросов и использовать стек Next.js, Supabase и Inngest для создания пайплайна реального времени с уведомлениями о превышении бюджета. Представлен open-source инструмент LLMeter.

Задача

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.

Результат

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.

Рабочий процесс

  • 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.

Доказательства

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.

Источник

  • Дата записи: 2026-09-07T19:07:43.072Z