cancel
Showing results for 
Search instead for 
Did you mean: 
Generative AI
Explore discussions on generative artificial intelligence techniques and applications within the Databricks Community. Share ideas, challenges, and breakthroughs in this cutting-edge field.
cancel
Showing results for 
Search instead for 
Did you mean: 

Claude Code User Usage Tracking

JoaoPigozzo
New Contributor III

I am using Databricks Model Serving as a proxy to connect Claude Code. I established the connection through Integrate coding agents (Connect coding agents to Databricks) by generating the environment configuration:

 

 
{
"env": {
"ANTHROPIC_MODEL": "databricks-claude-opus-4-6",
"ANTHROPIC_BASE_URL": "<my_databricks_workspace>",
"ANTHROPIC_AUTH_TOKEN": "<your_token_will_appear_here>",
"ANTHROPIC_CUSTOM_HEADERS": "x-databricks-use-coding-agent-mode: true",
"CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"
}
}
 
When I try to track the cost, it is not associated with a user.
 
SELECT
usage.usage_date,
usage.sku_name,
usage.usage_metadata.endpoint_name AS model_name,
SUM(usage.usage_quantity * list_prices.pricing.effective_list.default) AS total_cost
FROM system.billing.usage AS usage
JOIN system.billing.list_prices AS list_prices
ON usage.sku_name = list_prices.sku_name
AND usage.usage_end_time >= list_prices.price_start_time
AND (list_prices.price_end_time IS NULL OR usage.usage_end_time < list_prices.price_end_time)
WHERE
usage.usage_metadata.endpoint_name IS NOT NULL
AND usage.sku_name = 'PREMIUM_ANTHROPIC_MODEL_SERVING'
GROUP BY usage.usage_date, model_name, usage.sku_name
ORDER BY usage.usage_date, total_cost DESC

The result show user as 'null'. How can I check the usage associated with a specific user when using Model Serving as a proxy for Claude Code?

1 ACCEPTED SOLUTION

Accepted Solutions

Ashwin_DSA
Databricks Employee
Databricks Employee

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 usage 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***

View solution in original post

1 REPLY 1

Ashwin_DSA
Databricks Employee
Databricks Employee

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 usage 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***