guide
guide8 min read

Snowflake Cortex Credits Not in WAREHOUSE_METERING_HISTORY: How to Track Them

Find AI_SERVICES spend, attribute it to users and queries, and alert when it drifts

Snowflake Cortex credits are missing from WAREHOUSE_METERING_HISTORY because that view only meters virtual warehouses. Cortex AI usage is billed under the AI_SERVICES service type, which you find in SNOWFLAKE.ACCOUNT_USAGE.METERING_HISTORY. Per-query attribution comes from CORTEX_AI_FUNCTIONS_USAGE_HISTORY. This tutorial gives the SQL for both, a reconciled daily view, and a drift alert.

Key Takeaways

  • •WAREHOUSE_METERING_HISTORY covers warehouse compute only. Cortex AI Functions and Cortex Analyst are metered as service type AI_SERVICES in METERING_HISTORY.
  • •Per Snowflake's documentation, resource monitors work for warehouses only and cannot track spending on serverless features and AI services. Use budgets for those.
  • •CORTEX_AI_FUNCTIONS_USAGE_HISTORY gives credits per function, model, query, user, role and query tag. The older CORTEX_FUNCTIONS_USAGE_HISTORY and CORTEX_FUNCTIONS_QUERY_USAGE_HISTORY views are no longer updated.
  • •The AI credits in these views exclude the warehouse credits of the calling query, so a Cortex call costs you in two places.

Why Snowflake Cortex credits are not in WAREHOUSE_METERING_HISTORY

WAREHOUSE_METERING_HISTORY reports credits consumed by virtual warehouses. Cortex AI Functions bill per token, and Snowflake meters that usage separately from the warehouse that issued the query. The METERING_HISTORY reference lists AI_SERVICES as a SERVICE_TYPE value covering Cortex AI Functions (including the LLM functions) and Cortex Analyst. Snowflake notes that its list of service types is not exhaustive, so group by SERVICE_TYPE rather than hard-coding a filter list.

Two consequences follow. A cost report built on WAREHOUSE_METERING_HISTORY understates your bill by the full AI amount. And the warehouse that called AI_COMPLETE still shows its own compute credits, so the AI cost never appears next to the query that caused it.

Resource monitors will not catch this either. Snowflake's resource monitor documentation states that resource monitors work for warehouses only and that you cannot use one to track spending on serverless features and AI services. It points to budgets for those. Our view: a warehouse quota can look healthy while AI spend climbs.

Step 1: Find every service type in METERING_HISTORY

Start by seeing what you are billed for. This groups the last 30 days of credits by day and service type. Expect to see AI_SERVICES next to the warehouse metering type if anyone in the account calls Cortex.

sql SELECT DATE_TRUNC('day', start_time) AS usage_day, service_type, SUM(credits_used) AS credits FROM SNOWFLAKE.ACCOUNT_USAGE.METERING_HISTORY WHERE start_time >= DATEADD('day', -30, CURRENT_TIMESTAMP()) GROUP BY 1, 2 ORDER BY 1 DESC, 3 DESC;

Snowflake documents a latency of up to 180 minutes for this view, so do not alarm on today's partial numbers.

Step 2: Isolate AI_SERVICES by entity

Filter to AI_SERVICES and group by the NAME column to see which entities drive the spend. This is the number your finance team will quote.

sql SELECT DATE_TRUNC('day', start_time) AS usage_day, name, SUM(credits_used) AS ai_credits FROM SNOWFLAKE.ACCOUNT_USAGE.METERING_HISTORY WHERE service_type = 'AI_SERVICES' AND start_time >= DATEADD('day', -30, CURRENT_TIMESTAMP()) GROUP BY 1, 2 ORDER BY 1 DESC, 3 DESC;

Step 3: Attribute AI credits to users, roles and queries

METERING_HISTORY tells you how much. It does not tell you who. For that, use CORTEX_AI_FUNCTIONS_USAGE_HISTORY, which has one row per function, model, query and warehouse in one-hour windows, with USER_ID, ROLE_NAMES, QUERY_TAG and CREDITS (excluding warehouse credits). Snowflake's docs say the older CORTEX_FUNCTIONS_QUERY_USAGE_HISTORY view is no longer updated, so build on the newer one.

sql SELECT DATE_TRUNC('day', f.start_time) AS usage_day, u.name AS user_name, f.role_names[0]::STRING AS primary_role, f.function_name, f.model_name, f.query_tag, SUM(f.credits) AS ai_credits, COUNT(DISTINCT f.query_id) AS queries FROM SNOWFLAKE.ACCOUNT_USAGE.CORTEX_AI_FUNCTIONS_USAGE_HISTORY f LEFT JOIN SNOWFLAKE.ACCOUNT_USAGE.USERS u ON u.user_id::VARCHAR = f.user_id WHERE f.start_time >= DATEADD('day', -30, CURRENT_TIMESTAMP()) GROUP BY 1, 2, 3, 4, 5, 6 ORDER BY ai_credits DESC;

To see the most expensive individual queries, join to QUERY_HISTORY on QUERY_ID. This gives you the warehouse, the SQL text and the runtime beside the AI credits:

sql SELECT f.query_id, q.user_name, q.warehouse_name, f.function_name, f.model_name, SUM(f.credits) AS ai_credits, ANY_VALUE(q.total_elapsed_time) AS elapsed_ms, ANY_VALUE(LEFT(q.query_text, 200)) AS query_snippet FROM SNOWFLAKE.ACCOUNT_USAGE.CORTEX_AI_FUNCTIONS_USAGE_HISTORY f JOIN SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY q ON q.query_id = f.query_id WHERE f.start_time >= DATEADD('day', -7, CURRENT_TIMESTAMP()) GROUP BY 1, 2, 3, 4, 5 ORDER BY ai_credits DESC LIMIT 20;

Two limits from the view's documentation matter. Usage is included only from January 5, 2026 onward, and USER_ID, query tag and roles are available only for data acquired after February 16, 2026. Older rows will show NULL attribution.

Step 4: Know why the two sources will not match

Expect the AI_SERVICES total in METERING_HISTORY to be at least as large as the function-level total. AI_SERVICES also includes Cortex Analyst, which this function view does not cover, and some functions, such as AI_PARSE_DOCUMENT, are metered by pages rather than tokens. Windows also differ: the per-query view records usage in the hour a query finishes, and METERING_HISTORY has its own ingestion lag. Treat METERING_HISTORY as the billing total and the function view as the explanation of it. A gap that persists after two days is worth investigating.

Step 5: Build one reconciled daily view

Put warehouse and AI credits in one place so dashboards stop reading from WAREHOUSE_METERING_HISTORY alone. Keeping SERVICE_TYPE as the bucket means a new billing category shows up as its own row instead of vanishing.

sql CREATE OR REPLACE VIEW FINOPS.PUBLIC.DAILY_CREDITS AS SELECT DATE_TRUNC('day', start_time) AS usage_day, service_type AS bucket, SUM(credits_used) AS credits FROM SNOWFLAKE.ACCOUNT_USAGE.METERING_HISTORY GROUP BY 1, 2;

As a sanity check, compare the warehouse bucket here with SUM(credits_used) from WAREHOUSE_METERING_HISTORY for the same days. They should be close. A large difference means your dashboard is mixing sources.

Step 6: Alert when AI spend drifts

Alert on yesterday's AI credits against the trailing 7-day median. A median resists a single large backfill better than an average. This query returns a row only when yesterday exceeded twice the median, so you can run it from a Snowflake task or alert and send any non-empty result to your channel.

sql WITH baseline AS ( SELECT MEDIAN(credits) AS median_credits FROM FINOPS.PUBLIC.DAILY_CREDITS WHERE bucket = 'AI_SERVICES' AND usage_day >= DATEADD('day', -8, CURRENT_DATE()) AND usage_day < DATEADD('day', -1, CURRENT_DATE()) ), yesterday AS ( SELECT SUM(credits) AS credits FROM FINOPS.PUBLIC.DAILY_CREDITS WHERE bucket = 'AI_SERVICES' AND usage_day = DATEADD('day', -1, CURRENT_DATE()) ) SELECT y.credits AS yesterday_credits, b.median_credits, y.credits / NULLIF(b.median_credits, 0) AS ratio FROM yesterday y, baseline b WHERE y.credits > 2 * b.median_credits;

For hard limits, add a Snowflake budget on top. Per the resource monitor docs linked above, budgets are the supported way to track spending on AI services. Treat the alert as the early warning and the budget as the guardrail.

Running this from your terminal with Data Workers

If your team works in Claude Code or Cursor, you do not need to keep these queries in a notebook. Data Workers is fifteen MCP-native agents, and our Connectors Agent links Snowflake to the rest of them. You can ask a question such as "How much are we spending on Snowflake this month?" from the terminal. The open-source edition is read-only by default, which suits cost investigation, because nothing here needs write access. We covered the same terminal-first approach to pipelines and catalog work elsewhere on dataworkers.io.

Frequently Asked Questions

Why don't my Cortex credits show up in WAREHOUSE_METERING_HISTORY? That view only reports virtual warehouse compute. Cortex AI usage is metered as service type AI_SERVICES and appears in METERING_HISTORY, with per-query detail in CORTEX_AI_FUNCTIONS_USAGE_HISTORY.

Can a resource monitor cap Cortex spend? No. Snowflake's documentation says resource monitors work for warehouses only and cannot track spending on serverless features and AI services. Use a budget instead, and add the drift alert above for earlier warning.

Which view should I use for per-query Cortex attribution? Use CORTEX_AI_FUNCTIONS_USAGE_HISTORY. It carries QUERY_ID, USER_ID, ROLE_NAMES, QUERY_TAG and CREDITS, and join it to QUERY_HISTORY on QUERY_ID for SQL text and warehouse. The older function-level views are documented as no longer updated.

Do the AI credits include the warehouse that ran the query? No. The CREDITS column excludes warehouse credits, so the calling query's compute still appears in WAREHOUSE_METERING_HISTORY. Count both when you cost a Cortex workload.

How fresh is the data? METERING_HISTORY can lag by up to 180 minutes, and cloud services credits by up to 6 hours, according to Snowflake's docs. Alert on completed days rather than the current one.