Guide

LLM cost tracking per user: how to know who spent what

Vendor invoices tell you what you spent, not who spent it. Three ways to track LLM cost per user, team and model, with a worked example and what to watch for.

Vendor invoices tell you how much you spent on AI, not who spent it. To track LLM cost per person or team, every request needs to carry an identity, and something has to multiply its tokens by the right price. There are three ways to do that: separate provider keys, tagging requests in your code, or a gateway that issues a key per person and records cost on every request.

Updated 2 December 2026.

Why the invoice isn't enough

A typical month looks like this: one OpenAI bill, one from Groq, an OpenRouter top-up, and GPUs running your own models with no per-request bill at all. Finance asks three questions you can't answer:

  1. Which team or person drove the increase?
  2. Which models are we paying for that a cheaper one could handle?
  3. How much traffic could our own GPUs have taken instead?

How LLM cost is calculated

Every request has a cost you can compute:

cost = input tokens × input price + output tokens × output price

Prices are per million tokens and differ by model and provider, often with output tokens costing several times more than input. Some providers also price cached input differently.

Worked example. Suppose a model costs $0.60 per million input tokens and $2.40 per million output tokens, and a request uses 1,200 input and 400 output tokens:

1,200 × 0.60 / 1,000,000 = $0.00072
  400 × 2.40 / 1,000,000 = $0.00096
                    total = $0.00168

Tiny on its own. A person who sends 300 such requests a working day for 21 days costs about $10.58 a month. A script that sends one a second for a month costs about $4,350. That gap is why per-user tracking matters.

Method 1: separate provider keys per team

Create a separate API key, project or account at each provider for each team, and read the usage dashboards.

Pros: nothing to build.
Cons: works per team, not per person; one dashboard per provider; no view of self-hosted models; keys multiply and get shared anyway (why that hurts).

Method 2: tag requests in your code

Add a user or team identifier to each request, log token usage from each response, and compute cost in your own database or analytics tool.

Pros: precise, flexible.
Cons: every app has to do it correctly; prices have to be maintained for every model; nothing stops a request that's over budget; easy to miss scripts and notebooks.

Method 3: a gateway with a key per person

Put an LLM gateway between your apps and every model. Each person or app gets its own key from the gateway. The gateway sees every request, knows who sent it, counts tokens and records the cost, whichever provider served it. It can also stop a request when a budget is used up, rather than reporting the overspend a month later. More on how gateways work in what is an LLM gateway.

Pros: one place for all providers, including your own GPUs; limits enforced before money is spent; no changes in each app beyond the base URL and key.
Cons: one more service in the request path.

Separate keysTagging in codeGateway
Per personNoYes, if every app does itYes
Across all providersNoYes, with workYes
Self-hosted modelsNoWith workYes
Enforces budgetsProvider limits onlyNoYes
EffortLowHigh, ongoingMedium, once

What to track

Whichever method you use, record at least:

  • Who: user, team and key
  • What: model and provider that actually served the request (not just the one requested, if there was a fallback)
  • How much: input and output tokens, and cost in one currency
  • When: timestamp, so you can see trends and spikes

You don't need the prompt text to track cost. Leaving it out avoids storing sensitive data you'd then have to protect.

Budgets: the other half of cost tracking

Tracking tells you what happened. Budgets stop it happening again. Useful limits are:

  • Requests per minute per key: stops runaway scripts.
  • Tokens per day and per month per person: keeps everyday usage predictable.
  • Allowed models per person: keeps the most expensive models for the people who need them.

When a limit is hit, the caller should get a clear error, such as HTTP 429 with the time the limit resets, not a silent failure.

How AI Gateway handles it

AI Gateway by LayerX does method 3. Admins invite each person by email; each gets their own keys, daily and monthly token budgets and a list of allowed models, and each key has a requests-per-minute limit. The dashboard shows cost in US dollars per user, key, model and provider, across your own vLLM or Ollama servers and vendors like OpenAI, Groq, Together and OpenRouter. When a budget runs out, requests get a 429 with the reset time. AI Gateway records only usage data (date, model, key, token counts), never prompts or responses.

Other gateways track cost too. LiteLLM's open-source proxy has spend tracking per key, user and team; see LiteLLM Enterprise pricing for what's paid. Compare options in best LLM gateways.

Questions

How do I track OpenAI cost per user?

Either create separate projects or keys per team and read OpenAI's usage dashboard, log token usage with a user ID in your own code, or route requests through a gateway that gives each person a key and records cost per request.

How is LLM cost calculated?

Input tokens times the input price plus output tokens times the output price, using the model's per-million-token prices. Output tokens usually cost more than input.

Can I set a spending limit per user?

Not at most providers directly. A gateway can apply per-user token budgets and per-key rate limits and reject requests when they're used up.

Do I need to store prompts to track cost?

No. Token counts, model, provider, user and time are enough. Not storing prompts reduces privacy risk.

More posts

Keep reading.

See how AI Gateway fits your setup.

Tell us what you run today and how many people need access. We'll get back to you to learn more about your setup.

See how AI Gateway fits your setup.

What do you run today?