r/ClaudeCode • • 19h ago

Help/Question How do you get Claude Code cost per team when devs share API keys?

We have about 60 devs on Claude code using Console API keys. Each team got its own key and the Console usage page would split spend by team for us.

That worked fine until finance asked what each team spends. Turns out four people on payments have been sharing one key from a .env file, and two of our heaviest users got fed up with hitting limits and moved to their own Max plans. None of their usage shows up on our bill, and finance was definitely thrilled.

Right now finance is working off a spreadsheet where every dev pasted their/ cost output and a few just sent screenshots. It comes to 71% of the Console total, which kinda makes sense because /cost resets on/ clear and I know at least three people cleared before pasting.

The OTel export with a team attribute looks like the right way to do it, but that means running a collector for one number. The docs also say user. email is only included when available but I'm not sure it ever is on API key logins.

Is there a way to get Claude Code cost per team without standing up as a collector?

1 Upvotes

11 comments sorted by

•

u/AutoModerator 19h ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/Pissd_Tdn 19h ago

Finance person here,You're not going to get a per team number that ties in the invoice.

We just take the invoice total and split by whatever usage estimate engineering hands us.If the estimate says payments is 22% then payments get 22% then payments gets 22% of the invoice. A bit off is fine as long as you don't keep changing how you estimate, that's why auditors pick at.

Write down where the numbers come from and where the usage you can't attribute goes, shared keys included. We dump ours in a platform line.

Also ,the two on personal Max plans are an expense claim problem. I'd want to hear about those before the auditors do

1

u/Rameshbabu_Inderjit 18h ago

ccusage is what you want for the 71% problem . It reads the session logs under ~/. claude instead of /cost and a/ clear doesn't wipe those . Just run npx ccusage@latest monthly on each machine.

One thing , Claude Code deletes transcripts older than 30 days by default via cleanupPeriodDays. If finance wants a full quater you'll need to bump that first . And it's still price and one laptop at a time and good luck getting 60 devs to run it and send you the output

1

u/karol207 18h ago

A scheduled Cost API export, using an admin key, can group spend by `workspace_id` if you give each team its own Console workspace. No collector needed. Personal Max subscriptions still need a separate line; they won't appear as usage billed to your API organization.

1

u/OnoniewuGehovany99 18h ago

Why are 60 devs on API keys at LL? Team premium gives you per person usage rights in the admin console and your two Max plan guys will probably come back too

1

u/Leo__255 17h ago

you don't actually need to run your own collector for the otel route, claude code can send otlp straight to a hosted backend like grafana cloud's free tier, then it's one query grouped by your team attribute

1

u/Successful-Sky9914 15h ago

On user.email: the docs say it comes from your sign-in, so I wouldn't count on it with plain API keys.

You don't need it for a team split though. Set the team yourself with OTEL_RESOURCE_ATTRIBUTES="team.id=payments", and it attaches to every metric datapoint by default, including claude_code.cost.usage. It's per machine, so four people sharing one key doesn't matter anymore. The docs call the cost metric an approximation, so use it for the split and the Console for the total.

If you don't want a collector at all, one Console workspace per team is simplest, but you have to kill the shared .env key first or you get the same problem again.

1

u/athershu 15h ago

The OTel team attribute covers the API key part. The bit I'd worry about more is the two heaviest users on personal Max plans and the payments key sitting in a .env. No tagging reaches those, and it's not only spend you lose there: you also can't see what those sessions ran or what they had access to (I'd rotate that payments key regardless).

What worked better for us than chasing the meter was making the shared team setup the easier place to work, so the heavy users have no reason to leave it. Once the runs go through one place, cost per team is just which project each run was for, and nobody has to paste /cost into a spreadsheet.

1

u/SirRobinBlibs 10h ago

ccusage is the right fix for the 71% gap, as already noted, because /cost dies on /clear. The attribution problem is separate, and a collector will not solve it while four people share one key: Console bills that key as one customer, and user.email on OTel is only filled from a sign-in (or a cloud session's credentials), so API-key-only sessions often have no email to join on. Give each person or team their own Console key first, then the invoice already splits by key. If you still want team rollups in your own dashboards, set a custom attribute like team.id through OTEL_RESOURCE_ATTRIBUTES on those machines; that does need a collector, but you are then labelling already-separated keys, not trying to untangle a shared .env after the fact. Docs: https://code.claude.com/docs/en/monitoring-usage

1

u/Appropriate-Toe-2993 7h ago

The 71% gap is mostly the /cost reset, but a few things close most of the rest without a collector:

  1. Put the team tag in settings, not in each dev's shell. Claude Code's settings.json takes an env block, so OTEL_RESOURCE_ATTRIBUTES=team.id=payments set there (or in managed settings if you push config to laptops) survives people swapping keys or .env files.
  2. For the backfill, the session JSONL under ~/.claude/projects has token counts per message, including cache reads and writes, and /clear doesn't touch it. Price it per project folder and you get a team split for the past month, as long as nothing hit the 30-day cleanup.
  3. The Max-plan folks: their local logs still have the tokens, so you can show finance an API-equivalent number for them, labeled as an estimate. It won't tie to the invoice, but it explains the gap.

For finance I'd hand over two lines: billed spend split by team, and a separate off-invoice estimate for personal plans. Mixing them is where the spreadsheet breaks.