← Blog

How to Build an LLM Usage Analytics Dashboard

2026-11-12 · 5 min read · SubToAPI Team

If you're searching for how to build an LLM usage analytics dashboard, you're probably past the point of eyeballing provider console screenshots and need real numbers: tokens consumed per user, cost per feature, latency trends, and which teams are burning through budget. The short answer is that you need three things — a reliable source of usage metadata, a place to store it, and a way to query and visualize it. This guide walks through each piece so you can build it yourself, or decide it's not worth building at all.

What a usage analytics dashboard actually needs to answer

Before writing any code, define the questions the dashboard must answer. Most teams converge on the same core set:

If your dashboard can't answer "who spent what, on what, and how fast did it respond," it's not finished yet.

Where the data comes from

Every LLM response that includes usage metadata is your raw material. Anthropic's Messages API returns usage with input_tokens and output_tokens on every call. If you're calling Claude through a gateway like SubToAPI, the same fields come back on every request, which means you don't need to instrument your own token counting — you just need to capture and store what's already in the response.

curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-4",
    "max_tokens": 512,
    "messages": [{"role": "user", "content": "Summarize this ticket."}]
  }'

The response includes a usage object alongside the completion. That object is the seed of your entire analytics pipeline — everything downstream is aggregation and visualization. See /docs/messages for the full response shape.

Designing the data model

Keep the schema flat and append-only. You don't need a complex relational model to start — one event table per request is enough to build every dashboard view you'll want later.

CREATE TABLE llm_requests (
  id UUID PRIMARY KEY,
  created_at TIMESTAMPTZ NOT NULL,
  api_key_id TEXT,
  user_id TEXT,
  team_id TEXT,
  model TEXT,
  input_tokens INT,
  output_tokens INT,
  latency_ms INT,
  status_code INT,
  feature_tag TEXT
);

Two fields pay off disproportionately: feature_tag (a label you set client-side, like support-bot or email-draft) and team_id. Without them, you can tell how much was spent but not why, and "why" is what budget conversations actually need.

Building the ingestion pipeline

For most teams, a simple middleware wrapper around your LLM calls is enough:

async function callLLM(payload, context) {
  const start = Date.now();
  const res = await fetch("https://api.subtoapi.app/v1/messages", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
      "content-type": "application/json"
    },
    body: JSON.stringify(payload)
  });
  const data = await res.json();
  const latency = Date.now() - start;

  await logUsageEvent({
    createdAt: new Date(),
    model: payload.model,
    inputTokens: data.usage?.input_tokens ?? 0,
    outputTokens: data.usage?.output_tokens ?? 0,
    latencyMs: latency,
    statusCode: res.status,
    featureTag: context.featureTag,
    teamId: context.teamId
  });

  return data;
}

Write logUsageEvent to a queue or directly to your database — a message queue is safer under load, but for low-to-medium volume a direct insert works fine. Avoid logging on the client side; do it server-side where you control the LLM call, so you don't lose events to network failures or ad blockers.

Aggregation and visualization

Once events are landing in a table, the dashboard layer is mostly SQL plus a charting tool. A few queries cover 80% of what people want to see:

-- Daily cost by team (assuming you price tokens externally)
SELECT team_id, date_trunc('day', created_at) AS day,
       SUM(input_tokens) AS input_tokens,
       SUM(output_tokens) AS output_tokens
FROM llm_requests
GROUP BY 1, 2
ORDER BY 2 DESC;

-- p95 latency by model
SELECT model,
       percentile_cont(0.95) WITHIN GROUP (ORDER BY latency_ms) AS p95_latency
FROM llm_requests
GROUP BY model;

For visualization, you don't need to build custom charts — point Grafana, Metabase, or even a scheduled spreadsheet export at this table. The hard part was never the charts; it's getting clean, labeled usage events into one place consistently.

Build vs. buy

Building this pipeline is a reasonable weekend project, but it's recurring maintenance: new models change token pricing, retries need dedup logic, and someone has to own the dashboard when it breaks. If your actual goal is "see spend and usage per key or team" rather than "own a custom analytics stack," it's worth checking whether your API provider already does this.

SubToAPI's dashboard tracks usage and cost per application API key and per team seat automatically, since every request already carries token and latency metadata. If you're on Solo, Team, or Scale, that view is there without writing an ingestion pipeline. Compare plans at /pricing or start a free trial at /signup. For teams that still want to build their own analytics on top, the same usage data is available through the API responses themselves — see /docs/quickstart to get an API key and start logging events immediately.

Keeping the dashboard honest

A dashboard is only useful if the numbers match reality. Two habits prevent drift:

Questions

Do I need a separate database for usage analytics, or can I reuse my app's main database? For low volume, reuse your main database with a dedicated table. Once you're logging thousands of requests per day, move to a separate analytics database or data warehouse so heavy aggregation queries don't slow down your production app.

Can I get usage analytics without building this myself? Yes — if you're using SubToAPI, usage and cost per API key and team seat are already tracked in the dashboard, since token and latency data are returned on every request. Check /docs for details.

What's the minimum data I need to start building a dashboard? Timestamp, model, input/output tokens, latency, and status code per request. Add feature_tag and team_id as soon as you have more than one use case, since those are what make the dashboard actionable rather than just descriptive.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →