What you will be able to do
- Pick the ACCOUNT_USAGE view that answers a given Cortex cost question
- Build an hourly alert that emails when monthly AI function credits pass a threshold
- Explain how per-user limits and usage quotas cut off AI function access
- Attach a tag-based resource budget with threshold actions to a Cortex Agent
1.Which usage view answers which Cortex cost question
Each Cortex feature writes its own usage history in SNOWFLAKE.ACCOUNT_USAGE, at its own grain. Choosing the right view comes down to the unit the feature bills on: tokens for functions and REST calls, messages for Analyst, embedding and serving credits for Search, and PTUs for reserved capacity. At account level, METERING_DAILY_HISTORY and METERING_HISTORY show the total. Filter SERVICE_TYPE to AI_SERVICES for Cortex, or to SNOWPARK_CONTAINER_SERVICES for compute pools.
SELECT *
FROM SNOWFLAKE.ACCOUNT_USAGE.METERING_DAILY_HISTORY
WHERE SERVICE_TYPE='AI_SERVICES';| View | Grain | Answers |
|---|---|---|
| CORTEX_AISQL_USAGE_HISTORY | Hourly row per function, model, query and warehouse | Which AI functions and models a user or query is spending on |
| CORTEX_FUNCTIONS_QUERY_USAGE_HISTORY | Per query, one row per model used | Which queries consume the most credits and tokens |
| CORTEX_REST_API_USAGE_HISTORY | Per REST request, with TOKENS and TOKENS_GRANULAR (input vs output) | What REST API calls cost by model and user |
| CORTEX_ANALYST_USAGE_HISTORY | Hourly, with REQUEST_COUNT, CREDITS and USERNAME | Analyst messages and credits, so cost per request |
| CORTEX_SEARCH_DAILY_USAGE_HISTORY | Daily per service, split by consumption type | EMBED_TEXT token credits versus serving credits for each search service |
| CORTEX_SEARCH_SERVING_USAGE_HISTORY | Hourly per service | Serving credits at finer time grain |
| CORTEX_PROVISIONED_THROUGHPUT_USAGE_HISTORY | Per billing interval, with PTU_COUNT, PTU_CREDITS and term dates | Reserved-capacity charges |
| SNOWPARK_CONTAINER_SERVICES_HISTORY | Hourly | Compute pool credits only |
For a search service, CORTEX_SEARCH_DAILY_USAGE_HISTORY is the view that separates the always-on serving charge from the embedding charge incurred at refresh. The Analyst view counts messages and the REST view counts tokens per request, so neither has a Search breakdown. Warehouse refresh credits are not yet in the Search view, which is one more reason to give a new service a dedicated warehouse.
The AISQL view records usage when a query completes. A query that runs from 05:30 to 08:30 lands in the 08:00 hour, so a long batch shows up as one late spike. For coverage that includes AI_PARSE_DOCUMENT, use CORTEX_AI_FUNCTIONS_USAGE_HISTORY, the view the alert examples below query. It lags execution by at most five minutes.
Provisioned Throughput is reserved capacity, and its charges have their own view. CORTEX_PROVISIONED_THROUGHPUT_USAGE_HISTORY reports PTU_COUNT and PTU_CREDITS per interval between TERM_START_DATE and TERM_END_DATE, and it has no token column. If an AI bill has a credit line that no token count in the function or REST views explains, check this view.
Checkpoint 1 of 7· Match them up
Match each Account Usage view to the cost question it answers
Tap a term, then the definition that fits it.
Each view records usage in the unit and at the grain of its own feature. Only the daily Search view splits embedding cost from the standing serving cost. The serving view gives serving credits alone, by the hour. The functions query view ranks queries by credits and tokens. The SPCS view covers compute pools only.
“CORTEX_SEARCH_DAILY_USAGE_HISTORY view contains daily totals for EMBED_TEXT tokens compute and serving credit compute usage per service.”Source: docs.snowflake.com
Checkpoint 2 of 7· Fill the gap
Which SERVICE_TYPE value makes this query return the account's daily credits for Cortex AI services?
SELECT *
FROM SNOWFLAKE.ACCOUNT_USAGE.METERING_DAILY_HISTORY
WHERE SERVICE_TYPE=' ? ';At account level, Cortex spend appears in METERING_DAILY_HISTORY under SERVICE_TYPE AI_SERVICES. SNOWPARK_CONTAINER_SERVICES returns compute pool credits instead, and the other two values are not the service type the lesson gives for Cortex.
Source: docs.snowflake.comCheckpoint 3 of 7· Exam question
A cost analyst wants to see, for the last 30 days, how much a Cortex Search service is spending on maintaining its always-on index versus what it spent generating embeddings during data refreshes. Which view provides this breakdown by consumption type?
Correct answer: A — CORTEX_SEARCH_DAILY_USAGE_HISTORY
- A. This view reports daily Cortex Search credits broken out by consumption type, distinguishing serving (index maintenance) charges from embedding charges incurred during refreshes.
- B. This view reports hourly credit consumption for Cortex Analyst text-to-SQL requests, not Cortex Search serving or embedding costs.
- C. This view logs REST API inference request usage for Cortex functions invoked over HTTP, not the serving-versus-embedding split for a search service.
- D. This general-purpose view records executed SQL statements and does not separate Cortex Search's serving and embedding credit consumption.
2.Alerting on monthly AI function spend
A Snowflake alert can watch a usage view on a schedule and act when spend passes a line. The pattern has four parts. An email notification integration lists the allowed recipients. A state table records which months have already triggered. A stored procedure checks the state table, sums the month's credits and calls SYSTEM$SEND_EMAIL. The alert itself runs hourly and calls the procedure once the threshold is crossed. The role that owns all of this needs IMPORTED PRIVILEGES on the SNOWFLAKE database, CREATE INTEGRATION and EXECUTE ALERT.
CREATE OR REPLACE ALERT ai_functions_monthly_spend_alert
WAREHOUSE = <your_warehouse>
SCHEDULE = 'USING CRON 0 * * * * UTC' -- Runs every hour
IF (EXISTS (
SELECT 1
FROM SNOWFLAKE.ACCOUNT_USAGE.CORTEX_AI_FUNCTIONS_USAGE_HISTORY
WHERE START_TIME >= DATE_TRUNC('month', CURRENT_TIMESTAMP())
HAVING SUM(CREDITS) > 1000 -- adjust the limit accordingly
))
THEN
CALL SEND_MONTHLY_SPEND_ALERT(1000); -- please adjust the limit accordinglyEmail delivery fails on one setup detail more often than any other. Every recipient must appear in the integration's ALLOWED_RECIPIENTS and be passed as to_email in the procedure. Each must also be the verified EMAIL of a Snowflake user in the account. If any one of the three is out of sync, the call fails with a not-allowed error. Alerts are created suspended, so the alert does nothing until you run ALTER ALERT ... RESUME.
Checkpoint 4 of 7· Check yourself
An admin's monthly spend alert fires and the procedure calls SYSTEM$SEND_EMAIL. The call fails with an error saying the recipients are not allowed. The address is listed in the integration's ALLOWED_RECIPIENTS and is passed as to_email in the procedure. What is the most likely cause?
Each recipient must meet all three conditions: listed in ALLOWED_RECIPIENTS, passed as to_email, and set as the verified EMAIL of a Snowflake user in the account. Only the third condition is missing here. A suspended alert or a missing EXECUTE ALERT privilege would stop the procedure from running at all, so it would never reach a not-allowed email error.
“Set as the EMAIL field on a Snowflake user in this account, with the verification email confirmed.”Source: docs.snowflake.com
Sources7
3.Per-user spending limits and usage quotas
A per-user limit only works if the role you revoke is the user's only route to Cortex. By default SNOWFLAKE.CORTEX_USER is granted to PUBLIC, so every user can call AI functions regardless of what you revoke elsewhere. The documented pattern first revokes CORTEX_USER from PUBLIC and grants it through a custom AI_FUNCTIONS_USER_ROLE. A table then holds each user's monthly budget. An hourly task compares usage against that budget and removes the role from anyone over it, and a monthly task restores the role when the new month starts.
When every user should get the same credit limit, per-user quotas give you that directly, and they can optionally block users who reach the limit on Cortex Agents and other AI domains. A custom budget table is the better choice when limits vary by person, for example a larger allowance for a data science lead than for occasional analysts.
Checkpoint 5 of 7· Check yourself
Three weeks after rollout, the hourly task has removed AI_FUNCTIONS_USER_ROLE from an analyst who went over budget. The analyst's AI_COMPLETE queries still succeed. What setup step was missed?
By default, CORTEX_USER is granted to PUBLIC, so every user can call AI functions whatever you revoke elsewhere. Removing the custom role only cuts off access if CORTEX_USER was first revoked from PUBLIC and granted only through AI_FUNCTIONS_USER_ROLE.
“By default, all users have access to AI Functions (and other Snowflake Cortex features) because the SNOWFLAKE.CORTEX_USER database role is granted to the PUBLIC role.”Source: docs.snowflake.com
Checkpoint 6 of 7· Check yourself
Your FinOps team wants every user to get the same monthly credit limit. Users who reach it should also be blocked from Cortex Agents and other AI domains. Which mechanism fits this requirement most directly?
Per-user quotas give every user the same credit limit directly, and they can optionally block users on Cortex Agents and other AI domains. A custom budget table is for limits that differ from person to person. A resource budget caps spend for one agent object, not for each user. An alert only sends a notification.
“same per-user credit limits for each user, and optionally block users who reach a limit on Cortex Agents and other AI domains, use per-user quotas.”Source: docs.snowflake.com
4.Tag-based resource budgets for Cortex Agents
A resource budget caps what one Cortex Agent object spends in total, which its orchestration token limit cannot do. It uses tag-based cost attribution. You create a tag, set it on the agent, create a budget with a monthly credit limit, and point the budget at the tag. The same tags give chargeback: tag each business unit's agents with a different cost-center value and their credits can be attributed separately within one account.
ALTER AGENT IF EXISTS my_agent SET TAG cost_mgmt_db.tags.cost_center = 'org-level';CALL budgets_db.budgets_schema.my_budget!SET_RESOURCE_TAGS( [ [(SELECT SYSTEM$REFERENCE('TAG', 'cost_mgmt_db.tags.cost_center', 'SESSION', 'applybudget')), 'org-level'] ], 'UNION');Thresholds turn a budget into a control. Each threshold is a percentage of the monthly limit and runs a stored procedure, for example an alert at 80% and a role revocation at 100%. The procedures need USAGE granted to APPLICATION SNOWFLAKE. Thresholds can go past 100%, up to 500%. That lets an admin reinstate power users during a peak period and put a hard stop at 200%. A cycle-start action restores access when the month resets. Triggers can also fire on PROJECTED spend instead of ACTUAL.
Checkpoint 7 of 7· Fill the gap
You've already tagged my_agent with cost_center = 'org-level' and created my_budget. Now the budget has to track that agent's credits. Complete the call that links the tag to the budget.
CALL budgets_db.budgets_schema.my_budget! ? ( [ [(SELECT SYSTEM$REFERENCE('TAG', 'cost_mgmt_db.tags.cost_center', 'SESSION', 'applybudget')), 'org-level'] ], 'UNION');Resource budgets use tag-based cost attribution. SET_RESOURCE_TAGS points the budget at the tag value, so the agent's credits count against the budget. The other methods set the monthly limit, add a threshold action or set a cycle-start action, and none of them links a tag to the budget.
Source: docs.snowflake.comSources8
Practise it for real
Set up an hourly email alert that fires once per month when AI function credits pass a threshold
1.As ACCOUNTADMIN, grant your role IMPORTED PRIVILEGES on database SNOWFLAKE, CREATE INTEGRATION, EXECUTE ALERT, warehouse USAGE, and CREATE TABLE and CREATE PROCEDURE on a schema, then switch to that role.
Why: The objects must be owned by this role, and the role must be able to read ACCOUNT_USAGE.
You should see: USE ROLE succeeds and SELECT on CORTEX_AI_FUNCTIONS_USAGE_HISTORY returns rows.
2.Create the EMAIL notification integration ai_cost_alerts with your own verified address in ALLOWED_RECIPIENTS.
Why: SYSTEM$SEND_EMAIL delivers only to allowed, verified user addresses.
You should see: The integration shows as enabled.
3.Create the AI_FUNCTIONS_ALERT_STATE table and the SEND_MONTHLY_SPEND_ALERT procedure, replacing admin@company.com with your address.
Why: The state table stops duplicate emails within a month.
You should see: CALL SEND_MONTHLY_SPEND_ALERT(1000000) returns 'Threshold not exceeded'.
4.Create the alert with the threshold set to 0, then run ALTER ALERT ai_functions_monthly_spend_alert RESUME.
Why: A zero threshold fires right away, which proves the email path works.
You should see: Within the hour you receive an email, and INFORMATION_SCHEMA.ALERT_HISTORY shows a triggered run.
5.Delete this month's monthly_spend row from AI_FUNCTIONS_ALERT_STATE and recreate the alert with your real threshold.
Why: Otherwise the test row stops the alert from firing again this month.
You should see: SELECT on the state table returns no row for the current month.
Stuck? Get a nudge
If the email call fails with 'recipients ... are not allowed', check that the address is in ALLOWED_RECIPIENTS, used in the procedure, and verified on a Snowflake user.
Sources
(8)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://docs.snowflake.com/en/user-guide/snowflake-cortex/cortex-search/cortex-search-costsOfficial docs
“CORTEX_SEARCH_DAILY_USAGE_HISTORY view contains daily totals for EMBED_TEXT tokens compute and serving credit compute usage per service.”
↩︎ Which usage view answers which Cortex cost question“CORTEX_SEARCH_SERVING_USAGE_HISTORY view includes hourly serving credits per service.”
↩︎ Which usage view answers which Cortex cost question - 2.
“Each row in the view represents the usage for a specific combination of function, model, query, and warehouse.”
↩︎ Which usage view answers which Cortex cost question“Use CORTEX_AI_FUNCTIONS_USAGE_HISTORY to view all functions including AI_PARSE_DOCUMENT.”
↩︎ Which usage view answers which Cortex cost question - 3.https://docs.snowflake.com/en/sql-reference/account-usage/cortex_rest_api_usage_historyOfficial docs
“The information in the view includes the number of tokens processed and credits consumed for each REST API request.”
↩︎ Which usage view answers which Cortex cost question - 4.https://docs.snowflake.com/en/sql-reference/account-usage/cortex_provisioned_throughput_usage_historyOfficial docs
“PTU_CREDITS | NUMBER(38,9) | Number of credits billed during this interval.”
↩︎ Which usage view answers which Cortex cost question - 5.https://docs.snowflake.com/en/developer-guide/snowpark-container-services/accounts-orgs-usage-viewsOfficial docs
“In the METERING_HISTORY view, query for rows in which the service_type column contains the value SNOWPARK_CONTAINER_SERVICES.”
↩︎ Which usage view answers which Cortex cost question - 6.
“The query usage history is grouped by the models used in the query.”
↩︎ Which usage view answers which Cortex cost question - 7.
“The view has a maximum latency of five minutes”
↩︎ Which usage view answers which Cortex cost question“Listed in the integration’s ALLOWED_RECIPIENTS.”
↩︎ Alerting on monthly AI function spend“Now create a stored procedure to check if an alert was already sent this month, record the alert state, and send the email notification.”
↩︎ Alerting on monthly AI function spend“When a user exceeds their budget for the month, an hourly task revokes their access to AI Functions by removing AI_FUNCTIONS_USER_ROLE.”
↩︎ Per-user spending limits and usage quotas“A monthly task restores the role at the beginning of the next month.”
↩︎ Per-user spending limits and usage quotas“because the SNOWFLAKE.CORTEX_USER database role is granted to the PUBLIC role.”
↩︎ Exam trap 1“Set as the EMAIL field on a Snowflake user in this account, with the verification email confirmed.”
↩︎ Checkpoint“By default, all users have access to AI Functions (and other Snowflake Cortex features) because the SNOWFLAKE.CORTEX_USER database role is granted to the PUBLIC role.”
↩︎ Checkpoint - 8.https://docs.snowflake.com/en/user-guide/snowflake-cortex/cortex-agents-resource-budgetsOfficial docs
“set the same per-user credit limits for each user, and optionally block users who reach a limit on Cortex Agents and other AI domains”
↩︎ Per-user spending limits and usage quotas“You create a tag, apply it to a Cortex Agent object, and then associate that tag with a budget.”
↩︎ Tag-based resource budgets for Cortex Agents“You can configure thresholds beyond 100%, up to 500%, to handle these exception scenarios.”
↩︎ Tag-based resource budgets for Cortex Agents“it might take up to eight hours with standard budget (or two hours with latency optimized option) for the budget to be enforced.”
↩︎ Exam trap 2“same per-user credit limits for each user, and optionally block users who reach a limit on Cortex Agents and other AI domains, use per-user quotas.”
↩︎ Checkpoint