Claude API Usage Analytics Per Customer: A Guide
If you're building a product on top of Claude and multiple customers or tenants share your backend, you quickly run into a gap: Anthropic's console shows you organization-wide token usage, but nothing broken down by customer, workspace, or end user. If you need to bill customers based on consumption, enforce per-customer quotas, or just understand which accounts are driving your API costs, you have to build that attribution layer yourself — or use a layer that already does it.
This article covers the practical ways to get Claude API usage analytics per customer: tagging requests, issuing separate keys, logging token data from responses, and using a proxy that tracks usage per key out of the box.
Why per-customer usage tracking matters
Org-wide dashboards answer "how much did we spend this month," not "which customer is costing us the most" or "is this customer about to hit their plan limit." Without per-customer visibility you can't:
- Bill usage-based plans accurately
- Detect a single customer abusing the system or driving runaway costs
- Decide which customers need rate limits or throttling
- Forecast margin per account, which matters a lot once your volume grows
The fix is attribution: every call to Claude needs to be tied back to a specific customer ID, and the token usage from that call needs to be stored against that ID.
Approach 1: Tag requests and log usage yourself
The most direct method is to call the Claude API directly, pass a customer identifier through your own system (not through Anthropic, which doesn't support arbitrary per-request billing metadata), and log the usage object returned in every response.
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Summarize this ticket."}]
}'
The response includes an usage field with input_tokens and output_tokens. In your application code, wrap every call so you immediately write a row to your database:
async function callClaudeForCustomer(customerId, payload) {
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(payload),
});
const data = await res.json();
await db.usageLogs.insert({
customerId,
model: payload.model,
inputTokens: data.usage.input_tokens,
outputTokens: data.usage.output_tokens,
createdAt: new Date(),
});
return data;
}
From there, aggregate usageLogs by customerId to build dashboards, monthly invoices, or quota alerts. This works, but it means you own the logging pipeline, the storage, the aggregation queries, and the dashboard UI. For a handful of customers that's trivial; at scale it becomes a small internal product of its own.
Approach 2: Issue a separate key per customer
A cleaner separation is to give each customer (or each internal tenant) its own API key, then track usage at the key level instead of threading a customer ID through every call manually. This is useful when customers are fully isolated — separate rate limits, separate billing, separate revocation.
The tradeoff is that Anthropic's own API keys don't come with built-in per-key usage dashboards or spend limits you can self-serve. You'd still need to log usage per key yourself, same as approach 1, just keyed by api_key_id instead of customer_id.
This is exactly the gap tools like SubToAPI fill. SubToAPI sits between your app and Claude, issues scoped sub_live_... keys per customer or per team seat, and tracks usage metadata — tokens, requests — against each key automatically. You get the per-customer breakdown without building and maintaining the logging pipeline yourself.
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({
model: "claude-sonnet-4-5",
max_tokens: 1024,
messages: [{ role: "user", content: "Summarize this ticket." }],
}),
});
const data = await res.json();
console.log(data.usage); // tokens for this request, tied to the key that made it
If you issue a distinct key per customer at signup, every request made through that key is automatically attributed in the dashboard — no custom logging table required. See the quickstart and the messages docs for the full request/response shape.
What to track once you have attribution
Once requests are tagged by customer, decide what actually matters for your product:
- Tokens in / tokens out — the raw driver of cost, split because output tokens are typically priced higher
- Request count — useful for rate-limit and abuse detection independent of token volume
- Cost per customer — tokens multiplied by your model's per-token rate, aggregated per billing period
- Peak usage windows — helps size rate limits per plan tier
- Error/retry rate per customer — a customer hitting rate limits or malformed-request errors repeatedly is a support signal, not just a usage number
Most teams start with just tokens and request count, then add cost and error tracking once the first few customers approach a billing threshold.
Streaming and tool-use calls still need attribution
If your product streams responses or uses tool calling, don't forget those paths need the same tagging. Streamed responses send usage data in the final event, so your logging hook needs to listen for the end-of-stream event rather than the initial response. See streaming and tool use for the event shapes if you're building this yourself, or route those calls through the same per-customer key if you're using a gateway — the usage still rolls up correctly either way.
Keeping it simple as you scale
For a side project or early-stage product with a handful of customers, a single logging table keyed by customer ID is enough. Once you have dozens of customers on paid plans, enforcing hard quotas, or multiple team members needing visibility into spend, a dedicated layer — whether that's your own internal service or a hosted option like SubToAPI with per-seat keys and usage dashboards — saves you from rebuilding billing infrastructure every time a new plan tier gets added.
FAQ
Does Anthropic's console show usage broken down by customer? No. The Anthropic console reports usage at the organization and API key level, not per end customer. You need to either tag and log requests yourself or use a layer that issues distinct keys per customer and tracks usage against each one.
What's the simplest way to attribute Claude usage to a customer? Log the usage.input_tokens and usage.output_tokens fields from every API response against a customer ID in your own database. This requires no extra infrastructure beyond a table and a wrapper around your API calls.
Can I get per-customer usage without building my own logging system? Yes — issuing a separate API key per customer through a gateway like SubToAPI gives you automatic per-key usage tracking in a dashboard, so each customer's token and request counts are already attributed without custom code. See /docs/quickstart to set this up.