Spend Attribution

How do I track and cap Claude Code spend per developer?

Point Claude Code at Cognocient AI with ANTHROPIC_BASE_URL. Every request passes through to Anthropic unchanged, and you get per-developer cost, budgets that stop a runaway session, and the Emergency Freeze.

In the app: Settings → Proxy Keys · every planOpen in app →No account? Start free

Claude Code bills per token, and an agent that loops can spend hundreds of dollars in an afternoon. Routing it through Cognocient AI gives you the same controls as the rest of your AI traffic: live cost per developer, budgets enforced before a call reaches Anthropic, and a kill switch.

Set it up

  1. In Settings → AI Providers, add your Anthropic API key (once, for the organization).
  2. In Settings → Proxy Keys, create one Cognocient AI key per developer, named after them.
  3. Each developer sets:
export ANTHROPIC_BASE_URL="https://api.cognocient.com"
export ANTHROPIC_AUTH_TOKEN="sk-cog-THEIR-OWN-KEY"
# Optional attribution:
export ANTHROPIC_CUSTOM_HEADERS="X-Cost-User: ann@acme.com
X-Cost-Department: platform"

The same values can go in the env block of ~/.claude/settings.json, or in a managed settings file your IT team distributes. Claude Code sends the key as Authorization: Bearer; ANTHROPIC_API_KEY (sent as x-api-key) works too.

What you get

  • Cost per developer and session. Calls are tagged feature claude-code and grouped by Claude Code's session id. On the AI Coding Tools page they appear per developer, by X-Cost-User or the key's name.
  • Prompt caching costed correctly. Claude Code relies heavily on prompt caching; cache reads and writes are recorded and priced at their own rates.
  • Budgets. A Key budget caps one developer; a spend group budget caps a team; a model-group budget caps, say, all Opus usage. A refused call reaches Claude Code as an error it does not retry.
  • Velocity breakers stop a runaway session within a minute, on tokens and on dollars per minute, even when the budget still has room.
  • Emergency Freeze stops all of it at once.

What passes through, and what doesn't

The /v1/messages endpoint is a passthrough, not a translation. The request body and every anthropic-* header reach Anthropic exactly as Claude Code sent them, so new Claude Code features keep working without a Cognocient AI update. Responses, streaming events, retry-after, x-should-retry and anthropic-ratelimit-* headers come back unchanged. /v1/messages/count_tokens is forwarded too (free, not logged).

Not applied on this endpoint

Prompt guardrails (PII redaction would change the code being edited), response caching, routing rules, the Auto Router and provider failover do not run on /v1/messages: the client chose the model and the upstream is always Anthropic. Claude Code signed in with a claude.ai subscription and no gateway credential is billed by that subscription, not through your Anthropic key.

Claude Code usage that doesn't go through the proxy

If some developers use Claude Code directly against your Claude Console organization, connect an Anthropic Admin API key on the AI Coding Tools page to pull their daily usage and estimated cost from Anthropic's Claude Code Analytics API.

On this page