CertSafari
    Snowflake SnowPro Specialty: Gen AI (GES-C02)· Lessons

    Domain 3 · Lesson 10/15

    Tracking and capping Cortex spend with usage views, alerts and budgets

    Manage, monitor, and optimize Snowflake Cortex costs.

    11 min read
    7.25% of exam
    8 sources
    Published 21 Oct 2026
    Docs as of 4 Oct 2026

    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.

    Daily credits for all AI services in the accountsql
    SELECT *
      FROM SNOWFLAKE.ACCOUNT_USAGE.METERING_DAILY_HISTORY
      WHERE SERVICE_TYPE='AI_SERVICES';
    Cortex usage views and the question each one answers
    ViewGrainAnswers
    CORTEX_AISQL_USAGE_HISTORYHourly row per function, model, query and warehouseWhich AI functions and models a user or query is spending on
    CORTEX_FUNCTIONS_QUERY_USAGE_HISTORYPer query, one row per model usedWhich queries consume the most credits and tokens
    CORTEX_REST_API_USAGE_HISTORYPer REST request, with TOKENS and TOKENS_GRANULAR (input vs output)What REST API calls cost by model and user
    CORTEX_ANALYST_USAGE_HISTORYHourly, with REQUEST_COUNT, CREDITS and USERNAMEAnalyst messages and credits, so cost per request
    CORTEX_SEARCH_DAILY_USAGE_HISTORYDaily per service, split by consumption typeEMBED_TEXT token credits versus serving credits for each search service
    CORTEX_SEARCH_SERVING_USAGE_HISTORYHourly per serviceServing credits at finer time grain
    CORTEX_PROVISIONED_THROUGHPUT_USAGE_HISTORYPer billing interval, with PTU_COUNT, PTU_CREDITS and term datesReserved-capacity charges
    SNOWPARK_CONTAINER_SERVICES_HISTORYHourlyCompute 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.

    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=' ? ';

    Checkpoint 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?

    Sources1234567

    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.

    Hourly alert on monthly AI function credits (threshold appears twice)sql
    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 accordingly

    Email 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?

    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?

    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?

    Sources78

    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.

    Apply the cost-center tag to the agentsql
    ALTER AGENT IF EXISTS my_agent SET TAG cost_mgmt_db.tags.cost_center = 'org-level';
    Associate the tag with the budgetsql
    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');

    Sources8

    Practise it for real

    Set up an hourly email alert that fires once per month when AI function credits pass a threshold

    1. 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. 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. 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. 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. 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. 1.
      “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. 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. 3.
      “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. 5.
      “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
    5. 6.
      “The query usage history is grouped by the models used in the query.”
      ↩︎ Which usage view answers which Cortex cost question
    6. 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
    7. 8.
      “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

    Ready to test yourself?

    Practise the 26 questions on this subdomain.

    Spotted a mistake, or was something unclear? Tell us.