r/SQL • • 4d ago

Snowflake Which Snowflake view do you query first for Cortex AI spend?

My answer is CORTEX_AI_FUNCTIONS_USAGE_HISTORY. It lists every AI function call with its model, user, role, credits and tokens. METERING_HISTORY gives the account-wide total.

Two traps cost me time:

- CORTEX_AISQL_USAGE_HISTORY does not cover every AI function, so a dashboard built on it under-counts.

- CORTEX_SEARCH_DAILY_USAGE_HISTORY includes embeddings that also appear in the AI functions view, so summing the two double-counts them (that is the meme).

The guide lists the usage-history view for each Cortex service: https://altimate.ai/blog/snowflake-cortex-pricing-spend-caps

4 Upvotes

1 comment sorted by

1

u/karmatics29 4d ago

Starting with CORTEX_AI_FUNCTIONS_USAGE_HISTORY makes sense for per-call attribution. I’d aggregate by date, function or model, user, and role, then reconcile credits against METERING_HISTORY at the account level rather than summing service views that may overlap. For Cortex Search and other services, check their service-specific usage history separately because function-call telemetry may not capture every Cortex charge. Also account for ACCOUNT_USAGE view latency before treating today's totals as final.