Hi @JoaoPigozzo,
After some investigation, I found that when you use Databricks Model Serving as a proxy for Claude Code, what you see in system.billing.usage is expected. That table is is designed for cost attribution by SKU / endpoint, not per‑user analytics. For foundation models (e.g., PREMIUM_ANTHROPIC_MODEL_SERVING), identity_metadata is often not populated the way you’d expect, so "user = NULL" there is normal.
Unfortunately, there isn’t a single column in system.billing.usage that directly gives "user + $ cost" for Claude Code. The pattern is tokens per user from usage tables + cost per endpoint from billing.
If you want per‑user usage for Claude Code, the supported path is to use AI Gateway coding agents integration
This logs each request to system.ai_gateway.usage with a requester field (user or service principal). You can then do:
SELECT
requester,
endpoint_name,
date_trunc('day', event_time) AS day,
SUM(input_tokens) AS in_tokens,
SUM(output_tokens) AS out_tokens
FROM system.ai_gateway.usage
WHERE endpoint_name = '<your_coding_agent_endpoint>'
GROUP BY ALL
ORDER BY day DESC, in_tokens DESC;
Refer to u
sage table docs to understand the table strucutre and what is available for querying.
If you’re instead calling a plain Model Serving endpoint, enable AI Gateway usage tracking on that
endpoint and use system.serving.endpoint_usage for per‑request tokens + requester. You can still use system.billing.usage to get total endpoint cost. Then apportion that cost per user by their share of tokens from system.serving.endpoint_usage or system.ai_gateway.usage.
Does this give you a direction?
If this answer resolves your question, could you mark it as “Accept as Solution”? That helps other users quickly find the correct fix.
Regards,
Ashwin | Delivery Solution Architect @ Databricks
Helping you build and scale the Data Intelligence Platform.
***Opinions are my own***