← Blog

Track LLM API Spend Across Providers: A Practical Guide

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

If you're running production workloads against more than one LLM provider, you've probably noticed that cost visibility is the first thing to break. Each provider ships its own billing dashboard, its own usage export format, and its own definition of what counts as a "token." Tracking LLM API spend across providers means you need a single source of truth that normalizes usage data from every API you call, then attributes it to the right application, team, or customer.

The practical answer is: instrument spend at the request level (not just the invoice level), tag every call with metadata you control, and pull that data into one place on a schedule you can actually audit. Below is how to do that without building a full observability platform from scratch.

Why provider dashboards aren't enough

Anthropic, OpenAI, and other providers give you aggregate billing views, but they're built for "how much did I spend this month," not "which feature, customer, or team is driving that spend." That's a problem the moment you have:

None of the native dashboards answer "which service is burning through my Claude budget" or "is this spike from a bug or from a new feature." You need request-level metadata, not month-level totals.

Tag every request with metadata

The single highest-leverage thing you can do is attach structured metadata to every API call before it ever reaches the provider. At minimum, track:

If you're calling Claude directly, you're responsible for building and storing this metadata yourself, usually by wrapping your HTTP client in a logging layer that writes to your own database or a logging service before/after each request.

async function callLLM(prompt, meta) {
  const start = Date.now();
  const res = await fetch("https://api.anthropic.com/v1/messages", {
    method: "POST",
    headers: {
      "x-api-key": process.env.ANTHROPIC_API_KEY,
      "anthropic-version": "2023-06-01",
      "content-type": "application/json"
    },
    body: JSON.stringify({
      model: "claude-sonnet-4-5",
      max_tokens: 1024,
      messages: [{ role: "user", content: prompt }]
    })
  });
  const data = await res.json();
  logUsage({
    ...meta,
    model: data.model,
    input_tokens: data.usage.input_tokens,
    output_tokens: data.usage.output_tokens,
    latency_ms: Date.now() - start
  });
  return data;
}

Do this consistently for every provider you call, and you have a normalized usage log you can query regardless of who you're billed by.

Normalize cost, not just tokens

Token counts aren't comparable across providers or even across models from the same provider — pricing per million tokens varies, and input/output tokens are usually priced differently. Once you're logging token counts per request, convert them to a dollar cost at ingestion time using each provider's current rate card, and store the cost alongside the tokens. This way your dashboard shows spend in euros or dollars, not a soup of token counts that mean different things depending on the model.

A simple internal table works:

CREATE TABLE llm_usage (
  id SERIAL PRIMARY KEY,
  provider TEXT,
  model TEXT,
  app TEXT,
  environment TEXT,
  user_id TEXT,
  input_tokens INT,
  output_tokens INT,
  cost_usd NUMERIC,
  created_at TIMESTAMPTZ DEFAULT now()
);

From there, a few SQL queries give you daily spend by app, by model, by customer — the breakdowns native billing pages can't give you.

Use per-application API keys

Attribution gets much easier if you stop sharing one API key across every service. Issue a separate key per application, environment, or team, and let the provider's usage metadata do part of the attribution work for you.

This is one of the gaps SubToAPI fills if you're building on Claude specifically. Instead of one shared Anthropic key across your stack, SubToAPI lets you issue separate application API keys (sub_live_...) per app or team, each with its own usage metadata exposed through the dashboard and API. You get per-key token counts and request counts without having to build your own logging wrapper from scratch, and team members get their own seats instead of sharing credentials. Check the pricing page for Solo, Team, and Scale plans, or read the quickstart to see how key-based attribution works in practice.

Set budgets and alerts, not just reports

Tracking spend after the fact is necessary but not sufficient — you also want to know before the invoice arrives. Once you have cost-per-request logged, set thresholds:

A cron job that sums the last 24 hours of llm_usage and fires a Slack webhook when a threshold is crossed catches runaway costs same-day instead of at month-end.

Build one view across providers

Once each provider's usage is normalized into the same schema — provider, model, app, cost — a single dashboard (even a basic Grafana panel on top of your Postgres table) gives you cross-provider visibility: total spend this week, spend by provider, spend by app, and trend over time. That's the actual goal of tracking LLM API spend across providers: not replicating five separate billing pages, but having one place that answers "where is the money going" regardless of which provider served the request.

If your stack is Claude-heavy, you can shortcut a chunk of this by routing calls through SubToAPI and reading usage straight from its messages and streaming endpoints, which return token and cost metadata per request alongside the completion itself — no separate logging pipeline required for that portion of your spend.

questions

Do I need a separate database to track spend, or can I use provider dashboards? Provider dashboards are fine for a sanity check against your invoice, but they won't attribute spend to apps, teams, or customers. For real attribution you need to log usage per request yourself, even if it's just a simple table.

What's the easiest way to compare spend across different LLM providers? Normalize everything to cost in your own currency at ingestion time, not raw token counts — pricing per token varies by provider and model, so tokens alone aren't comparable.

Can SubToAPI help me track Claude spend specifically? Yes — SubToAPI issues per-application API keys with usage metadata (tokens, requests) visible in the dashboard, so you can attribute Claude spend by app or team without building custom logging for that part of your stack. See signup to try it.

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 →