How to Track API Usage Per Customer with Claude
If you're building a product on top of Claude and selling access to multiple customers, you'll quickly hit a wall: Anthropic's API gives you one key and one combined bill. There's no built-in way to see "customer A used 2M tokens this month, customer B used 50K." If you need that breakdown — for usage-based billing, fair-use limits, or just understanding your margins per account — you have to build it yourself or use a layer that already does it.
The short answer is: track usage by attaching a customer identifier to every request you make, log the token counts Claude returns in each response, and aggregate those logs by customer. You can do this with your own logging table, or you can skip the engineering work by issuing each customer their own API key through a metering gateway like SubToAPI, which tracks usage per key automatically.
Why Claude's Native API Doesn't Track This For You
Anthropic's API is designed for a single account calling it with a single key. The usage data it returns is per-request (input tokens, output tokens), but there's no concept of "sub-accounts" or "customers" baked into the key itself. If you have 200 customers hitting your backend, which then calls Claude with your one API key, Anthropic has no way of knowing those 200 customers exist — from their side, it's all you.
That's fine if you're building an internal tool. It becomes a real problem the moment you need to:
- Bill customers based on how much they actually use
- Cap usage per plan tier (e.g., free tier gets 100 requests/month)
- Spot which customer is driving your Claude bill before it shows up as a surprise invoice
- Give customers visibility into their own usage
None of that is possible without tracking at the application layer.
Three Ways to Track Per-Customer Usage
1. Log usage yourself, keyed by customer ID. Every Claude response includes a usage object with input_tokens and output_tokens. Capture that on every call, tag it with the customer ID from your own auth system, and write it to a database.
2. Issue a separate API key per customer inside your own backend. Instead of one shared key, generate a unique internal token per customer, map it to Claude calls, and track usage against that token. This is more work but gives you cleaner isolation and lets you revoke access per customer without touching anyone else.
3. Use a gateway that already separates usage by key. Tools like SubToAPI let you create application-level keys (sub_live_...) per customer or per project, and usage, cost, and request counts are tracked and reported per key automatically — no custom logging table required. See /docs/quickstart for how key creation and usage reporting work.
Building It Yourself: Logging Usage from Claude Responses
If you're going the DIY route, the pattern is straightforward. Every response from the Messages API includes usage data you can persist:
const response = 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: "Summarize this contract." }],
}),
});
const data = await response.json();
await db.usageLogs.insert({
customer_id: currentCustomer.id,
input_tokens: data.usage.input_tokens,
output_tokens: data.usage.output_tokens,
model: data.model,
created_at: new Date(),
});
Once you have rows like this, aggregating per-customer cost or request volume is a standard SQL query:
SELECT customer_id,
SUM(input_tokens) AS total_input,
SUM(output_tokens) AS total_output,
COUNT(*) AS requests
FROM usage_logs
WHERE created_at >= date_trunc('month', now())
GROUP BY customer_id
ORDER BY total_output DESC;
This works, but you're now maintaining a logging pipeline, a schema, retention policy, and probably a dashboard — on top of your actual product.
What Metrics to Track Per Customer
Whatever approach you use, the metrics worth capturing are the same:
- Input tokens and output tokens — the raw cost drivers
- Request count — useful for rate limiting and plan enforcement
- Model used — if you route between models, cost varies significantly
- Latency — helps spot customers hitting slow prompts or large contexts
- Error rate — failed requests often still consume quota or retries
If you expose any of this back to customers (a usage page in their dashboard), keep the breakdown simple: requests this period, tokens this period, and estimated cost if you're billing by usage.
Setting Limits and Alerts Per Customer
Tracking usage is only half the job — the other half is acting on it. Once you know per-customer volume, you can:
- Set a hard cap per plan tier and reject requests once a customer exceeds it
- Send a warning at 80% of quota before the cutoff
- Auto-upgrade or prompt an upsell when a customer consistently nears their limit
If you're issuing per-customer keys through SubToAPI, this is handled at the key level — each application key's usage is visible in the dashboard, so you can see consumption per customer without building the aggregation layer yourself. See /docs/messages for request/response details and /pricing for how seats and keys map to plans.
Choosing Between DIY and a Managed Layer
If you have one or two enterprise customers and a simple pricing model, a usage_logs table and a cron job to summarize it monthly is probably enough. If you have dozens or hundreds of customers, variable pricing, or need customers to self-serve their own usage data, building and maintaining that infrastructure stops being a weekend project and starts being a second product. At that point, a metering gateway that issues per-customer keys and reports usage out of the box — like SubToAPI, /signup — saves you from reinventing billing infrastructure that isn't your core product.
questions
Does Anthropic's API let me see usage broken down by customer? No. Anthropic bills and reports usage against your account as a whole. Per-customer breakdown has to be tracked at the application layer, either through your own logging or a third-party metering tool.
What's the minimum data I need to log to track usage per customer? At minimum: customer ID, input tokens, output tokens, and timestamp on every request. That's enough to compute cost, request volume, and monthly aggregates per customer.
Can I enforce usage limits per customer without building my own system? Yes — issuing a separate application API key per customer through a gateway like SubToAPI lets you track and cap usage per key without building a custom logging and limiting pipeline. Check /docs/tools and /docs/streaming for how key-scoped requests work in practice.