← Blog

Claude API Usage Analytics for SaaS: A Setup Guide

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

If you're building a SaaS product on top of Claude, "usage analytics" usually means one specific thing: knowing how much each customer, workspace, or feature is costing you in tokens and API calls, in near real time, without writing a custom billing pipeline from scratch. This matters because Anthropic's own console gives you account-wide totals, not per-tenant breakdowns — and per-tenant breakdowns are exactly what you need to price plans, catch abuse, and forecast margin.

This guide covers what to measure, how to instrument it, and two paths to get there: building it yourself or using a layer like SubToAPI that returns usage metadata with every response so you don't have to.

Why Claude API analytics is different for SaaS

When you're a single developer calling Claude for your own project, you mostly care about total spend. When you're running a SaaS with dozens or thousands of end users, you need usage data sliced by dimensions Anthropic's dashboard doesn't give you out of the box:

None of this is exotic engineering, but it's work you have to do deliberately. Skipping it is how SaaS teams end up with a surprise bill and no idea which customer caused it.

What to track, at minimum

1. Input and output tokens, separately

Claude's pricing (and most LLM pricing) treats input and output tokens differently, and output tokens are typically more expensive. Log both per request, not just a combined total — it changes how you optimize prompts later.

2. Request metadata

Tag every call with:

async function callClaude({ customerId, feature, prompt }) {
  const start = Date.now();
  const response = await anthropic.messages.create({
    model: "claude-opus-4",
    max_tokens: 1024,
    messages: [{ role: "user", content: prompt }],
  });

  await logUsage({
    customerId,
    feature,
    inputTokens: response.usage.input_tokens,
    outputTokens: response.usage.output_tokens,
    latencyMs: Date.now() - start,
  });

  return response;
}

3. Aggregate into daily/monthly rollups

Raw event logs are fine for debugging but too granular for dashboards. Roll up into daily totals per customer so your "usage this month" view doesn't require scanning millions of rows.

SELECT customer_id,
       DATE(created_at) AS day,
       SUM(input_tokens) AS input_tokens,
       SUM(output_tokens) AS output_tokens,
       COUNT(*) AS requests
FROM claude_usage_events
GROUP BY customer_id, day;

4. Cost attribution

Multiply token counts by the model's current price per million tokens, stored in a config table (not hardcoded) since Anthropic updates pricing periodically. This is the number product and finance teams actually want.

Building it yourself vs. getting it for free

Instrumenting all of this — the logging, the rollups, the per-key cost math, the dashboard — is a real project. It's not hard individually, but it adds up to weeks of work that doesn't touch your core product.

This is the gap SubToAPI fills. It sits between your app and Claude: you call https://api.subtoapi.app/v1/messages with a sub_live_... key instead of calling Anthropic directly, and every response includes usage metadata (tokens in, tokens out, which key made the call) so you can attribute cost per customer without building the logging layer yourself.

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

Because each application key maps to a customer, team, or environment in your dashboard, usage analytics per Claude API key becomes a byproduct of normal operation rather than a separate engineering effort. You can issue one key per customer, one per feature, or one per environment depending on how granular your billing needs to be — see /docs/quickstart for setup and /docs/messages for the request format.

Streaming and tool use don't break your analytics

If your product streams responses or uses Claude's tool-calling, your analytics pipeline needs to handle partial completions and multi-turn tool exchanges without double-counting tokens. SubToAPI's streaming endpoint (/docs/streaming) and tool-use support (/docs/tools) report final usage totals once a turn completes, so your per-customer rollups stay accurate even when the underlying request involved several tool round-trips.

Setting up alerts, not just dashboards

Analytics that nobody looks at until the invoice arrives isn't analytics, it's an autopsy. Set thresholds:

These three alone catch most of the operational surprises — a customer scraping your API through a chat feature, a prompt regression that doubled output length, or a noisy neighbor hitting rate limits for everyone else on a shared key.

Picking a granularity that matches your pricing model

If you bill customers flat monthly fees, you mostly need usage data for cost control and abuse detection. If you bill usage-based or have tiered plans with included quotas, you need per-customer token totals to be accurate enough to drive billing itself — which means your analytics and your billing system should read from the same source of truth, not two parallel logs that can drift apart.

Whichever model you choose, decide this early. Retrofitting granular per-customer tracking onto a system that only logged account-wide totals is far more painful than building it in from day one — or routing through a layer that already separates usage by key, as covered at /pricing for the different plan tiers (Solo, Team, Scale) that map to how many keys and seats you need.

questions

Do I need to build my own analytics pipeline to track Claude API usage per customer? No. You can instrument it yourself with token logging and rollups, or use a proxy layer like SubToAPI that attributes usage to individual application keys automatically, giving you per-customer data without custom infrastructure.

What's the most important metric for SaaS cost control? Cost per active customer per billing period, broken into input and output tokens. It's the number that tells you whether a plan tier is actually profitable, not just total spend.

Does streaming or tool use make usage tracking harder? It adds complexity if you're logging manually, since you need to sum tokens across streamed chunks or multi-turn tool calls. A proxy that reports final usage totals per completed turn avoids this problem entirely.

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 →