<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Claude Code User Usage Tracking in Generative AI</title>
    <link>https://community.databricks.com/t5/generative-ai/claude-code-user-usage-tracking/m-p/152054#M1726</link>
    <description>&lt;P&gt;I am using Databricks Model Serving as a proxy to connect Claude Code. I established the connection through &lt;STRONG&gt;Integrate coding agents (Connect coding agents to Databricks)&lt;/STRONG&gt; by generating the environment configuration:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;LI-CODE lang="markup"&gt;{
"env": {
"ANTHROPIC_MODEL": "databricks-claude-opus-4-6",
"ANTHROPIC_BASE_URL": "&amp;lt;my_databricks_workspace&amp;gt;",
"ANTHROPIC_AUTH_TOKEN": "&amp;lt;your_token_will_appear_here&amp;gt;",
"ANTHROPIC_CUSTOM_HEADERS": "x-databricks-use-coding-agent-mode: true",
"CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"
}
}&lt;/LI-CODE&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;When I try to track the cost, it is not associated with a user.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;LI-CODE lang="markup"&gt;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 &amp;gt;= list_prices.price_start_time
AND (list_prices.price_end_time IS NULL OR usage.usage_end_time &amp;lt; 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&lt;/LI-CODE&gt;&lt;P&gt;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?&lt;/P&gt;</description>
    <pubDate>Wed, 25 Mar 2026 17:31:34 GMT</pubDate>
    <dc:creator>JoaoPigozzo</dc:creator>
    <dc:date>2026-03-25T17:31:34Z</dc:date>
    <item>
      <title>Claude Code User Usage Tracking</title>
      <link>https://community.databricks.com/t5/generative-ai/claude-code-user-usage-tracking/m-p/152054#M1726</link>
      <description>&lt;P&gt;I am using Databricks Model Serving as a proxy to connect Claude Code. I established the connection through &lt;STRONG&gt;Integrate coding agents (Connect coding agents to Databricks)&lt;/STRONG&gt; by generating the environment configuration:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;LI-CODE lang="markup"&gt;{
"env": {
"ANTHROPIC_MODEL": "databricks-claude-opus-4-6",
"ANTHROPIC_BASE_URL": "&amp;lt;my_databricks_workspace&amp;gt;",
"ANTHROPIC_AUTH_TOKEN": "&amp;lt;your_token_will_appear_here&amp;gt;",
"ANTHROPIC_CUSTOM_HEADERS": "x-databricks-use-coding-agent-mode: true",
"CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"
}
}&lt;/LI-CODE&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;When I try to track the cost, it is not associated with a user.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;LI-CODE lang="markup"&gt;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 &amp;gt;= list_prices.price_start_time
AND (list_prices.price_end_time IS NULL OR usage.usage_end_time &amp;lt; 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&lt;/LI-CODE&gt;&lt;P&gt;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?&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2026 17:31:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/claude-code-user-usage-tracking/m-p/152054#M1726</guid>
      <dc:creator>JoaoPigozzo</dc:creator>
      <dc:date>2026-03-25T17:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: Claude Code User Usage Tracking</title>
      <link>https://community.databricks.com/t5/generative-ai/claude-code-user-usage-tracking/m-p/152079#M1727</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/165745"&gt;@JoaoPigozzo&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;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&amp;nbsp;is designed for cost attribution by SKU / endpoint, not per‑user analytics. For foundation models (e.g.,&amp;nbsp;PREMIUM_ANTHROPIC_MODEL_SERVING), identity_metadata is often not populated the way you’d expect, so "user = NULL" there is normal.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P class="p8i6j01 paragraph"&gt;If you want per‑user usage for Claude Code, the supported path is to use&amp;nbsp;&lt;A href="https://docs.databricks.com/en/ai-gateway/coding-agent-integration-beta.html" target="_self"&gt;AI Gateway coding agents integration&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;This logs each request to system.ai_gateway.usage with a requester field (user or service principal). You can then do:&lt;/P&gt;
&lt;DIV class="l8rrz21 _1ibi0s3dn" data-ui-element="code-block-container"&gt;
&lt;PRE&gt;&lt;CODE class="markdown-code-sql p8i6j0e hljs language-sql _12n1b832"&gt;&lt;SPAN class="hljs-keyword"&gt;SELECT&lt;/SPAN&gt;
  requester,
  endpoint_name,
  date_trunc(&lt;SPAN class="hljs-string"&gt;'day'&lt;/SPAN&gt;, event_time) &lt;SPAN class="hljs-keyword"&gt;AS&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;day&lt;/SPAN&gt;,
  &lt;SPAN class="hljs-built_in"&gt;SUM&lt;/SPAN&gt;(input_tokens)  &lt;SPAN class="hljs-keyword"&gt;AS&lt;/SPAN&gt; in_tokens,
  &lt;SPAN class="hljs-built_in"&gt;SUM&lt;/SPAN&gt;(output_tokens) &lt;SPAN class="hljs-keyword"&gt;AS&lt;/SPAN&gt; out_tokens
&lt;SPAN class="hljs-keyword"&gt;FROM&lt;/SPAN&gt; system.ai_gateway.usage
&lt;SPAN class="hljs-keyword"&gt;WHERE&lt;/SPAN&gt; endpoint_name &lt;SPAN class="hljs-operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="hljs-string"&gt;'&amp;lt;your_coding_agent_endpoint&amp;gt;'&lt;/SPAN&gt;
&lt;SPAN class="hljs-keyword"&gt;GROUP&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;BY&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;ALL&lt;/SPAN&gt;
&lt;SPAN class="hljs-keyword"&gt;ORDER&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;BY&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;day&lt;/SPAN&gt; &lt;SPAN class="hljs-keyword"&gt;DESC&lt;/SPAN&gt;, in_tokens &lt;SPAN class="hljs-keyword"&gt;DESC&lt;/SPAN&gt;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="l8rrz23 _1ibi0s3d6 _1ibi0s332 _1ibi0s3do _1ibi0s3bm _1ibi0s3ce"&gt;
&lt;DIV class="lqznwq0"&gt;Refer to u&lt;SPAN&gt;sage table &lt;A href="https://docs.databricks.com/en/ai-gateway/usage-tracking-beta.html" target="_self"&gt;docs&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;to understand the table strucutre and what is available for querying.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;If you’re instead calling a plain Model Serving endpoint, enable AI Gateway usage tracking on that &lt;A href="http://&amp;nbsp;https://docs.databricks.com/en/ai-gateway/configure-ai-gateway-endpoints.html" target="_self"&gt;endpoint&lt;/A&gt; and use system.serving.endpoint_usage for per‑request tokens + requester.&amp;nbsp;You can still use system.billing.usage to get total endpoint cost.&amp;nbsp;Then apportion that cost per user by their share of tokens from system.serving.endpoint_usage or system.ai_gateway.usage.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Does this give you a direction?&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT size="2" color="#FF6600"&gt;&lt;STRONG style="color: #1b3139; font-family: inherit;"&gt;&lt;I&gt;&lt;FONT color="#FF6600"&gt;If this answer resolves your question, could you mark it as “Accept as Solution”? That helps other users quickly find the correct fix.&lt;/FONT&gt;&lt;/I&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P class="p8i6j01 paragraph"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2026 22:15:47 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/claude-code-user-usage-tracking/m-p/152079#M1727</guid>
      <dc:creator>Ashwin_DSA</dc:creator>
      <dc:date>2026-03-25T22:15:47Z</dc:date>
    </item>
  </channel>
</rss>

